mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 09:25:25 +00:00
resolver: Migrate validation to behavior analysis
Migrate some of the validation logic over to use the results of behavior analysis. The most significant changes are: * Unreachable-statements now consider merge-points of control flow. For example, if all branches of a if-statement or switch-statement either return or discard, the next statement will be considered unreachable. * Unreachable statements are no longer an error, but a warning. See https://github.com/gpuweb/gpuweb/issues/2378. * Statements that follow a loops that does not break, or have a conditional will now be considered unreachable. * Unreachable statements produced by the SPIR-V reader are now removed using the new RemoveUnreachableStatements transform. Some other new changes include additional validation for the continuing block for for-loops, to match the rules of a loop continuing block. The new cases this validation is testing for are not expressible in WGSL, but some transforms may produce complex continuing statements that might violate these rules. All the writers are able to decay these complex for-loop continuing statements to regular loops. Bug: tint:1302 Change-Id: I0d8a48c73d5d5c30a1cddf92cc3383a692a58e61 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/71500 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
@@ -28,5 +28,9 @@ ForLoopStatement::ForLoopStatement(const ast::ForLoopStatement* declaration,
|
||||
|
||||
ForLoopStatement::~ForLoopStatement() = default;
|
||||
|
||||
const ast::ForLoopStatement* ForLoopStatement::Declaration() const {
|
||||
return static_cast<const ast::ForLoopStatement*>(Base::Declaration());
|
||||
}
|
||||
|
||||
} // namespace sem
|
||||
} // namespace tint
|
||||
|
||||
@@ -43,6 +43,9 @@ class ForLoopStatement : public Castable<ForLoopStatement, CompoundStatement> {
|
||||
/// Destructor
|
||||
~ForLoopStatement() override;
|
||||
|
||||
/// @returns the AST node
|
||||
const ast::ForLoopStatement* Declaration() const;
|
||||
|
||||
/// @returns the for-loop condition expression
|
||||
const Expression* Condition() const { return condition_; }
|
||||
|
||||
|
||||
@@ -106,11 +106,20 @@ class Statement : public Castable<Statement, Node> {
|
||||
/// @return the behaviors of this statement
|
||||
sem::Behaviors& Behaviors() { return behaviors_; }
|
||||
|
||||
/// @returns true if this statement is reachable by control flow according to
|
||||
/// the behavior analysis
|
||||
bool IsReachable() const { return is_reachable_; }
|
||||
|
||||
/// @param is_reachable whether this statement is reachable by control flow
|
||||
/// according to the behavior analysis
|
||||
void SetIsReachable(bool is_reachable) { is_reachable_ = is_reachable; }
|
||||
|
||||
private:
|
||||
const ast::Statement* const declaration_;
|
||||
const CompoundStatement* const parent_;
|
||||
const sem::Function* const function_;
|
||||
sem::Behaviors behaviors_{sem::Behavior::kNext};
|
||||
bool is_reachable_ = true;
|
||||
};
|
||||
|
||||
/// CompoundStatement is the base class of statements that can hold other
|
||||
|
||||
Reference in New Issue
Block a user