diff --git a/clang/lib/Basic/Targets/BPF.h b/clang/lib/Basic/Targets/BPF.h index 403431eae7c76..fd481b413250f 100644 --- a/clang/lib/Basic/Targets/BPF.h +++ b/clang/lib/Basic/Targets/BPF.h @@ -22,6 +22,7 @@ namespace clang { namespace targets { class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo { + bool HasSolanaFeature = false; static const Builtin::Info BuiltinInfo[]; public: @@ -34,21 +35,20 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo { IntMaxType = SignedLong; Int64Type = SignedLong; RegParmMax = 5; - auto isSolana = false; for (auto& it : Opts.FeaturesAsWritten) { if (it == "+solana") { - isSolana = true; + HasSolanaFeature = true; break; } } if (Triple.getArch() == llvm::Triple::bpfeb) { - if (isSolana) { + if (HasSolanaFeature) { resetDataLayout("E-m:e-p:64:64-i64:64-n32:64-S128"); } else { resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128"); } } else { - if (isSolana) { + if (HasSolanaFeature) { resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128"); } else { resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"); @@ -112,6 +112,8 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo { StringRef CPUName(Name); return isValidCPUName(CPUName); } + + bool hasExtIntType() const override { return HasSolanaFeature; } }; } // namespace targets } // namespace clang diff --git a/clang/test/CodeGen/ext-int-cc.c b/clang/test/CodeGen/ext-int-cc.c index 02e2f3aef2747..7a331a2f3968d 100644 --- a/clang/test/CodeGen/ext-int-cc.c +++ b/clang/test/CodeGen/ext-int-cc.c @@ -28,6 +28,7 @@ // RUN: %clang_cc1 -triple arm64_32-apple-ios -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64 // RUN: %clang_cc1 -triple arm64_32-apple-ios -target-abi darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64DARWIN // RUN: %clang_cc1 -triple arm -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=ARM +// RUN: %clang_cc1 -triple bpf -target-feature +solana -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=BPF // Make sure 128 and 64 bit versions are passed like integers, and that >128 // is passed indirectly. @@ -59,6 +60,7 @@ void ParamPassing(_ExtInt(129) a, _ExtInt(128) b, _ExtInt(64) c) {} // AARCH64: define void @ParamPassing(i129* byval(i129) align 8 %{{.+}}, i128 %{{.+}}, i64 %{{.+}}) // AARCH64DARWIN: define void @ParamPassing(i129* byval(i129) align 8 %{{.+}}, i128 %{{.+}}, i64 %{{.+}}) // ARM: define arm_aapcscc void @ParamPassing(i129* byval(i129) align 8 %{{.+}}, i128* byval(i128) align 8 %{{.+}}, i64 %{{.+}}) +// BPF: define void @ParamPassing(i129* byval(i129) align 8 %{{.+}}, i128 %{{.+}}, i64 %{{.+}}) void ParamPassing2(_ExtInt(129) a, _ExtInt(127) b, _ExtInt(63) c) {} // LIN64: define void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i64 %{{.+}}, i64 %{{.+}}, i64 %{{.+}}) @@ -88,6 +90,7 @@ void ParamPassing2(_ExtInt(129) a, _ExtInt(127) b, _ExtInt(63) c) {} // AARCH64: define void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i127 %{{.+}}, i63 %{{.+}}) // AARCH64DARWIN: define void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i127 %{{.+}}, i63 %{{.+}}) // ARM: define arm_aapcscc void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i127* byval(i127) align 8 %{{.+}}, i63 %{{.+}}) +// BPF: define void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i127 %{{.+}}, i63 %{{.+}}) // Make sure we follow the signext rules for promotable integer types. void ParamPassing3(_ExtInt(15) a, _ExtInt(31) b) {} @@ -118,6 +121,7 @@ void ParamPassing3(_ExtInt(15) a, _ExtInt(31) b) {} // AARCH64: define void @ParamPassing3(i15 %{{.+}}, i31 %{{.+}}) // AARCH64DARWIN: define void @ParamPassing3(i15 signext %{{.+}}, i31 signext %{{.+}}) // ARM: define arm_aapcscc void @ParamPassing3(i15 signext %{{.+}}, i31 signext %{{.+}}) +// BPF: define void @ParamPassing3(i15 signext %{{.+}}, i31 signext %{{.+}}) _ExtInt(63) ReturnPassing(){} // LIN64: define i64 @ReturnPassing( @@ -147,6 +151,7 @@ _ExtInt(63) ReturnPassing(){} // AARCH64: define i63 @ReturnPassing( // AARCH64DARWIN: define i63 @ReturnPassing( // ARM: define arm_aapcscc i63 @ReturnPassing( +// BPF: define i63 @ReturnPassing( _ExtInt(64) ReturnPassing2(){} // LIN64: define i64 @ReturnPassing2( @@ -176,6 +181,7 @@ _ExtInt(64) ReturnPassing2(){} // AARCH64: define i64 @ReturnPassing2( // AARCH64DARWIN: define i64 @ReturnPassing2( // ARM: define arm_aapcscc i64 @ReturnPassing2( +// BPF: define i64 @ReturnPassing2( _ExtInt(127) ReturnPassing3(){} // LIN64: define { i64, i64 } @ReturnPassing3( @@ -207,6 +213,7 @@ _ExtInt(127) ReturnPassing3(){} // AARCH64: define i127 @ReturnPassing3( // AARCH64DARWIN: define i127 @ReturnPassing3( // ARM: define arm_aapcscc void @ReturnPassing3(i127* noalias sret +// BPF: define i127 @ReturnPassing3( _ExtInt(128) ReturnPassing4(){} // LIN64: define { i64, i64 } @ReturnPassing4( @@ -236,6 +243,7 @@ _ExtInt(128) ReturnPassing4(){} // AARCH64: define i128 @ReturnPassing4( // AARCH64DARWIN: define i128 @ReturnPassing4( // ARM: define arm_aapcscc void @ReturnPassing4(i128* noalias sret +// BPF: define i128 @ReturnPassing4( _ExtInt(129) ReturnPassing5(){} // LIN64: define void @ReturnPassing5(i129* noalias sret @@ -265,6 +273,7 @@ _ExtInt(129) ReturnPassing5(){} // AARCH64: define void @ReturnPassing5(i129* noalias sret // AARCH64DARWIN: define void @ReturnPassing5(i129* noalias sret // ARM: define arm_aapcscc void @ReturnPassing5(i129* noalias sret +// BPF: define void @ReturnPassing5(i129* noalias sret // SparcV9 is odd in that it has a return-size limit of 256, not 128 or 64 // like other platforms, so test to make sure this behavior will still work. diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 9ceccef867797..73ea463e2f374 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -1110,13 +1110,6 @@ Optional getReproduceFile(const opt::InputArgList &args) { void LinkerDriver::link(ArrayRef argsArr) { ScopedTimer rootTimer(Timer::root()); - // Needed for LTO. - InitializeAllTargetInfos(); - InitializeAllTargets(); - InitializeAllTargetMCs(); - InitializeAllAsmParsers(); - InitializeAllAsmPrinters(); - // If the first command line argument is "/lib", link.exe acts like lib.exe. // We call our own implementation of lib.exe that understands bitcode files. if (argsArr.size() > 1 && StringRef(argsArr[1]).equals_lower("/lib")) { diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 4637a3b306daf..d8d517eb4eb96 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -281,17 +281,6 @@ void LinkerDriver::addLibrary(StringRef name) { error("unable to find library -l" + name); } -// This function is called on startup. We need this for LTO since -// LTO calls LLVM functions to compile bitcode files to native code. -// Technically this can be delayed until we read bitcode files, but -// we don't bother to do lazily because the initialization is fast. -static void initLLVM() { - InitializeAllTargets(); - InitializeAllTargetMCs(); - InitializeAllAsmPrinters(); - InitializeAllAsmParsers(); -} - // Some command line options or some combinations of them are not allowed. // This function checks for such errors. static void checkOptions() { @@ -518,7 +507,6 @@ void LinkerDriver::main(ArrayRef argsArr) { { llvm::TimeTraceScope timeScope("ExecuteLinker"); - initLLVM(); createFiles(args); if (errorCount()) return; diff --git a/lld/tools/lld/lld.cpp b/lld/tools/lld/lld.cpp index 8a8f8d04bbda6..2dbe66e4ab7e1 100644 --- a/lld/tools/lld/lld.cpp +++ b/lld/tools/lld/lld.cpp @@ -37,6 +37,7 @@ #include "llvm/Support/InitLLVM.h" #include "llvm/Support/Path.h" #include "llvm/Support/PluginLoader.h" +#include "llvm/Support/TargetSelect.h" #include using namespace lld; @@ -136,10 +137,22 @@ static Flavor parseFlavor(std::vector &v) { // and we use it to detect whether we are running tests or not. static bool canExitEarly() { return StringRef(getenv("LLD_IN_TEST")) != "1"; } +// This function is called on startup. We need this for LTO since +// LTO calls LLVM functions to compile bitcode files to native code. +// Technically this can be delayed until we read bitcode files, but +// we don't bother to do lazily because the initialization is fast. +static void initLLVM() { + InitializeAllTargets(); + InitializeAllTargetMCs(); + InitializeAllAsmPrinters(); + InitializeAllAsmParsers(); +} + /// Universal linker main(). This linker emulates the gnu, darwin, or /// windows linker based on the argv[0] or -flavor option. int main(int argc, const char **argv) { InitLLVM x(argc, argv); + initLLVM(); std::vector args(argv, argv + argc); switch (parseFlavor(args)) { diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index d0805bf3b3036..d9458a6ea42cd 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -53,17 +53,6 @@ enum { #undef OPTION }; -// This function is called on startup. We need this for LTO since -// LTO calls LLVM functions to compile bitcode files to native code. -// Technically this can be delayed until we read bitcode files, but -// we don't bother to do lazily because the initialization is fast. -static void initLLVM() { - InitializeAllTargets(); - InitializeAllTargetMCs(); - InitializeAllAsmPrinters(); - InitializeAllAsmParsers(); -} - class LinkerDriver { public: void link(ArrayRef argsArr); @@ -94,7 +83,6 @@ bool link(ArrayRef args, bool canExitEarly, raw_ostream &stdoutOS, config = make(); symtab = make(); - initLLVM(); LinkerDriver().link(args); // Exit immediately if we don't need to return to the caller. @@ -568,7 +556,6 @@ static void createSyntheticSymbols() { make(nullSignature, "__wasm_apply_relocs")); } - if (config->isPic) { WasmSym::stackPointer = createUndefinedGlobal( "__stack_pointer",