[IR] Store Triple in Module (NFC) (#129868)

The module currently stores the target triple as a string. This means
that any code that wants to actually use the triple first has to
instantiate a Triple, which is somewhat expensive. The change in #121652
caused a moderate compile-time regression due to this. While it would be
easy enough to work around, I think that architecturally, it makes more
sense to store the parsed Triple in the module, so that it can always be
directly queried.

For this change, I've opted not to add any magic conversions between
std::string and Triple for backwards-compatibilty purses, and instead
write out needed Triple()s or str()s explicitly. This is because I think
a decent number of them should be changed to work on Triple as well, to
avoid unnecessary conversions back and forth.

The only interesting part in this patch is that the default triple is
Triple("") instead of Triple() to preserve existing behavior. The former
defaults to using the ELF object format instead of unknown object
format. We should fix that as well.
This commit is contained in:
Nikita Popov 2025-03-06 10:27:47 +01:00 committed by GitHub
parent f01e760c08
commit 979c275097
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
111 changed files with 244 additions and 241 deletions

View File

@ -595,7 +595,7 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
// Create the TargetMachine for generating code.
std::string Error;
std::string Triple = TheModule->getTargetTriple();
std::string Triple = TheModule->getTargetTriple().str();
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
if (!TheTarget) {
if (MustCreateTM)

View File

@ -1032,7 +1032,7 @@ CodeGenAction::loadModule(MemoryBufferRef MBRef) {
// linker using merged object file.
if (!Bm) {
auto M = std::make_unique<llvm::Module>("empty", *VMContext);
M->setTargetTriple(CI.getTargetOpts().Triple);
M->setTargetTriple(Triple(CI.getTargetOpts().Triple));
return M;
}
Expected<std::unique_ptr<llvm::Module>> MOrErr =
@ -1123,10 +1123,10 @@ void CodeGenAction::ExecuteAction() {
return;
const TargetOptions &TargetOpts = CI.getTargetOpts();
if (TheModule->getTargetTriple() != TargetOpts.Triple) {
if (TheModule->getTargetTriple().str() != TargetOpts.Triple) {
Diagnostics.Report(SourceLocation(), diag::warn_fe_override_module)
<< TargetOpts.Triple;
TheModule->setTargetTriple(TargetOpts.Triple);
TheModule->setTargetTriple(Triple(TargetOpts.Triple));
}
EmbedObject(TheModule.get(), CodeGenOpts, Diagnostics);

View File

@ -151,7 +151,7 @@ namespace {
void Initialize(ASTContext &Context) override {
Ctx = &Context;
M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
M->setTargetTriple(Ctx->getTargetInfo().getTriple());
M->setDataLayout(Ctx->getTargetInfo().getDataLayoutString());
const auto &SDKVersion = Ctx->getTargetInfo().getSDKVersion();
if (!SDKVersion.empty())

View File

@ -255,7 +255,7 @@ public:
if (Diags.hasErrorOccurred())
return;
M->setTargetTriple(Ctx.getTargetInfo().getTriple().getTriple());
M->setTargetTriple(Ctx.getTargetInfo().getTriple());
M->setDataLayout(Ctx.getTargetInfo().getDataLayoutString());
// PCH files don't have a signature field in the control block,
@ -274,7 +274,7 @@ public:
// Ensure the target exists.
std::string Error;
auto Triple = Ctx.getTargetInfo().getTriple();
if (!llvm::TargetRegistry::lookupTarget(Triple.getTriple(), Error))
if (!llvm::TargetRegistry::lookupTarget(Triple, Error))
llvm::report_fatal_error(llvm::Twine(Error));
// Emit the serialized Clang AST into its own section.

View File

@ -83,7 +83,7 @@ llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {
std::error_code());
llvm::TargetOptions TO = llvm::TargetOptions();
llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
PTU.TheModule->getTargetTriple(), TargetOpts.CPU, "", TO,
PTU.TheModule->getTargetTriple().str(), TargetOpts.CPU, "", TO,
llvm::Reloc::Model::PIC_);
PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());

View File

@ -127,8 +127,8 @@ static std::string OptLLVM(const std::string &IR, CodeGenOptLevel OLvl) {
ErrorAndExit(E);
std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
M->getTargetTriple(), codegen::getCPUStr(), codegen::getFeaturesStr(),
Options, codegen::getExplicitRelocModel(),
M->getTargetTriple().str(), codegen::getCPUStr(),
codegen::getFeaturesStr(), Options, codegen::getExplicitRelocModel(),
codegen::getExplicitCodeModel(), OLvl));
if (!TM)
ErrorAndExit("Could not create target machine");

View File

@ -627,11 +627,11 @@ Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
return createStringError(Msg);
auto Options =
codegen::InitTargetOptionsFromCodeGenFlags(Triple(M.getTargetTriple()));
codegen::InitTargetOptionsFromCodeGenFlags(M.getTargetTriple());
StringRef CPU = "";
StringRef Features = "";
std::unique_ptr<TargetMachine> TM(
T->createTargetMachine(M.getTargetTriple(), CPU, Features, Options,
T->createTargetMachine(M.getTargetTriple().str(), CPU, Features, Options,
Reloc::PIC_, M.getCodeModel()));
if (M.getDataLayout().isDefault())
@ -650,7 +650,7 @@ Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
auto OS = std::make_unique<llvm::raw_fd_ostream>(FD, true);
legacy::PassManager CodeGenPasses;
TargetLibraryInfoImpl TLII(Triple(M.getTargetTriple()));
TargetLibraryInfoImpl TLII(M.getTargetTriple());
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
if (TM->addPassesToEmitFile(CodeGenPasses, *OS, nullptr,
CodeGenFileType::ObjectFile))
@ -674,8 +674,8 @@ wrapDeviceImages(ArrayRef<std::unique_ptr<MemoryBuffer>> Buffers,
LLVMContext Context;
Module M("offload.wrapper.module", Context);
M.setTargetTriple(
Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple()));
M.setTargetTriple(Triple(
Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple())));
switch (Kind) {
case OFK_OpenMP:

View File

@ -61,7 +61,7 @@ public:
TT.setOS(llvm::Triple::UnknownOS);
std::string UnusedErr;
return llvm::TargetRegistry::lookupTarget(TT.str(), UnusedErr);
return llvm::TargetRegistry::lookupTarget(TT, UnusedErr);
}
};

View File

@ -1389,10 +1389,10 @@ void CodeGenAction::executeAction() {
// given on the command-line).
llvm::TargetMachine &targetMachine = ci.getTargetMachine();
const std::string &theTriple = targetMachine.getTargetTriple().str();
const llvm::Triple &theTriple = targetMachine.getTargetTriple();
if (llvmModule->getTargetTriple() != theTriple) {
diags.Report(clang::diag::warn_fe_override_module) << theTriple;
diags.Report(clang::diag::warn_fe_override_module) << theTriple.str();
}
// Always set the triple and data layout, to make sure they match and are set.

View File

@ -67,7 +67,7 @@ EmulateInstructionMIPS::EmulateInstructionMIPS(
std::string Status;
llvm::Triple triple = arch.GetTriple();
const llvm::Target *target =
llvm::TargetRegistry::lookupTarget(triple.getTriple(), Status);
llvm::TargetRegistry::lookupTarget(triple, Status);
/*
* If we fail to get the target then we haven't registered it. The
@ -84,7 +84,7 @@ EmulateInstructionMIPS::EmulateInstructionMIPS(
LLVMInitializeMipsAsmPrinter();
LLVMInitializeMipsTargetMC();
LLVMInitializeMipsDisassembler();
target = llvm::TargetRegistry::lookupTarget(triple.getTriple(), Status);
target = llvm::TargetRegistry::lookupTarget(triple, Status);
}
#endif

View File

@ -67,7 +67,7 @@ EmulateInstructionMIPS64::EmulateInstructionMIPS64(
std::string Status;
llvm::Triple triple = arch.GetTriple();
const llvm::Target *target =
llvm::TargetRegistry::lookupTarget(triple.getTriple(), Status);
llvm::TargetRegistry::lookupTarget(triple, Status);
/*
* If we fail to get the target then we haven't registered it. The
@ -84,7 +84,7 @@ EmulateInstructionMIPS64::EmulateInstructionMIPS64(
LLVMInitializeMipsAsmPrinter();
LLVMInitializeMipsTargetMC();
LLVMInitializeMipsDisassembler();
target = llvm::TargetRegistry::lookupTarget(triple.getTriple(), Status);
target = llvm::TargetRegistry::lookupTarget(triple, Status);
}
#endif

View File

@ -207,7 +207,7 @@ int main(int Argc, char *Argv[]) {
ExitOnErr(JITTargetMachineBuilder::detectHost()));
} else {
Builder.setJITTargetMachineBuilder(
JITTargetMachineBuilder(Triple(M.getTargetTriple())));
JITTargetMachineBuilder(M.getTargetTriple()));
}
if (!M.getDataLayout().getStringRepresentation().empty())
Builder.setDataLayout(M.getDataLayout());

View File

@ -104,7 +104,7 @@ public:
StaticInitGVIterator(Module &M)
: I(M.global_values().begin()), E(M.global_values().end()),
ObjFmt(Triple(M.getTargetTriple()).getObjectFormat()) {
ObjFmt(M.getTargetTriple().getObjectFormat()) {
if (I != E) {
if (!isStaticInitGlobal(*I))
moveToNextStaticInitGlobal();

View File

@ -479,7 +479,7 @@ public:
/// not have an effect on \p M (see initialize)
OpenMPIRBuilder(Module &M)
: M(M), Builder(M.getContext()), OffloadInfoManager(this),
T(Triple(M.getTargetTriple())) {}
T(M.getTargetTriple()) {}
~OpenMPIRBuilder();
class AtomicInfo : public llvm::AtomicInfo {

View File

@ -31,6 +31,7 @@
#include "llvm/IR/SymbolTableListTraits.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/TargetParser/Triple.h"
#include <cstddef>
#include <cstdint>
#include <iterator>
@ -189,8 +190,10 @@ private:
std::string ModuleID; ///< Human readable identifier for the module
std::string SourceFileName; ///< Original source file name for module,
///< recorded in bitcode.
std::string TargetTriple; ///< Platform target triple Module compiled on
///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
/// Platform target triple Module compiled on
/// Format: (arch)(sub)-(vendor)-(sys)-(abi)
// FIXME: Default construction is not the same as empty triple :(
Triple TargetTriple = Triple("");
NamedMDSymTabType NamedMDSymTab; ///< NamedMDNode names.
DataLayout DL; ///< DataLayout associated with the module
StringMap<unsigned>
@ -294,8 +297,7 @@ public:
const DataLayout &getDataLayout() const { return DL; }
/// Get the target triple which is a string describing the target host.
/// @returns a string containing the target triple.
const std::string &getTargetTriple() const { return TargetTriple; }
const Triple &getTargetTriple() const { return TargetTriple; }
/// Get the global data context.
/// @returns LLVMContext - a container for LLVM's global information
@ -338,7 +340,7 @@ public:
void setDataLayout(const DataLayout &Other);
/// Set the target triple.
void setTargetTriple(StringRef T) { TargetTriple = std::string(T); }
void setTargetTriple(Triple T) { TargetTriple = std::move(T); }
/// Set the module-scope inline assembly blocks.
/// A trailing newline is added if the input doesn't have one.

View File

@ -118,14 +118,10 @@ public:
std::unique_ptr<Module> takeModule() { return std::move(Mod); }
/// Return the Module's target triple.
const std::string &getTargetTriple() {
return getModule().getTargetTriple();
}
const Triple &getTargetTriple() { return getModule().getTargetTriple(); }
/// Set the Module's target triple.
void setTargetTriple(StringRef Triple) {
getModule().setTargetTriple(Triple);
}
void setTargetTriple(Triple T) { getModule().setTargetTriple(T); }
/// Get the number of symbols
uint32_t getSymbolCount() {

View File

@ -693,12 +693,23 @@ struct TargetRegistry {
static iterator_range<iterator> targets();
/// lookupTarget - Lookup a target based on a target triple.
///
/// \param TripleStr - The triple to use for finding a target.
/// \param Error - On failure, an error string describing why no target was
/// found.
// TODO: Drop this in favor of the method accepting Triple.
static const Target *lookupTarget(StringRef TripleStr, std::string &Error) {
return lookupTarget(Triple(TripleStr), Error);
}
/// lookupTarget - Lookup a target based on a target triple.
///
/// \param Triple - The triple to use for finding a target.
/// \param Error - On failure, an error string describing why no target was
/// found.
static const Target *lookupTarget(StringRef Triple, std::string &Error);
static const Target *lookupTarget(const Triple &TheTriple,
std::string &Error);
/// lookupTarget - Lookup a target based on an architecture name
/// and a target triple. If the architecture name is non-empty,

View File

@ -463,6 +463,9 @@ public:
const std::string &getTriple() const { return Data; }
/// Whether the triple is empty / default constructed.
bool empty() const { return Data.empty(); }
/// Get the architecture (first) component of the triple.
StringRef getArchName() const;

View File

@ -24,7 +24,7 @@ using namespace dxil;
static ModuleMetadataInfo collectMetadataInfo(Module &M) {
ModuleMetadataInfo MMDAI;
Triple TT(Triple(M.getTargetTriple()));
const Triple &TT = M.getTargetTriple();
MMDAI.DXILVersion = TT.getDXILVersion();
MMDAI.ShaderModelVersion = TT.getOSVersion();
MMDAI.ShaderProfile = TT.getEnvironment();

View File

@ -127,7 +127,7 @@ class Lint : public InstVisitor<Lint> {
public:
Module *Mod;
Triple TT;
const Triple &TT;
const DataLayout *DL;
AliasAnalysis *AA;
AssumptionCache *AC;
@ -139,8 +139,8 @@ public:
Lint(Module *Mod, const DataLayout *DL, AliasAnalysis *AA,
AssumptionCache *AC, DominatorTree *DT, TargetLibraryInfo *TLI)
: Mod(Mod), TT(Triple::normalize(Mod->getTargetTriple())), DL(DL), AA(AA),
AC(AC), DT(DT), TLI(TLI), MessagesStr(Messages) {}
: Mod(Mod), TT(Mod->getTargetTriple()), DL(DL), AA(AA), AC(AC), DT(DT),
TLI(TLI), MessagesStr(Messages) {}
void WriteValues(ArrayRef<const Value *> Vs) {
for (const Value *V : Vs) {

View File

@ -118,7 +118,7 @@ static bool hasBcmp(const Triple &TT) {
return TT.isOSFreeBSD() || TT.isOSSolaris();
}
static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT,
static bool isCallingConvCCompatible(CallingConv::ID CC, const Triple &TT,
FunctionType *FuncTy) {
switch (CC) {
default:
@ -131,7 +131,7 @@ static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT,
// The iOS ABI diverges from the standard in some cases, so for now don't
// try to simplify those calls.
if (Triple(TT).isiOS())
if (TT.isiOS())
return false;
if (!FuncTy->getReturnType()->isPointerTy() &&
@ -1446,8 +1446,7 @@ TargetLibraryInfoImpl::getVectorMappingInfo(StringRef F, const ElementCount &VF,
TargetLibraryInfo TargetLibraryAnalysis::run(const Function &F,
FunctionAnalysisManager &) {
if (!BaselineInfoImpl)
BaselineInfoImpl =
TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
BaselineInfoImpl = TargetLibraryInfoImpl(F.getParent()->getTargetTriple());
return TargetLibraryInfo(*BaselineInfoImpl, &F);
}

View File

@ -522,7 +522,7 @@ bool LLParser::parseTargetDefinitions(DataLayoutCallbackTy DataLayoutCallback) {
// Run the override callback to potentially change the data layout string, and
// parse the data layout string.
if (auto LayoutOverride =
DataLayoutCallback(M->getTargetTriple(), TentativeDLStr)) {
DataLayoutCallback(M->getTargetTriple().str(), TentativeDLStr)) {
TentativeDLStr = *LayoutOverride;
DLStrLoc = {};
}
@ -646,7 +646,7 @@ bool LLParser::parseTargetDefinition(std::string &TentativeDLStr,
if (parseToken(lltok::equal, "expected '=' after target triple") ||
parseStringConstant(Str))
return true;
M->setTargetTriple(Str);
M->setTargetTriple(Triple(Str));
return false;
case lltok::kw_datalayout:
Lex.Lex();

View File

@ -4530,12 +4530,12 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
// Auto-upgrade the layout string
TentativeDataLayoutStr = llvm::UpgradeDataLayoutString(
TentativeDataLayoutStr, TheModule->getTargetTriple());
TentativeDataLayoutStr, TheModule->getTargetTriple().str());
// Apply override
if (Callbacks.DataLayout) {
if (auto LayoutOverride = (*Callbacks.DataLayout)(
TheModule->getTargetTriple(), TentativeDataLayoutStr))
TheModule->getTargetTriple().str(), TentativeDataLayoutStr))
TentativeDataLayoutStr = *LayoutOverride;
}
@ -4719,7 +4719,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
std::string S;
if (convertToString(Record, 0, S))
return error("Invalid record");
TheModule->setTargetTriple(S);
TheModule->setTargetTriple(Triple(S));
break;
}
case bitc::MODULE_CODE_DATALAYOUT: { // DATALAYOUT: [strchr x N]

View File

@ -1449,8 +1449,8 @@ serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta) {
void ModuleBitcodeWriter::writeModuleInfo() {
// Emit various pieces of data attached to a module.
if (!M.getTargetTriple().empty())
writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE, M.getTargetTriple(),
0 /*TODO*/);
writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE,
M.getTargetTriple().str(), 0 /*TODO*/);
const std::string &DL = M.getDataLayoutStr();
if (!DL.empty())
writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
@ -5331,7 +5331,7 @@ void BitcodeWriter::writeSymtab() {
std::string Err;
const Triple TT(M->getTargetTriple());
const Target *T = TargetRegistry::lookupTarget(TT.str(), Err);
const Target *T = TargetRegistry::lookupTarget(TT, Err);
if (!T || !T->hasMCAsmParser())
return;
}

View File

@ -619,7 +619,7 @@ void CodeViewDebug::beginModule(Module *M) {
return;
}
TheCPU = mapArchToCVCPUType(Triple(M->getTargetTriple()).getArch());
TheCPU = mapArchToCVCPUType(M->getTargetTriple().getArch());
// Get the current source language.
const MDNode *Node = *M->debug_compile_units_begin();
@ -845,7 +845,7 @@ void CodeViewDebug::emitCompilerInformation() {
Flags |= static_cast<uint32_t>(CompileSym3Flags::PGO);
}
using ArchType = llvm::Triple::ArchType;
ArchType Arch = Triple(MMI->getModule()->getTargetTriple()).getArch();
ArchType Arch = MMI->getModule()->getTargetTriple().getArch();
if (Asm->TM.Options.Hotpatch || Arch == ArchType::thumb ||
Arch == ArchType::aarch64) {
Flags |= static_cast<uint32_t>(CompileSym3Flags::HotPatch);
@ -1098,7 +1098,7 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
FuncName = std::string(GlobalValue::dropLLVMManglingEscape(GV->getName()));
// Emit FPO data, but only on 32-bit x86. No other platforms use it.
if (Triple(MMI->getModule()->getTargetTriple()).getArch() == Triple::x86)
if (MMI->getModule()->getTargetTriple().getArch() == Triple::x86)
OS.emitCVFPOData(Fn);
// Emit a symbol subsection, required by VS2012+ to find function boundaries.
@ -1560,7 +1560,7 @@ void CodeViewDebug::beginFunctionImpl(const MachineFunction *MF) {
}
// Mark branches that may potentially be using jump tables with labels.
bool isThumb = Triple(MMI->getModule()->getTargetTriple()).getArch() ==
bool isThumb = MMI->getModule()->getTargetTriple().getArch() ==
llvm::Triple::ArchType::thumb;
discoverJumpTableBranches(MF, isThumb);
}
@ -3068,7 +3068,7 @@ void CodeViewDebug::endFunctionImpl(const MachineFunction *MF) {
}
}
bool isThumb = Triple(MMI->getModule()->getTargetTriple()).getArch() ==
bool isThumb = MMI->getModule()->getTargetTriple().getArch() ==
llvm::Triple::ArchType::thumb;
collectDebugInfoForJumpTables(MF, isThumb);

View File

@ -342,8 +342,7 @@ static bool shouldCoalesceFragments(Function &F) {
// has not been explicitly set and instruction-referencing is turned on.
switch (CoalesceAdjacentFragmentsOpt) {
case cl::boolOrDefault::BOU_UNSET:
return debuginfoShouldUseDebugInstrRef(
Triple(F.getParent()->getTargetTriple()));
return debuginfoShouldUseDebugInstrRef(F.getParent()->getTargetTriple());
case cl::boolOrDefault::BOU_TRUE:
return true;
case cl::boolOrDefault::BOU_FALSE:

View File

@ -672,7 +672,7 @@ bool GlobalMergeImpl::run(Module &M) {
if (!EnableGlobalMerge)
return false;
IsMachO = Triple(M.getTargetTriple()).isOSBinFormatMachO();
IsMachO = M.getTargetTriple().isOSBinFormatMachO();
auto &DL = M.getDataLayout();
MapVector<std::pair<unsigned, StringRef>, SmallVector<GlobalVariable *, 0>>

View File

@ -253,8 +253,8 @@ MIRParserImpl::parseIRModule(DataLayoutCallbackTy DataLayoutCallback) {
// Create an empty module when the MIR file is empty.
NoMIRDocuments = true;
auto M = std::make_unique<Module>(Filename, Context);
if (auto LayoutOverride =
DataLayoutCallback(M->getTargetTriple(), M->getDataLayoutStr()))
if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
M->getDataLayoutStr()))
M->setDataLayout(*LayoutOverride);
return M;
}
@ -277,8 +277,8 @@ MIRParserImpl::parseIRModule(DataLayoutCallbackTy DataLayoutCallback) {
} else {
// Create an new, empty module.
M = std::make_unique<Module>(Filename, Context);
if (auto LayoutOverride =
DataLayoutCallback(M->getTargetTriple(), M->getDataLayoutStr()))
if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
M->getDataLayoutStr()))
M->setDataLayout(*LayoutOverride);
NoLLVMIR = true;
}

View File

@ -218,7 +218,7 @@ static bool ContainsProtectableArray(Type *Ty, Module *M, unsigned SSPBufferSize
// add stack protectors unless the array is a character array.
// However, in strong mode any array, regardless of type and size,
// triggers a protector.
if (!Strong && (InStruct || !Triple(M->getTargetTriple()).isOSDarwin()))
if (!Strong && (InStruct || !M->getTargetTriple().isOSDarwin()))
return false;
}

View File

@ -406,7 +406,7 @@ static void calculateCXXStateNumbers(WinEHFuncInfo &FuncInfo,
// stored in pre-order (outer first, inner next), not post-order
// Add to map here. Fix the CatchHigh after children are processed
const Module *Mod = BB->getParent()->getParent();
bool IsPreOrder = Triple(Mod->getTargetTriple()).isArch64Bit();
bool IsPreOrder = Mod->getTargetTriple().isArch64Bit();
if (IsPreOrder)
addTryBlockMapEntry(FuncInfo, TryLow, TryHigh, CatchLow, Handlers);
unsigned TBMEIdx = FuncInfo.TryBlockMap.size() - 1;

View File

@ -39,7 +39,7 @@ Expected<std::unique_ptr<TargetMachine>>
JITTargetMachineBuilder::createTargetMachine() {
std::string ErrMsg;
auto *TheTarget = TargetRegistry::lookupTarget(TT.getTriple(), ErrMsg);
auto *TheTarget = TargetRegistry::lookupTarget(TT, ErrMsg);
if (!TheTarget)
return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());

View File

@ -29,7 +29,7 @@ TargetMachine *EngineBuilder::selectTarget() {
// MCJIT can generate code for remote targets, but the old JIT and Interpreter
// must use the host architecture.
if (WhichEngine != EngineKind::Interpreter && M)
TT.setTriple(M->getTargetTriple());
TT = M->getTargetTriple();
return selectTarget(TT, MArch, MCPU, MAttrs);
}
@ -66,7 +66,7 @@ TargetMachine *EngineBuilder::selectTarget(const Triple &TargetTriple,
TheTriple.setArch(Type);
} else {
std::string Error;
TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), Error);
TheTarget = TargetRegistry::lookupTarget(TheTriple, Error);
if (!TheTarget) {
if (ErrorStr)
*ErrorStr = Error;

View File

@ -267,7 +267,7 @@ GlobalVariable *createFatbinDesc(Module &M, ArrayRef<char> Image, bool IsHIP,
StringRef Suffix) {
LLVMContext &C = M.getContext();
llvm::Type *Int8PtrTy = PointerType::getUnqual(C);
llvm::Triple Triple = llvm::Triple(M.getTargetTriple());
const llvm::Triple &Triple = M.getTargetTriple();
// Create the global string containing the fatbinary.
StringRef FatbinConstantSection =

View File

@ -41,7 +41,7 @@ offloading::getOffloadingEntryInitializer(Module &M, object::OffloadKind Kind,
Constant *Addr, StringRef Name,
uint64_t Size, uint32_t Flags,
uint64_t Data, Constant *AuxAddr) {
llvm::Triple Triple(M.getTargetTriple());
const llvm::Triple &Triple = M.getTargetTriple();
Type *PtrTy = PointerType::getUnqual(M.getContext());
Type *Int64Ty = Type::getInt64Ty(M.getContext());
Type *Int32Ty = Type::getInt32Ty(M.getContext());
@ -87,7 +87,7 @@ void offloading::emitOffloadingEntry(Module &M, object::OffloadKind Kind,
uint64_t Size, uint32_t Flags,
uint64_t Data, Constant *AuxAddr,
StringRef SectionName) {
llvm::Triple Triple(M.getTargetTriple());
const llvm::Triple &Triple = M.getTargetTriple();
auto [EntryInitializer, NameGV] = getOffloadingEntryInitializer(
M, Kind, Addr, Name, Size, Flags, Data, AuxAddr);
@ -110,7 +110,7 @@ void offloading::emitOffloadingEntry(Module &M, object::OffloadKind Kind,
std::pair<GlobalVariable *, GlobalVariable *>
offloading::getOffloadEntryArray(Module &M, StringRef SectionName) {
llvm::Triple Triple(M.getTargetTriple());
const llvm::Triple &Triple = M.getTargetTriple();
auto *ZeroInitilaizer =
ConstantAggregateZero::get(ArrayType::get(getEntryTy(M), 0u));

View File

@ -5511,7 +5511,7 @@ createTargetMachine(Function *F, CodeGenOptLevel OptLevel) {
StringRef CPU = F->getFnAttribute("target-cpu").getValueAsString();
StringRef Features = F->getFnAttribute("target-features").getValueAsString();
const std::string &Triple = M->getTargetTriple();
const std::string &Triple = M->getTargetTriple().str();
std::string Error;
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
@ -7762,7 +7762,7 @@ OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
// variable for possibly changing that to internal or private, or maybe
// create different versions of the function for different OMP internal
// variables.
auto Linkage = this->M.getTargetTriple().rfind("wasm32") == 0
auto Linkage = this->M.getTargetTriple().getArch() == Triple::wasm32
? GlobalValue::InternalLinkage
: GlobalValue::CommonLinkage;
auto *GV = new GlobalVariable(M, Ty, /*IsConstant=*/false, Linkage,

View File

@ -3039,7 +3039,7 @@ void AssemblyWriter::printModule(const Module *M) {
if (!DL.empty())
Out << "target datalayout = \"" << DL << "\"\n";
if (!M->getTargetTriple().empty())
Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
Out << "target triple = \"" << M->getTargetTriple().str() << "\"\n";
if (!M->getModuleInlineAsm().empty()) {
Out << '\n';

View File

@ -321,11 +321,11 @@ void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr) {
/*--.. Target triple .......................................................--*/
const char * LLVMGetTarget(LLVMModuleRef M) {
return unwrap(M)->getTargetTriple().c_str();
return unwrap(M)->getTargetTriple().str().c_str();
}
void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
unwrap(M)->setTargetTriple(Triple);
void LLVMSetTarget(LLVMModuleRef M, const char *TripleStr) {
unwrap(M)->setTargetTriple(Triple(TripleStr));
}
/*--.. Module flags ........................................................--*/

View File

@ -27,7 +27,7 @@ EHPersonality llvm::classifyEHPersonality(const Value *Pers) {
return EHPersonality::Unknown;
StringRef Name = F->getName();
if (Triple(F->getParent()->getTargetTriple()).isWindowsArm64EC()) {
if (F->getParent()->getTargetTriple().isWindowsArm64EC()) {
// ARM64EC function symbols are mangled by prefixing them with "#".
// Demangle them by skipping this prefix.
Name.consume_front("#");

View File

@ -359,16 +359,14 @@ bool GlobalObject::canIncreaseAlignment() const {
// alignment will be incorrect.
// Conservatively assume ELF if there's no parent pointer.
bool isELF =
(!Parent || Triple(Parent->getTargetTriple()).isOSBinFormatELF());
bool isELF = (!Parent || Parent->getTargetTriple().isOSBinFormatELF());
if (isELF && !isDSOLocal())
return false;
// GV with toc-data attribute is defined in a TOC entry. To mitigate TOC
// overflow, the alignment of such symbol should not be increased. Otherwise,
// padding is needed thus more TOC entries are wasted.
bool isXCOFF =
(!Parent || Triple(Parent->getTargetTriple()).isOSBinFormatXCOFF());
bool isXCOFF = (!Parent || Parent->getTargetTriple().isOSBinFormatXCOFF());
if (isXCOFF)
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
if (GV->hasAttribute("toc-data"))

View File

@ -52,7 +52,7 @@ ValueName *ValueSymbolTable::makeUniqueName(Value *V,
// identifiers. This breaks ABI demangling but at least ptxas accepts and
// compiles the program.
const Module *M = GV->getParent();
if (!(M && Triple(M->getTargetTriple()).isNVPTX()))
if (!(M && M->getTargetTriple().isNVPTX()))
AppenDot = true;
}

View File

@ -141,7 +141,7 @@ struct VerifierSupport {
raw_ostream *OS;
const Module &M;
ModuleSlotTracker MST;
Triple TT;
const Triple &TT;
const DataLayout &DL;
LLVMContext &Context;
@ -153,8 +153,8 @@ struct VerifierSupport {
bool TreatBrokenDebugInfoAsError = true;
explicit VerifierSupport(raw_ostream *OS, const Module &M)
: OS(OS), M(M), MST(&M), TT(Triple::normalize(M.getTargetTriple())),
DL(M.getDataLayout()), Context(M.getContext()) {}
: OS(OS), M(M), MST(&M), TT(M.getTargetTriple()), DL(M.getDataLayout()),
Context(M.getContext()) {}
private:
void Write(const Module *M) {

View File

@ -733,8 +733,9 @@ Error LTO::add(std::unique_ptr<InputFile> Input,
writeToResolutionFile(*Conf.ResolutionFile, Input.get(), Res);
if (RegularLTO.CombinedModule->getTargetTriple().empty()) {
RegularLTO.CombinedModule->setTargetTriple(Input->getTargetTriple());
if (Triple(Input->getTargetTriple()).isOSBinFormatELF())
Triple InputTriple(Input->getTargetTriple());
RegularLTO.CombinedModule->setTargetTriple(InputTriple);
if (InputTriple.isOSBinFormatELF())
Conf.VisibilityScheme = Config::ELF;
}

View File

@ -202,9 +202,9 @@ static void RegisterPassPlugins(ArrayRef<std::string> PassPlugins,
static std::unique_ptr<TargetMachine>
createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) {
StringRef TheTriple = M.getTargetTriple();
const Triple &TheTriple = M.getTargetTriple();
SubtargetFeatures Features;
Features.getDefaultSubtargetFeatures(Triple(TheTriple));
Features.getDefaultSubtargetFeatures(TheTriple);
for (const std::string &A : Conf.MAttrs)
Features.AddFeature(A);
@ -222,7 +222,7 @@ createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) {
CodeModel = M.getCodeModel();
std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
TheTriple, Conf.CPU, Features.getString(), Conf.Options, RelocModel,
TheTriple.str(), Conf.CPU, Features.getString(), Conf.Options, RelocModel,
CodeModel, Conf.CGOptLevel));
assert(TM && "Failed to create target machine");
@ -276,7 +276,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
RegisterPassPlugins(Conf.PassPlugins, PB);
std::unique_ptr<TargetLibraryInfoImpl> TLII(
new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())));
new TargetLibraryInfoImpl(TM->getTargetTriple()));
if (Conf.Freestanding)
TLII->disableAllFunctions();
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
@ -435,7 +435,7 @@ static void codegen(const Config &Conf, TargetMachine *TM,
TM->Options.ObjectFilenameForDebug = Stream->ObjectPathName;
legacy::PassManager CodeGenPasses;
TargetLibraryInfoImpl TLII(Triple(Mod.getTargetTriple()));
TargetLibraryInfoImpl TLII(Mod.getTargetTriple());
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
// No need to make index available if the module is empty.
// In theory these passes should not use the index for an empty
@ -515,9 +515,9 @@ static void splitCodeGen(const Config &C, TargetMachine *TM,
static Expected<const Target *> initAndLookupTarget(const Config &C,
Module &Mod) {
if (!C.OverrideTriple.empty())
Mod.setTargetTriple(C.OverrideTriple);
Mod.setTargetTriple(Triple(C.OverrideTriple));
else if (Mod.getTargetTriple().empty())
Mod.setTargetTriple(C.DefaultTriple);
Mod.setTargetTriple(Triple(C.DefaultTriple));
std::string Msg;
const Target *T = TargetRegistry::lookupTarget(Mod.getTargetTriple(), Msg);

View File

@ -383,12 +383,12 @@ bool LTOCodeGenerator::determineTarget() {
if (TargetMach)
return true;
TripleStr = MergedModule->getTargetTriple();
TripleStr = MergedModule->getTargetTriple().str();
llvm::Triple Triple(TripleStr);
if (TripleStr.empty()) {
TripleStr = sys::getDefaultTargetTriple();
MergedModule->setTargetTriple(TripleStr);
MergedModule->setTargetTriple(Triple);
}
llvm::Triple Triple(TripleStr);
// create target machine from info for merged modules
std::string ErrMsg;

View File

@ -200,14 +200,13 @@ LTOModule::makeLTOModule(MemoryBufferRef Buffer, const TargetOptions &options,
return EC;
std::unique_ptr<Module> &M = *MOrErr;
std::string TripleStr = M->getTargetTriple();
if (TripleStr.empty())
TripleStr = sys::getDefaultTargetTriple();
llvm::Triple Triple(TripleStr);
llvm::Triple Triple = M->getTargetTriple();
if (Triple.empty())
Triple = llvm::Triple(sys::getDefaultTargetTriple());
// find machine architecture for this module
std::string errMsg;
const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg);
const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
if (!march)
return make_error_code(object::object_error::arch_not_found);
@ -229,8 +228,8 @@ LTOModule::makeLTOModule(MemoryBufferRef Buffer, const TargetOptions &options,
CPU = "cyclone";
}
TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
options, std::nullopt);
TargetMachine *target = march->createTargetMachine(
Triple.str(), CPU, FeatureStr, options, std::nullopt);
std::unique_ptr<LTOModule> Ret(new LTOModule(std::move(M), Buffer, target));
Ret->parseSymbols();
@ -691,11 +690,11 @@ const char *LTOModule::getDependentLibrary(lto::InputFile *input, size_t index,
}
Expected<uint32_t> LTOModule::getMachOCPUType() const {
return MachO::getCPUType(Triple(Mod->getTargetTriple()));
return MachO::getCPUType(Mod->getTargetTriple());
}
Expected<uint32_t> LTOModule::getMachOCPUSubType() const {
return MachO::getCPUSubType(Triple(Mod->getTargetTriple()));
return MachO::getCPUSubType(Mod->getTargetTriple());
}
bool LTOModule::hasCtorDtor() const {

View File

@ -252,7 +252,7 @@ static void optimizeModule(Module &TheModule, TargetMachine &TM,
PassBuilder PB(&TM, PTO, PGOOpt, &PIC);
std::unique_ptr<TargetLibraryInfoImpl> TLII(
new TargetLibraryInfoImpl(Triple(TM.getTargetTriple())));
new TargetLibraryInfoImpl(TM.getTargetTriple()));
if (Freestanding)
TLII->disableAllFunctions();
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
@ -577,8 +577,7 @@ void ThinLTOCodeGenerator::crossReferenceSymbol(StringRef Name) {
// TargetMachine factory
std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
std::string ErrMsg;
const Target *TheTarget =
TargetRegistry::lookupTarget(TheTriple.str(), ErrMsg);
const Target *TheTarget = TargetRegistry::lookupTarget(TheTriple, ErrMsg);
if (!TheTarget) {
report_fatal_error(Twine("Can't load target for this Triple: ") + ErrMsg);
}
@ -677,7 +676,7 @@ void ThinLTOCodeGenerator::promote(Module &TheModule, ModuleSummaryIndex &Index,
// Convert the preserved symbols set from string to GUID
auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
File, PreservedSymbols, TheModule.getTargetTriple());
// Add used symbol to the preserved symbols.
addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
@ -730,7 +729,7 @@ void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule,
// Convert the preserved symbols set from string to GUID
auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
File, PreservedSymbols, TheModule.getTargetTriple());
addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
@ -770,7 +769,7 @@ void ThinLTOCodeGenerator::gatherImportedSummariesForModule(
// Convert the preserved symbols set from string to GUID
auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
File, PreservedSymbols, TheModule.getTargetTriple());
addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
@ -808,7 +807,7 @@ void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName,
// Convert the preserved symbols set from string to GUID
auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
File, PreservedSymbols, TheModule.getTargetTriple());
addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
@ -848,7 +847,7 @@ void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName,
void ThinLTOCodeGenerator::internalize(Module &TheModule,
ModuleSummaryIndex &Index,
const lto::InputFile &File) {
initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
initTMBuilder(TMBuilder, TheModule.getTargetTriple());
auto ModuleCount = Index.modulePaths().size();
auto ModuleIdentifier = TheModule.getModuleIdentifier();
@ -909,7 +908,7 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule,
* Perform post-importing ThinLTO optimizations.
*/
void ThinLTOCodeGenerator::optimize(Module &TheModule) {
initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
initTMBuilder(TMBuilder, TheModule.getTargetTriple());
// Optimize now
optimizeModule(TheModule, *TMBuilder.create(), OptLevel, Freestanding,

View File

@ -57,7 +57,7 @@ private:
// same names are added to llvm.compiler.used to prevent them from being
// deleted by optimizations.
void initializeLibCalls(const Module &TheModule) {
TargetLibraryInfoImpl TLII(Triple(TM.getTargetTriple()));
TargetLibraryInfoImpl TLII(TM.getTargetTriple());
TargetLibraryInfo TLI(TLII);
// TargetLibraryInfo has info on C runtime library calls on the current

View File

@ -1586,11 +1586,11 @@ Error IRLinker::run() {
!SrcTriple.isCompatibleWith(DstTriple))
emitWarning("Linking two modules of different target triples: '" +
SrcM->getModuleIdentifier() + "' is '" +
SrcM->getTargetTriple() + "' whereas '" +
DstM.getModuleIdentifier() + "' is '" + DstM.getTargetTriple() +
"'\n");
SrcM->getTargetTriple().str() + "' whereas '" +
DstM.getModuleIdentifier() + "' is '" +
DstM.getTargetTriple().str() + "'\n");
DstM.setTargetTriple(SrcTriple.merge(DstTriple));
DstM.setTargetTriple(Triple(SrcTriple.merge(DstTriple)));
// Loop over all of the linked values to compute type mappings.
computeTypeMapping();

View File

@ -139,7 +139,7 @@ const Target *TargetRegistry::lookupTarget(StringRef ArchName,
} else {
// Get the target specific parser.
std::string TempError;
TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), TempError);
TheTarget = TargetRegistry::lookupTarget(TheTriple, TempError);
if (!TheTarget) {
Error = "unable to get target for '" + TheTriple.getTriple() +
"', see --version and --triple.";
@ -150,19 +150,20 @@ const Target *TargetRegistry::lookupTarget(StringRef ArchName,
return TheTarget;
}
const Target *TargetRegistry::lookupTarget(StringRef TT, std::string &Error) {
const Target *TargetRegistry::lookupTarget(const Triple &TT,
std::string &Error) {
// Provide special warning when no targets are initialized.
if (targets().begin() == targets().end()) {
Error = "Unable to find target for this triple (no targets are registered)";
return nullptr;
}
Triple::ArchType Arch = Triple(TT).getArch();
Triple::ArchType Arch = TT.getArch();
auto ArchMatch = [&](const Target &T) { return T.ArchMatchFn(Arch); };
auto I = find_if(targets(), ArchMatch);
if (I == targets().end()) {
Error = ("No available targets are compatible with triple \"" + TT + "\"")
.str();
Error =
"No available targets are compatible with triple \"" + TT.str() + "\"";
return nullptr;
}

View File

@ -781,7 +781,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
std::vector<ELFPltEntry> ELFObjectFileBase::getPltEntries() const {
std::string Err;
const auto Triple = makeTriple();
const auto *T = TargetRegistry::lookupTarget(Triple.str(), Err);
const auto *T = TargetRegistry::lookupTarget(Triple, Err);
if (!T)
return {};
uint32_t JumpSlotReloc = 0, GlobDatReloc = 0;

View File

@ -66,7 +66,7 @@ basic_symbol_iterator IRObjectFile::symbol_end() const {
StringRef IRObjectFile::getTargetTriple() const {
// Each module must have the same target triple, so we arbitrarily access the
// first one.
return Mods[0]->getTargetTriple();
return Mods[0]->getTargetTriple().str();
}
Expected<MemoryBufferRef>

View File

@ -281,8 +281,7 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
setStr(Sym.IRName, GV->getName());
static const DenseSet<StringRef> PreservedSymbolsSet =
buildPreservedSymbolsSet(
llvm::Triple(GV->getParent()->getTargetTriple()));
buildPreservedSymbolsSet(GV->getParent()->getTargetTriple());
bool IsPreservedSymbol = PreservedSymbolsSet.contains(GV->getName());
if (Used.count(GV) || IsPreservedSymbol)
@ -350,9 +349,9 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
assert(!IRMods.empty());
Hdr.Version = storage::Header::kCurrentVersion;
setStr(Hdr.Producer, kExpectedProducerName);
setStr(Hdr.TargetTriple, IRMods[0]->getTargetTriple());
setStr(Hdr.TargetTriple, IRMods[0]->getTargetTriple().str());
setStr(Hdr.SourceFileName, IRMods[0]->getSourceFileName());
TT = Triple(IRMods[0]->getTargetTriple());
TT = IRMods[0]->getTargetTriple();
for (auto *M : IRMods)
if (Error Err = addModule(M))

View File

@ -78,7 +78,7 @@ initializeRecordStreamer(const Module &M,
std::string Err;
const Triple TT(M.getTargetTriple());
const Target *T = TargetRegistry::lookupTarget(TT.str(), Err);
const Target *T = TargetRegistry::lookupTarget(TT, Err);
assert(T && T->hasMCAsmParser());
std::unique_ptr<MCRegisterInfo> MRI(T->createMCRegInfo(TT.str()));

View File

@ -438,7 +438,7 @@ std::string getPGOFuncNameVarName(StringRef FuncName,
}
bool isGPUProfTarget(const Module &M) {
const auto &T = Triple(M.getTargetTriple());
const Triple &T = M.getTargetTriple();
return T.isAMDGPU() || T.isNVPTX();
}
@ -1437,7 +1437,7 @@ bool needsComdatForCounter(const GlobalObject &GO, const Module &M) {
if (GO.hasComdat())
return true;
if (!Triple(M.getTargetTriple()).supportsCOMDAT())
if (!M.getTargetTriple().supportsCOMDAT())
return false;
// See createPGOFuncNameVar for more details. To avoid link errors, profile

View File

@ -741,7 +741,7 @@ AArch64Arm64ECCallLowering::buildPatchableThunk(GlobalAlias *UnmangledAlias,
// Lower an indirect call with inline code.
void AArch64Arm64ECCallLowering::lowerCall(CallBase *CB) {
assert(Triple(CB->getModule()->getTargetTriple()).isOSWindows() &&
assert(CB->getModule()->getTargetTriple().isOSWindows() &&
"Only applicable for Windows targets");
IRBuilder<> B(CB);

View File

@ -74,7 +74,7 @@ static bool ShouldSignWithBKey(const Function &F, const AArch64Subtarget &STI) {
static bool hasELFSignedGOTHelper(const Function &F,
const AArch64Subtarget *STI) {
if (!Triple(STI->getTargetTriple()).isOSBinFormatELF())
if (!STI->getTargetTriple().isOSBinFormatELF())
return false;
const Module *M = F.getParent();
const auto *Flag = mdconst::extract_or_null<ConstantInt>(

View File

@ -430,8 +430,7 @@ void AArch64StackTagging::tagAlloca(AllocaInst *AI, Instruction *InsertBefore,
Intrinsic::aarch64_stgp);
InitializerBuilder IB(Size, DL, Ptr, SetTagFunc, SetTagZeroFunc, StgpFunc);
bool LittleEndian =
Triple(AI->getModule()->getTargetTriple()).isLittleEndian();
bool LittleEndian = AI->getModule()->getTargetTriple().isLittleEndian();
// Current implementation of initializer merging assumes little endianness.
if (MergeInit && !F->hasOptNone() && LittleEndian &&
Size < ClMergeInitSizeLimit) {
@ -473,7 +472,7 @@ Instruction *AArch64StackTagging::insertBaseTaggedPointer(
IRB.CreateIntrinsic(Intrinsic::aarch64_irg_sp, {},
{Constant::getNullValue(IRB.getInt64Ty())});
Base->setName("basetag");
auto TargetTriple = Triple(M.getTargetTriple());
const Triple &TargetTriple = M.getTargetTriple();
// This ABI will make it into Android API level 35.
// The ThreadLong format is the same as with HWASan, but the entries for
// stack MTE take two slots (16 bytes).

View File

@ -1129,8 +1129,8 @@ void AMDGPUSwLowerLDS::initAsanInfo() {
uint64_t Offset;
int Scale;
bool OrShadowOffset;
llvm::getAddressSanitizerParams(Triple(AMDGPUTM.getTargetTriple()), LongSize,
false, &Offset, &Scale, &OrShadowOffset);
llvm::getAddressSanitizerParams(AMDGPUTM.getTargetTriple(), LongSize, false,
&Offset, &Scale, &OrShadowOffset);
AsanInfo.Scale = Scale;
AsanInfo.Offset = Offset;
}

View File

@ -473,7 +473,7 @@ namespace dxil {
// would have been done at the time the module M is constructed in the earlier
// stages of compilation.
DXILOpBuilder::DXILOpBuilder(Module &M) : M(M), IRB(M.getContext()) {
Triple TT(Triple(M.getTargetTriple()));
const Triple &TT = M.getTargetTriple();
DXILVersion = TT.getDXILVersion();
ShaderStage = TT.getEnvironment();
// Ensure Environment type is known

View File

@ -358,7 +358,7 @@ public:
/// model and taking into account binding information from
/// DXILResourceBindingAnalysis.
bool lowerHandleFromBinding(Function &F) {
Triple TT(Triple(M.getTargetTriple()));
const Triple &TT = M.getTargetTriple();
if (TT.getDXILVersion() < VersionTuple(1, 6))
return lowerToCreateHandle(F);
return lowerToBindAndAnnotateHandle(F);
@ -528,7 +528,7 @@ public:
}
[[nodiscard]] bool lowerRawBufferLoad(Function &F) {
Triple TT(Triple(M.getTargetTriple()));
const Triple &TT = M.getTargetTriple();
VersionTuple DXILVersion = TT.getDXILVersion();
const DataLayout &DL = F.getDataLayout();
IRBuilder<> &IRB = OpBuilder.getIRB();
@ -628,7 +628,7 @@ public:
}
[[nodiscard]] bool lowerBufferStore(Function &F, bool IsRaw) {
Triple TT(Triple(M.getTargetTriple()));
const Triple &TT = M.getTargetTriple();
VersionTuple DXILVersion = TT.getDXILVersion();
const DataLayout &DL = F.getDataLayout();
IRBuilder<> &IRB = OpBuilder.getIRB();

View File

@ -1161,8 +1161,8 @@ void DXILBitcodeWriter::writeValueSymbolTableForwardDecl() {}
void DXILBitcodeWriter::writeModuleInfo() {
// Emit various pieces of data attached to a module.
if (!M.getTargetTriple().empty())
writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE, M.getTargetTriple(),
0 /*TODO*/);
writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE,
M.getTargetTriple().str(), 0 /*TODO*/);
const std::string &DL = M.getDataLayoutStr();
if (!DL.empty())
writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);

View File

@ -65,10 +65,10 @@ public:
std::string Data;
llvm::raw_string_ostream OS(Data);
const std::string OriginalTriple = M.getTargetTriple();
Triple OriginalTriple = M.getTargetTriple();
// Set to DXIL triple when write to bitcode.
// Only the output bitcode need to be DXIL triple.
M.setTargetTriple("dxil-ms-dx");
M.setTargetTriple(Triple("dxil-ms-dx"));
WriteDXILToFile(M, OS);

View File

@ -2406,7 +2406,7 @@ bool HexagonLoopIdiomRecognize::runOnCountableLoop(Loop *L) {
bool HexagonLoopIdiomRecognize::run(Loop *L) {
const Module &M = *L->getHeader()->getParent()->getParent();
if (Triple(M.getTargetTriple()).getArch() != Triple::hexagon)
if (M.getTargetTriple().getArch() != Triple::hexagon)
return false;
// If the loop could not be converted to canonical form, it must have an

View File

@ -523,9 +523,9 @@ public:
MipsAsmParser(const MCSubtargetInfo &sti, MCAsmParser &parser,
const MCInstrInfo &MII, const MCTargetOptions &Options)
: MCTargetAsmParser(Options, sti, MII),
ABI(MipsABIInfo::computeTargetABI(Triple(sti.getTargetTriple()),
sti.getCPU(), Options)) {
: MCTargetAsmParser(Options, sti, MII),
ABI(MipsABIInfo::computeTargetABI(sti.getTargetTriple(), sti.getCPU(),
Options)) {
MCAsmParserExtension::Initialize(parser);
parser.addAliasForDirective(".asciiz", ".asciz");

View File

@ -79,7 +79,7 @@ SPIRVTranslate(Module *M, std::string &SpirvObj, std::string &ErrMsg,
if (TargetTriple.getTriple().empty()) {
TargetTriple.setTriple(DefaultTriple);
M->setTargetTriple(DefaultTriple);
M->setTargetTriple(TargetTriple);
}
const Target *TheTarget =
TargetRegistry::lookupTarget(DefaultMArch, TargetTriple, ErrMsg);
@ -118,7 +118,7 @@ SPIRVTranslate(Module *M, std::string &SpirvObj, std::string &ErrMsg,
}
M->setDataLayout(MaybeDL.get());
TargetLibraryInfoImpl TLII(Triple(M->getTargetTriple()));
TargetLibraryInfoImpl TLII(M->getTargetTriple());
legacy::PassManager PM;
PM.add(new TargetLibraryInfoWrapperPass(TLII));
std::unique_ptr<MachineModuleInfoWrapperPass> MMIWP(
@ -148,9 +148,9 @@ SPIRVTranslateModule(Module *M, std::string &SpirvObj, std::string &ErrMsg,
const std::vector<std::string> &Opts) {
// optional: Opts[0] is a string representation of Triple,
// take Module triple otherwise
Triple TargetTriple(Opts.empty() || Opts[0].empty()
? M->getTargetTriple()
: Triple::normalize(Opts[0]));
Triple TargetTriple = Opts.empty() || Opts[0].empty()
? M->getTargetTriple()
: Triple(Triple::normalize(Opts[0]));
// optional: Opts[1] is a string representation of CodeGenOptLevel,
// no optimization otherwise
llvm::CodeGenOptLevel OLevel = CodeGenOptLevel::None;

View File

@ -958,9 +958,8 @@ void X86AsmPrinter::LowerASAN_CHECK_MEMACCESS(const MachineInstr &MI) {
uint64_t ShadowBase;
int MappingScale;
bool OrShadowOffset;
getAddressSanitizerParams(Triple(TM.getTargetTriple()), 64,
AccessInfo.CompileKernel, &ShadowBase,
&MappingScale, &OrShadowOffset);
getAddressSanitizerParams(TM.getTargetTriple(), 64, AccessInfo.CompileKernel,
&ShadowBase, &MappingScale, &OrShadowOffset);
StringRef Name = AccessInfo.IsWrite ? "store" : "load";
StringRef Op = OrShadowOffset ? "or" : "add";

View File

@ -171,7 +171,7 @@ public:
void CFGuardImpl::insertCFGuardCheck(CallBase *CB) {
assert(Triple(CB->getModule()->getTargetTriple()).isOSWindows() &&
assert(CB->getModule()->getTargetTriple().isOSWindows() &&
"Only applicable for Windows targets");
assert(CB->isIndirectCall() &&
"Control Flow Guard checks can only be added to indirect calls");
@ -200,7 +200,7 @@ void CFGuardImpl::insertCFGuardCheck(CallBase *CB) {
void CFGuardImpl::insertCFGuardDispatch(CallBase *CB) {
assert(Triple(CB->getModule()->getTargetTriple()).isOSWindows() &&
assert(CB->getModule()->getTargetTriple().isOSWindows() &&
"Only applicable for Windows targets");
assert(CB->isIndirectCall() &&
"Control Flow Guard checks can only be added to indirect calls");

View File

@ -659,8 +659,7 @@ void coro::BaseCloner::salvageDebugInfo() {
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;
// Only 64-bit ABIs have a register we can refer to with the entry value.
bool UseEntryValue =
llvm::Triple(OrigF.getParent()->getTargetTriple()).isArch64Bit();
bool UseEntryValue = OrigF.getParent()->getTargetTriple().isArch64Bit();
for (DbgVariableIntrinsic *DVI : Worklist)
coro::salvageDebugInfo(ArgToAllocaMap, *DVI, UseEntryValue);
for (DbgVariableRecord *DVR : DbgVariableRecords)

View File

@ -228,17 +228,17 @@ bool InternalizePass::internalizeModule(Module &M) {
// FIXME: We should probably add this (and the __stack_chk_guard) via some
// type of call-back in CodeGen.
AlwaysPreserved.insert("__stack_chk_fail");
if (Triple(M.getTargetTriple()).isOSAIX())
if (M.getTargetTriple().isOSAIX())
AlwaysPreserved.insert("__ssp_canary_word");
else
AlwaysPreserved.insert("__stack_chk_guard");
// Preserve the RPC interface for GPU host callbacks when internalizing.
if (Triple(M.getTargetTriple()).isNVPTX())
if (M.getTargetTriple().isNVPTX())
AlwaysPreserved.insert("__llvm_rpc_client");
// Mark all functions not in the api as internal.
IsWasm = Triple(M.getTargetTriple()).isOSBinFormatWasm();
IsWasm = M.getTargetTriple().isOSBinFormatWasm();
for (Function &I : M) {
if (!maybeInternalize(I, ComdatMap))
continue;

View File

@ -744,7 +744,7 @@ struct AddressSanitizer {
IntptrTy = Type::getIntNTy(*C, LongSize);
PtrTy = PointerType::getUnqual(*C);
Int32Ty = Type::getInt32Ty(*C);
TargetTriple = Triple(M.getTargetTriple());
TargetTriple = M.getTargetTriple();
Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel);
@ -905,7 +905,7 @@ public:
int LongSize = M.getDataLayout().getPointerSizeInBits();
IntptrTy = Type::getIntNTy(*C, LongSize);
PtrTy = PointerType::getUnqual(*C);
TargetTriple = Triple(M.getTargetTriple());
TargetTriple = M.getTargetTriple();
Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel);
if (ClOverrideDestructorKind != AsanDtorKind::Invalid)
@ -1038,8 +1038,7 @@ struct FunctionStackPoisoner : public InstVisitor<FunctionStackPoisoner> {
IntptrTy(ASan.IntptrTy),
IntptrPtrTy(PointerType::get(IntptrTy->getContext(), 0)),
Mapping(ASan.Mapping),
PoisonStack(ClStack &&
!Triple(F.getParent()->getTargetTriple()).isAMDGPU()) {}
PoisonStack(ClStack && !F.getParent()->getTargetTriple().isAMDGPU()) {}
bool runOnFunction() {
if (!PoisonStack)
@ -2710,7 +2709,7 @@ ModuleAddressSanitizer::getRedzoneSizeForGlobal(uint64_t SizeInBytes) const {
int ModuleAddressSanitizer::GetAsanVersion() const {
int LongSize = M.getDataLayout().getPointerSizeInBits();
bool isAndroid = Triple(M.getTargetTriple()).isAndroid();
bool isAndroid = M.getTargetTriple().isAndroid();
int Version = 8;
// 32-bit Android is one version ahead because of the switch to dynamic
// shadow.

View File

@ -904,7 +904,7 @@ bool GCOVProfiler::emitProfileNotes(
GlobalVariable *Counters = new GlobalVariable(
*M, CounterTy, false, GlobalValue::InternalLinkage,
Constant::getNullValue(CounterTy), "__llvm_gcov_ctr");
const llvm::Triple &Triple = llvm::Triple(M->getTargetTriple());
const llvm::Triple &Triple = M->getTargetTriple();
if (Triple.getObjectFormat() == llvm::Triple::XCOFF)
Counters->setSection("__llvm_gcov_ctr_section");
CountersBySP.emplace_back(Counters, SP);
@ -971,7 +971,7 @@ bool GCOVProfiler::emitProfileNotes(
}
if (EmitGCDA) {
const llvm::Triple &Triple = llvm::Triple(M->getTargetTriple());
const llvm::Triple &Triple = M->getTargetTriple();
if (Triple.getObjectFormat() == llvm::Triple::XCOFF)
emitModuleInitFunctionPtrs(CountersBySP);
else
@ -1053,7 +1053,7 @@ void GCOVProfiler::emitModuleInitFunctionPtrs(
CovInitGV->setInitializer(ConstantStruct::get(STy, InitFuncPtrs));
CovInitGV->setVisibility(GlobalValue::VisibilityTypes::DefaultVisibility);
CovInitGV->setSection(getInstrProfSectionName(
IPSK_covinit, Triple(M->getTargetTriple()).getObjectFormat()));
IPSK_covinit, M->getTargetTriple().getObjectFormat()));
CovInitGV->setAlignment(Align(INSTR_PROF_DATA_ALIGNMENT));
CovInitGV->setConstant(true);
}

View File

@ -489,7 +489,7 @@ PreservedAnalyses HWAddressSanitizerPass::run(Module &M,
if (checkIfAlreadyInstrumented(M, "nosanitize_hwaddress"))
return PreservedAnalyses::all();
const StackSafetyGlobalInfo *SSI = nullptr;
auto TargetTriple = llvm::Triple(M.getTargetTriple());
const Triple &TargetTriple = M.getTargetTriple();
if (shouldUseStackSafetyAnalysis(TargetTriple, Options.DisableOptimization))
SSI = &MAM.getResult<StackSafetyGlobalAnalysis>(M);
@ -665,7 +665,7 @@ void HWAddressSanitizer::removeFnAttributes(Function *F) {
/// inserts a call to __hwasan_init to the module's constructor list.
void HWAddressSanitizer::initializeModule() {
LLVM_DEBUG(dbgs() << "Init " << M.getName() << "\n");
TargetTriple = Triple(M.getTargetTriple());
TargetTriple = M.getTargetTriple();
for (Function &F : M.functions())
removeFnAttributes(&F);

View File

@ -69,7 +69,7 @@ public:
std::string SymbolName = INSTR_PROF_ORDERFILE_BUFFER_NAME_STR;
OrderFileBuffer = new GlobalVariable(M, BufferTy, false, GlobalValue::LinkOnceODRLinkage,
Constant::getNullValue(BufferTy), SymbolName);
Triple TT = Triple(M.getTargetTriple());
const Triple &TT = M.getTargetTriple();
OrderFileBuffer->setSection(
getInstrProfSectionName(IPSK_orderfile, TT.getObjectFormat()));

View File

@ -253,7 +253,7 @@ public:
InstrLowerer(Module &M, const InstrProfOptions &Options,
std::function<const TargetLibraryInfo &(Function &F)> GetTLI,
bool IsCS)
: M(M), Options(Options), TT(Triple(M.getTargetTriple())), IsCS(IsCS),
: M(M), Options(Options), TT(M.getTargetTriple()), IsCS(IsCS),
GetTLI(GetTLI), DataReferencedByCode(profDataReferencedByCode(M)) {}
bool lower();

View File

@ -283,7 +283,7 @@ private:
class ModuleMemProfiler {
public:
ModuleMemProfiler(Module &M) { TargetTriple = Triple(M.getTargetTriple()); }
ModuleMemProfiler(Module &M) { TargetTriple = M.getTargetTriple(); }
bool instrumentModule(Module &);
@ -426,7 +426,7 @@ MemProfiler::isInterestingMemoryAccess(Instruction *I) const {
if (GV->hasSection()) {
StringRef SectionName = GV->getSection();
// Check if the global is in the PGO counters section.
auto OF = Triple(I->getModule()->getTargetTriple()).getObjectFormat();
auto OF = I->getModule()->getTargetTriple().getObjectFormat();
if (SectionName.ends_with(
getInstrProfSectionName(IPSK_cnts, OF, /*AddSegmentInfo=*/false)))
return std::nullopt;
@ -542,7 +542,7 @@ void createProfileFileNameVar(Module &M) {
GlobalVariable *ProfileNameVar = new GlobalVariable(
M, ProfileNameConst->getType(), /*isConstant=*/true,
GlobalValue::WeakAnyLinkage, ProfileNameConst, MemProfFilenameVar);
Triple TT(M.getTargetTriple());
const Triple &TT = M.getTargetTriple();
if (TT.supportsCOMDAT()) {
ProfileNameVar->setLinkage(GlobalValue::ExternalLinkage);
ProfileNameVar->setComdat(M.getOrInsertComdat(MemProfFilenameVar));
@ -557,7 +557,7 @@ void createMemprofHistogramFlagVar(Module &M) {
auto MemprofHistogramFlag = new GlobalVariable(
M, IntTy1, true, GlobalValue::WeakAnyLinkage,
Constant::getIntegerValue(IntTy1, APInt(1, ClHistogram)), VarName);
Triple TT(M.getTargetTriple());
const Triple &TT = M.getTargetTriple();
if (TT.supportsCOMDAT()) {
MemprofHistogramFlag->setLinkage(GlobalValue::ExternalLinkage);
MemprofHistogramFlag->setComdat(M.getOrInsertComdat(VarName));
@ -571,7 +571,7 @@ void createMemprofDefaultOptionsVar(Module &M) {
GlobalVariable *OptionsVar = new GlobalVariable(
M, OptionsConst->getType(), /*isConstant=*/true,
GlobalValue::WeakAnyLinkage, OptionsConst, getMemprofOptionsSymbolName());
Triple TT(M.getTargetTriple());
const Triple &TT = M.getTargetTriple();
if (TT.supportsCOMDAT()) {
OptionsVar->setLinkage(GlobalValue::ExternalLinkage);
OptionsVar->setComdat(M.getOrInsertComdat(OptionsVar->getName()));

View File

@ -994,7 +994,7 @@ FunctionCallee MemorySanitizer::getKmsanShadowOriginAccessFn(bool isStore,
void MemorySanitizer::initializeModule(Module &M) {
auto &DL = M.getDataLayout();
TargetTriple = Triple(M.getTargetTriple());
TargetTriple = M.getTargetTriple();
bool ShadowPassed = ClShadowBase.getNumOccurrences() > 0;
bool OriginPassed = ClOriginBase.getNumOccurrences() > 0;

View File

@ -374,7 +374,7 @@ bool SanitizerBinaryMetadata::pretendAtomicAccess(const Value *Addr) {
// Some compiler-generated accesses are known racy, to avoid false positives
// in data-race analysis pretend they're atomic.
if (GV->hasSection()) {
const auto OF = Triple(Mod.getTargetTriple()).getObjectFormat();
const auto OF = Mod.getTargetTriple().getObjectFormat();
const auto ProfSec =
getInstrProfSectionName(IPSK_cnts, OF, /*AddSegmentInfo=*/false);
if (GV->getSection().ends_with(ProfSec))

View File

@ -400,7 +400,7 @@ bool ModuleSanitizerCoverage::instrumentModule() {
DL = &M.getDataLayout();
CurModule = &M;
CurModuleUniqueId = getUniqueModuleId(CurModule);
TargetTriple = Triple(M.getTargetTriple());
TargetTriple = M.getTargetTriple();
FunctionGuardArray = nullptr;
Function8bitCounterArray = nullptr;
FunctionBoolArray = nullptr;

View File

@ -360,7 +360,7 @@ static bool shouldInstrumentReadWriteFromAddress(const Module *M, Value *Addr) {
if (GV->hasSection()) {
StringRef SectionName = GV->getSection();
// Check if the global is in the PGO counters section.
auto OF = Triple(M->getTargetTriple()).getObjectFormat();
auto OF = M->getTargetTriple().getObjectFormat();
if (SectionName.ends_with(
getInstrProfSectionName(IPSK_cnts, OF, /*AddSegmentInfo=*/false)))
return false;

View File

@ -121,7 +121,7 @@ private:
} // namespace
TypeSanitizer::TypeSanitizer(Module &M)
: TargetTriple(Triple(M.getTargetTriple())),
: TargetTriple(M.getTargetTriple()),
AnonNameRegex("^_ZTS.*N[1-9][0-9]*_GLOBAL__N") {
const DataLayout &DL = M.getDataLayout();
IntptrTy = DL.getIntPtrType(M.getContext());

View File

@ -114,7 +114,8 @@ std::unique_ptr<Module> llvm::parseInputFile(StringRef Filename,
TargetTriple.setTriple(TheTriple.getTriple());
}
Result->setTargetTriple(TargetTriple.getTriple()); // override the triple
// override the triple
Result->setTargetTriple(TargetTriple);
return Result;
}

View File

@ -575,7 +575,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
return 1;
}
if (!TargetTriple.empty())
M->setTargetTriple(Triple::normalize(TargetTriple));
M->setTargetTriple(Triple(Triple::normalize(TargetTriple)));
std::optional<CodeModel::Model> CM_IR = M->getCodeModel();
if (!CM && CM_IR)
@ -633,7 +633,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
}
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfoImpl TLII(Triple(M->getTargetTriple()));
TargetLibraryInfoImpl TLII(M->getTargetTriple());
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (DisableSimplifyLibCalls)

View File

@ -373,13 +373,12 @@ private:
// currently handle external linking) we add a secondary module which defines
// an empty '__main' function.
static void addCygMingExtraModule(ExecutionEngine &EE, LLVMContext &Context,
StringRef TargetTripleStr) {
const Triple &TargetTriple) {
IRBuilder<> Builder(Context);
Triple TargetTriple(TargetTripleStr);
// Create a new module.
std::unique_ptr<Module> M = std::make_unique<Module>("CygMingHelper", Context);
M->setTargetTriple(TargetTripleStr);
M->setTargetTriple(TargetTriple);
// Create an empty function named "__main".
Type *ReturnTy;
@ -492,7 +491,7 @@ int main(int argc, char **argv, char * const *envp) {
// If we are supposed to override the target triple, do so now.
if (!TargetTriple.empty())
Mod->setTargetTriple(Triple::normalize(TargetTriple));
Mod->setTargetTriple(Triple(Triple::normalize(TargetTriple)));
// Enable MCJIT if desired.
RTDyldMemoryManager *RTDyldMM = nullptr;
@ -588,7 +587,7 @@ int main(int argc, char **argv, char * const *envp) {
// If the target is Cygwin/MingW and we are generating remote code, we
// need an extra module to help out with linking.
if (RemoteMCJIT && Triple(Mod->getTargetTriple()).isOSCygMing()) {
if (RemoteMCJIT && Mod->getTargetTriple().isOSCygMing()) {
addCygMingExtraModule(*EE, Context, Mod->getTargetTriple());
}
@ -932,7 +931,7 @@ int runOrcJIT(const char *ProgName) {
std::optional<DataLayout> DL;
MainModule.withModuleDo([&](Module &M) {
if (!M.getTargetTriple().empty())
TT = Triple(M.getTargetTriple());
TT = M.getTargetTriple();
if (!M.getDataLayout().isDefault())
DL = M.getDataLayout();
});

View File

@ -661,8 +661,7 @@ createRegInfo(const object::ObjectFile &Obj) {
TT.setVendor(Triple::UnknownVendor);
TT.setOS(Triple::UnknownOS);
std::string TargetLookupError;
const Target *TheTarget =
TargetRegistry::lookupTarget(TT.str(), TargetLookupError);
const Target *TheTarget = TargetRegistry::lookupTarget(TT, TargetLookupError);
if (!TargetLookupError.empty())
return nullptr;
MCRegInfo.reset(TheTarget->createMCRegInfo(TT.str()));

View File

@ -310,7 +310,7 @@ Error assembleToStream(const ExegesisTarget &ET,
MCContext &MCContext = MMIWP->getMMI().getContext();
legacy::PassManager PM;
TargetLibraryInfoImpl TLII(Triple(Module->getTargetTriple()));
TargetLibraryInfoImpl TLII(Module->getTargetTriple());
PM.add(new TargetLibraryInfoWrapperPass(TLII));
TargetPassConfig *TPC = TM->createPassConfig(PM);

View File

@ -91,7 +91,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
}
// Set up the module to build for our target.
M->setTargetTriple(TM->getTargetTriple().normalize());
M->setTargetTriple(TM->getTargetTriple());
M->setDataLayout(TM->createDataLayout());
// Build up a PM to do instruction selection.

View File

@ -124,7 +124,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
// Set up target dependant options
//
M->setTargetTriple(TM->getTargetTriple().normalize());
M->setTargetTriple(TM->getTargetTriple());
M->setDataLayout(TM->createDataLayout());
codegen::setFunctionAttributes(TM->getTargetCPU(),
TM->getTargetFeatureString(), *M);

View File

@ -302,11 +302,11 @@ lto_module_t lto_module_create_in_codegen_context(const void *mem,
void lto_module_dispose(lto_module_t mod) { delete unwrap(mod); }
const char* lto_module_get_target_triple(lto_module_t mod) {
return unwrap(mod)->getTargetTriple().c_str();
return unwrap(mod)->getTargetTriple().str().c_str();
}
void lto_module_set_target_triple(lto_module_t mod, const char *triple) {
return unwrap(mod)->setTargetTriple(StringRef(triple));
return unwrap(mod)->setTargetTriple(Triple(StringRef(triple)));
}
unsigned int lto_module_get_num_symbols(lto_module_t mod) {

View File

@ -577,7 +577,7 @@ extern "C" int optMain(
// If we are supposed to override the target triple, do so now.
if (!TargetTriple.empty())
M->setTargetTriple(Triple::normalize(TargetTriple));
M->setTargetTriple(Triple(Triple::normalize(TargetTriple)));
// Immediately run the verifier to catch any problems before starting up the
// pass pipelines. Otherwise we can crash on broken code during

View File

@ -218,7 +218,7 @@ static const char DiamondOfTrianglesRefGraph[] =
"}\n";
static LazyCallGraph buildCG(Module &M) {
TargetLibraryInfoImpl TLII(Triple(M.getTargetTriple()));
TargetLibraryInfoImpl TLII(M.getTargetTriple());
TargetLibraryInfo TLI(TLII);
auto GetTLI = [&TLI](Function &F) -> TargetLibraryInfo & { return TLI; };

View File

@ -50,6 +50,6 @@ Triple llvm::dwarf::utils::getDefaultTargetTripleForAddrSize(uint8_t AddrSize) {
bool llvm::dwarf::utils::isConfigurationSupported(Triple &T) {
initLLVMIfNeeded();
std::string Err;
const Target *TheTarget = TargetRegistry::lookupTarget(T.getTriple(), Err);
const Target *TheTarget = TargetRegistry::lookupTarget(T, Err);
return TheTarget && TheTarget->hasMCAsmBackend();
}

View File

@ -553,7 +553,7 @@ TEST(LogicalViewTest, CodeViewReader) {
TT.setOS(Triple::UnknownOS);
std::string TargetLookupError;
if (!TargetRegistry::lookupTarget(std::string(TT.str()), TargetLookupError))
if (!TargetRegistry::lookupTarget(TT, TargetLookupError))
return;
SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);

View File

@ -338,7 +338,7 @@ TEST(LogicalViewTest, DWARFReader) {
TT.setOS(Triple::UnknownOS);
std::string TargetLookupError;
if (!TargetRegistry::lookupTarget(std::string(TT.str()), TargetLookupError))
if (!TargetRegistry::lookupTarget(TT, TargetLookupError))
GTEST_SKIP();
SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);

View File

@ -40,7 +40,7 @@ protected:
Module *createEmptyModule(StringRef Name = StringRef()) {
Module * M = new Module(Name, Context);
M->setTargetTriple(Triple::normalize(BuilderTriple));
M->setTargetTriple(Triple(Triple::normalize(BuilderTriple)));
return M;
}

View File

@ -16,11 +16,11 @@ using namespace llvm;
bool OrcNativeTarget::NativeTargetInitialized = false;
ModuleBuilder::ModuleBuilder(LLVMContext &Context, StringRef Triple,
ModuleBuilder::ModuleBuilder(LLVMContext &Context, StringRef TripleStr,
StringRef Name)
: M(new Module(Name, Context)) {
if (Triple != "")
M->setTargetTriple(Triple);
: M(new Module(Name, Context)) {
if (TripleStr != "")
M->setTargetTriple(Triple(TripleStr));
}
void llvm::orc::CoreAPIsBasedStandardTest::OverridableDispatcher::dispatch(

View File

@ -73,7 +73,7 @@ static bool testSetProcessAllSections(std::unique_ptr<MemoryBuffer> Obj,
TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
LLVMContext Context;
auto M = std::make_unique<Module>("", Context);
M->setTargetTriple("x86_64-unknown-linux-gnu");
M->setTargetTriple(Triple("x86_64-unknown-linux-gnu"));
// These values are only here to ensure that the module is non-empty.
// They are no longer relevant to the test.
@ -88,7 +88,7 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
// to try to build a TM.
OrcNativeTarget::initialize();
std::unique_ptr<TargetMachine> TM(EngineBuilder().selectTarget(
Triple(M->getTargetTriple()), "", "", SmallVector<std::string, 1>()));
M->getTargetTriple(), "", "", SmallVector<std::string, 1>()));
if (!TM)
GTEST_SKIP();

View File

@ -165,7 +165,7 @@ TEST_F(ReOptimizeLayerTest, BasicReOptimization) {
ThreadSafeContext Ctx(std::make_unique<LLVMContext>());
auto M = std::make_unique<Module>("<main>", *Ctx.getContext());
M->setTargetTriple(sys::getProcessTriple());
M->setTargetTriple(Triple(sys::getProcessTriple()));
(void)createRetFunction(M.get(), "main", 42);

View File

@ -425,7 +425,7 @@ namespace llvm {
mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
"i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
"a:0:64-s:64:64-f80:128:128");
mod->setTargetTriple("x86_64-unknown-linux-gnu");
mod->setTargetTriple(Triple("x86_64-unknown-linux-gnu"));
// Type Definitions
std::vector<Type*>FuncTy_0_args;

View File

@ -71,7 +71,7 @@ void runChecks(
std::unique_ptr<Module> M = MParser->parseIRModule();
ASSERT_TRUE(M);
M->setTargetTriple(TM->getTargetTriple().getTriple());
M->setTargetTriple(TM->getTargetTriple());
M->setDataLayout(TM->createDataLayout());
MachineModuleInfo MMI(TM);

View File

@ -52,7 +52,7 @@ void runChecks(
std::unique_ptr<Module> M = MParser->parseIRModule();
ASSERT_TRUE(M);
M->setTargetTriple(TM->getTargetTriple().getTriple());
M->setTargetTriple(TM->getTargetTriple());
M->setDataLayout(TM->createDataLayout());
MachineModuleInfo MMI(TM);

Some files were not shown because too many files have changed in this diff Show More