Skip to content

Commit

Permalink
Disable SPIRV=>LLVM checking for split barrier extension as (currentl…
Browse files Browse the repository at this point in the history
…y) translator does not deal well with implicit arguments
  • Loading branch information
stanleygambarin authored and MrSidims committed Mar 11, 2023
1 parent a5f9890 commit a7c1418
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 106 deletions.
184 changes: 93 additions & 91 deletions lib/SPIRV/OCL20ToSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,16 +616,16 @@ void OCL20ToSPIRV::visitCallAsyncWorkGroupCopy(
CallInst *CI, const std::string &DemangledName) {
assert(CI->getCalledFunction() && "Unexpected indirect call");
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
mutateCallInstSPIRV(M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
if (DemangledName ==
OCLUtil::kOCLBuiltinName::AsyncWorkGroupCopy) {
Args.insert(Args.begin() + 3, addSizet(1));
}
Args.insert(Args.begin(), addInt32(ScopeWorkgroup));
return getSPIRVFuncName(OpGroupAsyncCopy);
},
&Attrs);
mutateCallInstSPIRV(
M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
if (DemangledName == OCLUtil::kOCLBuiltinName::AsyncWorkGroupCopy) {
Args.insert(Args.begin() + 3, addSizet(1));
}
Args.insert(Args.begin(), addInt32(ScopeWorkgroup));
return getSPIRVFuncName(OpGroupAsyncCopy);
},
&Attrs);
}

CallInst *
Expand Down Expand Up @@ -714,15 +714,16 @@ void OCL20ToSPIRV::transMemoryBarrier(CallInst *CI,
AtomicWorkItemFenceLiterals Lit) {
assert(CI->getCalledFunction() && "Unexpected indirect call");
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
mutateCallInstSPIRV(M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
Args.resize(2);
Args[0] = addInt32(map<Scope>(std::get<2>(Lit)));
Args[1] = addInt32(mapOCLMemSemanticToSPIRV(
std::get<0>(Lit), std::get<1>(Lit)));
return getSPIRVFuncName(OpMemoryBarrier);
},
&Attrs);
mutateCallInstSPIRV(
M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
Args.resize(2);
Args[0] = addInt32(map<Scope>(std::get<2>(Lit)));
Args[1] = addInt32(
mapOCLMemSemanticToSPIRV(std::get<0>(Lit), std::get<1>(Lit)));
return getSPIRVFuncName(OpMemoryBarrier);
},
&Attrs);
}

void OCL20ToSPIRV::visitCallAtomicLegacy(CallInst *CI, StringRef MangledName,
Expand Down Expand Up @@ -858,24 +859,24 @@ void OCL20ToSPIRV::transAtomicBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
void OCL20ToSPIRV::visitCallBarrier(CallInst *CI) {
auto Lit = getBarrierLiterals(CI);
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
mutateCallInstSPIRV(M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
Args.resize(3);
// Execution scope
Args[0] = addInt32(map<Scope>(std::get<2>(Lit)));
// Memory scope
Args[1] = addInt32(map<Scope>(std::get<1>(Lit)));
// Use sequential consistent memory order by default.
// But if the flags argument is set to 0, we use
// None(Relaxed) memory order.
unsigned MemFenceFlag = std::get<0>(Lit);
OCLMemOrderKind MemOrder =
MemFenceFlag ? OCLMO_seq_cst : OCLMO_relaxed;
Args[2] = addInt32(mapOCLMemSemanticToSPIRV(
MemFenceFlag, MemOrder)); // Memory semantics
return getSPIRVFuncName(OpControlBarrier);
},
&Attrs);
mutateCallInstSPIRV(
M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
Args.resize(3);
// Execution scope
Args[0] = addInt32(map<Scope>(std::get<2>(Lit)));
// Memory scope
Args[1] = addInt32(map<Scope>(std::get<1>(Lit)));
// Use sequential consistent memory order by default.
// But if the flags argument is set to 0, we use
// None(Relaxed) memory order.
unsigned MemFenceFlag = std::get<0>(Lit);
OCLMemOrderKind MemOrder = MemFenceFlag ? OCLMO_seq_cst : OCLMO_relaxed;
Args[2] = addInt32(mapOCLMemSemanticToSPIRV(
MemFenceFlag, MemOrder)); // Memory semantics
return getSPIRVFuncName(OpControlBarrier);
},
&Attrs);
}

