forked from OSchip/llvm-project
[clang][NFC] Extract the EmitAssemblyHelper::TargetTriple member
Few times in different methods of the EmitAssemblyHelper class the following code snippet is used to get the TargetTriple and then use it's single method to check some conditions: TargetTriple(TheModule->getTargetTriple()) The parsing of a target triple string is not a trivial operation and it takes time to repeat the parsing many times in different methods of the class and even numerous times in one method just to call a getter (llvm::Triple(TheModule->getTargetTriple()).getVendor()), for example. The patch extracts the TargetTriple member of the EmitAssemblyHelper class to parse the triple only once in the class' constructor. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D122587
This commit is contained in:
parent
9db1eb13b6
commit
87b28f5092
|
@ -118,6 +118,8 @@ class EmitAssemblyHelper {
|
|||
|
||||
std::unique_ptr<raw_pwrite_stream> OS;
|
||||
|
||||
Triple TargetTriple;
|
||||
|
||||
TargetIRAnalysis getTargetIRAnalysis() const {
|
||||
if (TM)
|
||||
return TM->getTargetIRAnalysis();
|
||||
|
@ -170,7 +172,8 @@ public:
|
|||
const LangOptions &LOpts, Module *M)
|
||||
: Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
|
||||
TargetOpts(TOpts), LangOpts(LOpts), TheModule(M),
|
||||
CodeGenerationTime("codegen", "Code Generation Time") {}
|
||||
CodeGenerationTime("codegen", "Code Generation Time"),
|
||||
TargetTriple(TheModule->getTargetTriple()) {}
|
||||
|
||||
~EmitAssemblyHelper() {
|
||||
if (CodeGenOpts.DisableFree)
|
||||
|
@ -695,7 +698,6 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
|
|||
// 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, CodeGenOpts));
|
||||
|
||||
|
@ -965,7 +967,6 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
|
|||
raw_pwrite_stream &OS,
|
||||
raw_pwrite_stream *DwoOS) {
|
||||
// Add LibraryInfo.
|
||||
llvm::Triple TargetTriple(TheModule->getTargetTriple());
|
||||
std::unique_ptr<TargetLibraryInfoImpl> TLII(
|
||||
createTLII(TargetTriple, CodeGenOpts));
|
||||
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
|
||||
|
@ -1054,10 +1055,8 @@ void EmitAssemblyHelper::EmitAssemblyWithLegacyPassManager(
|
|||
// Emit a module summary by default for Regular LTO except for ld64
|
||||
// targets
|
||||
bool EmitLTOSummary =
|
||||
(CodeGenOpts.PrepareForLTO &&
|
||||
!CodeGenOpts.DisableLLVMPasses &&
|
||||
llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
|
||||
llvm::Triple::Apple);
|
||||
(CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
|
||||
TargetTriple.getVendor() != llvm::Triple::Apple);
|
||||
if (EmitLTOSummary) {
|
||||
if (!TheModule->getModuleFlag("ThinLTO"))
|
||||
TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
|
||||
|
@ -1338,7 +1337,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
|
|||
|
||||
// Register the target library analysis directly and give it a customized
|
||||
// preset TLI.
|
||||
Triple TargetTriple(TheModule->getTargetTriple());
|
||||
std::unique_ptr<TargetLibraryInfoImpl> TLII(
|
||||
createTLII(TargetTriple, CodeGenOpts));
|
||||
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
|
||||
|
@ -1474,8 +1472,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
|
|||
// targets
|
||||
bool EmitLTOSummary =
|
||||
(CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
|
||||
llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
|
||||
llvm::Triple::Apple);
|
||||
TargetTriple.getVendor() != llvm::Triple::Apple);
|
||||
if (EmitLTOSummary) {
|
||||
if (!TheModule->getModuleFlag("ThinLTO"))
|
||||
TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
|
||||
|
|
Loading…
Reference in New Issue