Skip to content

Commit ccd6027

Browse files
antiagainstehsannas
authored andcommitted
[spirv] Add support for casting involving vector decomposition
Fixes microsoft#1673 Fixes microsoft#1675 Fixes microsoft#1676
1 parent 1fd8713 commit ccd6027

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

tools/clang/lib/SPIRV/InitListHandler.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ InitListHandler::InitListHandler(const ASTContext &ctx, SPIRVEmitter &emitter)
2727
spvBuilder(emitter.getSpirvBuilder()),
2828
diags(emitter.getDiagnosticsEngine()) {}
2929

30-
SpirvInstruction *InitListHandler::process(const InitListExpr *expr) {
30+
SpirvInstruction *InitListHandler::processInit(const InitListExpr *expr) {
3131
initializers.clear();
3232
scalars.clear();
3333

@@ -36,7 +36,22 @@ SpirvInstruction *InitListHandler::process(const InitListExpr *expr) {
3636
// tail of the vector. This is more efficient than using a deque.
3737
std::reverse(std::begin(initializers), std::end(initializers));
3838

39-
auto *init = createInitForType(expr->getType(), expr->getExprLoc());
39+
return doProcess(expr->getType(), expr->getExprLoc());
40+
}
41+
42+
SpirvInstruction *InitListHandler::processCast(QualType toType,
43+
const Expr *expr) {
44+
initializers.clear();
45+
scalars.clear();
46+
47+
initializers.push_back(expr);
48+
49+
return doProcess(toType, expr->getExprLoc());
50+
}
51+
52+
SpirvInstruction *InitListHandler::doProcess(QualType type,
53+
SourceLocation srcLoc) {
54+
auto *init = createInitForType(type, srcLoc);
4055

4156
if (init) {
4257
// For successful translation, we should have consumed all initializers and

tools/clang/lib/SPIRV/InitListHandler.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ class InitListHandler {
8383

8484
/// Processes the given InitListExpr and returns the <result-id> for the final
8585
/// SPIR-V value.
86-
SpirvInstruction *process(const InitListExpr *expr);
86+
SpirvInstruction *processInit(const InitListExpr *expr);
87+
88+
/// Casts the given Expr to the given toType and returns the <result-id> for
89+
/// the final SPIR-V value.
90+
SpirvInstruction *processCast(QualType toType, const Expr *expr);
8791

8892
private:
8993
/// \brief Wrapper method to create an error message and report it
@@ -97,7 +101,7 @@ class InitListHandler {
97101

98102
/// Processes the expressions in initializers and returns the <result-id> for
99103
/// the final SPIR-V value of the given type.
100-
uint32_t doProcess(QualType type, SourceLocation srcLoc);
104+
SpirvInstruction *doProcess(QualType type, SourceLocation srcLoc);
101105

102106
/// Flattens the given InitListExpr and puts all non-InitListExpr AST nodes
103107
/// into initializers.

tools/clang/lib/SPIRV/SPIRVEmitter.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -2291,8 +2291,10 @@ SpirvInstruction *SPIRVEmitter::doCastExpr(const CastExpr *expr) {
22912291
// as FlatConversion. For such cases, we can rely on the InitListHandler,
22922292
// which can decompse vectors/matrices.
22932293
else if (subExprType->isArrayType()) {
2294-
auto valId = InitListHandler(*this).processCast(expr->getType(), subExpr);
2295-
return SpirvEvalInfo(valId).setRValue();
2294+
auto *valInstr = InitListHandler(astContext, *this)
2295+
.processCast(expr->getType(), subExpr);
2296+
valInstr->setRValue();
2297+
return valInstr;
22962298
}
22972299

22982300
if (!subExprInstr)
@@ -4431,7 +4433,7 @@ SpirvInstruction *SPIRVEmitter::doInitListExpr(const InitListExpr *expr) {
44314433
return id;
44324434
}
44334435

4434-
SpirvInstruction *result = InitListHandler(astContext, *this).process(expr);
4436+
auto *result = InitListHandler(astContext, *this).processInit(expr);
44354437
result->setRValue();
44364438
return result;
44374439
}

0 commit comments

Comments
 (0)