Skip to content

Commit 1a9a204

Browse files
smilczekigcbot
authored andcommitted
Update IGC SPIRV translator for CompositeExtract
IGC SPIRV Translator fails to create SPIRVInstTemplateBase for CompositeExtract instructions. This commit updates the translator to handle CompositeExtract the same way upstream khronos translator does.
1 parent 0ed8e9e commit 1a9a204

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3648,23 +3648,21 @@ SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
36483648

36493649
case OpCompositeExtract: {
36503650
SPIRVCompositeExtract *CE = static_cast<SPIRVCompositeExtract *>(BV);
3651-
auto Type = CE->getComposite()->getType();
3652-
IGC_ASSERT_MESSAGE(BB, "Invalid BB");
3653-
if (Type->isTypeVector())
3654-
{
3655-
IGC_ASSERT_MESSAGE(CE->getIndices().size() == 1, "Invalid index");
3656-
return mapValue(BV, ExtractElementInst::Create(
3657-
transValue(CE->getComposite(), F, BB),
3658-
ConstantInt::get(*Context, APInt(32, CE->getIndices()[0])),
3659-
BV->getName(), BB));
3651+
IRBuilder<> Builder(*Context);
3652+
if (BB) {
3653+
Builder.SetInsertPoint(BB);
36603654
}
3661-
else
3662-
{
3663-
return mapValue(BV, ExtractValueInst::Create(
3664-
transValue(CE->getComposite(), F, BB),
3665-
CE->getIndices(),
3666-
BV->getName(), BB));
3655+
if (CE->getComposite()->getType()->isTypeVector()) {
3656+
IGC_ASSERT_MESSAGE(CE->getIndices().size() == 1, "Invalid index");
3657+
return mapValue(
3658+
BV, Builder.CreateExtractElement(
3659+
transValue(CE->getComposite(), F, BB),
3660+
ConstantInt::get(*Context, APInt(32, CE->getIndices()[0])),
3661+
BV->getName()));
36673662
}
3663+
return mapValue(
3664+
BV, Builder.CreateExtractValue(transValue(CE->getComposite(), F, BB),
3665+
CE->getIndices(), BV->getName()));
36683666
}
36693667
break;
36703668

IGC/AdaptorOCL/SPIRV/libSPIRV/SPIRVInstruction.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,30 +1331,31 @@ class SPIRVExtInst: public SPIRVFunctionCallGeneric<OpExtInst, 5> {
13311331
SPIRVExtInstSetKind ExtSetKind;
13321332
};
13331333

1334-
class SPIRVCompositeExtract:public SPIRVInstruction {
1334+
class SPIRVCompositeExtractBase:public SPIRVInstTemplateBase {
13351335
public:
1336-
const static Op OC = OpCompositeExtract;
1337-
// Incomplete constructor
1338-
SPIRVCompositeExtract():SPIRVInstruction(OC), Composite(SPIRVID_INVALID){}
1336+
SPIRVValue* getComposite() { return getValue(Ops[0]); }
1337+
const std::vector<SPIRVWord> getIndices() const {
1338+
return std::vector<SPIRVWord>(Ops.begin() + 1, Ops.end());
1339+
}
13391340

1340-
SPIRVValue *getComposite() { return getValue(Composite);}
1341-
const std::vector<SPIRVWord>& getIndices()const { return Indices;}
13421341
protected:
1343-
void setWordCount(SPIRVWord TheWordCount) {
1344-
SPIRVEntry::setWordCount(TheWordCount);
1345-
Indices.resize(TheWordCount - 4);
1346-
}
1347-
_SPIRV_DEF_DEC4(Type, Id, Composite, Indices)
13481342
// ToDo: validate the result type is consistent with the base type and indices
13491343
// need to trace through the base type for struct types
1350-
void validate()const {
1344+
void validate() const override {
13511345
SPIRVInstruction::validate();
1352-
IGC_ASSERT(getValueType(Composite)->isTypeArray() || getValueType(Composite)->isTypeStruct() || getValueType(Composite)->isTypeVector());
1346+
IGC_ASSERT(OpCode == OpCompositeExtract);
1347+
SPIRVId Composite = Ops[0];
1348+
(void)Composite;
1349+
IGC_ASSERT(getValueType(Composite)->isTypeArray() ||
1350+
getValueType(Composite)->isTypeStruct() ||
1351+
getValueType(Composite)->isTypeVector());
13531352
}
1354-
SPIRVId Composite;
1355-
std::vector<SPIRVWord> Indices;
13561353
};
13571354

1355+
typedef SPIRVInstTemplate<SPIRVCompositeExtractBase, OpCompositeExtract, true,
1356+
4, true>
1357+
SPIRVCompositeExtract;
1358+
13581359
class SPIRVCompositeInsert:public SPIRVInstruction {
13591360
public:
13601361
const static Op OC = OpCompositeInsert;

0 commit comments

Comments
 (0)