-
Notifications
You must be signed in to change notification settings - Fork 15.2k
LTO: Stop storing string triple #157991
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
Merged
Merged
LTO: Stop storing string triple #157991
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Simplify Triple computing code and avoid reconstruction and string based logic
@llvm/pr-subscribers-lto Author: Matt Arsenault (arsenm) ChangesSimplify Triple computing code and avoid reconstruction and Full diff: https://github.com/llvm/llvm-project/pull/157991.diff 2 Files Affected:
diff --git a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
index 391589acba40a..806d3c5bdfd77 100644
--- a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
+++ b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
@@ -239,7 +239,6 @@ struct LTOCodeGenerator {
std::string FeatureStr;
std::string NativeObjectPath;
const Target *MArch = nullptr;
- std::string TripleStr;
lto_diagnostic_handler_t DiagHandler = nullptr;
void *DiagContext = nullptr;
bool ShouldInternalize = EnableLTOInternalization;
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 23e22e7ffcd5c..6f13df73e787b 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -375,16 +375,12 @@ bool LTOCodeGenerator::determineTarget() {
if (TargetMach)
return true;
- TripleStr = MergedModule->getTargetTriple().str();
- if (TripleStr.empty()) {
- TripleStr = sys::getDefaultTargetTriple();
- MergedModule->setTargetTriple(Triple(TripleStr));
- }
- llvm::Triple Triple(TripleStr);
+ if (const Triple &TT = MergedModule->getTargetTriple(); TT.empty())
+ MergedModule->setTargetTriple(Triple(sys::getDefaultTargetTriple()));
// create target machine from info for merged modules
std::string ErrMsg;
- MArch = TargetRegistry::lookupTarget(Triple, ErrMsg);
+ MArch = TargetRegistry::lookupTarget(MergedModule->getTargetTriple(), ErrMsg);
if (!MArch) {
emitError(ErrMsg);
return false;
@@ -393,10 +389,10 @@ bool LTOCodeGenerator::determineTarget() {
// Construct LTOModule, hand over ownership of module and target. Use MAttr as
// the default set of features.
SubtargetFeatures Features(join(Config.MAttrs, ""));
- Features.getDefaultSubtargetFeatures(Triple);
+ Features.getDefaultSubtargetFeatures(MergedModule->getTargetTriple());
FeatureStr = Features.getString();
if (Config.CPU.empty())
- Config.CPU = lto::getThinLTODefaultCPU(Triple);
+ Config.CPU = lto::getThinLTODefaultCPU(MergedModule->getTargetTriple());
// If data-sections is not explicitly set or unset, set data-sections by
// default to match the behaviour of lld and gold plugin.
@@ -412,7 +408,7 @@ bool LTOCodeGenerator::determineTarget() {
std::unique_ptr<TargetMachine> LTOCodeGenerator::createTargetMachine() {
assert(MArch && "MArch is not set!");
return std::unique_ptr<TargetMachine>(MArch->createTargetMachine(
- Triple(TripleStr), Config.CPU, FeatureStr, Config.Options,
+ MergedModule->getTargetTriple(), Config.CPU, FeatureStr, Config.Options,
Config.RelocModel, std::nullopt, Config.CGOptLevel));
}
|
fhahn
reviewed
Sep 11, 2025
Co-authored-by: Florian Hahn <flo@fhahn.com>
fzou1
approved these changes
Sep 11, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Simplify Triple computing code and avoid reconstruction and
string based logic