Skip to content

Commit 0b727b2

Browse files
update usage of SPIR-V Backend API
1 parent 335ff78 commit 0b727b2

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

third_party/intel/lib/Target/SPIRV/SPIRVTranslation.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,14 @@ namespace llvm {
1919
using namespace llvm;
2020
using namespace SPIRV;
2121

22-
// TODO: The LLVM SPIR-V backend API has changed in
23-
// https://github.com/llvm/llvm-project/pull/124745 to improve the way SPIR-V
24-
// Backend API works with user facing options and allow for multithreading
25-
// within the host application. This PR in llvm-project breaks existing API
26-
// contract in how options are being interpreted inside the call, and we need to
27-
// update this file accordingly. After this change is visible in the LLVM
28-
// version from cmake/llvm-hash.txt we will need to update the call to
29-
// SPIRVTranslateModule(M, Result, ErrMsg, AllowExtNames, Opts) in a style of
30-
// SPIRVTranslate(M, Result, ErrMsg, {"all"}, CodeGenOptLevel::Aggressive,
31-
// Triple("spirv64v1.6-unknown-unknown")).
32-
3322
// The LLVM SPIR-V backend exposes an API call that translates LLVM module to
3423
// SPIR-V and writes results into a string as binary SPIR-V output, providing
35-
// diagnostics on fail and means of configuring translation
36-
// (https://github.com/llvm/llvm-project/pull/107216).
37-
extern "C" bool
38-
SPIRVTranslateModule(Module *M, std::string &SpirvObj, std::string &ErrMsg,
39-
const std::vector<std::string> &AllowExtNames,
40-
const std::vector<std::string> &Opts);
24+
// diagnostics on fail and means of configuring translation.
25+
extern "C" bool SPIRVTranslate(Module *M, std::string &SpirvObj,
26+
std::string &ErrMsg,
27+
const std::vector<std::string> &AllowExtNames,
28+
llvm::CodeGenOptLevel OLevel,
29+
Triple TargetTriple);
4130

4231
static inline Triple::SubArchType
4332
spirvVersionToSubArch(SPIRV::VersionNumber VN) {
@@ -63,10 +52,7 @@ spirvVersionToSubArch(SPIRV::VersionNumber VN) {
6352
bool runSpirvBackend(Module *M, std::string &Result, std::string &ErrMsg,
6453
const SPIRV::TranslatorOpts &TranslatorOpts) {
6554
static const std::string DefaultTriple = "spirv64v1.6-unknown-unknown";
66-
static const std::vector<std::string> Opts{
67-
"--avoid-spirv-capabilities", "Shader", "--translator-compatibility-mode",
68-
"--spirv-ext=all", "-spirv-O3"};
69-
static const std::vector<std::string> AllowExtNames;
55+
static const std::vector<std::string> AllowExtNames{"all"};
7056

7157
// Correct the Triple value if needed
7258
Triple TargetTriple(M->getTargetTriple());
@@ -79,16 +65,17 @@ bool runSpirvBackend(Module *M, std::string &Result, std::string &ErrMsg,
7965
// We need to reset Data Layout to conform with the TargetMachine
8066
M->setDataLayout("");
8167
}
68+
if (TargetTriple.getTriple().empty())
69+
TargetTriple.setTriple(DefaultTriple);
8270
if (TranslatorOpts.getMaxVersion() != VersionNumber::MaximumVersion) {
83-
if (TargetTriple.getTriple().empty())
84-
TargetTriple.setTriple(DefaultTriple);
8571
TargetTriple.setArch(TargetTriple.getArch(),
8672
spirvVersionToSubArch(TranslatorOpts.getMaxVersion()));
8773
M->setTargetTriple(TargetTriple.str());
8874
}
8975

9076
// Translate the Module into SPIR-V
91-
return SPIRVTranslateModule(M, Result, ErrMsg, AllowExtNames, Opts);
77+
return SPIRVTranslate(M, Result, ErrMsg, AllowExtNames,
78+
CodeGenOptLevel::Aggressive, TargetTriple);
9279
}
9380

9481
bool runSpirvBackend(Module *M, std::ostream &OS, std::string &ErrMsg,

0 commit comments

Comments
 (0)