resolver: Fix constant propagation for POC

Pipeline overidable constants are not compile-time constant.
If a module-scope const has an [[override]] decoration, do not assign
the constant value to it, as this will propagate, and the constant value
may become inlined in places that should be overridable.

Also: Rename sem::GlobalVariable::IsPipelineConstant() to
IsOverridable() to make it clearer that this is not a compile-time known
value. Add SetIsOverridable() so we can correctly set the
IsOverridable() flag even when there isn't an ID.

Change-Id: I5ede9dd180d5ff1696b3868ea4313fc28f93af4b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69140
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2021-11-11 19:12:36 +00:00
committed by Tint LUCI CQ
parent 3fe243b282
commit 6cdb1bf7c0
9 changed files with 63 additions and 54 deletions

View File

@@ -61,8 +61,7 @@ GlobalVariable::GlobalVariable(const ast::Variable* declaration,
Constant constant_value,
sem::BindingPoint binding_point)
: Base(declaration, type, storage_class, access, std::move(constant_value)),
binding_point_(binding_point),
is_pipeline_constant_(false) {}
binding_point_(binding_point) {}
GlobalVariable::~GlobalVariable() = default;

View File

@@ -129,22 +129,27 @@ class GlobalVariable : public Castable<GlobalVariable, Variable> {
/// @returns the resource binding point for the variable
sem::BindingPoint BindingPoint() const { return binding_point_; }
/// @returns the pipeline constant ID associated with the variable
uint16_t ConstantId() const { return constant_id_; }
/// @param id the constant identifier to assign to this variable
void SetConstantId(uint16_t id) {
constant_id_ = id;
is_pipeline_constant_ = true;
is_overridable_ = true;
}
/// @returns true if this variable is an overridable pipeline constant
bool IsPipelineConstant() const { return is_pipeline_constant_; }
/// @returns the pipeline constant ID associated with the variable
uint16_t ConstantId() const { return constant_id_; }
/// @param is_overridable true if this is a pipeline overridable constant
void SetIsOverridable(bool is_overridable = true) {
is_overridable_ = is_overridable;
}
/// @returns true if this is pipeline overridable constant
bool IsOverridable() const { return is_overridable_; }
private:
const sem::BindingPoint binding_point_;
bool is_pipeline_constant_ = false;
bool is_overridable_ = false;
uint16_t constant_id_ = 0;
};