tint: Pass constant::Values to ArrayOrStructCtor

This will allow the WGSL interpreter to use it (as the interpreter
does not have semantic nodes for its runtime results).

Change-Id: Icf81852d099b34cbb48c098bc116b4f08a3a7c61
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121545
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
James Price 2023-02-27 17:13:32 +00:00 committed by Dawn LUCI CQ
parent c5ec169b89
commit 806135658d
3 changed files with 7 additions and 12 deletions

View File

@ -1229,23 +1229,18 @@ ConstEval::Result ConstEval::Literal(const type::Type* ty, const ast::LiteralExp
}
ConstEval::Result ConstEval::ArrayOrStructCtor(const type::Type* ty,
utils::VectorRef<const sem::ValueExpression*> args) {
utils::VectorRef<const constant::Value*> args) {
if (args.IsEmpty()) {
return ZeroValue(ty);
}
if (args.Length() == 1 && args[0]->Type() == ty) {
// Identity constructor.
return args[0]->ConstantValue();
return args[0];
}
// Multiple arguments. Must be a value constructor.
utils::Vector<const constant::Value*, 4> els;
els.Reserve(args.Length());
for (auto* arg : args) {
els.Push(arg->ConstantValue());
}
return builder.create<constant::Composite>(ty, std::move(els));
return builder.create<constant::Composite>(ty, std::move(args));
}
ConstEval::Result ConstEval::Conv(const type::Type* ty,

View File

@ -77,11 +77,10 @@ class ConstEval {
// Constant value evaluation methods, to be called directly from Resolver
////////////////////////////////////////////////////////////////////////////////////////////////
/// @param ty the target type - must be an array or initializer
/// @param ty the target type - must be an array or struct
/// @param args the input arguments
/// @return the constructed value, or null if the value cannot be calculated
Result ArrayOrStructCtor(const type::Type* ty,
utils::VectorRef<const sem::ValueExpression*> args);
Result ArrayOrStructCtor(const type::Type* ty, utils::VectorRef<const constant::Value*> args);
/// @param ty the target type
/// @param value the value being converted

View File

@ -2011,7 +2011,8 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
auto stage = args_stage; // The evaluation stage of the call
const constant::Value* value = nullptr; // The constant value for the call
if (stage == sem::EvaluationStage::kConstant) {
if (auto r = const_eval_.ArrayOrStructCtor(ty, args)) {
auto els = utils::Transform(args, [&](auto* arg) { return arg->ConstantValue(); });
if (auto r = const_eval_.ArrayOrStructCtor(ty, std::move(els))) {
value = r.Get();
} else {
return nullptr;