diff options
author | Nikita Popov <npopov@redhat.com> | 2025-03-06 10:27:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-06 10:27:47 +0100 |
commit | 979c275097a642e9b96c6b0a12f013c831af3a6e (patch) | |
tree | af2b2a814562e086ef34605665b304ceae887007 /llvm/lib/LTO/LTOBackend.cpp | |
parent | f01e760c08365426de95f02dc2c2dc670eb47352 (diff) | |
download | llvm-979c275097a642e9b96c6b0a12f013c831af3a6e.zip llvm-979c275097a642e9b96c6b0a12f013c831af3a6e.tar.gz llvm-979c275097a642e9b96c6b0a12f013c831af3a6e.tar.bz2 |
[IR] Store Triple in Module (NFC) (#129868)
The module currently stores the target triple as a string. This means
that any code that wants to actually use the triple first has to
instantiate a Triple, which is somewhat expensive. The change in #121652
caused a moderate compile-time regression due to this. While it would be
easy enough to work around, I think that architecturally, it makes more
sense to store the parsed Triple in the module, so that it can always be
directly queried.
For this change, I've opted not to add any magic conversions between
std::string and Triple for backwards-compatibilty purses, and instead
write out needed Triple()s or str()s explicitly. This is because I think
a decent number of them should be changed to work on Triple as well, to
avoid unnecessary conversions back and forth.
The only interesting part in this patch is that the default triple is
Triple("") instead of Triple() to preserve existing behavior. The former
defaults to using the ELF object format instead of unknown object
format. We should fix that as well.
Diffstat (limited to 'llvm/lib/LTO/LTOBackend.cpp')
-rw-r--r-- | llvm/lib/LTO/LTOBackend.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index 8a2dddc..b38252a 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -202,9 +202,9 @@ static void RegisterPassPlugins(ArrayRef<std::string> PassPlugins, static std::unique_ptr<TargetMachine> createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) { - StringRef TheTriple = M.getTargetTriple(); + const Triple &TheTriple = M.getTargetTriple(); SubtargetFeatures Features; - Features.getDefaultSubtargetFeatures(Triple(TheTriple)); + Features.getDefaultSubtargetFeatures(TheTriple); for (const std::string &A : Conf.MAttrs) Features.AddFeature(A); @@ -222,7 +222,7 @@ createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) { CodeModel = M.getCodeModel(); std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine( - TheTriple, Conf.CPU, Features.getString(), Conf.Options, RelocModel, + TheTriple.str(), Conf.CPU, Features.getString(), Conf.Options, RelocModel, CodeModel, Conf.CGOptLevel)); assert(TM && "Failed to create target machine"); @@ -276,7 +276,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM, RegisterPassPlugins(Conf.PassPlugins, PB); std::unique_ptr<TargetLibraryInfoImpl> TLII( - new TargetLibraryInfoImpl(Triple(TM->getTargetTriple()))); + new TargetLibraryInfoImpl(TM->getTargetTriple())); if (Conf.Freestanding) TLII->disableAllFunctions(); FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); }); @@ -435,7 +435,7 @@ static void codegen(const Config &Conf, TargetMachine *TM, TM->Options.ObjectFilenameForDebug = Stream->ObjectPathName; legacy::PassManager CodeGenPasses; - TargetLibraryInfoImpl TLII(Triple(Mod.getTargetTriple())); + TargetLibraryInfoImpl TLII(Mod.getTargetTriple()); CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII)); // No need to make index available if the module is empty. // In theory these passes should not use the index for an empty @@ -515,9 +515,9 @@ static void splitCodeGen(const Config &C, TargetMachine *TM, static Expected<const Target *> initAndLookupTarget(const Config &C, Module &Mod) { if (!C.OverrideTriple.empty()) - Mod.setTargetTriple(C.OverrideTriple); + Mod.setTargetTriple(Triple(C.OverrideTriple)); else if (Mod.getTargetTriple().empty()) - Mod.setTargetTriple(C.DefaultTriple); + Mod.setTargetTriple(Triple(C.DefaultTriple)); std::string Msg; const Target *T = TargetRegistry::lookupTarget(Mod.getTargetTriple(), Msg); |