50void parseSPIRVCommandLineOptions(
const std::vector<std::string> &
Options,
52 static constexpr const char *Origin =
"SPIRVTranslateModule";
54 std::vector<const char *> Argv(1, Origin);
56 Argv.push_back(Arg.c_str());
61std::once_flag InitOnceFlag;
62void InitializeSPIRVTarget() {
63 std::call_once(InitOnceFlag, []() {
81 const std::vector<std::string> &AllowExtNames,
82 const std::vector<std::string> &Opts) {
84 static const std::string DefaultTriple =
"spirv64-unknown-unknown";
85 static const std::string DefaultMArch =
"";
90 parseSPIRVCommandLineOptions(Opts, &ErrorStream);
91 if (!Errors.empty()) {
100 ErrMsg =
"Invalid optimization level!";
106 std::set<SPIRV::Extension::Extension> AllowedExtIds;
109 if (!UnknownExt.
empty()) {
110 ErrMsg =
"Unknown SPIR-V extension: " + UnknownExt.
str();
116 InitializeSPIRVTarget();
118 Triple TargetTriple(SpvTargetTriple.empty()
119 ? M->getTargetTriple()
123 M->setTargetTriple(DefaultTriple);
135 std::optional<Reloc::Model> RM;
136 std::optional<CodeModel::Model> CM;
137 std::unique_ptr<TargetMachine>
Target =
141 ErrMsg =
"Could not allocate target machine!";
145 if (M->getCodeModel())
146 Target->setCodeModel(*M->getCodeModel());
148 std::string DLStr = M->getDataLayoutStr();
150 DLStr.empty() ?
Target->createDataLayout().getStringRepresentation()
156 M->setDataLayout(MaybeDL.
get());
168 if (
Target->addPassesToEmitFile(PM, OutStream,
nullptr,
170 ErrMsg =
"Target machine cannot emit a file of this type";
175 SpirvObj = OutBuffer.
str();
#define LLVM_EXTERNAL_VISIBILITY
Module.h This file contains the declarations for the Module class.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVAsmPrinter()
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVTargetMC()
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVTargetInfo()
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVTarget()
Target-Independent Code Generator Pass Configuration Options pass.
static 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.
MachineModuleInfo & getMMI()
const MCContext & getContext() const
A Module instance is used to store all the information related to an LLVM module.
static void addExtensionsToClOpt(const std::set< SPIRV::Extension::Extension > &AllowList)
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(StringRef 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.
std::string normalize() const
Return the normalized form of this triple's string.
void setTriple(const Twine &Str)
Set all components to the new triple Str.
const std::string & getTriple() const
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.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
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.
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
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 llvm::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 Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.