Skip to content

Commit

Permalink
[SYCL] Sync with SPIRV Translator cdf2aa4609
Browse files Browse the repository at this point in the history
Synced with:
cdf2aa4609 Fix var/ptr annotation and lifetime start intrinsic translation

Excluded the following syncs with LLVM:
2cdb947d4 Update LLVM to r358377
72bcddd08 Sync with LLVM
6183f7c486 Sync with LLVM

Signed-off-by: Artem Gindinson <[email protected]>
  • Loading branch information
AGindinson authored and romanovvlad committed Apr 23, 2019
1 parent 978ee22 commit 11e6695
Show file tree
Hide file tree
Showing 70 changed files with 2,040 additions and 2,029 deletions.
4 changes: 3 additions & 1 deletion llvm-spirv/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ script:
-DLLVM_BUILD_TOOLS=ON \
-DLLVM_BUILD_TESTS=ON \
-DLLVM_INCLUDE_TESTS=ON \
-DSKIP_SPIRV_DEBUG_INFO_TESTS=ON \
-DSPIRV_SKIP_CLANG_BUILD=ON \
-DSPIRV_SKIP_DEBUG_INFO_TESTS=ON \
-DLLVM_LIT_ARGS="-sv --no-progress-bar" \
-G "Unix Makefiles"
ln -s /usr/lib/llvm-9/bin/clang bin/
fi
- if [ $CHECK_FORMAT == "1" ]; then
cd ..;
Expand Down
2 changes: 1 addition & 1 deletion llvm-spirv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Where `llvm_build_dir` is the LLVM build directory.
The translator can be built as a regular LLVM subproject. To do that you need to clone it to `llvm/projects` or `llvm/tools` directory.
```
git clone http://llvm.org/git/llvm.git
cd llvm/project
cd llvm/projects
git clone https://github.com/KhronosGroup/SPIRV-LLVM-Translator.git
```
Run(re-run) cmake as usually for LLVM. After that you should have `llvm-spirv` and `check-llvm-spirv` targets available.
Expand Down
2 changes: 1 addition & 1 deletion llvm-spirv/lib/SPIRV/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ add_llvm_library(LLVMSPIRVLib

target_include_directories(LLVMSPIRVLib
PRIVATE
${LLVM_INCLUDE_DIR}
${LLVM_INCLUDE_DIRS}
${LLVM_SPIRV_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/libSPIRV
Expand Down
27 changes: 17 additions & 10 deletions llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,18 @@ SPIRVEntry *LLVMToSPIRVDbgTran::getScope(DIScope *S) {
}
}

SPIRVEntry *LLVMToSPIRVDbgTran::getGlobalVariable(const DIGlobalVariable *GV) {
for (GlobalVariable &V : M->globals()) {
SmallVector<DIGlobalVariableExpression *, 4> GVs;
V.getDebugInfo(GVs);
for (DIGlobalVariableExpression *GVE : GVs) {
if (GVE->getVariable() == GV)
return SPIRVWriter->transValue(&V, nullptr);
}
}
return getDebugInfoNone();
}

SPIRVWord mapDebugFlags(DINode::DIFlags DFlags) {
SPIRVWord Flags = 0;
if ((DFlags & DINode::FlagAccessibility) == DINode::FlagPublic)
Expand Down Expand Up @@ -758,20 +770,15 @@ LLVMToSPIRVDbgTran::transDbgGlobalVariable(const DIGlobalVariable *GV) {
if (Context && (isa<DINamespace>(Context) || isa<DISubprogram>(Context)))
Parent = transDbgEntry(Context);
Ops[ParentIdx] = Parent->getId();
Ops[LinkageNameIdx] = BM->getString(GV->getLinkageName())->getId();

// Variable
SPIRVEntry *Var = getDebugInfoNone();
llvm::GlobalVariable *V = M->getGlobalVariable(GV->getName());
if (!V)
V = M->getGlobalVariable(GV->getLinkageName());
if (V)
Var = SPIRVWriter->transValue(V, nullptr);
Ops[VariableIdx] = Var->getId();

Ops[LinkageNameIdx] = BM->getString(GV->getLinkageName())->getId();
Ops[VariableIdx] = getGlobalVariable(GV)->getId();
Ops[FlagsIdx] = transDebugFlags(GV);

// Check if GV is the definition of previously declared static member
if (DIDerivedType *StaticMember = GV->getStaticDataMemberDeclaration())
Ops.push_back(transDbgEntry(StaticMember)->getId());

return BM->addDebugInfo(SPIRVDebug::GlobalVariable, getVoidTy(), Ops);
}

Expand Down
1 change: 1 addition & 0 deletions llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class LLVMToSPIRVDbgTran {
SPIRVType *getVoidTy();
SPIRVEntry *getScope(DIScopeRef SR);
SPIRVEntry *getScope(DIScope *SR);
SPIRVEntry *getGlobalVariable(const DIGlobalVariable *GV);

// No debug info
SPIRVEntry *getDebugInfoNone();
Expand Down
36 changes: 24 additions & 12 deletions llvm-spirv/lib/SPIRV/OCL20ToSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,16 +827,28 @@ void OCL20ToSPIRV::transAtomicBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
const size_t ArgsCount = Args.size();
const size_t ScopeIdx = ArgsCount - 1;
const size_t OrderIdx = ScopeIdx - NumOrder;
Args[ScopeIdx] =
mapUInt(M, cast<ConstantInt>(Args[ScopeIdx]), [](unsigned I) {
return map<Scope>(static_cast<OCLScopeKind>(I));
if (auto ScopeInt = dyn_cast_or_null<ConstantInt>(Args[ScopeIdx])) {
Args[ScopeIdx] = mapUInt(M, ScopeInt, [](unsigned I) {
return map<Scope>(static_cast<OCLScopeKind>(I));
});
} else {
// SPIR-V 1.3 r6 s2.16.2: All <id> used for Scope and Memory
// Semantics must be of an OpConstant.
Ctx->emitError(CI, "memory_scope argument needs to be constant");
}
for (size_t I = 0; I < NumOrder; ++I) {
if (auto OrderInt =
dyn_cast_or_null<ConstantInt>(Args[OrderIdx + I])) {
Args[OrderIdx + I] = mapUInt(M, OrderInt, [](unsigned Ord) {
return mapOCLMemSemanticToSPIRV(
0, static_cast<OCLMemOrderKind>(Ord));
});
for (size_t I = 0; I < NumOrder; ++I)
Args[OrderIdx + I] = mapUInt(
M, cast<ConstantInt>(Args[OrderIdx + I]), [](unsigned Ord) {
return mapOCLMemSemanticToSPIRV(
0, static_cast<OCLMemOrderKind>(Ord));
});
} else {
// SPIR-V 1.3 r6 s2.16.2: All <id> used for Scope and Memory
// Semantics must be of an OpConstant.
Ctx->emitError(CI, "memory_order argument needs to be constant");
}
}
// Order of args in SPIR-V:
// object, scope, 1-2 order, 0-2 other args
std::swap(Args[1], Args[ScopeIdx]);
Expand Down Expand Up @@ -1229,9 +1241,9 @@ void OCL20ToSPIRV::transWorkItemBuiltinsToVariables() {
bool IsVec = I.getFunctionType()->getNumParams() > 0;
Type *GVType =
IsVec ? VectorType::get(I.getReturnType(), 3) : I.getReturnType();
auto BV = new GlobalVariable(
*M, GVType, true, GlobalValue::ExternalLinkage, nullptr, BuiltinVarName,
0, GlobalVariable::NotThreadLocal, SPIRAS_Constant);
auto BV = new GlobalVariable(*M, GVType, true, GlobalValue::ExternalLinkage,
nullptr, BuiltinVarName, 0,
GlobalVariable::NotThreadLocal, SPIRAS_Input);
std::vector<Instruction *> InstList;
for (auto UI = I.user_begin(), UE = I.user_end(); UI != UE; ++UI) {
auto CI = dyn_cast<CallInst>(*UI);
Expand Down
24 changes: 2 additions & 22 deletions llvm-spirv/lib/SPIRV/OCLUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ unsigned getExtOp(StringRef OrigName, const std::string &GivenDemangledName) {
case ParamType::FLOAT:
Prefix = "f";
break;
default:
llvm_unreachable("unknown mangling!");
case ParamType::UNKNOWN:
break;
}
Found = OCLExtOpMap::rfind(Prefix + DemangledName, &EOC);
}
Expand All @@ -188,18 +188,6 @@ unsigned getExtOp(StringRef OrigName, const std::string &GivenDemangledName) {
return ~0U;
}

std::unique_ptr<SPIRVEntry> getSPIRVInst(const OCLBuiltinTransInfo &Info) {
Op OC = OpNop;
unsigned ExtOp = ~0U;
SPIRVEntry *Entry = nullptr;
if (OCLSPIRVBuiltinMap::find(Info.UniqName, &OC))
Entry = SPIRVEntry::create(OC);
else if ((ExtOp = getExtOp(Info.MangledName, Info.UniqName)) != ~0U)
Entry = static_cast<SPIRVEntry *>(
SPIRVEntry::createUnique(SPIRVEIS_OpenCL, ExtOp).get());
return std::unique_ptr<SPIRVEntry>(Entry);
}

///////////////////////////////////////////////////////////////////////////////
//
// Functions for getting module info
Expand Down Expand Up @@ -613,14 +601,6 @@ Instruction *mutateCallInstOCL(
return mutateCallInst(M, CI, ArgMutate, RetMutate, &BtnInfo, Attrs);
}

void mutateFunctionOCL(
Function *F,
std::function<std::string(CallInst *, std::vector<Value *> &)> ArgMutate,
AttributeList *Attrs) {
OCLBuiltinFuncMangleInfo BtnInfo(F);
return mutateFunction(F, ArgMutate, &BtnInfo, Attrs, false);
}

static std::pair<StringRef, StringRef>
getSrcAndDstElememntTypeName(BitCastInst *BIC) {
if (!BIC)
Expand Down
9 changes: 0 additions & 9 deletions llvm-spirv/lib/SPIRV/OCLUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@ const static char TypePrefix[] = "opencl.intel_sub_group_avc_";
/// function is translated to an extended instruction, otherwise ~0U.
unsigned getExtOp(StringRef MangledName, const std::string &DemangledName = "");

/// Get an empty SPIR-V instruction.
std::unique_ptr<SPIRVEntry> getSPIRVInst(const OCLBuiltinTransInfo &Info);

/// Get literal arguments of call of atomic_work_item_fence.
AtomicWorkItemFenceLiterals getAtomicWorkItemFenceLiterals(CallInst *CI);

Expand Down Expand Up @@ -383,12 +380,6 @@ Instruction *mutateCallInstOCL(
std::function<Instruction *(CallInst *)> RetMutate,
AttributeList *Attrs = nullptr);

/// Mutate a function to OpenCL builtin function.
void mutateFunctionOCL(
Function *F,
std::function<std::string(CallInst *, std::vector<Value *> &)> ArgMutate,
AttributeList *Attrs = nullptr);

/// Check if instruction is bitcast from spirv.ConstantSampler to spirv.Sampler
bool isSamplerInitializer(Instruction *Inst);

Expand Down
3 changes: 3 additions & 0 deletions llvm-spirv/lib/SPIRV/SPIRVInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ enum SPIRAddressSpace {
SPIRAS_Constant,
SPIRAS_Local,
SPIRAS_Generic,
SPIRAS_Input,
SPIRAS_Count,
};

Expand All @@ -192,6 +193,7 @@ template <> inline void SPIRVMap<SPIRAddressSpace, std::string>::init() {
add(SPIRAS_Constant, "Constant");
add(SPIRAS_Local, "Local");
add(SPIRAS_Generic, "Generic");
add(SPIRAS_Input, "Input");
}
typedef SPIRVMap<SPIRAddressSpace, SPIRVStorageClassKind>
SPIRAddrSpaceCapitalizedNameMap;
Expand All @@ -203,6 +205,7 @@ inline void SPIRVMap<SPIRAddressSpace, SPIRVStorageClassKind>::init() {
add(SPIRAS_Constant, StorageClassUniformConstant);
add(SPIRAS_Local, StorageClassWorkgroup);
add(SPIRAS_Generic, StorageClassGeneric);
add(SPIRAS_Input, StorageClassInput);
}
typedef SPIRVMap<SPIRAddressSpace, SPIRVStorageClassKind> SPIRSPIRVAddrSpaceMap;

Expand Down
2 changes: 1 addition & 1 deletion llvm-spirv/lib/SPIRV/SPIRVLowerConstExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace SPIRV {

cl::opt<bool> SPIRVLowerConst(
"spirv-lower-const-expr", cl::init(true),
cl::desc("LLVM/SPIR-V translation enalbe lowering constant expression"));
cl::desc("LLVM/SPIR-V translation enable lowering constant expression"));

class SPIRVLowerConstExpr : public ModulePass {
public:
Expand Down
Loading

0 comments on commit 11e6695

Please sign in to comment.