Skip to content

Commit 819aa35

Browse files
authored
MC: Use Triple form of lookupTarget in more places (#157591)
1 parent cfd24cd commit 819aa35

28 files changed

+134
-139
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,9 @@ ToolChain::getTargetAndModeFromProgramName(StringRef PN) {
519519
StringRef Prefix(ProgName);
520520
Prefix = Prefix.slice(0, LastComponent);
521521
std::string IgnoredError;
522-
bool IsRegistered = llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError);
522+
523+
llvm::Triple Triple(Prefix);
524+
bool IsRegistered = llvm::TargetRegistry::lookupTarget(Triple, IgnoredError);
523525
return ParsedClangName{std::string(Prefix), ModeSuffix, DS->ModeFlag,
524526
IsRegistered};
525527
}

clang/lib/Parse/ParseStmtAsm.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,12 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
509509

510510
// We need an actual supported target.
511511
const llvm::Triple &TheTriple = Actions.Context.getTargetInfo().getTriple();
512-
const std::string &TT = TheTriple.getTriple();
513512
const llvm::Target *TheTarget = nullptr;
514513
if (!TheTriple.isX86()) {
515514
Diag(AsmLoc, diag::err_msasm_unsupported_arch) << TheTriple.getArchName();
516515
} else {
517516
std::string Error;
518-
TheTarget = llvm::TargetRegistry::lookupTarget(TT, Error);
517+
TheTarget = llvm::TargetRegistry::lookupTarget(TheTriple, Error);
519518
if (!TheTarget)
520519
Diag(AsmLoc, diag::err_msasm_unable_to_create_target) << Error;
521520
}

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -756,59 +756,56 @@ class RuntimeDyldCheckerExprEval {
756756

757757
Expected<TargetInfo> getTargetInfo(const Triple &TT, const StringRef &CPU,
758758
const SubtargetFeatures &TF) const {
759-
760-
auto TripleName = TT.str();
761759
std::string ErrorStr;
762-
const Target *TheTarget =
763-
TargetRegistry::lookupTarget(TripleName, ErrorStr);
760+
const Target *TheTarget = TargetRegistry::lookupTarget(TT, ErrorStr);
764761
if (!TheTarget)
765-
return make_error<StringError>("Error accessing target '" + TripleName +
762+
return make_error<StringError>("Error accessing target '" + TT.str() +
766763
"': " + ErrorStr,
767764
inconvertibleErrorCode());
768765

769766
std::unique_ptr<MCSubtargetInfo> STI(
770767
TheTarget->createMCSubtargetInfo(TT, CPU, TF.getString()));
771768
if (!STI)
772769
return make_error<StringError>("Unable to create subtarget for " +
773-
TripleName,
770+
TT.str(),
774771
inconvertibleErrorCode());
775772

776773
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT));
777774
if (!MRI)
778775
return make_error<StringError>("Unable to create target register info "
779776
"for " +
780-
TripleName,
777+
TT.str(),
781778
inconvertibleErrorCode());
782779

783780
MCTargetOptions MCOptions;
784781
std::unique_ptr<MCAsmInfo> MAI(
785782
TheTarget->createMCAsmInfo(*MRI, TT, MCOptions));
786783
if (!MAI)
787784
return make_error<StringError>("Unable to create target asm info " +
788-
TripleName,
785+
TT.str(),
789786
inconvertibleErrorCode());
790787

791-
auto Ctx = std::make_unique<MCContext>(Triple(TripleName), MAI.get(),
788+
auto Ctx = std::make_unique<MCContext>(Triple(TT.str()), MAI.get(),
792789
MRI.get(), STI.get());
793790

794791
std::unique_ptr<MCDisassembler> Disassembler(
795792
TheTarget->createMCDisassembler(*STI, *Ctx));
796793
if (!Disassembler)
797794
return make_error<StringError>("Unable to create disassembler for " +
798-
TripleName,
795+
TT.str(),
799796
inconvertibleErrorCode());
800797

801798
std::unique_ptr<MCInstrInfo> MII(TheTarget->createMCInstrInfo());
802799
if (!MII)
803800
return make_error<StringError>("Unable to create instruction info for" +
804-
TripleName,
801+
TT.str(),
805802
inconvertibleErrorCode());
806803

807-
std::unique_ptr<MCInstPrinter> InstPrinter(TheTarget->createMCInstPrinter(
808-
Triple(TripleName), 0, *MAI, *MII, *MRI));
804+
std::unique_ptr<MCInstPrinter> InstPrinter(
805+
TheTarget->createMCInstPrinter(TT, 0, *MAI, *MII, *MRI));
809806
if (!InstPrinter)
810807
return make_error<StringError>(
811-
"Unable to create instruction printer for" + TripleName,
808+
"Unable to create instruction printer for" + TT.str(),
812809
inconvertibleErrorCode());
813810

814811
return TargetInfo({TheTarget, std::move(STI), std::move(MRI),

llvm/lib/LTO/LTOCodeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ bool LTOCodeGenerator::determineTarget() {
384384

385385
// create target machine from info for merged modules
386386
std::string ErrMsg;
387-
MArch = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
387+
MArch = TargetRegistry::lookupTarget(Triple, ErrMsg);
388388
if (!MArch) {
389389
emitError(ErrMsg);
390390
return false;

llvm/lib/MC/MCDisassembler/Disassembler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ LLVMCreateDisasmCPUFeatures(const char *TT, const char *CPU,
4444
const char *Features, void *DisInfo, int TagType,
4545
LLVMOpInfoCallback GetOpInfo,
4646
LLVMSymbolLookupCallback SymbolLookUp) {
47+
Triple TheTriple(TT);
48+
4749
// Get the target.
4850
std::string Error;
49-
const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
51+
const Target *TheTarget = TargetRegistry::lookupTarget(TheTriple, Error);
5052
if (!TheTarget)
5153
return nullptr;
5254

53-
Triple TheTriple(TT);
5455
std::unique_ptr<const MCRegisterInfo> MRI(
5556
TheTarget->createMCRegInfo(TheTriple));
5657
if (!MRI)

llvm/lib/Target/TargetMachineC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ LLVMBool LLVMGetTargetFromTriple(const char* TripleStr, LLVMTargetRef *T,
8383
char **ErrorMessage) {
8484
std::string Error;
8585

86-
*T = wrap(TargetRegistry::lookupTarget(TripleStr, Error));
86+
Triple TT(TripleStr);
87+
*T = wrap(TargetRegistry::lookupTarget(TT, Error));
8788

8889
if (!*T) {
8990
if (ErrorMessage)

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,64 +2582,63 @@ struct TargetInfo {
25822582
static TargetInfo
25832583
getTargetInfo(const Triple &TT,
25842584
const SubtargetFeatures &TF = SubtargetFeatures()) {
2585-
auto TripleName = TT.str();
25862585
std::string ErrorStr;
2587-
const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, ErrorStr);
2586+
const Target *TheTarget = TargetRegistry::lookupTarget(TT, ErrorStr);
25882587
if (!TheTarget)
2589-
ExitOnErr(make_error<StringError>("Error accessing target '" + TripleName +
2588+
ExitOnErr(make_error<StringError>("Error accessing target '" + TT.str() +
25902589
"': " + ErrorStr,
25912590
inconvertibleErrorCode()));
25922591

25932592
std::unique_ptr<MCSubtargetInfo> STI(
25942593
TheTarget->createMCSubtargetInfo(TT, "", TF.getString()));
25952594
if (!STI)
25962595
ExitOnErr(
2597-
make_error<StringError>("Unable to create subtarget for " + TripleName,
2596+
make_error<StringError>("Unable to create subtarget for " + TT.str(),
25982597
inconvertibleErrorCode()));
25992598

26002599
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT));
26012600
if (!MRI)
26022601
ExitOnErr(make_error<StringError>("Unable to create target register info "
26032602
"for " +
2604-
TripleName,
2603+
TT.str(),
26052604
inconvertibleErrorCode()));
26062605

26072606
MCTargetOptions MCOptions;
26082607
std::unique_ptr<MCAsmInfo> MAI(
26092608
TheTarget->createMCAsmInfo(*MRI, TT, MCOptions));
26102609
if (!MAI)
2611-
ExitOnErr(make_error<StringError>("Unable to create target asm info " +
2612-
TripleName,
2613-
inconvertibleErrorCode()));
2610+
ExitOnErr(
2611+
make_error<StringError>("Unable to create target asm info " + TT.str(),
2612+
inconvertibleErrorCode()));
26142613

2615-
auto Ctx = std::make_unique<MCContext>(Triple(TripleName), MAI.get(),
2616-
MRI.get(), STI.get());
2614+
auto Ctx = std::make_unique<MCContext>(Triple(TT.str()), MAI.get(), MRI.get(),
2615+
STI.get());
26172616

26182617
std::unique_ptr<MCDisassembler> Disassembler(
26192618
TheTarget->createMCDisassembler(*STI, *Ctx));
26202619
if (!Disassembler)
2621-
ExitOnErr(make_error<StringError>("Unable to create disassembler for " +
2622-
TripleName,
2623-
inconvertibleErrorCode()));
2620+
ExitOnErr(
2621+
make_error<StringError>("Unable to create disassembler for " + TT.str(),
2622+
inconvertibleErrorCode()));
26242623

26252624
std::unique_ptr<MCInstrInfo> MII(TheTarget->createMCInstrInfo());
26262625
if (!MII)
26272626
ExitOnErr(make_error<StringError>("Unable to create instruction info for" +
2628-
TripleName,
2627+
TT.str(),
26292628
inconvertibleErrorCode()));
26302629

26312630
std::unique_ptr<MCInstrAnalysis> MIA(
26322631
TheTarget->createMCInstrAnalysis(MII.get()));
26332632
if (!MIA)
26342633
ExitOnErr(make_error<StringError>(
2635-
"Unable to create instruction analysis for" + TripleName,
2634+
"Unable to create instruction analysis for" + TT.str(),
26362635
inconvertibleErrorCode()));
26372636

26382637
std::unique_ptr<MCInstPrinter> InstPrinter(
2639-
TheTarget->createMCInstPrinter(Triple(TripleName), 0, *MAI, *MII, *MRI));
2638+
TheTarget->createMCInstPrinter(Triple(TT.str()), 0, *MAI, *MII, *MRI));
26402639
if (!InstPrinter)
26412640
ExitOnErr(make_error<StringError>(
2642-
"Unable to create instruction printer for" + TripleName,
2641+
"Unable to create instruction printer for" + TT.str(),
26432642
inconvertibleErrorCode()));
26442643
return {TheTarget, std::move(STI), std::move(MRI),
26452644
std::move(MAI), std::move(Ctx), std::move(Disassembler),

llvm/tools/llvm-objdump/MachODump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ static const Target *GetTarget(const MachOObjectFile *MachOObj,
147147

148148
// Get the target specific parser.
149149
std::string Error;
150-
const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
150+
const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
151151
if (TheTarget && ThumbTripleName.empty())
152152
return TheTarget;
153153

154-
*ThumbTarget = TargetRegistry::lookupTarget(ThumbTripleName, Error);
154+
*ThumbTarget = TargetRegistry::lookupTarget(ThumbTriple, Error);
155155
if (*ThumbTarget)
156156
return TheTarget;
157157

llvm/tools/llvm-split/llvm-split.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,23 @@ int main(int argc, char **argv) {
243243
cl::HideUnrelatedOptions({&SplitCategory, &getColorCategory()});
244244
cl::ParseCommandLineOptions(argc, argv, "LLVM module splitter\n");
245245

246+
Triple TT(MTriple);
247+
246248
std::unique_ptr<TargetMachine> TM;
247249
if (!MTriple.empty()) {
248250
InitializeAllTargets();
249251
InitializeAllTargetMCs();
250252

251253
std::string Error;
252-
const Target *T = TargetRegistry::lookupTarget(MTriple, Error);
254+
const Target *T = TargetRegistry::lookupTarget(TT, Error);
253255
if (!T) {
254256
errs() << "unknown target '" << MTriple << "': " << Error << "\n";
255257
return 1;
256258
}
257259

258260
TargetOptions Options;
259261
TM = std::unique_ptr<TargetMachine>(T->createTargetMachine(
260-
Triple(MTriple), MCPU, /*FS*/ "", Options, std::nullopt, std::nullopt));
262+
TT, MCPU, /*FS*/ "", Options, std::nullopt, std::nullopt));
261263
}
262264

263265
std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context);

llvm/tools/sancov/sancov.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ static void getObjectCoveragePoints(const object::ObjectFile &O,
706706
auto TripleName = TheTriple.getTriple();
707707

708708
std::string Error;
709-
const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
709+
const Target *TheTarget = TargetRegistry::lookupTarget(TheTriple, Error);
710710
failIfNotEmpty(Error);
711711

712712
std::unique_ptr<const MCSubtargetInfo> STI(

0 commit comments

Comments
 (0)