From 84cc0d5ea07cdfaf8fa102e2f68661572e65779a Mon Sep 17 00:00:00 2001 From: Christian Hagedorn Date: Tue, 19 Sep 2023 17:01:32 +0200 Subject: [PATCH] Add verification for predicate blocks --- src/hotspot/share/opto/predicates.cpp | 15 +++++++++++++++ src/hotspot/share/opto/predicates.hpp | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/opto/predicates.cpp b/src/hotspot/share/opto/predicates.cpp index adcacd2f1fb39..377a3beca2669 100644 --- a/src/hotspot/share/opto/predicates.cpp +++ b/src/hotspot/share/opto/predicates.cpp @@ -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) { diff --git a/src/hotspot/share/opto/predicates.hpp b/src/hotspot/share/opto/predicates.hpp index 0f5c8fe3264b1..d273ab09dc420 100644 --- a/src/hotspot/share/opto/predicates.hpp +++ b/src/hotspot/share/opto/predicates.hpp @@ -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