Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,9 @@ ToolChain::getTargetAndModeFromProgramName(StringRef PN) {
StringRef Prefix(ProgName);
Prefix = Prefix.slice(0, LastComponent);
std::string IgnoredError;
bool IsRegistered = llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError);

llvm::Triple Triple(Prefix);
bool IsRegistered = llvm::TargetRegistry::lookupTarget(Triple, IgnoredError);
return ParsedClangName{std::string(Prefix), ModeSuffix, DS->ModeFlag,
IsRegistered};
}
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Parse/ParseStmtAsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,12 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {

// We need an actual supported target.
const llvm::Triple &TheTriple = Actions.Context.getTargetInfo().getTriple();
const std::string &TT = TheTriple.getTriple();
const llvm::Target *TheTarget = nullptr;
if (!TheTriple.isX86()) {
Diag(AsmLoc, diag::err_msasm_unsupported_arch) << TheTriple.getArchName();
} else {
std::string Error;
TheTarget = llvm::TargetRegistry::lookupTarget(TT, Error);
TheTarget = llvm::TargetRegistry::lookupTarget(TheTriple, Error);
if (!TheTarget)
Diag(AsmLoc, diag::err_msasm_unable_to_create_target) << Error;
}
Expand Down
25 changes: 11 additions & 14 deletions llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,59 +756,56 @@ class RuntimeDyldCheckerExprEval {

Expected<TargetInfo> getTargetInfo(const Triple &TT, const StringRef &CPU,
const SubtargetFeatures &TF) const {

auto TripleName = TT.str();
std::string ErrorStr;
const Target *TheTarget =
TargetRegistry::lookupTarget(TripleName, ErrorStr);
const Target *TheTarget = TargetRegistry::lookupTarget(TT, ErrorStr);
if (!TheTarget)
return make_error<StringError>("Error accessing target '" + TripleName +
return make_error<StringError>("Error accessing target '" + TT.str() +
"': " + ErrorStr,
inconvertibleErrorCode());

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

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

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

auto Ctx = std::make_unique<MCContext>(Triple(TripleName), MAI.get(),
auto Ctx = std::make_unique<MCContext>(Triple(TT.str()), MAI.get(),
MRI.get(), STI.get());

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

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

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

return TargetInfo({TheTarget, std::move(STI), std::move(MRI),
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/LTO/LTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ bool LTOCodeGenerator::determineTarget() {

// create target machine from info for merged modules
std::string ErrMsg;
MArch = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
MArch = TargetRegistry::lookupTarget(Triple, ErrMsg);
if (!MArch) {
emitError(ErrMsg);
return false;
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/MC/MCDisassembler/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ LLVMCreateDisasmCPUFeatures(const char *TT, const char *CPU,
const char *Features, void *DisInfo, int TagType,
LLVMOpInfoCallback GetOpInfo,
LLVMSymbolLookupCallback SymbolLookUp) {
Triple TheTriple(TT);

// Get the target.
std::string Error;
const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
const Target *TheTarget = TargetRegistry::lookupTarget(TheTriple, Error);
if (!TheTarget)
return nullptr;

Triple TheTriple(TT);
std::unique_ptr<const MCRegisterInfo> MRI(
TheTarget->createMCRegInfo(TheTriple));
if (!MRI)
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/TargetMachineC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ LLVMBool LLVMGetTargetFromTriple(const char* TripleStr, LLVMTargetRef *T,
char **ErrorMessage) {
std::string Error;

*T = wrap(TargetRegistry::lookupTarget(TripleStr, Error));
Triple TT(TripleStr);
*T = wrap(TargetRegistry::lookupTarget(TT, Error));

if (!*T) {
if (ErrorMessage)
Expand Down
33 changes: 16 additions & 17 deletions llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2582,64 +2582,63 @@ struct TargetInfo {
static TargetInfo
getTargetInfo(const Triple &TT,
const SubtargetFeatures &TF = SubtargetFeatures()) {
auto TripleName = TT.str();
std::string ErrorStr;
const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, ErrorStr);
const Target *TheTarget = TargetRegistry::lookupTarget(TT, ErrorStr);
if (!TheTarget)
ExitOnErr(make_error<StringError>("Error accessing target '" + TripleName +
ExitOnErr(make_error<StringError>("Error accessing target '" + TT.str() +
"': " + ErrorStr,
inconvertibleErrorCode()));

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

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

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

auto Ctx = std::make_unique<MCContext>(Triple(TripleName), MAI.get(),
MRI.get(), STI.get());
auto Ctx = std::make_unique<MCContext>(Triple(TT.str()), MAI.get(), MRI.get(),
STI.get());

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

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

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

std::unique_ptr<MCInstPrinter> InstPrinter(
TheTarget->createMCInstPrinter(Triple(TripleName), 0, *MAI, *MII, *MRI));
TheTarget->createMCInstPrinter(Triple(TT.str()), 0, *MAI, *MII, *MRI));
if (!InstPrinter)
ExitOnErr(make_error<StringError>(
"Unable to create instruction printer for" + TripleName,
"Unable to create instruction printer for" + TT.str(),
inconvertibleErrorCode()));
return {TheTarget, std::move(STI), std::move(MRI),
std::move(MAI), std::move(Ctx), std::move(Disassembler),
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/llvm-objdump/MachODump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ static const Target *GetTarget(const MachOObjectFile *MachOObj,

// Get the target specific parser.
std::string Error;
const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
if (TheTarget && ThumbTripleName.empty())
return TheTarget;

*ThumbTarget = TargetRegistry::lookupTarget(ThumbTripleName, Error);
*ThumbTarget = TargetRegistry::lookupTarget(ThumbTriple, Error);
if (*ThumbTarget)
return TheTarget;

Expand Down
6 changes: 4 additions & 2 deletions llvm/tools/llvm-split/llvm-split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,23 @@ int main(int argc, char **argv) {
cl::HideUnrelatedOptions({&SplitCategory, &getColorCategory()});
cl::ParseCommandLineOptions(argc, argv, "LLVM module splitter\n");

Triple TT(MTriple);

std::unique_ptr<TargetMachine> TM;
if (!MTriple.empty()) {
InitializeAllTargets();
InitializeAllTargetMCs();

std::string Error;
const Target *T = TargetRegistry::lookupTarget(MTriple, Error);
const Target *T = TargetRegistry::lookupTarget(TT, Error);
if (!T) {
errs() << "unknown target '" << MTriple << "': " << Error << "\n";
return 1;
}

TargetOptions Options;
TM = std::unique_ptr<TargetMachine>(T->createTargetMachine(
Triple(MTriple), MCPU, /*FS*/ "", Options, std::nullopt, std::nullopt));
TT, MCPU, /*FS*/ "", Options, std::nullopt, std::nullopt));
}

std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context);
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/sancov/sancov.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ static void getObjectCoveragePoints(const object::ObjectFile &O,
auto TripleName = TheTriple.getTriple();

std::string Error;
const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
const Target *TheTarget = TargetRegistry::lookupTarget(TheTriple, Error);
failIfNotEmpty(Error);

std::unique_ptr<const MCSubtargetInfo> STI(
Expand Down
3 changes: 2 additions & 1 deletion llvm/unittests/CodeGen/TestAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ llvm::Expected<std::unique_ptr<TestAsmPrinter>>
TestAsmPrinter::create(const std::string &TripleStr, uint16_t DwarfVersion,
dwarf::DwarfFormat DwarfFormat) {
std::string ErrorStr;
const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrorStr);
Triple TT(TripleStr);
const Target *TheTarget = TargetRegistry::lookupTarget(TT, ErrorStr);
if (!TheTarget)
return std::unique_ptr<TestAsmPrinter>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ class DWARFExpressionCompactPrinterTest : public ::testing::Test {
InitializeAllTargetMCs();
InitializeAllAsmPrinters();

std::string TripleName = "armv8a-linux-gnueabi";
Triple TT("armv8a-linux-gnueabi");
std::string ErrorStr;

const Target *TheTarget =
TargetRegistry::lookupTarget(TripleName, ErrorStr);
const Target *TheTarget = TargetRegistry::lookupTarget(TT, ErrorStr);

if (!TheTarget)
return;

MRI.reset(TheTarget->createMCRegInfo(Triple(TripleName)));
MRI.reset(TheTarget->createMCRegInfo(TT));
}

void TestExprPrinter(ArrayRef<uint8_t> ExprData, StringRef Expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DWARFExpressionCopyBytesTest : public ::testing::Test {
InitializeAllAsmPrinters();

std::string ErrorStr;
TheTarget = TargetRegistry::lookupTarget(TripleName, ErrorStr);
TheTarget = TargetRegistry::lookupTarget(TheTriple, ErrorStr);
if (!TheTarget)
return;

Expand Down
Loading