-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IR] Store Triple in Module (NFC) #129868
Conversation
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 llvm#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.
@llvm/pr-subscribers-flang-driver @llvm/pr-subscribers-backend-aarch64 Author: Nikita Popov (nikic) ChangesThe 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. Patch is 87.54 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/129868.diff 93 Files Affected:
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 1750719e17670..62a0e3c69bad1 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -595,7 +595,7 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
// Create the TargetMachine for generating code.
std::string Error;
- std::string Triple = TheModule->getTargetTriple();
+ std::string Triple = TheModule->getTargetTriple().str();
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
if (!TheTarget) {
if (MustCreateTM)
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 7aa3639cabf39..4321efd49af36 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1032,7 +1032,7 @@ CodeGenAction::loadModule(MemoryBufferRef MBRef) {
// linker using merged object file.
if (!Bm) {
auto M = std::make_unique<llvm::Module>("empty", *VMContext);
- M->setTargetTriple(CI.getTargetOpts().Triple);
+ M->setTargetTriple(Triple(CI.getTargetOpts().Triple));
return M;
}
Expected<std::unique_ptr<llvm::Module>> MOrErr =
@@ -1123,10 +1123,10 @@ void CodeGenAction::ExecuteAction() {
return;
const TargetOptions &TargetOpts = CI.getTargetOpts();
- if (TheModule->getTargetTriple() != TargetOpts.Triple) {
+ if (TheModule->getTargetTriple().str() != TargetOpts.Triple) {
Diagnostics.Report(SourceLocation(), diag::warn_fe_override_module)
<< TargetOpts.Triple;
- TheModule->setTargetTriple(TargetOpts.Triple);
+ TheModule->setTargetTriple(Triple(TargetOpts.Triple));
}
EmbedObject(TheModule.get(), CodeGenOpts, Diagnostics);
diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp
index d4e0ab0339a8b..09a7d79ae4afb 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -151,7 +151,7 @@ namespace {
void Initialize(ASTContext &Context) override {
Ctx = &Context;
- M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
+ M->setTargetTriple(Ctx->getTargetInfo().getTriple());
M->setDataLayout(Ctx->getTargetInfo().getDataLayoutString());
const auto &SDKVersion = Ctx->getTargetInfo().getSDKVersion();
if (!SDKVersion.empty())
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
index 788c8b932ab52..e32778d1b4767 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
@@ -255,7 +255,7 @@ class PCHContainerGenerator : public ASTConsumer {
if (Diags.hasErrorOccurred())
return;
- M->setTargetTriple(Ctx.getTargetInfo().getTriple().getTriple());
+ M->setTargetTriple(Ctx.getTargetInfo().getTriple());
M->setDataLayout(Ctx.getTargetInfo().getDataLayoutString());
// PCH files don't have a signature field in the control block,
diff --git a/clang/lib/Interpreter/DeviceOffload.cpp b/clang/lib/Interpreter/DeviceOffload.cpp
index 1999d63d1aa04..8fb484d185704 100644
--- a/clang/lib/Interpreter/DeviceOffload.cpp
+++ b/clang/lib/Interpreter/DeviceOffload.cpp
@@ -77,13 +77,13 @@ llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {
std::string Error;
const llvm::Target *Target = llvm::TargetRegistry::lookupTarget(
- PTU.TheModule->getTargetTriple(), Error);
+ PTU.TheModule->getTargetTriple().str(), Error);
if (!Target)
return llvm::make_error<llvm::StringError>(std::move(Error),
std::error_code());
llvm::TargetOptions TO = llvm::TargetOptions();
llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
- PTU.TheModule->getTargetTriple(), TargetOpts.CPU, "", TO,
+ PTU.TheModule->getTargetTriple().str(), TargetOpts.CPU, "", TO,
llvm::Reloc::Model::PIC_);
PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
diff --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index 798b34b3ef0af..4618c0bcc6be8 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -127,8 +127,8 @@ static std::string OptLLVM(const std::string &IR, CodeGenOptLevel OLvl) {
ErrorAndExit(E);
std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
- M->getTargetTriple(), codegen::getCPUStr(), codegen::getFeaturesStr(),
- Options, codegen::getExplicitRelocModel(),
+ M->getTargetTriple().str(), codegen::getCPUStr(),
+ codegen::getFeaturesStr(), Options, codegen::getExplicitRelocModel(),
codegen::getExplicitCodeModel(), OLvl));
if (!TM)
ErrorAndExit("Could not create target machine");
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 7db8f3e27d704..5f5d103bbcf49 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -622,16 +622,17 @@ Expected<StringRef> writeOffloadFile(const OffloadFile &File) {
Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
llvm::TimeTraceScope TimeScope("Compile module");
std::string Msg;
- const Target *T = TargetRegistry::lookupTarget(M.getTargetTriple(), Msg);
+ const Target *T =
+ TargetRegistry::lookupTarget(M.getTargetTriple().str(), Msg);
if (!T)
return createStringError(Msg);
auto Options =
- codegen::InitTargetOptionsFromCodeGenFlags(Triple(M.getTargetTriple()));
+ codegen::InitTargetOptionsFromCodeGenFlags(M.getTargetTriple());
StringRef CPU = "";
StringRef Features = "";
std::unique_ptr<TargetMachine> TM(
- T->createTargetMachine(M.getTargetTriple(), CPU, Features, Options,
+ T->createTargetMachine(M.getTargetTriple().str(), CPU, Features, Options,
Reloc::PIC_, M.getCodeModel()));
if (M.getDataLayout().isDefault())
@@ -650,7 +651,7 @@ Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
auto OS = std::make_unique<llvm::raw_fd_ostream>(FD, true);
legacy::PassManager CodeGenPasses;
- TargetLibraryInfoImpl TLII(Triple(M.getTargetTriple()));
+ TargetLibraryInfoImpl TLII(M.getTargetTriple());
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
if (TM->addPassesToEmitFile(CodeGenPasses, *OS, nullptr,
CodeGenFileType::ObjectFile))
@@ -674,8 +675,8 @@ wrapDeviceImages(ArrayRef<std::unique_ptr<MemoryBuffer>> Buffers,
LLVMContext Context;
Module M("offload.wrapper.module", Context);
- M.setTargetTriple(
- Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple()));
+ M.setTargetTriple(Triple(
+ Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple())));
switch (Kind) {
case OFK_OpenMP:
diff --git a/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp b/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
index f498a97442c44..78152af052c07 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
+++ b/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
@@ -207,7 +207,7 @@ int main(int Argc, char *Argv[]) {
ExitOnErr(JITTargetMachineBuilder::detectHost()));
} else {
Builder.setJITTargetMachineBuilder(
- JITTargetMachineBuilder(Triple(M.getTargetTriple())));
+ JITTargetMachineBuilder(M.getTargetTriple()));
}
if (!M.getDataLayout().getStringRepresentation().empty())
Builder.setDataLayout(M.getDataLayout());
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h
index 593f7a41337cb..67347e851ca1b 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h
@@ -104,7 +104,7 @@ class StaticInitGVIterator {
StaticInitGVIterator(Module &M)
: I(M.global_values().begin()), E(M.global_values().end()),
- ObjFmt(Triple(M.getTargetTriple()).getObjectFormat()) {
+ ObjFmt(M.getTargetTriple().getObjectFormat()) {
if (I != E) {
if (!isStaticInitGlobal(*I))
moveToNextStaticInitGlobal();
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 80b4aa2bd2855..28909cef4748d 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -479,7 +479,7 @@ class OpenMPIRBuilder {
/// not have an effect on \p M (see initialize)
OpenMPIRBuilder(Module &M)
: M(M), Builder(M.getContext()), OffloadInfoManager(this),
- T(Triple(M.getTargetTriple())) {}
+ T(M.getTargetTriple()) {}
~OpenMPIRBuilder();
class AtomicInfo : public llvm::AtomicInfo {
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 12b50fc506516..48dc29c24c582 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -31,6 +31,7 @@
#include "llvm/IR/SymbolTableListTraits.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/CodeGen.h"
+#include "llvm/TargetParser/Triple.h"
#include <cstddef>
#include <cstdint>
#include <iterator>
@@ -189,8 +190,10 @@ class LLVM_ABI Module {
std::string ModuleID; ///< Human readable identifier for the module
std::string SourceFileName; ///< Original source file name for module,
///< recorded in bitcode.
- std::string TargetTriple; ///< Platform target triple Module compiled on
- ///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
+ /// Platform target triple Module compiled on
+ /// Format: (arch)(sub)-(vendor)-(sys0-(abi)
+ // FIXME: Default construction is not the same as empty triple :(
+ Triple TargetTriple = Triple("");
NamedMDSymTabType NamedMDSymTab; ///< NamedMDNode names.
DataLayout DL; ///< DataLayout associated with the module
StringMap<unsigned>
@@ -294,8 +297,7 @@ class LLVM_ABI Module {
const DataLayout &getDataLayout() const { return DL; }
/// Get the target triple which is a string describing the target host.
- /// @returns a string containing the target triple.
- const std::string &getTargetTriple() const { return TargetTriple; }
+ const Triple &getTargetTriple() const { return TargetTriple; }
/// Get the global data context.
/// @returns LLVMContext - a container for LLVM's global information
@@ -338,7 +340,7 @@ class LLVM_ABI Module {
void setDataLayout(const DataLayout &Other);
/// Set the target triple.
- void setTargetTriple(StringRef T) { TargetTriple = std::string(T); }
+ void setTargetTriple(Triple T) { TargetTriple = std::move(T); }
/// Set the module-scope inline assembly blocks.
/// A trailing newline is added if the input doesn't have one.
diff --git a/llvm/include/llvm/LTO/legacy/LTOModule.h b/llvm/include/llvm/LTO/legacy/LTOModule.h
index e861a56bcbac1..91a38b7c0da80 100644
--- a/llvm/include/llvm/LTO/legacy/LTOModule.h
+++ b/llvm/include/llvm/LTO/legacy/LTOModule.h
@@ -118,14 +118,10 @@ struct LTOModule {
std::unique_ptr<Module> takeModule() { return std::move(Mod); }
/// Return the Module's target triple.
- const std::string &getTargetTriple() {
- return getModule().getTargetTriple();
- }
+ const Triple &getTargetTriple() { return getModule().getTargetTriple(); }
/// Set the Module's target triple.
- void setTargetTriple(StringRef Triple) {
- getModule().setTargetTriple(Triple);
- }
+ void setTargetTriple(Triple T) { getModule().setTargetTriple(T); }
/// Get the number of symbols
uint32_t getSymbolCount() {
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 09c0d223d9b4d..390ed7fbab8c0 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -463,6 +463,9 @@ class Triple {
const std::string &getTriple() const { return Data; }
+ /// Whether the triple is empty / default constructed.
+ bool empty() const { return Data.empty(); }
+
/// Get the architecture (first) component of the triple.
StringRef getArchName() const;
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index a7f666a3f8b48..87aa14e9c701f 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -24,7 +24,7 @@ using namespace dxil;
static ModuleMetadataInfo collectMetadataInfo(Module &M) {
ModuleMetadataInfo MMDAI;
- Triple TT(Triple(M.getTargetTriple()));
+ const Triple &TT = M.getTargetTriple();
MMDAI.DXILVersion = TT.getDXILVersion();
MMDAI.ShaderModelVersion = TT.getOSVersion();
MMDAI.ShaderProfile = TT.getEnvironment();
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index e9d96a0c2972a..1db0ca372d797 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -139,7 +139,7 @@ class Lint : public InstVisitor<Lint> {
Lint(Module *Mod, const DataLayout *DL, AliasAnalysis *AA,
AssumptionCache *AC, DominatorTree *DT, TargetLibraryInfo *TLI)
- : Mod(Mod), TT(Triple::normalize(Mod->getTargetTriple())), DL(DL), AA(AA),
+ : Mod(Mod), TT(Mod->getTargetTriple().normalize()), DL(DL), AA(AA),
AC(AC), DT(DT), TLI(TLI), MessagesStr(Messages) {}
void WriteValues(ArrayRef<const Value *> Vs) {
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 8557901192e40..3a8cdf946da37 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -118,7 +118,7 @@ static bool hasBcmp(const Triple &TT) {
return TT.isOSFreeBSD() || TT.isOSSolaris();
}
-static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT,
+static bool isCallingConvCCompatible(CallingConv::ID CC, const Triple &TT,
FunctionType *FuncTy) {
switch (CC) {
default:
@@ -131,7 +131,7 @@ static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT,
// The iOS ABI diverges from the standard in some cases, so for now don't
// try to simplify those calls.
- if (Triple(TT).isiOS())
+ if (TT.isiOS())
return false;
if (!FuncTy->getReturnType()->isPointerTy() &&
@@ -1446,8 +1446,7 @@ TargetLibraryInfoImpl::getVectorMappingInfo(StringRef F, const ElementCount &VF,
TargetLibraryInfo TargetLibraryAnalysis::run(const Function &F,
FunctionAnalysisManager &) {
if (!BaselineInfoImpl)
- BaselineInfoImpl =
- TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
+ BaselineInfoImpl = TargetLibraryInfoImpl(F.getParent()->getTargetTriple());
return TargetLibraryInfo(*BaselineInfoImpl, &F);
}
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 777bf5f7bb386..c8d792981793d 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -522,7 +522,7 @@ bool LLParser::parseTargetDefinitions(DataLayoutCallbackTy DataLayoutCallback) {
// Run the override callback to potentially change the data layout string, and
// parse the data layout string.
if (auto LayoutOverride =
- DataLayoutCallback(M->getTargetTriple(), TentativeDLStr)) {
+ DataLayoutCallback(M->getTargetTriple().str(), TentativeDLStr)) {
TentativeDLStr = *LayoutOverride;
DLStrLoc = {};
}
@@ -646,7 +646,7 @@ bool LLParser::parseTargetDefinition(std::string &TentativeDLStr,
if (parseToken(lltok::equal, "expected '=' after target triple") ||
parseStringConstant(Str))
return true;
- M->setTargetTriple(Str);
+ M->setTargetTriple(Triple(Str));
return false;
case lltok::kw_datalayout:
Lex.Lex();
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index d687495c42de6..e4dc7d6ed86b0 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -4530,12 +4530,12 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
// Auto-upgrade the layout string
TentativeDataLayoutStr = llvm::UpgradeDataLayoutString(
- TentativeDataLayoutStr, TheModule->getTargetTriple());
+ TentativeDataLayoutStr, TheModule->getTargetTriple().str());
// Apply override
if (Callbacks.DataLayout) {
if (auto LayoutOverride = (*Callbacks.DataLayout)(
- TheModule->getTargetTriple(), TentativeDataLayoutStr))
+ TheModule->getTargetTriple().str(), TentativeDataLayoutStr))
TentativeDataLayoutStr = *LayoutOverride;
}
@@ -4719,7 +4719,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
std::string S;
if (convertToString(Record, 0, S))
return error("Invalid record");
- TheModule->setTargetTriple(S);
+ TheModule->setTargetTriple(Triple(S));
break;
}
case bitc::MODULE_CODE_DATALAYOUT: { // DATALAYOUT: [strchr x N]
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 440a2c9ace8a3..6e2e45a51069d 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1449,8 +1449,8 @@ serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta) {
void ModuleBitcodeWriter::writeModuleInfo() {
// Emit various pieces of data attached to a module.
if (!M.getTargetTriple().empty())
- writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE, M.getTargetTriple(),
- 0 /*TODO*/);
+ writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE,
+ M.getTargetTriple().str(), 0 /*TODO*/);
const std::string &DL = M.getDataLayoutStr();
if (!DL.empty())
writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index bda0e266d01de..5c3b900ca29b6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -619,7 +619,7 @@ void CodeViewDebug::beginModule(Module *M) {
return;
}
- TheCPU = mapArchToCVCPUType(Triple(M->getTargetTriple()).getArch());
+ TheCPU = mapArchToCVCPUType(M->getTargetTriple().getArch());
// Get the current source language.
const MDNode *Node = *M->debug_compile_units_begin();
@@ -845,7 +845,7 @@ void CodeViewDebug::emitCompilerInformation() {
Flags |= static_cast<uint32_t>(CompileSym3Flags::PGO);
}
using ArchType = llvm::Triple::ArchType;
- ArchType Arch = Triple(MMI->getModule()->getTargetTriple()).getArch();
+ ArchType Arch = MMI->getModule()->getTargetTriple().getArch();
if (Asm->TM.Options.Hotpatch || Arch == ArchType::thumb ||
Arch == ArchType::aarch64) {
Flags |= static_cast<uint32_t>(CompileSym3Flags::HotPatch);
@@ -1098,7 +1098,7 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
FuncName = std::string(GlobalValue::dropLLVMManglingEscape(GV->getName()));
// Emit FPO data, but only on 32-bit x86. No other platforms use it.
- if (Triple(MMI->getModule()->getTargetTriple()).getArch() == Triple::x86)
+ if (MMI->getModule()->getTargetTriple().getArch() == Triple::x86)
OS.emitCVFPOData(Fn);
// Emit a symbol subsection, required by VS2012+ to find function boundaries.
@@ -1560,7 +1560,7 @@ void CodeViewDebug::beginFunctionImpl(const MachineFunction *MF) {
}
// Mark branches that may potentially be using jump tables with labels.
- bool isThumb = Triple(MMI->getModule()->getTargetTriple()).getArch() ==
+ bool isThumb = MMI->getModule()->getTargetTriple().getArch() ==
llvm::Triple::ArchType::thumb;
discoverJumpTableBranches(MF, isThumb);
}
@@ -3068,7 +3068,7 @@ void CodeViewDebug::endFunctionImpl(const MachineFunction *MF) {
}
}
- bool isThumb = T...
[truncated]
|
@llvm/pr-subscribers-backend-x86 Author: Nikita Popov (nikic) ChangesThe 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. Patch is 87.54 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/129868.diff 93 Files Affected:
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 1750719e17670..62a0e3c69bad1 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -595,7 +595,7 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
// Create the TargetMachine for generating code.
std::string Error;
- std::string Triple = TheModule->getTargetTriple();
+ std::string Triple = TheModule->getTargetTriple().str();
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
if (!TheTarget) {
if (MustCreateTM)
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 7aa3639cabf39..4321efd49af36 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1032,7 +1032,7 @@ CodeGenAction::loadModule(MemoryBufferRef MBRef) {
// linker using merged object file.
if (!Bm) {
auto M = std::make_unique<llvm::Module>("empty", *VMContext);
- M->setTargetTriple(CI.getTargetOpts().Triple);
+ M->setTargetTriple(Triple(CI.getTargetOpts().Triple));
return M;
}
Expected<std::unique_ptr<llvm::Module>> MOrErr =
@@ -1123,10 +1123,10 @@ void CodeGenAction::ExecuteAction() {
return;
const TargetOptions &TargetOpts = CI.getTargetOpts();
- if (TheModule->getTargetTriple() != TargetOpts.Triple) {
+ if (TheModule->getTargetTriple().str() != TargetOpts.Triple) {
Diagnostics.Report(SourceLocation(), diag::warn_fe_override_module)
<< TargetOpts.Triple;
- TheModule->setTargetTriple(TargetOpts.Triple);
+ TheModule->setTargetTriple(Triple(TargetOpts.Triple));
}
EmbedObject(TheModule.get(), CodeGenOpts, Diagnostics);
diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp
index d4e0ab0339a8b..09a7d79ae4afb 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -151,7 +151,7 @@ namespace {
void Initialize(ASTContext &Context) override {
Ctx = &Context;
- M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
+ M->setTargetTriple(Ctx->getTargetInfo().getTriple());
M->setDataLayout(Ctx->getTargetInfo().getDataLayoutString());
const auto &SDKVersion = Ctx->getTargetInfo().getSDKVersion();
if (!SDKVersion.empty())
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
index 788c8b932ab52..e32778d1b4767 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
@@ -255,7 +255,7 @@ class PCHContainerGenerator : public ASTConsumer {
if (Diags.hasErrorOccurred())
return;
- M->setTargetTriple(Ctx.getTargetInfo().getTriple().getTriple());
+ M->setTargetTriple(Ctx.getTargetInfo().getTriple());
M->setDataLayout(Ctx.getTargetInfo().getDataLayoutString());
// PCH files don't have a signature field in the control block,
diff --git a/clang/lib/Interpreter/DeviceOffload.cpp b/clang/lib/Interpreter/DeviceOffload.cpp
index 1999d63d1aa04..8fb484d185704 100644
--- a/clang/lib/Interpreter/DeviceOffload.cpp
+++ b/clang/lib/Interpreter/DeviceOffload.cpp
@@ -77,13 +77,13 @@ llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {
std::string Error;
const llvm::Target *Target = llvm::TargetRegistry::lookupTarget(
- PTU.TheModule->getTargetTriple(), Error);
+ PTU.TheModule->getTargetTriple().str(), Error);
if (!Target)
return llvm::make_error<llvm::StringError>(std::move(Error),
std::error_code());
llvm::TargetOptions TO = llvm::TargetOptions();
llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
- PTU.TheModule->getTargetTriple(), TargetOpts.CPU, "", TO,
+ PTU.TheModule->getTargetTriple().str(), TargetOpts.CPU, "", TO,
llvm::Reloc::Model::PIC_);
PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
diff --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index 798b34b3ef0af..4618c0bcc6be8 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -127,8 +127,8 @@ static std::string OptLLVM(const std::string &IR, CodeGenOptLevel OLvl) {
ErrorAndExit(E);
std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
- M->getTargetTriple(), codegen::getCPUStr(), codegen::getFeaturesStr(),
- Options, codegen::getExplicitRelocModel(),
+ M->getTargetTriple().str(), codegen::getCPUStr(),
+ codegen::getFeaturesStr(), Options, codegen::getExplicitRelocModel(),
codegen::getExplicitCodeModel(), OLvl));
if (!TM)
ErrorAndExit("Could not create target machine");
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 7db8f3e27d704..5f5d103bbcf49 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -622,16 +622,17 @@ Expected<StringRef> writeOffloadFile(const OffloadFile &File) {
Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
llvm::TimeTraceScope TimeScope("Compile module");
std::string Msg;
- const Target *T = TargetRegistry::lookupTarget(M.getTargetTriple(), Msg);
+ const Target *T =
+ TargetRegistry::lookupTarget(M.getTargetTriple().str(), Msg);
if (!T)
return createStringError(Msg);
auto Options =
- codegen::InitTargetOptionsFromCodeGenFlags(Triple(M.getTargetTriple()));
+ codegen::InitTargetOptionsFromCodeGenFlags(M.getTargetTriple());
StringRef CPU = "";
StringRef Features = "";
std::unique_ptr<TargetMachine> TM(
- T->createTargetMachine(M.getTargetTriple(), CPU, Features, Options,
+ T->createTargetMachine(M.getTargetTriple().str(), CPU, Features, Options,
Reloc::PIC_, M.getCodeModel()));
if (M.getDataLayout().isDefault())
@@ -650,7 +651,7 @@ Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
auto OS = std::make_unique<llvm::raw_fd_ostream>(FD, true);
legacy::PassManager CodeGenPasses;
- TargetLibraryInfoImpl TLII(Triple(M.getTargetTriple()));
+ TargetLibraryInfoImpl TLII(M.getTargetTriple());
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
if (TM->addPassesToEmitFile(CodeGenPasses, *OS, nullptr,
CodeGenFileType::ObjectFile))
@@ -674,8 +675,8 @@ wrapDeviceImages(ArrayRef<std::unique_ptr<MemoryBuffer>> Buffers,
LLVMContext Context;
Module M("offload.wrapper.module", Context);
- M.setTargetTriple(
- Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple()));
+ M.setTargetTriple(Triple(
+ Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple())));
switch (Kind) {
case OFK_OpenMP:
diff --git a/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp b/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
index f498a97442c44..78152af052c07 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
+++ b/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
@@ -207,7 +207,7 @@ int main(int Argc, char *Argv[]) {
ExitOnErr(JITTargetMachineBuilder::detectHost()));
} else {
Builder.setJITTargetMachineBuilder(
- JITTargetMachineBuilder(Triple(M.getTargetTriple())));
+ JITTargetMachineBuilder(M.getTargetTriple()));
}
if (!M.getDataLayout().getStringRepresentation().empty())
Builder.setDataLayout(M.getDataLayout());
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h
index 593f7a41337cb..67347e851ca1b 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h
@@ -104,7 +104,7 @@ class StaticInitGVIterator {
StaticInitGVIterator(Module &M)
: I(M.global_values().begin()), E(M.global_values().end()),
- ObjFmt(Triple(M.getTargetTriple()).getObjectFormat()) {
+ ObjFmt(M.getTargetTriple().getObjectFormat()) {
if (I != E) {
if (!isStaticInitGlobal(*I))
moveToNextStaticInitGlobal();
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 80b4aa2bd2855..28909cef4748d 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -479,7 +479,7 @@ class OpenMPIRBuilder {
/// not have an effect on \p M (see initialize)
OpenMPIRBuilder(Module &M)
: M(M), Builder(M.getContext()), OffloadInfoManager(this),
- T(Triple(M.getTargetTriple())) {}
+ T(M.getTargetTriple()) {}
~OpenMPIRBuilder();
class AtomicInfo : public llvm::AtomicInfo {
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 12b50fc506516..48dc29c24c582 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -31,6 +31,7 @@
#include "llvm/IR/SymbolTableListTraits.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/CodeGen.h"
+#include "llvm/TargetParser/Triple.h"
#include <cstddef>
#include <cstdint>
#include <iterator>
@@ -189,8 +190,10 @@ class LLVM_ABI Module {
std::string ModuleID; ///< Human readable identifier for the module
std::string SourceFileName; ///< Original source file name for module,
///< recorded in bitcode.
- std::string TargetTriple; ///< Platform target triple Module compiled on
- ///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
+ /// Platform target triple Module compiled on
+ /// Format: (arch)(sub)-(vendor)-(sys0-(abi)
+ // FIXME: Default construction is not the same as empty triple :(
+ Triple TargetTriple = Triple("");
NamedMDSymTabType NamedMDSymTab; ///< NamedMDNode names.
DataLayout DL; ///< DataLayout associated with the module
StringMap<unsigned>
@@ -294,8 +297,7 @@ class LLVM_ABI Module {
const DataLayout &getDataLayout() const { return DL; }
/// Get the target triple which is a string describing the target host.
- /// @returns a string containing the target triple.
- const std::string &getTargetTriple() const { return TargetTriple; }
+ const Triple &getTargetTriple() const { return TargetTriple; }
/// Get the global data context.
/// @returns LLVMContext - a container for LLVM's global information
@@ -338,7 +340,7 @@ class LLVM_ABI Module {
void setDataLayout(const DataLayout &Other);
/// Set the target triple.
- void setTargetTriple(StringRef T) { TargetTriple = std::string(T); }
+ void setTargetTriple(Triple T) { TargetTriple = std::move(T); }
/// Set the module-scope inline assembly blocks.
/// A trailing newline is added if the input doesn't have one.
diff --git a/llvm/include/llvm/LTO/legacy/LTOModule.h b/llvm/include/llvm/LTO/legacy/LTOModule.h
index e861a56bcbac1..91a38b7c0da80 100644
--- a/llvm/include/llvm/LTO/legacy/LTOModule.h
+++ b/llvm/include/llvm/LTO/legacy/LTOModule.h
@@ -118,14 +118,10 @@ struct LTOModule {
std::unique_ptr<Module> takeModule() { return std::move(Mod); }
/// Return the Module's target triple.
- const std::string &getTargetTriple() {
- return getModule().getTargetTriple();
- }
+ const Triple &getTargetTriple() { return getModule().getTargetTriple(); }
/// Set the Module's target triple.
- void setTargetTriple(StringRef Triple) {
- getModule().setTargetTriple(Triple);
- }
+ void setTargetTriple(Triple T) { getModule().setTargetTriple(T); }
/// Get the number of symbols
uint32_t getSymbolCount() {
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 09c0d223d9b4d..390ed7fbab8c0 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -463,6 +463,9 @@ class Triple {
const std::string &getTriple() const { return Data; }
+ /// Whether the triple is empty / default constructed.
+ bool empty() const { return Data.empty(); }
+
/// Get the architecture (first) component of the triple.
StringRef getArchName() const;
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index a7f666a3f8b48..87aa14e9c701f 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -24,7 +24,7 @@ using namespace dxil;
static ModuleMetadataInfo collectMetadataInfo(Module &M) {
ModuleMetadataInfo MMDAI;
- Triple TT(Triple(M.getTargetTriple()));
+ const Triple &TT = M.getTargetTriple();
MMDAI.DXILVersion = TT.getDXILVersion();
MMDAI.ShaderModelVersion = TT.getOSVersion();
MMDAI.ShaderProfile = TT.getEnvironment();
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index e9d96a0c2972a..1db0ca372d797 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -139,7 +139,7 @@ class Lint : public InstVisitor<Lint> {
Lint(Module *Mod, const DataLayout *DL, AliasAnalysis *AA,
AssumptionCache *AC, DominatorTree *DT, TargetLibraryInfo *TLI)
- : Mod(Mod), TT(Triple::normalize(Mod->getTargetTriple())), DL(DL), AA(AA),
+ : Mod(Mod), TT(Mod->getTargetTriple().normalize()), DL(DL), AA(AA),
AC(AC), DT(DT), TLI(TLI), MessagesStr(Messages) {}
void WriteValues(ArrayRef<const Value *> Vs) {
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 8557901192e40..3a8cdf946da37 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -118,7 +118,7 @@ static bool hasBcmp(const Triple &TT) {
return TT.isOSFreeBSD() || TT.isOSSolaris();
}
-static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT,
+static bool isCallingConvCCompatible(CallingConv::ID CC, const Triple &TT,
FunctionType *FuncTy) {
switch (CC) {
default:
@@ -131,7 +131,7 @@ static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT,
// The iOS ABI diverges from the standard in some cases, so for now don't
// try to simplify those calls.
- if (Triple(TT).isiOS())
+ if (TT.isiOS())
return false;
if (!FuncTy->getReturnType()->isPointerTy() &&
@@ -1446,8 +1446,7 @@ TargetLibraryInfoImpl::getVectorMappingInfo(StringRef F, const ElementCount &VF,
TargetLibraryInfo TargetLibraryAnalysis::run(const Function &F,
FunctionAnalysisManager &) {
if (!BaselineInfoImpl)
- BaselineInfoImpl =
- TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
+ BaselineInfoImpl = TargetLibraryInfoImpl(F.getParent()->getTargetTriple());
return TargetLibraryInfo(*BaselineInfoImpl, &F);
}
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 777bf5f7bb386..c8d792981793d 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -522,7 +522,7 @@ bool LLParser::parseTargetDefinitions(DataLayoutCallbackTy DataLayoutCallback) {
// Run the override callback to potentially change the data layout string, and
// parse the data layout string.
if (auto LayoutOverride =
- DataLayoutCallback(M->getTargetTriple(), TentativeDLStr)) {
+ DataLayoutCallback(M->getTargetTriple().str(), TentativeDLStr)) {
TentativeDLStr = *LayoutOverride;
DLStrLoc = {};
}
@@ -646,7 +646,7 @@ bool LLParser::parseTargetDefinition(std::string &TentativeDLStr,
if (parseToken(lltok::equal, "expected '=' after target triple") ||
parseStringConstant(Str))
return true;
- M->setTargetTriple(Str);
+ M->setTargetTriple(Triple(Str));
return false;
case lltok::kw_datalayout:
Lex.Lex();
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index d687495c42de6..e4dc7d6ed86b0 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -4530,12 +4530,12 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
// Auto-upgrade the layout string
TentativeDataLayoutStr = llvm::UpgradeDataLayoutString(
- TentativeDataLayoutStr, TheModule->getTargetTriple());
+ TentativeDataLayoutStr, TheModule->getTargetTriple().str());
// Apply override
if (Callbacks.DataLayout) {
if (auto LayoutOverride = (*Callbacks.DataLayout)(
- TheModule->getTargetTriple(), TentativeDataLayoutStr))
+ TheModule->getTargetTriple().str(), TentativeDataLayoutStr))
TentativeDataLayoutStr = *LayoutOverride;
}
@@ -4719,7 +4719,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
std::string S;
if (convertToString(Record, 0, S))
return error("Invalid record");
- TheModule->setTargetTriple(S);
+ TheModule->setTargetTriple(Triple(S));
break;
}
case bitc::MODULE_CODE_DATALAYOUT: { // DATALAYOUT: [strchr x N]
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 440a2c9ace8a3..6e2e45a51069d 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1449,8 +1449,8 @@ serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta) {
void ModuleBitcodeWriter::writeModuleInfo() {
// Emit various pieces of data attached to a module.
if (!M.getTargetTriple().empty())
- writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE, M.getTargetTriple(),
- 0 /*TODO*/);
+ writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE,
+ M.getTargetTriple().str(), 0 /*TODO*/);
const std::string &DL = M.getDataLayoutStr();
if (!DL.empty())
writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index bda0e266d01de..5c3b900ca29b6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -619,7 +619,7 @@ void CodeViewDebug::beginModule(Module *M) {
return;
}
- TheCPU = mapArchToCVCPUType(Triple(M->getTargetTriple()).getArch());
+ TheCPU = mapArchToCVCPUType(M->getTargetTriple().getArch());
// Get the current source language.
const MDNode *Node = *M->debug_compile_units_begin();
@@ -845,7 +845,7 @@ void CodeViewDebug::emitCompilerInformation() {
Flags |= static_cast<uint32_t>(CompileSym3Flags::PGO);
}
using ArchType = llvm::Triple::ArchType;
- ArchType Arch = Triple(MMI->getModule()->getTargetTriple()).getArch();
+ ArchType Arch = MMI->getModule()->getTargetTriple().getArch();
if (Asm->TM.Options.Hotpatch || Arch == ArchType::thumb ||
Arch == ArchType::aarch64) {
Flags |= static_cast<uint32_t>(CompileSym3Flags::HotPatch);
@@ -1098,7 +1098,7 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
FuncName = std::string(GlobalValue::dropLLVMManglingEscape(GV->getName()));
// Emit FPO data, but only on 32-bit x86. No other platforms use it.
- if (Triple(MMI->getModule()->getTargetTriple()).getArch() == Triple::x86)
+ if (MMI->getModule()->getTargetTriple().getArch() == Triple::x86)
OS.emitCVFPOData(Fn);
// Emit a symbol subsection, required by VS2012+ to find function boundaries.
@@ -1560,7 +1560,7 @@ void CodeViewDebug::beginFunctionImpl(const MachineFunction *MF) {
}
// Mark branches that may potentially be using jump tables with labels.
- bool isThumb = Triple(MMI->getModule()->getTargetTriple()).getArch() ==
+ bool isThumb = MMI->getModule()->getTargetTriple().getArch() ==
llvm::Triple::ArchType::thumb;
discoverJumpTableBranches(MF, isThumb);
}
@@ -3068,7 +3068,7 @@ void CodeViewDebug::endFunctionImpl(const MachineFunction *MF) {
}
}
- bool isThumb = T...
[truncated]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/203/builds/3703 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/205/builds/2494 Here is the relevant piece of the build log for the reference
|
Try to fix share libs build after #129868.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/204/builds/2515 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/14104 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/14101 Here is the relevant piece of the build log for the reference
|
To fix the shared libs build after #129868.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/24811 Here is the relevant piece of the build log for the reference
|
lands and reverts 979c275 [IR] Store Triple in Module (NFC) (llvm#129868)
setTargetTriple now accepts Triple rather than string llvm/llvm-project#129868 updated `setTargetTriple`
setTargetTriple now accepts Triple rather than string llvm/llvm-project#129868 updated `setTargetTriple`
setTargetTriple now accepts Triple rather than string llvm/llvm-project#129868 updated `setTargetTriple`
Rollup merge of rust-lang#138137 - ZequanWu:fix-triple, r=cuviper setTargetTriple now accepts Triple rather than string llvm/llvm-project#129868 updated `setTargetTriple`
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.
Compile-time: https://llvm-compile-time-tracker.com/compare.php?from=e5d5503e4efa48b61194b1e70e469aba91297bec&to=8187b17ebd5ab65ad8bcc0b4ec288d77cb4f739c&stat=instructions:u