Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/CodeGen/BackendUtil.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
#include "llvm/Support/TimeProfiler.h" | #include "llvm/Support/TimeProfiler.h" | ||||
#include "llvm/Support/Timer.h" | #include "llvm/Support/Timer.h" | ||||
#include "llvm/Support/raw_ostream.h" | #include "llvm/Support/raw_ostream.h" | ||||
#include "llvm/Target/TargetMachine.h" | #include "llvm/Target/TargetMachine.h" | ||||
#include "llvm/Target/TargetOptions.h" | #include "llvm/Target/TargetOptions.h" | ||||
#include "llvm/Transforms/Coroutines.h" | #include "llvm/Transforms/Coroutines.h" | ||||
#include "llvm/Transforms/IPO.h" | #include "llvm/Transforms/IPO.h" | ||||
#include "llvm/Transforms/IPO/AlwaysInliner.h" | #include "llvm/Transforms/IPO/AlwaysInliner.h" | ||||
#include "llvm/Transforms/IPO/LowerTypeTests.h" | |||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h" | #include "llvm/Transforms/IPO/PassManagerBuilder.h" | ||||
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" | #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" | ||||
#include "llvm/Transforms/InstCombine/InstCombine.h" | #include "llvm/Transforms/InstCombine/InstCombine.h" | ||||
#include "llvm/Transforms/Instrumentation.h" | #include "llvm/Transforms/Instrumentation.h" | ||||
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h" | #include "llvm/Transforms/Instrumentation/AddressSanitizer.h" | ||||
#include "llvm/Transforms/Instrumentation/BoundsChecking.h" | #include "llvm/Transforms/Instrumentation/BoundsChecking.h" | ||||
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h" | #include "llvm/Transforms/Instrumentation/GCOVProfiler.h" | ||||
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h" | #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h" | ||||
▲ Show 20 Lines • Show All 486 Lines • ▼ Show 20 Lines | void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, | ||||
// Figure out TargetLibraryInfo. This needs to be added to MPM and FPM | // Figure out TargetLibraryInfo. This needs to be added to MPM and FPM | ||||
// manually (and not via PMBuilder), since some passes (eg. InstrProfiling) | // manually (and not via PMBuilder), since some passes (eg. InstrProfiling) | ||||
// are inserted before PMBuilder ones - they'd get the default-constructed | // are inserted before PMBuilder ones - they'd get the default-constructed | ||||
// TLI with an unknown target otherwise. | // TLI with an unknown target otherwise. | ||||
Triple TargetTriple(TheModule->getTargetTriple()); | Triple TargetTriple(TheModule->getTargetTriple()); | ||||
std::unique_ptr<TargetLibraryInfoImpl> TLII( | std::unique_ptr<TargetLibraryInfoImpl> TLII( | ||||
createTLII(TargetTriple, CodeGenOpts)); | createTLII(TargetTriple, CodeGenOpts)); | ||||
// If we reached here with a non-empty index file name, then the index file | |||||
// was empty and we are not performing ThinLTO backend compilation (used in | |||||
// testing in a distributed build environment). Drop any the type test | |||||
// assume sequences inserted for whole program vtables so that codegen doesn't | |||||
// complain. | |||||
if (!CodeGenOpts.ThinLTOIndexFile.empty()) | |||||
MPM.add(createLowerTypeTestsPass(/*ExportSummary=*/nullptr, | |||||
evgeny777: Test case? | |||||
See clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp. Specifically the second block of clang invocations: // Also check type test are lowered when the distributed ThinLTO backend clang // invocation is passed an empty index file, in which case a non-ThinLTO // compilation pipeline is invoked. If not lowered then LLVM CodeGen may assert. I'm testing both the new and old PMs, as well as the new PM O0 path (basically all paths modified in this file). tejohnson: See clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp. Specifically the second block… | |||||
/*ImportSummary=*/nullptr, | |||||
/*DropTypeTests=*/true)); | |||||
PassManagerBuilderWrapper PMBuilder(TargetTriple, CodeGenOpts, LangOpts); | PassManagerBuilderWrapper PMBuilder(TargetTriple, CodeGenOpts, LangOpts); | ||||
// At O0 and O1 we only run the always inliner which is more efficient. At | // At O0 and O1 we only run the always inliner which is more efficient. At | ||||
// higher optimization levels we run the normal inliner. | // higher optimization levels we run the normal inliner. | ||||
if (CodeGenOpts.OptimizationLevel <= 1) { | if (CodeGenOpts.OptimizationLevel <= 1) { | ||||
bool InsertLifetimeIntrinsics = (CodeGenOpts.OptimizationLevel != 0 && | bool InsertLifetimeIntrinsics = (CodeGenOpts.OptimizationLevel != 0 && | ||||
!CodeGenOpts.DisableLifetimeMarkers); | !CodeGenOpts.DisableLifetimeMarkers); | ||||
PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics); | PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics); | ||||
▲ Show 20 Lines • Show All 545 Lines • ▼ Show 20 Lines | #include "llvm/Support/Extension.def" | ||||
ModulePassManager MPM(CodeGenOpts.DebugPassManager); | ModulePassManager MPM(CodeGenOpts.DebugPassManager); | ||||
if (!CodeGenOpts.DisableLLVMPasses) { | if (!CodeGenOpts.DisableLLVMPasses) { | ||||
bool IsThinLTO = CodeGenOpts.PrepareForThinLTO; | bool IsThinLTO = CodeGenOpts.PrepareForThinLTO; | ||||
bool IsLTO = CodeGenOpts.PrepareForLTO; | bool IsLTO = CodeGenOpts.PrepareForLTO; | ||||
if (CodeGenOpts.OptimizationLevel == 0) { | if (CodeGenOpts.OptimizationLevel == 0) { | ||||
// If we reached here with a non-empty index file name, then the index | |||||
// file was empty and we are not performing ThinLTO backend compilation | |||||
// (used in testing in a distributed build environment). Drop any the type | |||||
// test assume sequences inserted for whole program vtables so that | |||||
// codegen doesn't complain. | |||||
if (!CodeGenOpts.ThinLTOIndexFile.empty()) | |||||
MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr, | |||||
/*ImportSummary=*/nullptr, | |||||
/*DropTypeTests=*/true)); | |||||
if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts)) | if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts)) | ||||
MPM.addPass(GCOVProfilerPass(*Options)); | MPM.addPass(GCOVProfilerPass(*Options)); | ||||
if (Optional<InstrProfOptions> Options = | if (Optional<InstrProfOptions> Options = | ||||
getInstrProfOptions(CodeGenOpts, LangOpts)) | getInstrProfOptions(CodeGenOpts, LangOpts)) | ||||
MPM.addPass(InstrProfiling(*Options, false)); | MPM.addPass(InstrProfiling(*Options, false)); | ||||
// Build a minimal pipeline based on the semantics required by Clang, | // Build a minimal pipeline based on the semantics required by Clang, | ||||
// which is just that always inlining occurs. Further, disable generating | // which is just that always inlining occurs. Further, disable generating | ||||
Show All 20 Lines | if (CodeGenOpts.OptimizationLevel == 0) { | ||||
MPM.addPass(CanonicalizeAliasesPass()); | MPM.addPass(CanonicalizeAliasesPass()); | ||||
MPM.addPass(NameAnonGlobalPass()); | MPM.addPass(NameAnonGlobalPass()); | ||||
} | } | ||||
} else { | } else { | ||||
// Map our optimization levels into one of the distinct levels used to | // Map our optimization levels into one of the distinct levels used to | ||||
// configure the pipeline. | // configure the pipeline. | ||||
PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts); | PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts); | ||||
// If we reached here with a non-empty index file name, then the index | |||||
// file was empty and we are not performing ThinLTO backend compilation | |||||
// (used in testing in a distributed build environment). Drop any the type | |||||
// test assume sequences inserted for whole program vtables so that | |||||
// codegen doesn't complain. | |||||
if (!CodeGenOpts.ThinLTOIndexFile.empty()) | |||||
PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) { | |||||
MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr, | |||||
/*ImportSummary=*/nullptr, | |||||
/*DropTypeTests=*/true)); | |||||
}); | |||||
PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) { | PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) { | ||||
MPM.addPass(createModuleToFunctionPassAdaptor( | MPM.addPass(createModuleToFunctionPassAdaptor( | ||||
EntryExitInstrumenterPass(/*PostInlining=*/false))); | EntryExitInstrumenterPass(/*PostInlining=*/false))); | ||||
}); | }); | ||||
// Register callbacks to schedule sanitizer passes at the appropriate part of | // Register callbacks to schedule sanitizer passes at the appropriate part of | ||||
// the pipeline. | // the pipeline. | ||||
// FIXME: either handle asan/the remaining sanitizers or error out | // FIXME: either handle asan/the remaining sanitizers or error out | ||||
▲ Show 20 Lines • Show All 415 Lines • Show Last 20 Lines |
Test case?