Skip to content

Commit

Permalink
Add verification for predicate blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
chhagedorn committed Sep 19, 2023
1 parent 32020ae commit 84cc0d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/hotspot/share/opto/predicates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ ParsePredicateNode* ParsePredicateIterator::next() {
return _parse_predicates.at(_current_index++);
}

#ifdef ASSERT
// Check that the block has at most one Parse Predicate and that we only find Regular Predicate nodes (i.e. IfProj,
// If, or RangeCheck nodes.
void PredicateBlock::verify_block() {
Node* next = _parse_predicate.entry(); // Skip unique Parse Predicate of this block if present
while (next != _entry) {
assert(!next->is_ParsePredicate(), "can only have one Parse Predicate in a block");
const int opcode = next->Opcode();
assert(next->is_IfProj() || opcode == Op_If || opcode == Op_RangeCheck,
"Regular Predicates consist of an IfProj and an If or RangeCheck node");
next = next->in(0);
}
}
#endif // ASSERT

// Walk over all Regular Predicates of this block (if any) and return the first node not belonging to the block
// anymore (i.e. entry to the first Regular Predicate in this block if any or `regular_predicate_proj` otherwise).
Node* PredicateBlock::skip_regular_predicates(Node* regular_predicate_proj, Deoptimization::DeoptReason deopt_reason) {
Expand Down
5 changes: 4 additions & 1 deletion src/hotspot/share/opto/predicates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,14 @@ class PredicateBlock : public StackObj {
Node* _entry;

static Node* skip_regular_predicates(Node* regular_predicate_proj, Deoptimization::DeoptReason deopt_reason);
DEBUG_ONLY(void verify_block();)

public:
PredicateBlock(Node* predicate_proj, Deoptimization::DeoptReason deopt_reason)
: _parse_predicate(predicate_proj, deopt_reason),
_entry(skip_regular_predicates(_parse_predicate.entry(), deopt_reason)) {}
_entry(skip_regular_predicates(_parse_predicate.entry(), deopt_reason)) {
DEBUG_ONLY(verify_block();)
}

// Returns the control input node into this Regular Predicate block. This is either:
// - The control input to the first If node in the block representing a Runtime Predicate if there is at least one
Expand Down

0 comments on commit 84cc0d5

Please sign in to comment.