37std::once_flag InitOnceFlag;
38void InitializeSPIRVTarget() {
39 std::call_once(InitOnceFlag, []() {
43 LLVMInitializeSPIRVAsmPrinter();
56 const std::vector<std::string> &AllowExtNames,
59 static const std::string DefaultTriple =
"spirv64-unknown-unknown";
60 static const std::string DefaultMArch =
"";
62 std::set<SPIRV::Extension::Extension> AllowedExtIds;
65 if (!UnknownExt.
empty()) {
66 ErrMsg =
"Unknown SPIR-V extension: " + UnknownExt.
str();
71 InitializeSPIRVTarget();
75 M->setTargetTriple(TargetTriple);
87 std::optional<Reloc::Model> RM;
88 std::optional<CodeModel::Model> CM;
90 TargetTriple,
"",
"",
Options, RM, CM, OLevel));
92 ErrMsg =
"Could not allocate target machine!";
99 ->initAvailableExtensions(AllowedExtIds);
101 if (M->getCodeModel())
102 Target->setCodeModel(*M->getCodeModel());
104 std::string DLStr = M->getDataLayoutStr();
106 DLStr.empty() ?
Target->createDataLayout().getStringRepresentation()
112 M->setDataLayout(MaybeDL.
get());
117 std::unique_ptr<MachineModuleInfoWrapperPass> MMIWP(
119 Target->getObjFileLowering()->Initialize(MMIWP->getMMI().getContext(),
124 if (
Target->addPassesToEmitFile(PM, OutStream,
nullptr,
126 ErrMsg =
"Target machine cannot emit a file of this type";
131 SpirvObj = OutBuffer.
str();
140 const std::vector<std::string> &AllowExtNames,
141 const std::vector<std::string> &Opts) {
144 Triple TargetTriple = Opts.
empty() || Opts[0].empty()
145 ? M->getTargetTriple()
150 if (Opts.size() > 1 && !Opts[1].empty()) {
154 ErrMsg =
"Invalid optimization level!";
159 std::move(TargetTriple));
#define LLVM_EXTERNAL_VISIBILITY
Module.h This file contains the declarations for the Module class.
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVTargetMC()
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVTargetInfo()
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVTarget()
Target-Independent Code Generator Pass Configuration Options pass.
static LLVM_ABI Expected< DataLayout > parse(StringRef LayoutString)
Parse a data layout string and return the layout.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
A Module instance is used to store all the information related to an LLVM module.
const SPIRVSubtarget * getSubtargetImpl() const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef str() const
Explicit conversion to StringRef.
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
Implementation of the target library information.
Target - Wrapper for Target specific information.
TargetMachine * createTargetMachine(const Triple &TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOptLevel OL=CodeGenOptLevel::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
Triple - Helper class for working with autoconf configuration names.
LLVM_ABI void setTriple(const Twine &Str)
Set all components to the new triple Str.
static LLVM_ABI std::string normalize(StringRef Str, CanonicalForm Form=CanonicalForm::ANY)
Turn an arbitrary machine specification into the canonical triple form (or something sensible that th...
const std::string & getTriple() const
bool empty() const
Whether the triple is empty / default constructed.
PassManager manages ModulePassManagers.
void add(Pass *P) override
Add a pass to the queue of passes to run.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
A raw_ostream that writes to an SmallVector or SmallString.
std::optional< CodeGenOptLevel > parseLevel(char C)
Parse C as a single digit integer and get matching CodeGenLevel.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_EXTERNAL_VISIBILITY bool SPIRVTranslate(Module *M, std::string &SpirvObj, std::string &ErrMsg, const std::vector< std::string > &AllowExtNames, llvm::CodeGenOptLevel OLevel, Triple TargetTriple)
CodeGenOptLevel
Code generation optimization level.
LLVM_EXTERNAL_VISIBILITY bool SPIRVTranslateModule(Module *M, std::string &SpirvObj, std::string &ErrMsg, const std::vector< std::string > &AllowExtNames, const std::vector< std::string > &Opts)
const char * toString(DWARFSectionKind Kind)
static StringRef checkExtensions(const std::vector< std::string > &ExtNames, std::set< SPIRV::Extension::Extension > &AllowedExtensions)
Validates and converts extension names into internal enum values.
static const Target * lookupTarget(StringRef TripleStr, std::string &Error)
lookupTarget - Lookup a target based on a target triple.