aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2025-03-06 10:27:47 +0100
committerGitHub <noreply@github.com>2025-03-06 10:27:47 +0100
commit979c275097a642e9b96c6b0a12f013c831af3a6e (patch)
treeaf2b2a814562e086ef34605665b304ceae887007 /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
parentf01e760c08365426de95f02dc2c2dc670eb47352 (diff)
downloadllvm-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/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 440a2c9..a3556af 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*/);
@@ -5331,7 +5331,7 @@ void BitcodeWriter::writeSymtab() {
std::string Err;
const Triple TT(M->getTargetTriple());
- const Target *T = TargetRegistry::lookupTarget(TT.str(), Err);
+ const Target *T = TargetRegistry::lookupTarget(TT, Err);
if (!T || !T->hasMCAsmParser())
return;
}