Author: Matt Arsenault Date: 2025-06-26T15:26:04+09:00 New Revision: fff720d6419b92be068ac4f3ac7e8333a781ee20
URL: https://github.com/llvm/llvm-project/commit/fff720d6419b92be068ac4f3ac7e8333a781ee20 DIFF: https://github.com/llvm/llvm-project/commit/fff720d6419b92be068ac4f3ac7e8333a781ee20.diff LOG: Triple: Forward declare Twine and remove include (#145685) Added: Modified: clang/lib/Lex/PPMacroExpansion.cpp llvm/include/llvm/TargetParser/Triple.h llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp llvm/lib/MC/MCDisassembler/Disassembler.h llvm/lib/MC/MCSectionELF.cpp llvm/lib/MC/MCSubtargetInfo.cpp llvm/lib/Object/ArchiveWriter.cpp llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h llvm/lib/TargetParser/CSKYTargetParser.cpp llvm/lib/TargetParser/LoongArchTargetParser.cpp llvm/lib/TargetParser/Triple.cpp llvm/lib/TargetParser/Unix/Host.inc Removed: ################################################################################ diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index b8b91e32179af..890567cfd3246 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1461,8 +1461,7 @@ static IdentifierInfo *ExpectFeatureIdentifierInfo(Token &Tok, /// Implements the __is_target_arch builtin macro. static bool isTargetArch(const TargetInfo &TI, const IdentifierInfo *II) { - std::string ArchName = II->getName().lower() + "--"; - llvm::Triple Arch(ArchName); + llvm::Triple Arch(II->getName().lower() + "--"); const llvm::Triple &TT = TI.getTriple(); if (TT.isThumb()) { // arm matches thumb or thumbv7. armv7 matches thumbv7. @@ -1491,9 +1490,7 @@ static bool isTargetVendor(const TargetInfo &TI, const IdentifierInfo *II) { /// Implements the __is_target_os builtin macro. static bool isTargetOS(const TargetInfo &TI, const IdentifierInfo *II) { - std::string OSName = - (llvm::Twine("unknown-unknown-") + II->getName().lower()).str(); - llvm::Triple OS(OSName); + llvm::Triple OS(llvm::Twine("unknown-unknown-") + II->getName().lower()); if (OS.getOS() == llvm::Triple::Darwin) { // Darwin matches macos, ios, etc. return TI.getTriple().isOSDarwin(); @@ -1504,12 +1501,11 @@ static bool isTargetOS(const TargetInfo &TI, const IdentifierInfo *II) { /// Implements the __is_target_environment builtin macro. static bool isTargetEnvironment(const TargetInfo &TI, const IdentifierInfo *II) { - std::string EnvName = (llvm::Twine("---") + II->getName().lower()).str(); - llvm::Triple Env(EnvName); + llvm::Triple Env(llvm::Twine("---") + II->getName().lower()); // The unknown environment is matched only if // '__is_target_environment(unknown)' is used. if (Env.getEnvironment() == llvm::Triple::UnknownEnvironment && - EnvName != "---unknown") + Env.getEnvironmentName() != "unknown") return false; return TI.getTriple().getEnvironment() == Env.getEnvironment(); } @@ -1521,9 +1517,7 @@ static bool isTargetVariantOS(const TargetInfo &TI, const IdentifierInfo *II) { if (!VariantTriple) return false; - std::string OSName = - (llvm::Twine("unknown-unknown-") + II->getName().lower()).str(); - llvm::Triple OS(OSName); + llvm::Triple OS(llvm::Twine("unknown-unknown-") + II->getName().lower()); if (OS.getOS() == llvm::Triple::Darwin) { // Darwin matches macos, ios, etc. return VariantTriple->isOSDarwin(); @@ -1540,8 +1534,7 @@ static bool isTargetVariantEnvironment(const TargetInfo &TI, const llvm::Triple *VariantTriple = TI.getDarwinTargetVariantTriple(); if (!VariantTriple) return false; - std::string EnvName = (llvm::Twine("---") + II->getName().lower()).str(); - llvm::Triple Env(EnvName); + llvm::Triple Env(llvm::Twine("---") + II->getName().lower()); return VariantTriple->getEnvironment() == Env.getEnvironment(); } return false; diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h index 1865be6e95dea..cbf85b2ff74f5 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -9,7 +9,7 @@ #ifndef LLVM_TARGETPARSER_TRIPLE_H #define LLVM_TARGETPARSER_TRIPLE_H -#include "llvm/ADT/Twine.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/VersionTuple.h" @@ -20,6 +20,7 @@ #undef sparc namespace llvm { +class Twine; /// Triple - Helper class for working with autoconf configuration names. For /// historical reasons, we also call these 'triples' (they used to contain @@ -349,7 +350,12 @@ class Triple { /// triple fields unknown. Triple() = default; + LLVM_ABI explicit Triple(std::string &&Str); + explicit Triple(StringRef Str) : Triple(Str.str()) {} + explicit Triple(const char *Str) : Triple(std::string(Str)) {} + explicit Triple(const std::string &Str) : Triple(std::string(Str)) {} LLVM_ABI explicit Triple(const Twine &Str); + LLVM_ABI Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr); LLVM_ABI Triple(const Twine &ArchStr, const Twine &VendorStr, diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 792a194aeb499..c5e166cef6da6 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -633,7 +633,7 @@ bool LLParser::parseTargetDefinition(std::string &TentativeDLStr, if (parseToken(lltok::equal, "expected '=' after target triple") || parseStringConstant(Str)) return true; - M->setTargetTriple(Triple(Str)); + M->setTargetTriple(Triple(std::move(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 e91f791ab5788..c6549e72d48c0 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4695,7 +4695,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit, std::string S; if (convertToString(Record, 0, S)) return error("Invalid record"); - TheModule->setTargetTriple(Triple(S)); + TheModule->setTargetTriple(Triple(std::move(S))); break; } case bitc::MODULE_CODE_DATALAYOUT: { // DATALAYOUT: [strchr x N] diff --git a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp index 4a3503a2da7db..125ffd597bf23 100644 --- a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp +++ b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp @@ -197,7 +197,7 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out, return make_error<StringError>("createMCAsmBackend failed", inconvertibleErrorCode()); - Triple T(getTargetTriple().str()); + Triple T(getTargetTriple()); AsmStreamer.reset(getTarget().createMCObjectStreamer( T, Context, std::unique_ptr<MCAsmBackend>(MAB), DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut) diff --git a/llvm/lib/MC/MCDisassembler/Disassembler.h b/llvm/lib/MC/MCDisassembler/Disassembler.h index 3cb2479d388f6..4c34d86437b1f 100644 --- a/llvm/lib/MC/MCDisassembler/Disassembler.h +++ b/llvm/lib/MC/MCDisassembler/Disassembler.h @@ -98,7 +98,7 @@ class LLVMDisasmContext { MAI(std::move(MAI)), MRI(std::move(MRI)), MSI(std::move(MSI)), MII(std::move(MII)), Ctx(std::move(Ctx)), DisAsm(std::move(DisAsm)), IP(std::move(IP)), Options(0), CommentStream(CommentsToEmit) {} - const std::string &getTripleName() const { return TripleName; } + StringRef getTripleName() const { return TripleName; } void *getDisInfo() const { return DisInfo; } int getTagType() const { return TagType; } LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; } diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp index 72a959b1c9208..181c4ff25d541 100644 --- a/llvm/lib/MC/MCSectionELF.cpp +++ b/llvm/lib/MC/MCSectionELF.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCSectionELF.h" +#include "llvm/ADT/Twine.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCExpr.h" diff --git a/llvm/lib/MC/MCSubtargetInfo.cpp b/llvm/lib/MC/MCSubtargetInfo.cpp index d86eaad48420d..89a08327dd259 100644 --- a/llvm/lib/MC/MCSubtargetInfo.cpp +++ b/llvm/lib/MC/MCSubtargetInfo.cpp @@ -9,6 +9,7 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" #include "llvm/MC/MCInstrItineraries.h" #include "llvm/MC/MCSchedule.h" #include "llvm/Support/Format.h" diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp index c61ba868efe60..6fc0889afc6a8 100644 --- a/llvm/lib/Object/ArchiveWriter.cpp +++ b/llvm/lib/Object/ArchiveWriter.cpp @@ -700,7 +700,7 @@ static bool isECObject(object::SymbolicFile &Obj) { getBitcodeTargetTriple(Obj.getMemoryBufferRef()); if (!TripleStr) return false; - Triple T(*TripleStr); + Triple T(std::move(*TripleStr)); return T.isWindowsArm64EC() || T.getArch() == Triple::x86_64; } @@ -719,7 +719,7 @@ static bool isAnyArm64COFF(object::SymbolicFile &Obj) { getBitcodeTargetTriple(Obj.getMemoryBufferRef()); if (!TripleStr) return false; - Triple T(*TripleStr); + Triple T(std::move(*TripleStr)); return T.isOSWindows() && T.getArch() == Triple::aarch64; } diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h index 23826cc22250a..7c24f428d78e4 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h +++ b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h @@ -14,6 +14,7 @@ #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H #define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H +#include "llvm/ADT/SmallVector.h" #include "llvm/IR/CallingConv.h" #include "llvm/Support/Alignment.h" #include "llvm/TargetParser/Triple.h" diff --git a/llvm/lib/TargetParser/CSKYTargetParser.cpp b/llvm/lib/TargetParser/CSKYTargetParser.cpp index 006d2bb342acc..5fea08e38e2db 100644 --- a/llvm/lib/TargetParser/CSKYTargetParser.cpp +++ b/llvm/lib/TargetParser/CSKYTargetParser.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "llvm/TargetParser/CSKYTargetParser.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringSwitch.h" using namespace llvm; diff --git a/llvm/lib/TargetParser/LoongArchTargetParser.cpp b/llvm/lib/TargetParser/LoongArchTargetParser.cpp index db68498609b57..572a278a39fce 100644 --- a/llvm/lib/TargetParser/LoongArchTargetParser.cpp +++ b/llvm/lib/TargetParser/LoongArchTargetParser.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/TargetParser/LoongArchTargetParser.h" +#include "llvm/ADT/SmallVector.h" using namespace llvm; using namespace llvm::LoongArch; diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp index 42ed914f6dc73..a348640d75f26 100644 --- a/llvm/lib/TargetParser/Triple.cpp +++ b/llvm/lib/TargetParser/Triple.cpp @@ -1018,7 +1018,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { /// /// This stores the string representation and parses the various pieces into /// enum members. -Triple::Triple(const Twine &Str) : Data(Str.str()) { +Triple::Triple(std::string &&Str) : Data(std::move(Str)) { // Do minimal parsing by hand here. SmallVector<StringRef, 4> Components; StringRef(Data).split(Components, '-', /*MaxSplit*/ 3); @@ -1049,6 +1049,8 @@ Triple::Triple(const Twine &Str) : Data(Str.str()) { ObjectFormat = getDefaultFormat(*this); } +Triple::Triple(const Twine &Str) : Triple(Str.str()) {} + /// Construct a triple from string representations of the architecture, /// vendor, and OS. /// diff --git a/llvm/lib/TargetParser/Unix/Host.inc b/llvm/lib/TargetParser/Unix/Host.inc index a33fe6fff8936..ef9e288ee3a01 100644 --- a/llvm/lib/TargetParser/Unix/Host.inc +++ b/llvm/lib/TargetParser/Unix/Host.inc @@ -55,7 +55,7 @@ static std::string updateTripleOSVersion(std::string TargetTripleString) { // On AIX, the AIX version and release should be that of the current host // unless if the version has already been specified. if (Triple(LLVM_HOST_TRIPLE).getOS() == Triple::AIX) { - Triple TT(TargetTripleString); + Triple TT(std::move(TargetTripleString)); if (TT.getOS() == Triple::AIX && !TT.getOSMajorVersion()) { struct utsname name; if (uname(&name) != -1) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits