diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:28 +0000 |
commit | 94a0819fe3a0d679c3042a77bfe6a2afc505daea (patch) | |
tree | 2b827afe6a05f3538db3f7803a88c4587fe85648 /compiler/rustc_llvm | |
parent | Adding upstream version 1.64.0+dfsg1. (diff) | |
download | rustc-94a0819fe3a0d679c3042a77bfe6a2afc505daea.tar.xz rustc-94a0819fe3a0d679c3042a77bfe6a2afc505daea.zip |
Adding upstream version 1.66.0+dfsg1.upstream/1.66.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_llvm')
-rw-r--r-- | compiler/rustc_llvm/build.rs | 11 | ||||
-rw-r--r-- | compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp | 13 | ||||
-rw-r--r-- | compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp | 11 | ||||
-rw-r--r-- | compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 304 | ||||
-rw-r--r-- | compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | 114 | ||||
-rw-r--r-- | compiler/rustc_llvm/src/lib.rs | 2 |
6 files changed, 89 insertions, 366 deletions
diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 62ef5804d..28e092c1e 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -242,6 +242,13 @@ fn main() { println!("cargo:rustc-link-lib=uuid"); } else if target.contains("netbsd") || target.contains("haiku") || target.contains("darwin") { println!("cargo:rustc-link-lib=z"); + } else if target.starts_with("arm") + || target.starts_with("mips-") + || target.starts_with("mipsel-") + || target.starts_with("powerpc-") + { + // 32-bit targets need to link libatomic. + println!("cargo:rustc-link-lib=atomic"); } cmd.args(&components); @@ -335,10 +342,10 @@ fn main() { }; // RISC-V GCC erroneously requires libatomic for sub-word - // atomic operations. FreeBSD uses Clang as its system + // atomic operations. Some BSD uses Clang as its system // compiler and provides no libatomic in its base system so // does not want this. - if !target.contains("freebsd") && target.starts_with("riscv") { + if target.starts_with("riscv") && !target.contains("freebsd") && !target.contains("openbsd") { println!("cargo:rustc-link-lib=atomic"); } diff --git a/compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp index 97541e615..448a1f62f 100644 --- a/compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp @@ -154,19 +154,6 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef Child, size_t *Size) { return Name.data(); } -extern "C" const char *LLVMRustArchiveChildData(LLVMRustArchiveChildRef Child, - size_t *Size) { - StringRef Buf; - Expected<StringRef> BufOrErr = Child->getBuffer(); - if (!BufOrErr) { - LLVMRustSetLastError(toString(BufOrErr.takeError()).c_str()); - return nullptr; - } - Buf = BufOrErr.get(); - *Size = Buf.size(); - return Buf.data(); -} - extern "C" LLVMRustArchiveMemberRef LLVMRustArchiveMemberNew(char *Filename, char *Name, LLVMRustArchiveChildRef Child) { diff --git a/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp index 154f554d6..7da6ab713 100644 --- a/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp @@ -24,17 +24,10 @@ extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer( const char* const Filenames[], size_t FilenamesLen, RustStringRef BufferOut) { -#if LLVM_VERSION_GE(13,0) SmallVector<std::string,32> FilenameRefs; for (size_t i = 0; i < FilenamesLen; i++) { FilenameRefs.push_back(std::string(Filenames[i])); } -#else - SmallVector<StringRef,32> FilenameRefs; - for (size_t i = 0; i < FilenamesLen; i++) { - FilenameRefs.push_back(StringRef(Filenames[i])); - } -#endif auto FilenamesWriter = coverage::CoverageFilenamesSectionWriter( makeArrayRef(FilenameRefs)); RawRustStringOstream OS(BufferOut); @@ -109,9 +102,5 @@ extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) { } extern "C" uint32_t LLVMRustCoverageMappingVersion() { -#if LLVM_VERSION_GE(13, 0) return coverage::CovMapVersion::Version6; -#else - return coverage::CovMapVersion::Version5; -#endif } diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 0a6bd4999..18d37d95a 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -31,10 +31,12 @@ #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/IPO/AlwaysInliner.h" #include "llvm/Transforms/IPO/FunctionImport.h" +#include "llvm/Transforms/IPO/Internalize.h" +#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" #include "llvm/Transforms/Utils/AddDiscriminators.h" #include "llvm/Transforms/Utils/FunctionImportUtils.h" #include "llvm/LTO/LTO.h" -#include "llvm/Bitcode/BitcodeWriterPass.h" +#include "llvm/Bitcode/BitcodeWriter.h" #include "llvm-c/Transforms/PassManagerBuilder.h" #include "llvm/Transforms/Instrumentation.h" @@ -67,7 +69,9 @@ extern "C" void LLVMInitializePasses() { initializeAnalysis(Registry); initializeTransformUtils(Registry); initializeInstCombine(Registry); +#if LLVM_VERSION_LT(16, 0) initializeInstrumentation(Registry); +#endif initializeTarget(Registry); } @@ -90,167 +94,6 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) { timeTraceProfilerCleanup(); } -extern "C" LLVMPassRef LLVMRustFindAndCreatePass(const char *PassName) { -#if LLVM_VERSION_LT(15, 0) - StringRef SR(PassName); - PassRegistry *PR = PassRegistry::getPassRegistry(); - - const PassInfo *PI = PR->getPassInfo(SR); - if (PI) { - return wrap(PI->createPass()); - } - return nullptr; -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" LLVMPassRef LLVMRustCreateAddressSanitizerFunctionPass(bool Recover) { -#if LLVM_VERSION_LT(15, 0) - const bool CompileKernel = false; - const bool UseAfterScope = true; - - return wrap(createAddressSanitizerFunctionPass(CompileKernel, Recover, UseAfterScope)); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" LLVMPassRef LLVMRustCreateModuleAddressSanitizerPass(bool Recover) { -#if LLVM_VERSION_LT(15, 0) - const bool CompileKernel = false; - - return wrap(createModuleAddressSanitizerLegacyPassPass(CompileKernel, Recover)); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" LLVMPassRef LLVMRustCreateMemorySanitizerPass(int TrackOrigins, bool Recover) { -#if LLVM_VERSION_LT(15, 0) - const bool CompileKernel = false; - - return wrap(createMemorySanitizerLegacyPassPass( - MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel})); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" LLVMPassRef LLVMRustCreateThreadSanitizerPass() { -#if LLVM_VERSION_LT(15, 0) - return wrap(createThreadSanitizerLegacyPassPass()); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" LLVMPassRef LLVMRustCreateHWAddressSanitizerPass(bool Recover) { -#if LLVM_VERSION_LT(15, 0) - const bool CompileKernel = false; - - return wrap(createHWAddressSanitizerLegacyPassPass(CompileKernel, Recover)); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" void LLVMRustAddPass(LLVMPassManagerRef PMR, LLVMPassRef RustPass) { -#if LLVM_VERSION_LT(15, 0) - assert(RustPass); - Pass *Pass = unwrap(RustPass); - PassManagerBase *PMB = unwrap(PMR); - PMB->add(Pass); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" LLVMPassManagerBuilderRef LLVMRustPassManagerBuilderCreate() { -#if LLVM_VERSION_LT(15, 0) - return LLVMPassManagerBuilderCreate(); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" void LLVMRustPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB) { -#if LLVM_VERSION_LT(15, 0) - LLVMPassManagerBuilderDispose(PMB); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" void LLVMRustPassManagerBuilderPopulateFunctionPassManager( - LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM) { -#if LLVM_VERSION_LT(15, 0) - LLVMPassManagerBuilderPopulateFunctionPassManager(PMB, PM); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" void LLVMRustPassManagerBuilderPopulateModulePassManager( - LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM) { -#if LLVM_VERSION_LT(15, 0) - LLVMPassManagerBuilderPopulateModulePassManager(PMB, PM); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" void LLVMRustPassManagerBuilderPopulateLTOPassManager( - LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM, bool Internalize, bool RunInliner) { -#if LLVM_VERSION_LT(15, 0) - LLVMPassManagerBuilderPopulateLTOPassManager(PMB, PM, Internalize, RunInliner); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" -void LLVMRustPassManagerBuilderPopulateThinLTOPassManager( - LLVMPassManagerBuilderRef PMBR, - LLVMPassManagerRef PMR -) { -#if LLVM_VERSION_LT(15, 0) - unwrap(PMBR)->populateThinLTOPassManager(*unwrap(PMR)); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" void LLVMRustPassManagerBuilderUseInlinerWithThreshold( - LLVMPassManagerBuilderRef PMB, unsigned Threshold) { -#if LLVM_VERSION_LT(15, 0) - LLVMPassManagerBuilderUseInlinerWithThreshold(PMB, Threshold); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -extern "C" -void LLVMRustAddLastExtensionPasses( - LLVMPassManagerBuilderRef PMBR, LLVMPassRef *Passes, size_t NumPasses) { -#if LLVM_VERSION_LT(15, 0) - auto AddExtensionPasses = [Passes, NumPasses]( - const PassManagerBuilder &Builder, PassManagerBase &PM) { - for (size_t I = 0; I < NumPasses; I++) { - PM.add(unwrap(Passes[I])); - } - }; - // Add the passes to both of the pre-finalization extension points, - // so they are run for optimized and non-optimized builds. - unwrap(PMBR)->addExtension(PassManagerBuilder::EP_OptimizerLast, - AddExtensionPasses); - unwrap(PMBR)->addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0, - AddExtensionPasses); -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - #ifdef LLVM_COMPONENT_X86 #define SUBTARGET_X86 SUBTARGET(X86) #else @@ -596,47 +439,6 @@ extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) { delete unwrap(TM); } -extern "C" void LLVMRustConfigurePassManagerBuilder( - LLVMPassManagerBuilderRef PMBR, LLVMRustCodeGenOptLevel OptLevel, - bool MergeFunctions, bool SLPVectorize, bool LoopVectorize, bool PrepareForThinLTO, - const char* PGOGenPath, const char* PGOUsePath, const char* PGOSampleUsePath, - int SizeLevel) { -#if LLVM_VERSION_LT(15, 0) - unwrap(PMBR)->MergeFunctions = MergeFunctions; - unwrap(PMBR)->SLPVectorize = SLPVectorize; - unwrap(PMBR)->OptLevel = fromRust(OptLevel); - unwrap(PMBR)->LoopVectorize = LoopVectorize; - unwrap(PMBR)->PrepareForThinLTO = PrepareForThinLTO; - unwrap(PMBR)->SizeLevel = SizeLevel; - unwrap(PMBR)->DisableUnrollLoops = SizeLevel != 0; - - if (PGOGenPath) { - assert(!PGOUsePath && !PGOSampleUsePath); - unwrap(PMBR)->EnablePGOInstrGen = true; - unwrap(PMBR)->PGOInstrGen = PGOGenPath; - } else if (PGOUsePath) { - assert(!PGOSampleUsePath); - unwrap(PMBR)->PGOInstrUse = PGOUsePath; - } else if (PGOSampleUsePath) { - unwrap(PMBR)->PGOSampleUse = PGOSampleUsePath; - } -#else - report_fatal_error("Legacy PM not supported with LLVM 15"); -#endif -} - -// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo` -// field of a PassManagerBuilder, we expose our own method of doing so. -extern "C" void LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMBR, - LLVMModuleRef M, - bool DisableSimplifyLibCalls) { - Triple TargetTriple(unwrap(M)->getTargetTriple()); - TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl(TargetTriple); - if (DisableSimplifyLibCalls) - TLI->disableAllFunctions(); - unwrap(PMBR)->LibraryInfo = TLI; -} - // Unfortunately, the LLVM C API doesn't provide a way to create the // TargetLibraryInfo pass, so we use this method to do so. extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMR, LLVMModuleRef M, @@ -648,27 +450,6 @@ extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMR, LLVMModuleRef M, unwrap(PMR)->add(new TargetLibraryInfoWrapperPass(TLII)); } -// Unfortunately, the LLVM C API doesn't provide an easy way of iterating over -// all the functions in a module, so we do that manually here. You'll find -// similar code in clang's BackendUtil.cpp file. -extern "C" void LLVMRustRunFunctionPassManager(LLVMPassManagerRef PMR, - LLVMModuleRef M) { - llvm::legacy::FunctionPassManager *P = - unwrap<llvm::legacy::FunctionPassManager>(PMR); - P->doInitialization(); - - // Upgrade all calls to old intrinsics first. - for (Module::iterator I = unwrap(M)->begin(), E = unwrap(M)->end(); I != E;) - UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove - - for (Module::iterator I = unwrap(M)->begin(), E = unwrap(M)->end(); I != E; - ++I) - if (!I->isDeclaration()) - P->run(*I); - - P->doFinalization(); -} - extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) { // Initializing the command-line options more than once is not allowed. So, // check if they've already been initialized. (This could happen if we're @@ -812,7 +593,7 @@ struct LLVMRustSanitizerOptions { }; extern "C" LLVMRustResult -LLVMRustOptimizeWithNewPassManager( +LLVMRustOptimize( LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef, LLVMRustPassBuilderOptLevel OptLevelRust, @@ -822,7 +603,8 @@ LLVMRustOptimizeWithNewPassManager( bool DisableSimplifyLibCalls, bool EmitLifetimeMarkers, LLVMRustSanitizerOptions *SanitizerOptions, const char *PGOGenPath, const char *PGOUsePath, - bool InstrumentCoverage, bool InstrumentGCOV, + bool InstrumentCoverage, const char *InstrProfileOutput, + bool InstrumentGCOV, const char *PGOSampleUsePath, bool DebugInfoForProfiling, void* LlvmSelfProfiler, LLVMRustSelfProfileBeforePassCallback BeforePassCallback, @@ -869,19 +651,11 @@ LLVMRustOptimizeWithNewPassManager( PGOOptions::NoCSAction, DebugInfoForProfiling); } -#if LLVM_VERSION_GE(13, 0) PassBuilder PB(TM, PTO, PGOOpt, &PIC); LoopAnalysisManager LAM; FunctionAnalysisManager FAM; CGSCCAnalysisManager CGAM; ModuleAnalysisManager MAM; -#else - PassBuilder PB(DebugPassManager, TM, PTO, PGOOpt, &PIC); - LoopAnalysisManager LAM(DebugPassManager); - FunctionAnalysisManager FAM(DebugPassManager); - CGSCCAnalysisManager CGAM(DebugPassManager); - ModuleAnalysisManager MAM(DebugPassManager); -#endif FAM.registerPass([&] { return PB.buildDefaultAAPipeline(); }); @@ -922,8 +696,11 @@ LLVMRustOptimizeWithNewPassManager( if (InstrumentCoverage) { PipelineStartEPCallbacks.push_back( - [](ModulePassManager &MPM, OptimizationLevel Level) { + [InstrProfileOutput](ModulePassManager &MPM, OptimizationLevel Level) { InstrProfOptions Options; + if (InstrProfileOutput) { + Options.InstrProfileOutput = InstrProfileOutput; + } MPM.addPass(InstrProfiling(Options, false)); } ); @@ -931,18 +708,28 @@ LLVMRustOptimizeWithNewPassManager( if (SanitizerOptions) { if (SanitizerOptions->SanitizeMemory) { +#if LLVM_VERSION_GE(14, 0) + MemorySanitizerOptions Options( + SanitizerOptions->SanitizeMemoryTrackOrigins, + SanitizerOptions->SanitizeMemoryRecover, + /*CompileKernel=*/false, + /*EagerChecks=*/true); +#else MemorySanitizerOptions Options( SanitizerOptions->SanitizeMemoryTrackOrigins, SanitizerOptions->SanitizeMemoryRecover, /*CompileKernel=*/false); +#endif OptimizerLastEPCallbacks.push_back( [Options](ModulePassManager &MPM, OptimizationLevel Level) { -#if LLVM_VERSION_GE(14, 0) +#if LLVM_VERSION_GE(14, 0) && LLVM_VERSION_LT(16, 0) MPM.addPass(ModuleMemorySanitizerPass(Options)); #else MPM.addPass(MemorySanitizerPass(Options)); #endif +#if LLVM_VERSION_LT(16, 0) MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options))); +#endif } ); } @@ -973,8 +760,12 @@ LLVMRustOptimizeWithNewPassManager( /*UseAfterScope=*/true, AsanDetectStackUseAfterReturnMode::Runtime, }; +#if LLVM_VERSION_LT(16, 0) MPM.addPass(ModuleAddressSanitizerPass(opts)); #else + MPM.addPass(AddressSanitizerPass(opts)); +#endif +#else MPM.addPass(ModuleAddressSanitizerPass( /*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover)); MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass( @@ -1015,11 +806,7 @@ LLVMRustOptimizeWithNewPassManager( } } -#if LLVM_VERSION_GE(13, 0) ModulePassManager MPM; -#else - ModulePassManager MPM(DebugPassManager); -#endif bool NeedThinLTOBufferPasses = UseThinLTOBuffers; if (!NoPrepopulatePasses) { // The pre-link pipelines don't support O0 and require using budilO0DefaultPipeline() instead. @@ -1227,15 +1014,8 @@ extern "C" void LLVMRustPrintPasses() { PR->enumerateWith(&Listener); } -extern "C" void LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMBR, - bool AddLifetimes) { - unwrap(PMBR)->Inliner = llvm::createAlwaysInlinerLegacyPass(AddLifetimes); -} - extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols, size_t Len) { - llvm::legacy::PassManager passes; - auto PreserveFunctions = [=](const GlobalValue &GV) { for (size_t I = 0; I < Len; I++) { if (GV.getName() == Symbols[I]) { @@ -1245,9 +1025,7 @@ extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols, return false; }; - passes.add(llvm::createInternalizePass(PreserveFunctions)); - - passes.run(*unwrap(M)); + internalizeModule(*unwrap(M), PreserveFunctions); } extern "C" void @@ -1268,7 +1046,7 @@ extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) { extern "C" void LLVMRustSetModuleCodeModel(LLVMModuleRef M, LLVMRustCodeModel Model) { auto CM = fromRust(Model); - if (!CM.hasValue()) + if (!CM) return; unwrap(M)->setCodeModel(*CM); } @@ -1434,17 +1212,13 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules, Ret->ResolvedODR[ModuleIdentifier][GUID] = NewLinkage; }; -#if LLVM_VERSION_GE(13,0) // Uses FromPrevailing visibility scheme which works for many binary // formats. We probably could and should use ELF visibility scheme for many of // our targets, however. lto::Config conf; thinLTOResolvePrevailingInIndex(conf, Ret->Index, isPrevailing, recordNewLinkage, Ret->GUIDPreservedSymbols); -#else - thinLTOResolvePrevailingInIndex(Ret->Index, isPrevailing, recordNewLinkage, - Ret->GUIDPreservedSymbols); -#endif + // Here we calculate an `ExportedGUIDs` set for use in the `isExported` // callback below. This callback below will dictate the linkage for all // summaries in the index, and we basically just only want to ensure that dead @@ -1599,13 +1373,23 @@ LLVMRustThinLTOBufferCreate(LLVMModuleRef M, bool is_thin) { { raw_string_ostream OS(Ret->data); { - legacy::PassManager PM; if (is_thin) { - PM.add(createWriteThinLTOBitcodePass(OS)); + PassBuilder PB; + LoopAnalysisManager LAM; + FunctionAnalysisManager FAM; + CGSCCAnalysisManager CGAM; + ModuleAnalysisManager MAM; + PB.registerModuleAnalyses(MAM); + PB.registerCGSCCAnalyses(CGAM); + PB.registerFunctionAnalyses(FAM); + PB.registerLoopAnalyses(LAM); + PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); + ModulePassManager MPM; + MPM.addPass(ThinLTOBitcodeWriterPass(OS, nullptr)); + MPM.run(*unwrap(M), MAM); } else { - PM.add(createBitcodeWriterPass(OS)); + WriteBitcodeToFile(*unwrap(M), OS); } - PM.run(*unwrap(M)); } } return Ret.release(); diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 5f5b5de79..6f36281af 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -12,7 +12,7 @@ #include "llvm/Object/COFFImportFile.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Pass.h" -#include "llvm/Bitcode/BitcodeWriterPass.h" +#include "llvm/Bitcode/BitcodeWriter.h" #include "llvm/Support/Signals.h" #include "llvm/ADT/Optional.h" @@ -406,51 +406,6 @@ extern "C" LLVMValueRef LLVMRustBuildAtomicStore(LLVMBuilderRef B, return wrap(SI); } -// FIXME: Use the C-API LLVMBuildAtomicCmpXchg and LLVMSetWeak -// once we raise our minimum support to LLVM 10. -extern "C" LLVMValueRef -LLVMRustBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Target, - LLVMValueRef Old, LLVMValueRef Source, - LLVMAtomicOrdering Order, - LLVMAtomicOrdering FailureOrder, LLVMBool Weak) { -#if LLVM_VERSION_GE(13,0) - // Rust probably knows the alignment of the target value and should be able to - // specify something more precise than MaybeAlign here. See also - // https://reviews.llvm.org/D97224 which may be a useful reference. - AtomicCmpXchgInst *ACXI = unwrap(B)->CreateAtomicCmpXchg( - unwrap(Target), unwrap(Old), unwrap(Source), llvm::MaybeAlign(), fromRust(Order), - fromRust(FailureOrder)); -#else - AtomicCmpXchgInst *ACXI = unwrap(B)->CreateAtomicCmpXchg( - unwrap(Target), unwrap(Old), unwrap(Source), fromRust(Order), - fromRust(FailureOrder)); -#endif - ACXI->setWeak(Weak); - return wrap(ACXI); -} - -enum class LLVMRustSynchronizationScope { - SingleThread, - CrossThread, -}; - -static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) { - switch (Scope) { - case LLVMRustSynchronizationScope::SingleThread: - return SyncScope::SingleThread; - case LLVMRustSynchronizationScope::CrossThread: - return SyncScope::System; - default: - report_fatal_error("bad SynchronizationScope."); - } -} - -extern "C" LLVMValueRef -LLVMRustBuildAtomicFence(LLVMBuilderRef B, LLVMAtomicOrdering Order, - LLVMRustSynchronizationScope Scope) { - return wrap(unwrap(B)->CreateFence(fromRust(Order), fromRust(Scope))); -} - enum class LLVMRustAsmDialect { Att, Intel, @@ -472,19 +427,11 @@ LLVMRustInlineAsm(LLVMTypeRef Ty, char *AsmString, size_t AsmStringLen, char *Constraints, size_t ConstraintsLen, LLVMBool HasSideEffects, LLVMBool IsAlignStack, LLVMRustAsmDialect Dialect, LLVMBool CanThrow) { -#if LLVM_VERSION_GE(13, 0) return wrap(InlineAsm::get(unwrap<FunctionType>(Ty), StringRef(AsmString, AsmStringLen), StringRef(Constraints, ConstraintsLen), HasSideEffects, IsAlignStack, fromRust(Dialect), CanThrow)); -#else - return wrap(InlineAsm::get(unwrap<FunctionType>(Ty), - StringRef(AsmString, AsmStringLen), - StringRef(Constraints, ConstraintsLen), - HasSideEffects, IsAlignStack, - fromRust(Dialect))); -#endif } extern "C" bool LLVMRustInlineAsmVerify(LLVMTypeRef Ty, char *Constraints, @@ -924,6 +871,30 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantMemberType( fromRust(Flags), unwrapDI<DIType>(Ty))); } +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticMemberType( + LLVMRustDIBuilderRef Builder, + LLVMMetadataRef Scope, + const char *Name, + size_t NameLen, + LLVMMetadataRef File, + unsigned LineNo, + LLVMMetadataRef Ty, + LLVMRustDIFlags Flags, + LLVMValueRef val, + uint32_t AlignInBits +) { + return wrap(Builder->createStaticMemberType( + unwrapDI<DIDescriptor>(Scope), + StringRef(Name, NameLen), + unwrapDI<DIFile>(File), + LineNo, + unwrapDI<DIType>(Ty), + fromRust(Flags), + unwrap<llvm::ConstantInt>(val), + AlignInBits + )); +} + extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateLexicalBlock( LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned Col) { @@ -1250,10 +1221,8 @@ static LLVMRustDiagnosticKind toRust(DiagnosticKind Kind) { return LLVMRustDiagnosticKind::Linker; case DK_Unsupported: return LLVMRustDiagnosticKind::Unsupported; -#if LLVM_VERSION_GE(13, 0) case DK_SrcMgr: return LLVMRustDiagnosticKind::SrcMgr; -#endif default: return (Kind >= DK_FirstRemark && Kind <= DK_LastRemark) ? LLVMRustDiagnosticKind::OptimizationRemarkOther @@ -1327,30 +1296,11 @@ extern "C" LLVMTypeKind LLVMRustGetTypeKind(LLVMTypeRef Ty) { DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SMDiagnostic, LLVMSMDiagnosticRef) -#if LLVM_VERSION_LT(13, 0) -using LLVMInlineAsmDiagHandlerTy = LLVMContext::InlineAsmDiagHandlerTy; -#else -using LLVMInlineAsmDiagHandlerTy = void*; -#endif - -extern "C" void LLVMRustSetInlineAsmDiagnosticHandler( - LLVMContextRef C, LLVMInlineAsmDiagHandlerTy H, void *CX) { - // Diagnostic handlers were unified in LLVM change 5de2d189e6ad, so starting - // with LLVM 13 this function is gone. -#if LLVM_VERSION_LT(13, 0) - unwrap(C)->setInlineAsmDiagnosticHandler(H, CX); -#endif -} - extern "C" LLVMSMDiagnosticRef LLVMRustGetSMDiagnostic( LLVMDiagnosticInfoRef DI, unsigned *Cookie) { -#if LLVM_VERSION_GE(13, 0) llvm::DiagnosticInfoSrcMgr *SM = static_cast<llvm::DiagnosticInfoSrcMgr *>(unwrap(DI)); *Cookie = SM->getLocCookie(); return wrap(&SM->getSMDiag()); -#else - report_fatal_error("Shouldn't get called on older versions"); -#endif } extern "C" bool LLVMRustUnpackSMDiagnostic(LLVMSMDiagnosticRef DRef, @@ -1629,6 +1579,14 @@ extern "C" LLVMValueRef LLVMRustConstInBoundsGEP2(LLVMTypeRef Ty, return wrap(ConstantExpr::getInBoundsGetElementPtr(unwrap(Ty), Val, IdxList)); } +extern "C" bool LLVMRustConstIntGetZExtValue(LLVMValueRef CV, uint64_t *value) { + auto C = unwrap<llvm::ConstantInt>(CV); + if (C->getBitWidth() > 64) + return false; + *value = C->getZExtValue(); + return true; +} + // Returns true if both high and low were successfully set. Fails in case constant wasn’t any of // the common sizes (1, 8, 16, 32, 64, 128 bits) extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext, uint64_t *high, uint64_t *low) @@ -1712,11 +1670,7 @@ LLVMRustModuleBufferCreate(LLVMModuleRef M) { auto Ret = std::make_unique<LLVMRustModuleBuffer>(); { raw_string_ostream OS(Ret->data); - { - legacy::PassManager PM; - PM.add(createBitcodeWriterPass(OS)); - PM.run(*unwrap(M)); - } + WriteBitcodeToFile(*unwrap(M), OS); } return Ret.release(); } diff --git a/compiler/rustc_llvm/src/lib.rs b/compiler/rustc_llvm/src/lib.rs index 8eade02a4..8542dcf5b 100644 --- a/compiler/rustc_llvm/src/lib.rs +++ b/compiler/rustc_llvm/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] // NOTE: This crate only exists to allow linking on mingw targets. |