void OCL20ToSPIRV::visitCallConvert(CallInst *CI, StringRef MangledName,
Expand Down Expand Up @@ -924,12 +925,12 @@ void OCL20ToSPIRV::visitCallConvert(CallInst *CI, StringRef MangledName,
}
assert(CI->getCalledFunction() && "Unexpected indirect call");
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
mutateCallInstSPIRV(M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
return getSPIRVFuncName(OC,
TargetTyName + Sat + Rounding);
},
&Attrs);
mutateCallInstSPIRV(
M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
return getSPIRVFuncName(OC, TargetTyName + Sat + Rounding);
},
&Attrs);
}

void OCL20ToSPIRV::visitCallGroupBuiltin(CallInst *CI, StringRef MangledName,
Expand Down Expand Up @@ -1072,12 +1073,13 @@ void OCL20ToSPIRV::transBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
} else
return;
if (!Info.RetTy)
mutateCallInstSPIRV(M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
Info.PostProc(Args);
return Info.UniqName + Info.Postfix;
},
&Attrs);
mutateCallInstSPIRV(
M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
Info.PostProc(Args);
return Info.UniqName + Info.Postfix;
},
&Attrs);
else
mutateCallInstSPIRV(
M, CI,
Expand Down Expand Up @@ -1389,15 +1391,15 @@ void OCL20ToSPIRV::visitCallGetFence(CallInst *CI, StringRef MangledName,
Op OC = OpNop;
OCLSPIRVBuiltinMap::find(DemangledName, &OC);
std::string SPIRVName = getSPIRVFuncName(OC);
mutateCallInstSPIRV(M, CI,
[=](CallInst *, std::vector<Value *> &Args, Type *&Ret) {
return SPIRVName;
},
[=](CallInst *NewCI) -> Instruction * {
return BinaryOperator::CreateLShr(NewCI, getInt32(M, 8),
"", CI);
},
&Attrs);
mutateCallInstSPIRV(
M, CI,
[=](CallInst *, std::vector<Value *> &Args, Type *&Ret) {
return SPIRVName;
},
[=](CallInst *NewCI) -> Instruction * {
return BinaryOperator::CreateLShr(NewCI, getInt32(M, 8), "", CI);
},
&Attrs);
}

void OCL20ToSPIRV::visitCallDot(CallInst *CI) {
Expand Down Expand Up @@ -1479,15 +1481,15 @@ void OCL20ToSPIRV::visitCallGetImageChannel(CallInst *CI, StringRef MangledName,
Op OC = OpNop;
OCLSPIRVBuiltinMap::find(DemangledName, &OC);
std::string SPIRVName = getSPIRVFuncName(OC);
mutateCallInstSPIRV(M, CI,
[=](CallInst *, std::vector<Value *> &Args, Type *&Ret) {
return SPIRVName;
},
[=](CallInst *NewCI) -> Instruction * {
return BinaryOperator::CreateAdd(
NewCI, getInt32(M, Offset), "", CI);
},
&Attrs);
mutateCallInstSPIRV(
M, CI,
[=](CallInst *, std::vector<Value *> &Args, Type *&Ret) {
return SPIRVName;
},
[=](CallInst *NewCI) -> Instruction * {
return BinaryOperator::CreateAdd(NewCI, getInt32(M, Offset), "", CI);
},
&Attrs);
}
void OCL20ToSPIRV::visitCallEnqueueKernel(CallInst *CI,
const std::string &DemangledName) {
Expand Down Expand Up @@ -1569,29 +1571,29 @@ void OCL20ToSPIRV::visitCallKernelQuery(CallInst *CI,
auto *BlockF = cast<Function>(GetUnderlyingObject(BlockFVal, DL));

AttributeList Attrs = CI->getCalledFunction()->getAttributes();
mutateCallInst(M, CI,
[=](CallInst *CI, std::vector<Value *> &Args) {
Value *Param = *Args.rbegin();
Type *ParamType = GetUnderlyingObject(Param, DL)->getType();
if (PointerType *PT = dyn_cast<PointerType>(ParamType)) {
ParamType = PT->getElementType();
}
// Last arg corresponds to SPIRV Param operand.
// Insert Invoke in front of Param.
// Add Param Size and Param Align at the end.
Args[BlockFIdx] = BlockF;
Args.push_back(getInt32(M, DL.getTypeStoreSize(ParamType)));
Args.push_back(
getInt32(M, DL.getPrefTypeAlignment(ParamType)));

Op Opcode = OCLSPIRVBuiltinMap::map(DemangledName);
// Adding "__" postfix, so in case we have multiple such
// functions and their names will have numerical postfix,
// then the numerical postfix will be droped and we will get
// correct function name.
return getSPIRVFuncName(Opcode, kSPIRVName::Postfix);
},
/*BuiltinFuncMangleInfo*/ nullptr, &Attrs);
mutateCallInst(
M, CI,
[=](CallInst *CI, std::vector<Value *> &Args) {
Value *Param = *Args.rbegin();
Type *ParamType = GetUnderlyingObject(Param, DL)->getType();
if (PointerType *PT = dyn_cast<PointerType>(ParamType)) {
ParamType = PT->getElementType();
}
// Last arg corresponds to SPIRV Param operand.
// Insert Invoke in front of Param.
// Add Param Size and Param Align at the end.
Args[BlockFIdx] = BlockF;
Args.push_back(getInt32(M, DL.getTypeStoreSize(ParamType)));
Args.push_back(getInt32(M, DL.getPrefTypeAlignment(ParamType)));

Op Opcode = OCLSPIRVBuiltinMap::map(DemangledName);
// Adding "__" postfix, so in case we have multiple such
// functions and their names will have numerical postfix,
// then the numerical postfix will be droped and we will get
// correct function name.
return getSPIRVFuncName(Opcode, kSPIRVName::Postfix);
},
/*BuiltinFuncMangleInfo*/ nullptr, &Attrs);
}

// Add postfix to overloaded intel subgroup block read/write builtins
Expand Down Expand Up @@ -1854,7 +1856,7 @@ void OCL20ToSPIRV::visitSubgroupAVCBuiltinCallWithSampler(
}

void OCL20ToSPIRV::visitCallSplitBarrierINTEL(CallInst *CI,
StringRef DemangledName) {
StringRef DemangledName) {
auto Lit = getBarrierLiterals(CI);
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
Op OpCode =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
; RUN: llvm-spirv %t.spv -o %t.rev.bc -r --spirv-target-env=CL1.2
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; RUN: not llvm-spirv %t.bc 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
; CHECK-ERROR: RequiresExtension: Feature requires the following SPIR-V extension:
; CHECK-ERROR-NEXT: SPV_INTEL_split_barrier
; FAIL: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; ModuleID = 'split_barrier.cl'
source_filename = "split_barrier.cl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
; RUN: llvm-spirv %t.spv -o %t.rev.bc -r --spirv-target-env=CL2.0
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; RUN: not llvm-spirv %t.bc 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
; CHECK-ERROR: RequiresExtension: Feature requires the following SPIR-V extension:
; CHECK-ERROR-NEXT: SPV_INTEL_split_barrier
; FAIL: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; ModuleID = 'split_barrier.cl'
source_filename = "split_barrier.cl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@

; RUN: llvm-spirv %t.spv -o %t.rev.bc -r --spirv-target-env=SPV-IR
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; RUN: not llvm-spirv %t.bc 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
; CHECK-ERROR: RequiresExtension: Feature requires the following SPIR-V extension:
; CHECK-ERROR-NEXT: SPV_INTEL_split_barrier
; FAIL: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; ModuleID = 'split_barrier_spirv.cl'
source_filename = "split_barrier_spirv.cl"
Expand Down

0 comments on commit a7c1418

Please sign in to comment.