33std::once_flag InitOnceFlag;
34void InitializeSPIRVTarget() {
35 std::call_once(InitOnceFlag, []() {
39 LLVMInitializeSPIRVAsmPrinter();
52 const std::vector<std::string> &AllowExtNames,
55 static const std::string DefaultTriple =
"spirv64-unknown-unknown";
56 static const std::string DefaultMArch =
"";
61 if (!UnknownExt.
empty()) {
62 ErrMsg =
"Unknown SPIR-V extension: " + UnknownExt.
str();
67 InitializeSPIRVTarget();
71 M->setTargetTriple(TargetTriple);
83 std::optional<Reloc::Model> RM;
84 std::optional<CodeModel::Model> CM;
86 TargetTriple,
"",
"",
Options, RM, CM, OLevel));
88 ErrMsg =
"Could not allocate target machine!";
97 if (M->getCodeModel())
98 Target->setCodeModel(*M->getCodeModel());
100 std::string DLStr = M->getDataLayoutStr();
107 M->setDataLayout(MaybeDL.
get());
116 SpirvObj = OutBuffer.
str();
125 const std::vector<std::string> &AllowExtNames,
126 const std::vector<std::string> &Opts) {
129 Triple TargetTriple = Opts.empty() || Opts[0].empty()
130 ? M->getTargetTriple()
135 if (Opts.size() > 1 && !Opts[1].empty()) {
139 ErrMsg =
"Invalid optimization level!";
144 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.
Lightweight error class with error context and mandatory checking.
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.
void initAvailableExtensions(const ExtensionSet &AllowedExtIds)
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.
Represent a constant reference to a string, i.e.
std::string str() const
Get the contents as an std::string.
constexpr bool empty() const
Check if the string is empty.
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 std::string computeDataLayout(StringRef ABIName="") const
Compute the LLVM IR data layout string based on the triple.
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
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.
DenseSet< SPIRV::Extension::Extension > ExtensionSet
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)
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI Error runCodeGenPipeline(TargetMachine &TM, Module &M, raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS, CodeGenFileType CGFT, bool DisableVerify=true, bool DisableSimplifyLibCalls=false, IntrusiveRefCntPtr< vfs::FileSystem > VFS=vfs::getRealFileSystem())
static StringRef checkExtensions(ArrayRef< std::string > ExtNames, ExtensionSet &AllowedExtensions)
Validates and converts extension names into internal enum values.
static LLVM_ABI const Target * lookupTarget(const Triple &TheTriple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.