Skip to content

Commit fff720d

Browse files
authored
Triple: Forward declare Twine and remove include (#145685)
1 parent c824325 commit fff720d

File tree

14 files changed

+28
-22
lines changed

14 files changed

+28
-22
lines changed

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,8 +1461,7 @@ static IdentifierInfo *ExpectFeatureIdentifierInfo(Token &Tok,
14611461

14621462
/// Implements the __is_target_arch builtin macro.
14631463
static bool isTargetArch(const TargetInfo &TI, const IdentifierInfo *II) {
1464-
std::string ArchName = II->getName().lower() + "--";
1465-
llvm::Triple Arch(ArchName);
1464+
llvm::Triple Arch(II->getName().lower() + "--");
14661465
const llvm::Triple &TT = TI.getTriple();
14671466
if (TT.isThumb()) {
14681467
// arm matches thumb or thumbv7. armv7 matches thumbv7.
@@ -1491,9 +1490,7 @@ static bool isTargetVendor(const TargetInfo &TI, const IdentifierInfo *II) {
14911490

14921491
/// Implements the __is_target_os builtin macro.
14931492
static bool isTargetOS(const TargetInfo &TI, const IdentifierInfo *II) {
1494-
std::string OSName =
1495-
(llvm::Twine("unknown-unknown-") + II->getName().lower()).str();
1496-
llvm::Triple OS(OSName);
1493+
llvm::Triple OS(llvm::Twine("unknown-unknown-") + II->getName().lower());
14971494
if (OS.getOS() == llvm::Triple::Darwin) {
14981495
// Darwin matches macos, ios, etc.
14991496
return TI.getTriple().isOSDarwin();
@@ -1504,12 +1501,11 @@ static bool isTargetOS(const TargetInfo &TI, const IdentifierInfo *II) {
15041501
/// Implements the __is_target_environment builtin macro.
15051502
static bool isTargetEnvironment(const TargetInfo &TI,
15061503
const IdentifierInfo *II) {
1507-
std::string EnvName = (llvm::Twine("---") + II->getName().lower()).str();
1508-
llvm::Triple Env(EnvName);
1504+
llvm::Triple Env(llvm::Twine("---") + II->getName().lower());
15091505
// The unknown environment is matched only if
15101506
// '__is_target_environment(unknown)' is used.
15111507
if (Env.getEnvironment() == llvm::Triple::UnknownEnvironment &&
1512-
EnvName != "---unknown")
1508+
Env.getEnvironmentName() != "unknown")
15131509
return false;
15141510
return TI.getTriple().getEnvironment() == Env.getEnvironment();
15151511
}
@@ -1521,9 +1517,7 @@ static bool isTargetVariantOS(const TargetInfo &TI, const IdentifierInfo *II) {
15211517
if (!VariantTriple)
15221518
return false;
15231519

1524-
std::string OSName =
1525-
(llvm::Twine("unknown-unknown-") + II->getName().lower()).str();
1526-
llvm::Triple OS(OSName);
1520+
llvm::Triple OS(llvm::Twine("unknown-unknown-") + II->getName().lower());
15271521
if (OS.getOS() == llvm::Triple::Darwin) {
15281522
// Darwin matches macos, ios, etc.
15291523
return VariantTriple->isOSDarwin();
@@ -1540,8 +1534,7 @@ static bool isTargetVariantEnvironment(const TargetInfo &TI,
15401534
const llvm::Triple *VariantTriple = TI.getDarwinTargetVariantTriple();
15411535
if (!VariantTriple)
15421536
return false;
1543-
std::string EnvName = (llvm::Twine("---") + II->getName().lower()).str();
1544-
llvm::Triple Env(EnvName);
1537+
llvm::Triple Env(llvm::Twine("---") + II->getName().lower());
15451538
return VariantTriple->getEnvironment() == Env.getEnvironment();
15461539
}
15471540
return false;

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_TARGETPARSER_TRIPLE_H
1010
#define LLVM_TARGETPARSER_TRIPLE_H
1111

12-
#include "llvm/ADT/Twine.h"
12+
#include "llvm/ADT/StringRef.h"
1313
#include "llvm/Support/Compiler.h"
1414
#include "llvm/Support/VersionTuple.h"
1515

@@ -20,6 +20,7 @@
2020
#undef sparc
2121

2222
namespace llvm {
23+
class Twine;
2324

2425
/// Triple - Helper class for working with autoconf configuration names. For
2526
/// historical reasons, we also call these 'triples' (they used to contain
@@ -349,7 +350,12 @@ class Triple {
349350
/// triple fields unknown.
350351
Triple() = default;
351352

353+
LLVM_ABI explicit Triple(std::string &&Str);
354+
explicit Triple(StringRef Str) : Triple(Str.str()) {}
355+
explicit Triple(const char *Str) : Triple(std::string(Str)) {}
356+
explicit Triple(const std::string &Str) : Triple(std::string(Str)) {}
352357
LLVM_ABI explicit Triple(const Twine &Str);
358+
353359
LLVM_ABI Triple(const Twine &ArchStr, const Twine &VendorStr,
354360
const Twine &OSStr);
355361
LLVM_ABI Triple(const Twine &ArchStr, const Twine &VendorStr,

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ bool LLParser::parseTargetDefinition(std::string &TentativeDLStr,
633633
if (parseToken(lltok::equal, "expected '=' after target triple") ||
634634
parseStringConstant(Str))
635635
return true;
636-
M->setTargetTriple(Triple(Str));
636+
M->setTargetTriple(Triple(std::move(Str)));
637637
return false;
638638
case lltok::kw_datalayout:
639639
Lex.Lex();

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4695,7 +4695,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
46954695
std::string S;
46964696
if (convertToString(Record, 0, S))
46974697
return error("Invalid record");
4698-
TheModule->setTargetTriple(Triple(S));
4698+
TheModule->setTargetTriple(Triple(std::move(S)));
46994699
break;
47004700
}
47014701
case bitc::MODULE_CODE_DATALAYOUT: { // DATALAYOUT: [strchr x N]

llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out,
197197
return make_error<StringError>("createMCAsmBackend failed",
198198
inconvertibleErrorCode());
199199

200-
Triple T(getTargetTriple().str());
200+
Triple T(getTargetTriple());
201201
AsmStreamer.reset(getTarget().createMCObjectStreamer(
202202
T, Context, std::unique_ptr<MCAsmBackend>(MAB),
203203
DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut)

llvm/lib/MC/MCDisassembler/Disassembler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class LLVMDisasmContext {
9898
MAI(std::move(MAI)), MRI(std::move(MRI)), MSI(std::move(MSI)),
9999
MII(std::move(MII)), Ctx(std::move(Ctx)), DisAsm(std::move(DisAsm)),
100100
IP(std::move(IP)), Options(0), CommentStream(CommentsToEmit) {}
101-
const std::string &getTripleName() const { return TripleName; }
101+
StringRef getTripleName() const { return TripleName; }
102102
void *getDisInfo() const { return DisInfo; }
103103
int getTagType() const { return TagType; }
104104
LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; }

llvm/lib/MC/MCSectionELF.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/MC/MCSectionELF.h"
10+
#include "llvm/ADT/Twine.h"
1011
#include "llvm/BinaryFormat/ELF.h"
1112
#include "llvm/MC/MCAsmInfo.h"
1213
#include "llvm/MC/MCExpr.h"

llvm/lib/MC/MCSubtargetInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "llvm/MC/MCSubtargetInfo.h"
1010
#include "llvm/ADT/ArrayRef.h"
1111
#include "llvm/ADT/StringRef.h"
12+
#include "llvm/ADT/Twine.h"
1213
#include "llvm/MC/MCInstrItineraries.h"
1314
#include "llvm/MC/MCSchedule.h"
1415
#include "llvm/Support/Format.h"

llvm/lib/Object/ArchiveWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ static bool isECObject(object::SymbolicFile &Obj) {
700700
getBitcodeTargetTriple(Obj.getMemoryBufferRef());
701701
if (!TripleStr)
702702
return false;
703-
Triple T(*TripleStr);
703+
Triple T(std::move(*TripleStr));
704704
return T.isWindowsArm64EC() || T.getArch() == Triple::x86_64;
705705
}
706706

@@ -719,7 +719,7 @@ static bool isAnyArm64COFF(object::SymbolicFile &Obj) {
719719
getBitcodeTargetTriple(Obj.getMemoryBufferRef());
720720
if (!TripleStr)
721721
return false;
722-
Triple T(*TripleStr);
722+
Triple T(std::move(*TripleStr));
723723
return T.isOSWindows() && T.getArch() == Triple::aarch64;
724724
}
725725

llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
1515
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
1616

17+
#include "llvm/ADT/SmallVector.h"
1718
#include "llvm/IR/CallingConv.h"
1819
#include "llvm/Support/Alignment.h"
1920
#include "llvm/TargetParser/Triple.h"

0 commit comments

Comments
 (0)