@@ -971,27 +971,18 @@ _SPIRV_OP(Ordered)
971
971
_SPIRV_OP(Unordered)
972
972
#undef _SPIRV_OP
973
973
974
- class SPIRVSelect : public SPIRVInstruction {
974
+ class SPIRVSelectBase : public SPIRVInstTemplateBase {
975
975
public:
976
- // Complete constructor
977
- SPIRVSelect (SPIRVId TheId, SPIRVType *TheType, SPIRVId TheCondition,
978
- SPIRVId TheOp1, SPIRVId TheOp2, SPIRVBasicBlock *TheBB,
979
- SPIRVModule *TheM)
980
- : SPIRVInstruction(6 , OpSelect, TheType, TheId, TheBB, TheM),
981
- Condition (TheCondition), Op1(TheOp1), Op2(TheOp2) {
982
- validate ();
983
- }
984
- // Incomplete constructor
985
- SPIRVSelect ()
986
- : SPIRVInstruction(OpSelect), Condition(SPIRVID_INVALID),
987
- Op1(SPIRVID_INVALID), Op2(SPIRVID_INVALID) {}
988
- SPIRVValue *getCondition () { return getValue (Condition); }
989
- SPIRVValue *getTrueValue () { return getValue (Op1); }
990
- SPIRVValue *getFalseValue () { return getValue (Op2); }
976
+ SPIRVValue *getCondition () { return getValue (Ops[0 ]); }
977
+ SPIRVValue *getTrueValue () { return getValue (Ops[1 ]); }
978
+ SPIRVValue *getFalseValue () { return getValue (Ops[2 ]); }
991
979
992
980
protected:
993
- _SPIRV_DEF_ENCDEC5 (Type, Id, Condition, Op1, Op2)
994
981
void validate () const override {
982
+ SPIRVId Condition = Ops[0 ];
983
+ SPIRVId Op1 = Ops[1 ];
984
+ SPIRVId Op2 = Ops[2 ];
985
+
995
986
SPIRVInstruction::validate ();
996
987
if (getValue (Condition)->isForward () || getValue (Op1)->isForward () ||
997
988
getValue (Op2)->isForward ())
@@ -1005,11 +996,10 @@ class SPIRVSelect : public SPIRVInstruction {
1005
996
assert (getType () == getValueType (Op1) && getType () == getValueType (Op2) &&
1006
997
" Inconsistent type" );
1007
998
}
1008
- SPIRVId Condition;
1009
- SPIRVId Op1;
1010
- SPIRVId Op2;
1011
999
};
1012
1000
1001
+ typedef SPIRVInstTemplate<SPIRVSelectBase, OpSelect, true , 6 > SPIRVSelect;
1002
+
1013
1003
class SPIRVSelectionMerge : public SPIRVInstruction {
1014
1004
public:
1015
1005
static const Op OC = OpSelectionMerge;
@@ -1899,87 +1889,58 @@ class SPIRVCompositeConstruct : public SPIRVInstruction {
1899
1889
std::vector<SPIRVId> Constituents;
1900
1890
};
1901
1891
1902
- class SPIRVCompositeExtract : public SPIRVInstruction {
1892
+ class SPIRVCompositeExtractBase : public SPIRVInstTemplateBase {
1903
1893
public:
1904
- const static Op OC = OpCompositeExtract;
1905
- // Complete constructor
1906
- SPIRVCompositeExtract (SPIRVType *TheType, SPIRVId TheId, SPIRVId TheComposite,
1907
- const std::vector<SPIRVWord> &TheIndices,
1908
- SPIRVBasicBlock *TheBB, SPIRVModule *TheM)
1909
- : SPIRVInstruction(TheIndices.size() + 4 , OC, TheType, TheId, TheBB,
1910
- TheM),
1911
- Composite (TheComposite), Indices(TheIndices) {
1912
- validate ();
1894
+ SPIRVValue *getComposite () { return getValue (Ops[0 ]); }
1895
+ const std::vector<SPIRVWord> getIndices () const {
1896
+ return std::vector<SPIRVWord>(Ops.begin () + 1 , Ops.end ());
1913
1897
}
1914
- // Incomplete constructor
1915
- SPIRVCompositeExtract () : SPIRVInstruction(OC), Composite(SPIRVID_INVALID) {}
1916
-
1917
- SPIRVValue *getComposite () { return getValue (Composite); }
1918
- const std::vector<SPIRVWord> &getIndices () const { return Indices; }
1919
1898
1920
1899
protected:
1921
- void setWordCount (SPIRVWord TheWordCount) override {
1922
- SPIRVEntry::setWordCount (TheWordCount);
1923
- Indices.resize (TheWordCount - 4 );
1924
- }
1925
- _SPIRV_DEF_ENCDEC4 (Type, Id, Composite, Indices)
1926
1900
// ToDo: validate the result type is consistent with the base type and indices
1927
1901
// need to trace through the base type for struct types
1928
1902
void validate () const override {
1929
1903
SPIRVInstruction::validate ();
1904
+ assert (OpCode == OpCompositeExtract);
1905
+ SPIRVId Composite = Ops[0 ];
1906
+ (void )Composite;
1930
1907
assert (getValueType (Composite)->isTypeArray () ||
1931
1908
getValueType (Composite)->isTypeStruct () ||
1932
1909
getValueType (Composite)->isTypeVector ());
1933
1910
}
1934
- SPIRVId Composite;
1935
- std::vector<SPIRVWord> Indices;
1936
1911
};
1937
1912
1938
- class SPIRVCompositeInsert : public SPIRVInstruction {
1913
+ typedef SPIRVInstTemplate<SPIRVCompositeExtractBase, OpCompositeExtract, true ,
1914
+ 4 , true >
1915
+ SPIRVCompositeExtract;
1916
+
1917
+ class SPIRVCompositeInsertBase : public SPIRVInstTemplateBase {
1939
1918
public:
1940
- const static Op OC = OpCompositeInsert;
1941
- const static SPIRVWord FixedWordCount = 5 ;
1942
- // Complete constructor
1943
- SPIRVCompositeInsert (SPIRVType *TheType, SPIRVId TheId, SPIRVId TheObject,
1944
- SPIRVId TheComposite,
1945
- const std::vector<SPIRVWord> &TheIndices,
1946
- SPIRVBasicBlock *TheBB, SPIRVModule *TheM)
1947
- : SPIRVInstruction(TheIndices.size() + FixedWordCount, OC, TheType, TheId,
1948
- TheBB, TheM),
1949
- Object (TheObject), Composite(TheComposite), Indices(TheIndices) {
1950
- validate ();
1919
+ SPIRVValue *getObject () { return getValue (Ops[0 ]); }
1920
+ SPIRVValue *getComposite () { return getValue (Ops[1 ]); }
1921
+ const std::vector<SPIRVWord> getIndices () const {
1922
+ return std::vector<SPIRVWord>(Ops.begin () + 2 , Ops.end ());
1951
1923
}
1952
- // Incomplete constructor
1953
- SPIRVCompositeInsert ()
1954
- : SPIRVInstruction(OC), Object(SPIRVID_INVALID),
1955
- Composite(SPIRVID_INVALID) {}
1956
-
1957
- SPIRVValue *getObject () { return getValue (Object); }
1958
- SPIRVValue *getComposite () { return getValue (Composite); }
1959
- const std::vector<SPIRVWord> &getIndices () const { return Indices; }
1960
1924
1961
1925
protected:
1962
- void setWordCount (SPIRVWord TheWordCount) override {
1963
- SPIRVEntry::setWordCount (TheWordCount);
1964
- Indices.resize (TheWordCount - FixedWordCount);
1965
- }
1966
- _SPIRV_DEF_ENCDEC5 (Type, Id, Object, Composite, Indices)
1967
1926
// ToDo: validate the object type is consistent with the base type and indices
1968
1927
// need to trace through the base type for struct types
1969
1928
void validate () const override {
1970
1929
SPIRVInstruction::validate ();
1971
- assert (OpCode == OC);
1972
- assert (WordCount == Indices.size () + FixedWordCount);
1930
+ assert (OpCode == OpCompositeInsert);
1931
+ SPIRVId Composite = Ops[1 ];
1932
+ (void )Composite;
1973
1933
assert (getValueType (Composite)->isTypeArray () ||
1974
1934
getValueType (Composite)->isTypeStruct () ||
1975
1935
getValueType (Composite)->isTypeVector ());
1976
1936
assert (Type == getValueType (Composite));
1977
1937
}
1978
- SPIRVId Object;
1979
- SPIRVId Composite;
1980
- std::vector<SPIRVWord> Indices;
1981
1938
};
1982
1939
1940
+ typedef SPIRVInstTemplate<SPIRVCompositeInsertBase, OpCompositeInsert, true , 5 ,
1941
+ true >
1942
+ SPIRVCompositeInsert;
1943
+
1983
1944
class SPIRVCopyObject : public SPIRVInstruction {
1984
1945
public:
1985
1946
const static Op OC = OpCopyObject;
@@ -2176,52 +2137,34 @@ class SPIRVVectorInsertDynamic : public SPIRVInstruction {
2176
2137
SPIRVId ComponentId;
2177
2138
};
2178
2139
2179
- class SPIRVVectorShuffle : public SPIRVInstruction {
2140
+ class SPIRVVectorShuffleBase : public SPIRVInstTemplateBase {
2180
2141
public:
2181
- const static Op OC = OpVectorShuffle;
2182
- const static SPIRVWord FixedWordCount = 5 ;
2183
- // Complete constructor
2184
- SPIRVVectorShuffle (SPIRVId TheId, SPIRVType *TheType, SPIRVId TheVector1,
2185
- SPIRVId TheVector2,
2186
- const std::vector<SPIRVWord> &TheComponents,
2187
- SPIRVBasicBlock *TheBB, SPIRVModule *TheM)
2188
- : SPIRVInstruction(TheComponents.size() + FixedWordCount, OC, TheType,
2189
- TheId, TheBB, TheM),
2190
- Vector1 (TheVector1), Vector2(TheVector2), Components(TheComponents) {
2191
- validate ();
2142
+ SPIRVValue *getVector1 () { return getValue (Ops[0 ]); }
2143
+ SPIRVValue *getVector2 () { return getValue (Ops[1 ]); }
2144
+ const std::vector<SPIRVWord> getComponents () const {
2145
+ return std::vector<SPIRVWord>(Ops.begin () + 2 , Ops.end ());
2192
2146
}
2193
- // Incomplete constructor
2194
- SPIRVVectorShuffle ()
2195
- : SPIRVInstruction(OC), Vector1(SPIRVID_INVALID),
2196
- Vector2(SPIRVID_INVALID) {}
2197
-
2198
- SPIRVValue *getVector1 () { return getValue (Vector1); }
2199
- SPIRVValue *getVector2 () { return getValue (Vector2); }
2200
- const std::vector<SPIRVWord> &getComponents () const { return Components; }
2201
2147
2202
2148
protected:
2203
- void setWordCount (SPIRVWord TheWordCount) override {
2204
- SPIRVEntry::setWordCount (TheWordCount);
2205
- Components.resize (TheWordCount - FixedWordCount);
2206
- }
2207
- _SPIRV_DEF_ENCDEC5 (Type, Id, Vector1, Vector2, Components)
2208
2149
void validate () const override {
2209
2150
SPIRVInstruction::validate ();
2210
- assert (OpCode == OC);
2211
- assert (WordCount == Components.size () + FixedWordCount);
2151
+ SPIRVId Vector1 = Ops[0 ];
2152
+ SPIRVId Vector2 = Ops[1 ];
2153
+ assert (OpCode == OpVectorShuffle);
2212
2154
assert (Type->isTypeVector ());
2213
2155
assert (Type->getVectorComponentType () ==
2214
2156
getValueType (Vector1)->getVectorComponentType ());
2215
2157
if (getValue (Vector1)->isForward () || getValue (Vector2)->isForward ())
2216
2158
return ;
2217
2159
assert (getValueType (Vector1) == getValueType (Vector2));
2218
- assert (Components .size () == Type->getVectorComponentCount ());
2160
+ assert (Ops .size () - 2 == Type->getVectorComponentCount ());
2219
2161
}
2220
- SPIRVId Vector1;
2221
- SPIRVId Vector2;
2222
- std::vector<SPIRVWord> Components;
2223
2162
};
2224
2163
2164
+ typedef SPIRVInstTemplate<SPIRVVectorShuffleBase, OpVectorShuffle, true , 5 ,
2165
+ true >
2166
+ SPIRVVectorShuffle;
2167
+
2225
2168
class SPIRVControlBarrier : public SPIRVInstruction {
2226
2169
public:
2227
2170
static const Op OC = OpControlBarrier;
0 commit comments