[llvm] 819aa35 - MC: Use Triple form of lookupTarget in more places (#157591)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 00:33:44 PDT 2025
Author: Matt Arsenault
Date: 2025-09-09T16:33:39+09:00
New Revision: 819aa3521ead28abaa9df6b35dca0529f4524fb8
URL: https://github.com/llvm/llvm-project/commit/819aa3521ead28abaa9df6b35dca0529f4524fb8
DIFF: https://github.com/llvm/llvm-project/commit/819aa3521ead28abaa9df6b35dca0529f4524fb8.diff
LOG: MC: Use Triple form of lookupTarget in more places (#157591)
Added:
Modified:
clang/lib/Driver/ToolChain.cpp
clang/lib/Parse/ParseStmtAsm.cpp
llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/lib/MC/MCDisassembler/Disassembler.cpp
llvm/lib/Target/TargetMachineC.cpp
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
llvm/tools/llvm-objdump/MachODump.cpp
llvm/tools/llvm-split/llvm-split.cpp
llvm/tools/sancov/sancov.cpp
llvm/unittests/CodeGen/TestAsmPrinter.cpp
llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp
llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h
llvm/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h
llvm/unittests/MC/AMDGPU/Disassembler.cpp
llvm/unittests/MC/DwarfLineTableHeaders.cpp
llvm/unittests/MC/MCInstPrinter.cpp
llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
llvm/unittests/MC/SystemZ/SystemZMCDisassemblerTest.cpp
llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
llvm/unittests/Target/AArch64/MCInstrAnalysisTest.cpp
llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp
llvm/unittests/Target/RISCV/MCInstrAnalysisTest.cpp
llvm/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp
llvm/unittests/tools/llvm-exegesis/PowerPC/AnalysisTest.cpp
llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 49c89ab0c037f..a9041d26c7ba4 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -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};
}
diff --git a/clang/lib/Parse/ParseStmtAsm.cpp b/clang/lib/Parse/ParseStmtAsm.cpp
index 48338566e789d..d434ddbae6f58 100644
--- a/clang/lib/Parse/ParseStmtAsm.cpp
+++ b/clang/lib/Parse/ParseStmtAsm.cpp
@@ -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;
}
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
index df702130450d5..afe3b671547d8 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
@@ -756,13 +756,10 @@ 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());
@@ -770,14 +767,14 @@ class RuntimeDyldCheckerExprEval {
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;
@@ -785,30 +782,30 @@ class RuntimeDyldCheckerExprEval {
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),
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 09b91d81225a8..cdeab98ff6c98 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -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;
diff --git a/llvm/lib/MC/MCDisassembler/Disassembler.cpp b/llvm/lib/MC/MCDisassembler/Disassembler.cpp
index ba5e9feb601ca..0429227f0fecf 100644
--- a/llvm/lib/MC/MCDisassembler/Disassembler.cpp
+++ b/llvm/lib/MC/MCDisassembler/Disassembler.cpp
@@ -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)
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp
index da6d35c8c8b43..aba6ea436e767 100644
--- a/llvm/lib/Target/TargetMachineC.cpp
+++ b/llvm/lib/Target/TargetMachineC.cpp
@@ -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)
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 6ff91b4bf47b8..31bf6a9d2d9c8 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -2582,11 +2582,10 @@ 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()));
@@ -2594,52 +2593,52 @@ getTargetInfo(const Triple &TT,
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),
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index 9b0eb63921964..8e9c91fde544d 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -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;
diff --git a/llvm/tools/llvm-split/llvm-split.cpp b/llvm/tools/llvm-split/llvm-split.cpp
index 97713c481a71a..a2877af782b80 100644
--- a/llvm/tools/llvm-split/llvm-split.cpp
+++ b/llvm/tools/llvm-split/llvm-split.cpp
@@ -243,13 +243,15 @@ 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;
@@ -257,7 +259,7 @@ int main(int argc, char **argv) {
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);
diff --git a/llvm/tools/sancov/sancov.cpp b/llvm/tools/sancov/sancov.cpp
index b57a9d703459a..a0585fad024c7 100644
--- a/llvm/tools/sancov/sancov.cpp
+++ b/llvm/tools/sancov/sancov.cpp
@@ -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(
diff --git a/llvm/unittests/CodeGen/TestAsmPrinter.cpp b/llvm/unittests/CodeGen/TestAsmPrinter.cpp
index 0c799ef901a0b..8d30e457178fc 100644
--- a/llvm/unittests/CodeGen/TestAsmPrinter.cpp
+++ b/llvm/unittests/CodeGen/TestAsmPrinter.cpp
@@ -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>();
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
index db7690668facc..41acc8240c720 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
@@ -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);
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp
index b67dd6a9d237d..f51c2004d46c0 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp
@@ -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;
diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp b/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
index 8a4924fa92723..bc43515b3b1d2 100644
--- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
+++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
@@ -78,11 +78,10 @@ class TestReserveAllocationSpaceMemoryManager: public SectionMemoryManager {
uintptr_t UsedDataSizeRO;
uintptr_t ReservedDataSizeRW;
uintptr_t UsedDataSizeRW;
-
- TestReserveAllocationSpaceMemoryManager() :
- ReservedCodeSize(0), UsedCodeSize(0), ReservedDataSizeRO(0),
- UsedDataSizeRO(0), ReservedDataSizeRW(0), UsedDataSizeRW(0) {
- }
+
+ TestReserveAllocationSpaceMemoryManager()
+ : ReservedCodeSize(0), UsedCodeSize(0), ReservedDataSizeRO(0),
+ UsedDataSizeRO(0), ReservedDataSizeRW(0), UsedDataSizeRW(0) {}
bool needsToReserveAllocationSpace() override { return true; }
@@ -105,16 +104,16 @@ class TestReserveAllocationSpaceMemoryManager: public SectionMemoryManager {
unsigned SectionID, StringRef SectionName,
bool IsReadOnly) override {
useSpace(IsReadOnly ? &UsedDataSizeRO : &UsedDataSizeRW, Size, Alignment);
- return SectionMemoryManager::allocateDataSection(Size, Alignment,
- SectionID, SectionName, IsReadOnly);
+ return SectionMemoryManager::allocateDataSection(Size, Alignment, SectionID,
+ SectionName, IsReadOnly);
}
uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName) override {
useSpace(&UsedCodeSize, Size, Alignment);
- return SectionMemoryManager::allocateCodeSection(Size, Alignment,
- SectionID, SectionName);
+ return SectionMemoryManager::allocateCodeSection(Size, Alignment, SectionID,
+ SectionName);
}
};
@@ -160,42 +159,42 @@ class MCJITCAPITest : public testing::Test, public MCJITTestAPICommon {
else if (Module)
LLVMDisposeModule(Module);
}
-
+
void buildSimpleFunction() {
Module = LLVMModuleCreateWithName("simple_module");
-
- LLVMSetTarget(Module, HostTriple.c_str());
-
+
+ LLVMSetTarget(Module, HostTripleName.c_str());
+
Function = LLVMAddFunction(Module, "simple_function",
LLVMFunctionType(LLVMInt32Type(), nullptr,0, 0));
LLVMSetFunctionCallConv(Function, LLVMCCallConv);
-
+
LLVMBasicBlockRef entry = LLVMAppendBasicBlock(Function, "entry");
LLVMBuilderRef builder = LLVMCreateBuilder();
LLVMPositionBuilderAtEnd(builder, entry);
LLVMBuildRet(builder, LLVMConstInt(LLVMInt32Type(), 42, 0));
-
+
LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error);
LLVMDisposeMessage(Error);
-
+
LLVMDisposeBuilder(builder);
}
-
+
void buildFunctionThatUsesStackmap() {
Module = LLVMModuleCreateWithName("simple_module");
-
- LLVMSetTarget(Module, HostTriple.c_str());
-
+
+ LLVMSetTarget(Module, HostTripleName.c_str());
+
LLVMTypeRef stackmapParamTypes[] = { LLVMInt64Type(), LLVMInt32Type() };
LLVMTypeRef stackmapTy =
LLVMFunctionType(LLVMVoidType(), stackmapParamTypes, 2, 1);
LLVMValueRef stackmap = LLVMAddFunction(
Module, "llvm.experimental.stackmap", stackmapTy);
LLVMSetLinkage(stackmap, LLVMExternalLinkage);
-
+
Function = LLVMAddFunction(Module, "simple_function",
LLVMFunctionType(LLVMInt32Type(), nullptr, 0, 0));
-
+
LLVMBasicBlockRef entry = LLVMAppendBasicBlock(Function, "entry");
LLVMBuilderRef builder = LLVMCreateBuilder();
LLVMPositionBuilderAtEnd(builder, entry);
@@ -205,70 +204,70 @@ class MCJITCAPITest : public testing::Test, public MCJITTestAPICommon {
};
LLVMBuildCall2(builder, stackmapTy, stackmap, stackmapArgs, 3, "");
LLVMBuildRet(builder, LLVMConstInt(LLVMInt32Type(), 42, 0));
-
+
LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error);
LLVMDisposeMessage(Error);
-
+
LLVMDisposeBuilder(builder);
}
-
+
void buildModuleWithCodeAndData() {
Module = LLVMModuleCreateWithName("simple_module");
-
- LLVMSetTarget(Module, HostTriple.c_str());
-
+
+ LLVMSetTarget(Module, HostTripleName.c_str());
+
// build a global int32 variable initialized to 42.
- LLVMValueRef GlobalVar = LLVMAddGlobal(Module, LLVMInt32Type(), "intVal");
+ LLVMValueRef GlobalVar = LLVMAddGlobal(Module, LLVMInt32Type(), "intVal");
LLVMSetInitializer(GlobalVar, LLVMConstInt(LLVMInt32Type(), 42, 0));
-
+
{
Function = LLVMAddFunction(Module, "getGlobal",
LLVMFunctionType(LLVMInt32Type(), nullptr, 0, 0));
LLVMSetFunctionCallConv(Function, LLVMCCallConv);
-
+
LLVMBasicBlockRef Entry = LLVMAppendBasicBlock(Function, "entry");
LLVMBuilderRef Builder = LLVMCreateBuilder();
LLVMPositionBuilderAtEnd(Builder, Entry);
-
+
LLVMValueRef IntVal =
LLVMBuildLoad2(Builder, LLVMInt32Type(), GlobalVar, "intVal");
LLVMBuildRet(Builder, IntVal);
-
+
LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error);
LLVMDisposeMessage(Error);
-
+
LLVMDisposeBuilder(Builder);
}
-
+
{
LLVMTypeRef ParamTypes[] = { LLVMInt32Type() };
Function2 = LLVMAddFunction(
Module, "setGlobal", LLVMFunctionType(LLVMVoidType(), ParamTypes, 1, 0));
LLVMSetFunctionCallConv(Function2, LLVMCCallConv);
-
+
LLVMBasicBlockRef Entry = LLVMAppendBasicBlock(Function2, "entry");
LLVMBuilderRef Builder = LLVMCreateBuilder();
LLVMPositionBuilderAtEnd(Builder, Entry);
-
+
LLVMValueRef Arg = LLVMGetParam(Function2, 0);
LLVMBuildStore(Builder, Arg, GlobalVar);
LLVMBuildRetVoid(Builder);
-
+
LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error);
LLVMDisposeMessage(Error);
-
+
LLVMDisposeBuilder(Builder);
}
}
-
+
void buildMCJITOptions() {
LLVMInitializeMCJITCompilerOptions(&Options, sizeof(Options));
Options.OptLevel = 2;
-
+
// Just ensure that this field still exists.
Options.NoFramePointerElim = false;
}
-
+
void useRoundTripSectionMemoryManager() {
Options.MCJMM = LLVMCreateSimpleMCJITMemoryManager(
new SectionMemoryManager(),
@@ -283,7 +282,7 @@ class MCJITCAPITest : public testing::Test, public MCJITTestAPICommon {
0, LLVMCreateMCJITCompilerForModule(&Engine, Module, &Options,
sizeof(Options), &Error));
}
-
+
void buildAndRunPasses() {
LLVMPassBuilderOptionsRef Options = LLVMCreatePassBuilderOptions();
if (LLVMErrorRef E =
@@ -296,7 +295,7 @@ class MCJITCAPITest : public testing::Test, public MCJITTestAPICommon {
LLVMDisposePassBuilderOptions(Options);
}
-
+
void buildAndRunOptPasses() {
LLVMPassBuilderOptionsRef Options = LLVMCreatePassBuilderOptions();
if (LLVMErrorRef E =
@@ -309,7 +308,7 @@ class MCJITCAPITest : public testing::Test, public MCJITTestAPICommon {
LLVMDisposePassBuilderOptions(Options);
}
-
+
LLVMModuleRef Module;
LLVMValueRef Function;
LLVMValueRef Function2;
@@ -321,7 +320,7 @@ class MCJITCAPITest : public testing::Test, public MCJITTestAPICommon {
TEST_F(MCJITCAPITest, simple_function) {
SKIP_UNSUPPORTED_PLATFORM;
-
+
buildSimpleFunction();
buildMCJITOptions();
buildMCJITEngine();
@@ -337,7 +336,7 @@ TEST_F(MCJITCAPITest, gva) {
SKIP_UNSUPPORTED_PLATFORM;
Module = LLVMModuleCreateWithName("simple_module");
- LLVMSetTarget(Module, HostTriple.c_str());
+ LLVMSetTarget(Module, HostTripleName.c_str());
LLVMValueRef GlobalVar = LLVMAddGlobal(Module, LLVMInt32Type(), "simple_value");
LLVMSetInitializer(GlobalVar, LLVMConstInt(LLVMInt32Type(), 42, 0));
@@ -367,7 +366,7 @@ TEST_F(MCJITCAPITest, gfa) {
TEST_F(MCJITCAPITest, custom_memory_manager) {
SKIP_UNSUPPORTED_PLATFORM;
-
+
buildSimpleFunction();
buildMCJITOptions();
useRoundTripSectionMemoryManager();
@@ -383,11 +382,11 @@ TEST_F(MCJITCAPITest, custom_memory_manager) {
TEST_F(MCJITCAPITest, stackmap_creates_compact_unwind_on_darwin) {
SKIP_UNSUPPORTED_PLATFORM;
-
+
// This test is also not supported on non-x86 platforms.
if (Triple(HostTriple).getArch() != Triple::x86_64)
GTEST_SKIP();
-
+
buildFunctionThatUsesStackmap();
buildMCJITOptions();
useRoundTripSectionMemoryManager();
@@ -399,7 +398,7 @@ TEST_F(MCJITCAPITest, stackmap_creates_compact_unwind_on_darwin) {
EXPECT_EQ(42, functionPointer());
EXPECT_TRUE(didCallAllocateCodeSection);
-
+
// Up to this point, the test is specific only to X86-64. But this next
// expectation is only valid on Darwin because it assumes that unwind
// data is made available only through compact_unwind. It would be
@@ -424,7 +423,7 @@ TEST_F(MCJITCAPITest, MAYBE_reserve_allocation_space) {
SKIP_UNSUPPORTED_PLATFORM;
TestReserveAllocationSpaceMemoryManager* MM = new TestReserveAllocationSpaceMemoryManager();
-
+
buildModuleWithCodeAndData();
buildMCJITOptions();
Options.MCJMM = wrap(MM);
@@ -442,7 +441,7 @@ TEST_F(MCJITCAPITest, MAYBE_reserve_allocation_space) {
EXPECT_LE(MM->UsedCodeSize, MM->ReservedCodeSize);
EXPECT_LE(MM->UsedDataSizeRO, MM->ReservedDataSizeRO);
EXPECT_LE(MM->UsedDataSizeRW, MM->ReservedDataSizeRW);
- EXPECT_TRUE(MM->UsedCodeSize > 0);
+ EXPECT_TRUE(MM->UsedCodeSize > 0);
EXPECT_TRUE(MM->UsedDataSizeRW > 0);
}
@@ -471,7 +470,7 @@ TEST_F(MCJITCAPITest, addGlobalMapping) {
SKIP_UNSUPPORTED_PLATFORM;
Module = LLVMModuleCreateWithName("testModule");
- LLVMSetTarget(Module, HostTriple.c_str());
+ LLVMSetTarget(Module, HostTripleName.c_str());
LLVMTypeRef FunctionType = LLVMFunctionType(LLVMInt32Type(), nullptr, 0, 0);
LLVMValueRef MappedFn = LLVMAddFunction(Module, "mapped_fn", FunctionType);
diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h
index 13484e1bd9029..e2b44de2d0ebb 100644
--- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h
+++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h
@@ -37,9 +37,7 @@ namespace llvm {
class MCJITTestAPICommon {
protected:
- MCJITTestAPICommon()
- : HostTriple(sys::getProcessTriple())
- {
+ MCJITTestAPICommon() : HostTripleName(sys::getProcessTriple()) {
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
@@ -49,9 +47,10 @@ class MCJITTestAPICommon {
#ifdef _WIN32
// On Windows, generate ELF objects by specifying "-elf" in triple
- HostTriple += "-elf";
+ HostTripleName += "-elf";
#endif // _WIN32
- HostTriple = Triple::normalize(HostTriple);
+ HostTripleName = Triple::normalize(HostTripleName);
+ HostTriple = Triple(HostTripleName);
}
bool HostCanBeTargeted() {
@@ -81,19 +80,18 @@ class MCJITTestAPICommon {
/// Returns true if the host OS is known to support MCJIT
bool OSSupportsMCJIT() {
- Triple Host(HostTriple);
-
- if (find(UnsupportedEnvironments, Host.getEnvironment()) !=
+ if (find(UnsupportedEnvironments, HostTriple.getEnvironment()) !=
UnsupportedEnvironments.end())
return false;
- if (!is_contained(UnsupportedOSs, Host.getOS()))
+ if (!is_contained(UnsupportedOSs, HostTriple.getOS()))
return true;
return false;
}
- std::string HostTriple;
+ std::string HostTripleName;
+ Triple HostTriple;
SmallVector<Triple::ArchType, 4> SupportedArchs;
SmallVector<Triple::ArchType, 1> HasSubArchs;
SmallVector<std::string, 2> SupportedSubArchs; // We need to own the memory
diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h
index 1928adc2d7e72..0f10be205e4b9 100644
--- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h
+++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h
@@ -33,14 +33,14 @@ class TrivialModuleBuilder {
protected:
LLVMContext Context;
IRBuilder<> Builder;
- std::string BuilderTriple;
+ const Triple &BuilderTriple;
- TrivialModuleBuilder(const std::string &Triple)
- : Builder(Context), BuilderTriple(Triple) {}
+ TrivialModuleBuilder(const Triple &TT)
+ : Builder(Context), BuilderTriple(TT) {}
Module *createEmptyModule(StringRef Name = StringRef()) {
Module * M = new Module(Name, Context);
- M->setTargetTriple(Triple(Triple::normalize(BuilderTriple)));
+ M->setTargetTriple(BuilderTriple);
return M;
}
diff --git a/llvm/unittests/MC/AMDGPU/Disassembler.cpp b/llvm/unittests/MC/AMDGPU/Disassembler.cpp
index 7174ad54c8248..b5adf695d9e66 100644
--- a/llvm/unittests/MC/AMDGPU/Disassembler.cpp
+++ b/llvm/unittests/MC/AMDGPU/Disassembler.cpp
@@ -71,14 +71,13 @@ TEST(AMDGPUDisassembler, MultiDisassembler) {
LLVMInitializeAMDGPUDisassembler();
std::string Error;
- const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
+ Triple TT(TripleName);
+ const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
// Skip test if AMDGPU not built.
if (!TheTarget)
GTEST_SKIP();
- Triple TT(TripleName);
-
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT));
std::unique_ptr<MCAsmInfo> MAI(
TheTarget->createMCAsmInfo(*MRI, TT, MCTargetOptions()));
@@ -141,15 +140,15 @@ TEST(AMDGPUDisassembler, UCVersionOverride) {
LLVMInitializeAMDGPUTargetMC();
LLVMInitializeAMDGPUDisassembler();
+ Triple TT(TripleName);
+
std::string Error;
- const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
+ const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
// Skip test if AMDGPU not built.
if (!TheTarget)
GTEST_SKIP();
- Triple TT(TripleName);
-
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT));
std::unique_ptr<MCAsmInfo> MAI(
TheTarget->createMCAsmInfo(*MRI, TT, MCTargetOptions()));
diff --git a/llvm/unittests/MC/DwarfLineTableHeaders.cpp b/llvm/unittests/MC/DwarfLineTableHeaders.cpp
index fec8b438ee5db..f685f28619135 100644
--- a/llvm/unittests/MC/DwarfLineTableHeaders.cpp
+++ b/llvm/unittests/MC/DwarfLineTableHeaders.cpp
@@ -57,7 +57,7 @@ class DwarfLineTableHeaders : public ::testing::Test {
// If we didn't build x86, do not run the test.
std::string Error;
- TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
+ TheTarget = TargetRegistry::lookupTarget(TT, Error);
if (!TheTarget)
return;
diff --git a/llvm/unittests/MC/MCInstPrinter.cpp b/llvm/unittests/MC/MCInstPrinter.cpp
index 0b7c3fa9cc11a..3a6de54941d3f 100644
--- a/llvm/unittests/MC/MCInstPrinter.cpp
+++ b/llvm/unittests/MC/MCInstPrinter.cpp
@@ -35,8 +35,7 @@ class MCInstPrinterTest : public ::testing::Test {
Triple TT(TripleName);
std::string ErrorStr;
- const Target *TheTarget =
- TargetRegistry::lookupTarget(TripleName, ErrorStr);
+ const Target *TheTarget = TargetRegistry::lookupTarget(TT, ErrorStr);
// If we didn't build x86, do not run the test.
if (!TheTarget)
diff --git a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
index 6480f60b3667d..ec02c1d077cc6 100644
--- a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
+++ b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
@@ -60,7 +60,7 @@ class SystemZAsmLexerTest : public ::testing::Test {
// Object File and Streamer support for the z/OS target.
std::string Error;
- TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
+ TheTarget = TargetRegistry::lookupTarget(Triple, Error);
EXPECT_NE(TheTarget, nullptr);
MRI.reset(TheTarget->createMCRegInfo(Triple));
diff --git a/llvm/unittests/MC/SystemZ/SystemZMCDisassemblerTest.cpp b/llvm/unittests/MC/SystemZ/SystemZMCDisassemblerTest.cpp
index 2e98252146579..01ff1f37f434b 100644
--- a/llvm/unittests/MC/SystemZ/SystemZMCDisassemblerTest.cpp
+++ b/llvm/unittests/MC/SystemZ/SystemZMCDisassemblerTest.cpp
@@ -38,7 +38,7 @@ struct Context {
// If we didn't build SystemZ, do not run the test.
std::string Error;
- const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
+ const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
if (!TheTarget)
return;
diff --git a/llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp b/llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
index a028a164595e1..8d4e46c081e19 100644
--- a/llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
+++ b/llvm/unittests/MC/X86/X86MCDisassemblerTest.cpp
@@ -38,7 +38,7 @@ struct Context {
// If we didn't build x86, do not run the test.
std::string Error;
- const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
+ const Target *TheTarget = TargetRegistry::lookupTarget(TheTriple, Error);
if (!TheTarget)
return;
diff --git a/llvm/unittests/Target/AArch64/MCInstrAnalysisTest.cpp b/llvm/unittests/Target/AArch64/MCInstrAnalysisTest.cpp
index 271d19ee3a1f9..b1cc425970a9e 100644
--- a/llvm/unittests/Target/AArch64/MCInstrAnalysisTest.cpp
+++ b/llvm/unittests/Target/AArch64/MCInstrAnalysisTest.cpp
@@ -34,8 +34,8 @@ class InstrAnalysisTest : public testing::TestWithParam<const char *> {
InstrAnalysisTest() {
std::string Error;
- const Target *TheTarget =
- TargetRegistry::lookupTarget(Triple::normalize(GetParam()), Error);
+ Triple TT(Triple::normalize(GetParam()));
+ const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
Info = std::unique_ptr<const MCInstrInfo>(TheTarget->createMCInstrInfo());
Analysis = std::unique_ptr<const MCInstrAnalysis>(
TheTarget->createMCInstrAnalysis(Info.get()));
diff --git a/llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp b/llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp
index 468ee79615d64..3d9e687ca24bb 100644
--- a/llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp
+++ b/llvm/unittests/Target/LoongArch/MCInstrAnalysisTest.cpp
@@ -33,8 +33,8 @@ class InstrAnalysisTest : public testing::TestWithParam<const char *> {
InstrAnalysisTest() {
std::string Error;
- const Target *TheTarget =
- TargetRegistry::lookupTarget(Triple::normalize(GetParam()), Error);
+ Triple TT(Triple::normalize(GetParam()));
+ const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
Info = std::unique_ptr<const MCInstrInfo>(TheTarget->createMCInstrInfo());
Analysis = std::unique_ptr<const MCInstrAnalysis>(
TheTarget->createMCInstrAnalysis(Info.get()));
diff --git a/llvm/unittests/Target/RISCV/MCInstrAnalysisTest.cpp b/llvm/unittests/Target/RISCV/MCInstrAnalysisTest.cpp
index 2ef92c7f30f68..018b202b65b7e 100644
--- a/llvm/unittests/Target/RISCV/MCInstrAnalysisTest.cpp
+++ b/llvm/unittests/Target/RISCV/MCInstrAnalysisTest.cpp
@@ -33,8 +33,8 @@ class InstrAnalysisTest : public testing::TestWithParam<const char *> {
InstrAnalysisTest() {
std::string Error;
- const Target *TheTarget =
- TargetRegistry::lookupTarget(Triple::normalize(GetParam()), Error);
+ Triple TT(Triple::normalize(GetParam()));
+ const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
Info = std::unique_ptr<const MCInstrInfo>(TheTarget->createMCInstrInfo());
Analysis = std::unique_ptr<const MCInstrAnalysis>(
TheTarget->createMCInstrAnalysis(Info.get()));
diff --git a/llvm/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp
index 635b3eeff72ad..7a66117b7080c 100644
--- a/llvm/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp
@@ -38,7 +38,7 @@ class AArch64TargetTest : public ::testing::Test {
: TT(kTriple), ExegesisTarget_(ExegesisTarget::lookup(TT)) {
EXPECT_THAT(ExegesisTarget_, NotNull());
std::string error;
- Target_ = TargetRegistry::lookupTarget(kTriple, error);
+ Target_ = TargetRegistry::lookupTarget(TT, error);
EXPECT_THAT(Target_, NotNull());
STI_.reset(
Target_->createMCSubtargetInfo(TT, "generic", /*no features*/ ""));
diff --git a/llvm/unittests/tools/llvm-exegesis/PowerPC/AnalysisTest.cpp b/llvm/unittests/tools/llvm-exegesis/PowerPC/AnalysisTest.cpp
index 47314e2174cc1..b6335ee3378ef 100644
--- a/llvm/unittests/tools/llvm-exegesis/PowerPC/AnalysisTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/PowerPC/AnalysisTest.cpp
@@ -29,8 +29,7 @@ class PPCAnalysisTest : public ::testing::Test {
const StringRef TripleName = "powerpc64le-unknown-linux";
const Triple TT(TripleName);
std::string error;
- const Target *const TheTarget =
- TargetRegistry::lookupTarget(TripleName, error);
+ const Target *const TheTarget = TargetRegistry::lookupTarget(TT, error);
if (!TheTarget) {
errs() << error << "\n";
return;
diff --git a/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
index 959086f5887f1..3708f18369eaa 100644
--- a/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
@@ -39,7 +39,7 @@ class PowerPCTargetTest : public PPCTestBase {
: TT(kTriple), ExegesisTarget_(ExegesisTarget::lookup(TT)) {
EXPECT_THAT(ExegesisTarget_, NotNull());
std::string error;
- Target_ = TargetRegistry::lookupTarget(kTriple, error);
+ Target_ = TargetRegistry::lookupTarget(TT, error);
EXPECT_THAT(Target_, NotNull());
}
More information about the llvm-commits
mailing list