wenlei created this revision.
wenlei added reviewers: tejohnson, nikic, mehdi_amini, hoyFB.
Herald added subscribers: cfe-commits, hiraditya.
Herald added a project: clang.
Minor changes to reduce the copying needed for TLI and TLA by using move
whenever possible.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77952
Files:
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Analysis/TargetLibraryInfo.h
llvm/lib/Analysis/TargetLibraryInfo.cpp
Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===================================================================
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -583,8 +583,8 @@
ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
AvailableArray);
- for (unsigned i = 0; i < NumVecLibs; i++)
- VecLibDescs[i] = TLI.VecLibDescs[i];
+ std::move(std::begin(TLI.VecLibDescs), std::end(TLI.VecLibDescs),
+ VecLibDescs);
}
TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
@@ -1677,6 +1677,12 @@
initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
}
+TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
+ TargetLibraryInfoImpl &&TLIImpl)
+ : ImmutablePass(ID), TLA(std::move(TLIImpl)) {
+ initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
+}
+
AnalysisKey TargetLibraryAnalysis::Key;
// Register the basic pass.
Index: llvm/include/llvm/Analysis/TargetLibraryInfo.h
===================================================================
--- llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -452,7 +452,11 @@
/// Construct a library analysis with baseline Module-level info.
///
/// This will be supplemented with Function-specific info in the Result.
- TargetLibraryAnalysis(TargetLibraryInfoImpl BaselineInfoImpl)
+ TargetLibraryAnalysis(const Triple &T)
+ : BaselineInfoImpl(TargetLibraryInfoImpl(T)) {}
+ TargetLibraryAnalysis(const TargetLibraryInfoImpl &BaselineInfoImpl)
+ : BaselineInfoImpl(BaselineInfoImpl) {}
+ TargetLibraryAnalysis(TargetLibraryInfoImpl &&BaselineInfoImpl)
: BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
TargetLibraryInfo run(const Function &F, FunctionAnalysisManager &);
@@ -475,6 +479,7 @@
TargetLibraryInfoWrapperPass();
explicit TargetLibraryInfoWrapperPass(const Triple &T);
explicit TargetLibraryInfoWrapperPass(const TargetLibraryInfoImpl &TLI);
+ explicit TargetLibraryInfoWrapperPass(TargetLibraryInfoImpl &&TLI);
TargetLibraryInfo &getTLI(const Function &F) {
FunctionAnalysisManager DummyFAM;
Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -352,10 +352,6 @@
PM.add(createStackSafetyGlobalInfoWrapperPass(/*SetMetadata=*/true));
}
-static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple) {
- return new TargetLibraryInfoImpl(TargetTriple);
-}
-
static void addSymbolRewriterPass(const CodeGenOptions &Opts,
legacy::PassManager *MPM) {
llvm::SymbolRewriter::RewriteDescriptorList DL;
@@ -541,13 +537,6 @@
if (CodeGenOpts.DisableLLVMPasses)
return;
- // Figure out TargetLibraryInfo. This needs to be added to MPM and FPM
- // manually (and not via PMBuilder), since some passes (eg. InstrProfiling)
- // are inserted before PMBuilder ones - they'd get the default-constructed
- // TLI with an unknown target otherwise.
- Triple TargetTriple(TheModule->getTargetTriple());
- std::unique_ptr<TargetLibraryInfoImpl> TLII(createTLII(TargetTriple));
-
// 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
@@ -558,6 +547,7 @@
/*ImportSummary=*/nullptr,
/*DropTypeTests=*/true));
+ Triple TargetTriple(TheModule->getTargetTriple());
PassManagerBuilderWrapper PMBuilder(TargetTriple, CodeGenOpts, LangOpts);
// At O0 and O1 we only run the always inliner which is more efficient. At
@@ -591,7 +581,11 @@
PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO;
PMBuilder.RerollLoops = CodeGenOpts.RerollLoops;
- MPM.add(new TargetLibraryInfoWrapperPass(*TLII));
+ // Figure out TargetLibraryInfo. This needs to be added to MPM and FPM
+ // manually (and not via PMBuilder), since some passes (eg. InstrProfiling)
+ // are inserted before PMBuilder ones - they'd get the default-constructed
+ // TLI with an unknown target otherwise.
+ MPM.add(new TargetLibraryInfoWrapperPass(TargetTriple));
if (TM)
TM->adjustPassManager(PMBuilder);
@@ -692,7 +686,7 @@
}
// Set up the per-function pass manager.
- FPM.add(new TargetLibraryInfoWrapperPass(*TLII));
+ FPM.add(new TargetLibraryInfoWrapperPass(TargetTriple));
if (CodeGenOpts.VerifyModule)
FPM.add(createVerifierPass());
@@ -788,8 +782,7 @@
raw_pwrite_stream *DwoOS) {
// Add LibraryInfo.
llvm::Triple TargetTriple(TheModule->getTargetTriple());
- std::unique_ptr<TargetLibraryInfoImpl> TLII(createTLII(TargetTriple));
- CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
+ CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TargetTriple));
// Normal mode, emit a .s or .o file by running the code generator. Note,
// this also adds codegenerator level optimization passes.
@@ -1124,8 +1117,7 @@
// Register the target library analysis directly and give it a customized
// preset TLI.
Triple TargetTriple(TheModule->getTargetTriple());
- std::unique_ptr<TargetLibraryInfoImpl> TLII(createTLII(TargetTriple));
- FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
+ FAM.registerPass([&] { return TargetLibraryAnalysis(TargetTriple); });
// Register all the basic analyses with the managers.
PB.registerModuleAnalyses(MAM);
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits