Skip to content

Commit 68d4c4c

Browse files
NikitaRudenkoIntelvladimirlaz
authored andcommitted
Move SPIRVAllowUnknownIntrinsics option to TranslatorOpts class
1 parent fcc607a commit 68d4c4c

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

llvm-spirv/include/LLVMSPIRVOpts.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ class TranslatorOpts {
137137

138138
FPContractMode getFPContractMode() const { return FPCMode; }
139139

140+
bool isSPIRVAllowUnknownIntrinsicsEnabled() const noexcept {
141+
return SPIRVAllowUnknownIntrinsics;
142+
}
143+
144+
void
145+
setSPIRVAllowUnknownIntrinsicsEnabled(bool AllowUnknownIntrinsics) noexcept {
146+
SPIRVAllowUnknownIntrinsics = AllowUnknownIntrinsics;
147+
}
148+
140149
private:
141150
// Common translation options
142151
VersionNumber MaxVersion = VersionNumber::MaximumVersion;
@@ -159,6 +168,10 @@ class TranslatorOpts {
159168
// - FPContractMode::Fast allows *all* operations to be contracted
160169
// for all entry points
161170
FPContractMode FPCMode = FPContractMode::On;
171+
172+
// Unknown LLVM intrinsics will be translated as external function calls in
173+
// SPIR-V
174+
bool SPIRVAllowUnknownIntrinsics = false;
162175
};
163176

164177
} // namespace SPIRV

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ using namespace OCLUtil;
9292

9393
namespace SPIRV {
9494

95-
cl::opt<bool> SPIRVAllowUnknownIntrinsics(
96-
"spirv-allow-unknown-intrinsics", cl::init(false),
97-
cl::desc("Unknown LLVM intrinsics will be translated as external function "
98-
"calls in SPIR-V"));
99-
10095
static void foreachKernelArgMD(
10196
MDNode *MD, SPIRVFunction *BF,
10297
std::function<void(const std::string &Str, SPIRVFunctionParameter *BA)>
@@ -509,8 +504,8 @@ SPIRVFunction *LLVMToSPIRV::transFunctionDecl(Function *F) {
509504
if (auto BF = getTranslatedValue(F))
510505
return static_cast<SPIRVFunction *>(BF);
511506

512-
if (F->isIntrinsic() &&
513-
(!SPIRVAllowUnknownIntrinsics || isKnownIntrinsic(F->getIntrinsicID()))) {
507+
if (F->isIntrinsic() && (!BM->isSPIRVAllowUnknownIntrinsicsEnabled() ||
508+
isKnownIntrinsic(F->getIntrinsicID()))) {
514509
// We should not translate LLVM intrinsics as a function
515510
assert(none_of(F->user_begin(), F->user_end(),
516511
[this](User *U) { return getTranslatedValue(U); }) &&
@@ -2131,7 +2126,7 @@ SPIRVValue *LLVMToSPIRV::transIntrinsicInst(IntrinsicInst *II,
21312126
// change is pending the trap/abort intrisinc implementation.
21322127
return nullptr;
21332128
default:
2134-
if (SPIRVAllowUnknownIntrinsics)
2129+
if (BM->isSPIRVAllowUnknownIntrinsicsEnabled())
21352130
return BM->addCallInst(
21362131
transFunctionDecl(II->getCalledFunction()),
21372132
transArguments(II, BB,

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVModule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ class SPIRVModule {
476476
return TranslationOpts.getFPContractMode();
477477
}
478478

479+
bool isSPIRVAllowUnknownIntrinsicsEnabled() const noexcept {
480+
return TranslationOpts.isSPIRVAllowUnknownIntrinsicsEnabled();
481+
}
482+
479483
// I/O functions
480484
friend spv_ostream &operator<<(spv_ostream &O, SPIRVModule &M);
481485
friend std::istream &operator>>(std::istream &I, SPIRVModule &M);

llvm-spirv/tools/llvm-spirv/llvm-spirv.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ static cl::opt<SPIRV::FPContractMode> FPCMode(
178178
SPIRV::FPContractMode::Fast, "fast",
179179
"allow all operations to be contracted for all entry points")));
180180

181+
cl::opt<bool> SPIRVAllowUnknownIntrinsics(
182+
"spirv-allow-unknown-intrinsics", cl::init(false),
183+
cl::desc("Unknown LLVM intrinsics will be translated as external function "
184+
"calls in SPIR-V"));
185+
181186
static std::string removeExt(const std::string &FileName) {
182187
size_t Pos = FileName.find_last_of(".");
183188
if (Pos != std::string::npos)
@@ -553,6 +558,16 @@ int main(int Ac, char **Av) {
553558
return -1;
554559
}
555560

561+
if (SPIRVAllowUnknownIntrinsics.getNumOccurrences() != 0) {
562+
if (IsReverse) {
563+
errs()
564+
<< "Note: --spirv-allow-unknown-intrinsics option ignored as it only "
565+
"affects translation from LLVM IR to SPIR-V";
566+
} else {
567+
Opts.setSPIRVAllowUnknownIntrinsicsEnabled(SPIRVAllowUnknownIntrinsics);
568+
}
569+
}
570+
556571
#ifdef _SPIRV_SUPPORT_TEXT_FMT
557572
if (ToText && (ToBinary || IsReverse || IsRegularization)) {
558573
errs() << "Cannot use -to-text with -to-binary, -r, -s\n";

0 commit comments

Comments
 (0)