Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nslator into amd-staging
  • Loading branch information
AlexVlx committed Jan 17, 2025
2 parents b8f411a + 197a800 commit 4e8a01b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 21 deletions.
14 changes: 7 additions & 7 deletions lib/SPIRV/LLVMToSPIRVDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ LLVMToSPIRVDbgTran::transDbgArrayTypeOpenCL(const DICompositeType *AT) {
SPIRVWordVec LowerBounds(N);
for (unsigned I = 0; I < N; ++I) {
DISubrange *SR = cast<DISubrange>(AR[I]);
ConstantInt *Count = SR->getCount().get<ConstantInt *>();
ConstantInt *Count = cast<ConstantInt *>(SR->getCount());
if (AT->isVector()) {
assert(N == 1 && "Multidimensional vector is not expected!");
Ops[ComponentCountIdx] = static_cast<SPIRVWord>(Count->getZExtValue());
Expand All @@ -710,7 +710,7 @@ LLVMToSPIRVDbgTran::transDbgArrayTypeOpenCL(const DICompositeType *AT) {
if (auto *DIExprLB = dyn_cast<MDNode>(RawLB))
LowerBounds[I] = transDbgEntry(DIExprLB)->getId();
else {
ConstantInt *ConstIntLB = SR->getLowerBound().get<ConstantInt *>();
ConstantInt *ConstIntLB = cast<ConstantInt *>(SR->getLowerBound());
LowerBounds[I] = SPIRVWriter->transValue(ConstIntLB, nullptr)->getId();
}
} else {
Expand All @@ -733,7 +733,7 @@ LLVMToSPIRVDbgTran::transDbgArrayTypeNonSemantic(const DICompositeType *AT) {
Ops.resize(SubrangesIdx + N);
for (unsigned I = 0; I < N; ++I) {
DISubrange *SR = cast<DISubrange>(AR[I]);
ConstantInt *Count = SR->getCount().get<ConstantInt *>();
ConstantInt *Count = cast<ConstantInt *>(SR->getCount());
if (AT->isVector()) {
assert(N == 1 && "Multidimensional vector is not expected!");
Ops[ComponentCountIdx] = static_cast<SPIRVWord>(Count->getZExtValue());
Expand Down Expand Up @@ -809,13 +809,13 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgSubrangeType(const DISubrange *ST) {
ConstantInt *IntNode = nullptr;
switch (Idx) {
case LowerBoundIdx:
IntNode = ST->getLowerBound().get<ConstantInt *>();
IntNode = cast<ConstantInt *>(ST->getLowerBound());
break;
case UpperBoundIdx:
IntNode = ST->getUpperBound().get<ConstantInt *>();
IntNode = cast<ConstantInt *>(ST->getUpperBound());
break;
case CountIdx:
IntNode = ST->getCount().get<ConstantInt *>();
IntNode = cast<ConstantInt *>(ST->getCount());
break;
}
Ops[Idx] = IntNode ? SPIRVWriter->transValue(IntNode, nullptr)->getId()
Expand All @@ -830,7 +830,7 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgSubrangeType(const DISubrange *ST) {
Ops[StrideIdx] = transDbgEntry(Node)->getId();
else
Ops[StrideIdx] =
SPIRVWriter->transValue(ST->getStride().get<ConstantInt *>(), nullptr)
SPIRVWriter->transValue(cast<ConstantInt *>(ST->getStride()), nullptr)
->getId();
}
return BM->addDebugInfo(SPIRVDebug::TypeSubrange, getVoidTy(), Ops);
Expand Down
7 changes: 3 additions & 4 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2705,11 +2705,11 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
case SPIRVEIS_NonSemantic_Shader_DebugInfo_200:
if (!M->IsNewDbgInfoFormat) {
return mapValue(
BV, DbgTran->transDebugIntrinsic(ExtInst, BB).get<Instruction *>());
BV, cast<Instruction *>(DbgTran->transDebugIntrinsic(ExtInst, BB)));
} else {
auto MaybeRecord = DbgTran->transDebugIntrinsic(ExtInst, BB);
if (!MaybeRecord.isNull()) {
auto *Record = MaybeRecord.get<DbgRecord *>();
auto *Record = cast<DbgRecord *>(MaybeRecord);
Record->setDebugLoc(
DbgTran->transDebugScope(static_cast<SPIRVInstruction *>(BV)));
}
Expand Down Expand Up @@ -3756,8 +3756,7 @@ Instruction *SPIRVToLLVM::transBuiltinFromInst(const std::string &FuncName,
Func->addFnAttr(Attribute::Convergent);
}
CallInst *Call;
if (OC == OpCooperativeMatrixLengthKHR &&
Ops[0]->getOpCode() == OpTypeCooperativeMatrixKHR) {
if (OC == OpCooperativeMatrixLengthKHR) {
// OpCooperativeMatrixLengthKHR needs special handling as its operand is
// a Type instead of a Value.
llvm::Type *MatTy = transType(reinterpret_cast<SPIRVType *>(Ops[0]));
Expand Down
8 changes: 4 additions & 4 deletions lib/SPIRV/SPIRVToLLVMDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ SPIRVToLLVMDbgTran::transTypeArrayNonSemantic(const SPIRVExtInst *DebugInst) {
if (DebugInst->getExtOp() == SPIRVDebug::TypeArray) {
for (size_t I = SubrangesIdx; I < Ops.size(); ++I) {
auto *SR = transDebugInst<DISubrange>(BM->get<SPIRVExtInst>(Ops[I]));
if (auto *Count = SR->getCount().get<ConstantInt *>())
if (auto *Count = cast<ConstantInt *>(SR->getCount()))
TotalCount *= Count->getSExtValue() > 0 ? Count->getSExtValue() : 0;
Subscripts.push_back(SR);
}
Expand All @@ -444,7 +444,7 @@ SPIRVToLLVMDbgTran::transTypeArrayDynamic(const SPIRVExtInst *DebugInst) {
SmallVector<llvm::Metadata *, 8> Subscripts;
for (size_t I = SubrangesIdx; I < Ops.size(); ++I) {
auto *SR = transDebugInst<DISubrange>(BM->get<SPIRVExtInst>(Ops[I]));
if (auto *Count = SR->getCount().get<ConstantInt *>())
if (auto *Count = cast<ConstantInt *>(SR->getCount()))
TotalCount *= Count->getSExtValue() > 0 ? Count->getSExtValue() : 0;
Subscripts.push_back(SR);
}
Expand Down Expand Up @@ -1609,10 +1609,10 @@ SPIRVToLLVMDbgTran::transDebugIntrinsic(const SPIRVExtInst *DebugInst,
if (!MDs.empty()) {
DIArgList *AL = DIArgList::get(M->getContext(), MDs);
if (M->IsNewDbgInfoFormat) {
cast<DbgVariableRecord>(DbgValIntr.get<DbgRecord *>())
cast<DbgVariableRecord>(cast<DbgRecord *>(DbgValIntr))
->setRawLocation(AL);
} else {
cast<DbgVariableIntrinsic>(DbgValIntr.get<Instruction *>())
cast<DbgVariableIntrinsic>(cast<Instruction *>(DbgValIntr))
->setRawLocation(AL);
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6832,6 +6832,10 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
transValue(CI->getArgOperand(2), BB), BB);
return BM->addStoreInst(transValue(CI->getArgOperand(0), BB), V, {}, BB);
}
case OpCooperativeMatrixLengthKHR: {
return BM->addCooperativeMatrixLengthKHRInst(
transScavengedType(CI), transType(CI->getArgOperand(0)->getType()), BB);
}
case OpGroupNonUniformShuffleDown: {
Function *F = CI->getCalledFunction();
if (F->arg_size() && F->getArg(0)->hasStructRetAttr()) {
Expand Down
11 changes: 11 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ class SPIRVModuleImpl : public SPIRVModule {
SPIRVTypeTaskSequenceINTEL *addTaskSequenceINTELType() override;
SPIRVInstruction *addTaskSequenceGetINTELInst(SPIRVType *, SPIRVValue *,
SPIRVBasicBlock *) override;
SPIRVInstruction *
addCooperativeMatrixLengthKHRInst(SPIRVType *, SPIRVType *,
SPIRVBasicBlock *) override;
SPIRVType *addOpaqueGenericType(Op) override;
SPIRVTypeDeviceEvent *addDeviceEventType() override;
SPIRVTypeQueue *addQueueType() override;
Expand Down Expand Up @@ -1094,6 +1097,14 @@ SPIRVInstruction *SPIRVModuleImpl::addTaskSequenceGetINTELInst(
BB);
}

SPIRVInstruction *SPIRVModuleImpl::addCooperativeMatrixLengthKHRInst(
SPIRVType *RetTy, SPIRVType *MatTy, SPIRVBasicBlock *BB) {
return addInstruction(
SPIRVInstTemplateBase::create(OpCooperativeMatrixLengthKHR, RetTy,
getId(), getVec(MatTy->getId()), BB, this),
BB);
}

SPIRVType *SPIRVModuleImpl::addOpaqueGenericType(Op TheOpCode) {
return addType(new SPIRVTypeOpaqueGeneric(TheOpCode, this, getId()));
}
Expand Down
3 changes: 3 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ class SPIRVModule {
virtual SPIRVTypeTaskSequenceINTEL *addTaskSequenceINTELType() = 0;
virtual SPIRVInstruction *
addTaskSequenceGetINTELInst(SPIRVType *, SPIRVValue *, SPIRVBasicBlock *) = 0;
virtual SPIRVInstruction *
addCooperativeMatrixLengthKHRInst(SPIRVType *, SPIRVType *,
SPIRVBasicBlock *) = 0;
virtual SPIRVTypeVoid *addVoidType() = 0;
virtual SPIRVType *addOpaqueGenericType(Op) = 0;
virtual SPIRVTypeDeviceEvent *addDeviceEventType() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
; CHECK-SPIRV-DAG: TypeCooperativeMatrixKHR [[#MatTy3:]] [[#Int8Ty]] [[#Const2]] [[#Const48]] [[#Const12]] [[#Const1]]
; CHECK-SPIRV: CooperativeMatrixConstructCheckedINTEL [[#MatTy1]]
; CHECK-SPIRV: CooperativeMatrixLoadCheckedINTEL [[#MatTy2]] [[#Load1:]]
; TODO: Pass Matrix Type Id instead of Matrix Id to CooperativeMatrixLengthKHR.
; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#Load1]]
; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#MatTy2]]
; CHECK-SPIRV: CooperativeMatrixLoadCheckedINTEL [[#MatTy3]]
; CHECK-SPIRV: CooperativeMatrixMulAddKHR [[#MatTy1]]
; CHECK-SPIRV: CooperativeMatrixStoreCheckedINTEL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
; CHECK-SPIRV-DAG: TypeCooperativeMatrixKHR [[#MatTy3:]] [[#Int8Ty]] [[#Const2]] [[#Const48]] [[#Const12]] [[#Const1]]
; CHECK-SPIRV: CompositeConstruct [[#MatTy1]]
; CHECK-SPIRV: CooperativeMatrixLoadKHR [[#MatTy2]] [[#Load1:]]
; TODO: Pass Matrix Type Id instead of Matrix Id to CooperativeMatrixLengthKHR.
; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#Load1]]
; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#MatTy2]]
; CHECK-SPIRV: CooperativeMatrixPrefetchINTEL
; CHECK-SPIRV: CooperativeMatrixLoadKHR [[#MatTy3]]
; CHECK-SPIRV: CooperativeMatrixMulAddKHR [[#MatTy1]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
; CHECK-SPIRV-DAG: TypeCooperativeMatrixKHR [[#MatTy3:]] [[#Int8Ty]] [[#Const2]] [[#Const48]] [[#Const12]] [[#Const1]]
; CHECK-SPIRV: CompositeConstruct [[#MatTy1]]
; CHECK-SPIRV: CooperativeMatrixLoadKHR [[#MatTy2]] [[#Load1:]]
; TODO: Pass Matrix Type Id instead of Matrix Id to CooperativeMatrixLengthKHR.
; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#Load1]]
; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#MatTy2]]
; CHECK-SPIRV: CooperativeMatrixLoadKHR [[#MatTy3]]
; CHECK-SPIRV: CooperativeMatrixMulAddKHR [[#MatTy1]]
; CHECK-SPIRV: CooperativeMatrixStoreKHR
Expand Down

0 comments on commit 4e8a01b

Please sign in to comment.