aboutsummaryrefslogtreecommitdiffstats
path: root/src/amd/compiler/aco_validate.cpp
diff options
context:
space:
mode:
authorRhys Perry <[email protected]>2019-11-19 14:19:49 +0000
committerRhys Perry <[email protected]>2019-12-02 16:56:05 +0000
commit06fc83989c04368f14e004ba5543c6b5daa6c098 (patch)
treeb57fb84cc0cb6bcc536bc29783c7c02c98a74ef5 /src/amd/compiler/aco_validate.cpp
parentb6fd679a9e68e1707bffda48ed7cb0bb79ea9f23 (diff)
aco: validate the CFG
Signed-off-by: Rhys Perry <[email protected]> Reviewed-by: Daniel Schürmann <[email protected]>
Diffstat (limited to 'src/amd/compiler/aco_validate.cpp')
-rw-r--r--src/amd/compiler/aco_validate.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/amd/compiler/aco_validate.cpp b/src/amd/compiler/aco_validate.cpp
index dbfce6314c8..8d2bf8449db 100644
--- a/src/amd/compiler/aco_validate.cpp
+++ b/src/amd/compiler/aco_validate.cpp
@@ -60,6 +60,12 @@ void validate(Program* program, FILE * output)
is_valid = false;
}
};
+ auto check_block = [&output, &is_valid](bool check, const char * msg, aco::Block * block) -> void {
+ if (!check) {
+ fprintf(output, "%s: BB%u\n", msg, block->index);
+ is_valid = false;
+ }
+ };
for (Block& block : program->blocks) {
for (aco_ptr<Instruction>& instr : block.instructions) {
@@ -246,6 +252,31 @@ void validate(Program* program, FILE * output)
}
}
}
+
+ /* validate CFG */
+ for (unsigned i = 0; i < program->blocks.size(); i++) {
+ Block& block = program->blocks[i];
+ check_block(block.index == i, "block.index must match actual index", &block);
+
+ /* predecessors/successors should be sorted */
+ for (unsigned j = 0; j + 1 < block.linear_preds.size(); j++)
+ check_block(block.linear_preds[j] < block.linear_preds[j + 1], "linear predecessors must be sorted", &block);
+ for (unsigned j = 0; j + 1 < block.logical_preds.size(); j++)
+ check_block(block.logical_preds[j] < block.logical_preds[j + 1], "logical predecessors must be sorted", &block);
+ for (unsigned j = 0; j + 1 < block.linear_succs.size(); j++)
+ check_block(block.linear_succs[j] < block.linear_succs[j + 1], "linear successors must be sorted", &block);
+ for (unsigned j = 0; j + 1 < block.logical_succs.size(); j++)
+ check_block(block.logical_succs[j] < block.logical_succs[j + 1], "logical successors must be sorted", &block);
+
+ /* critical edges are not allowed */
+ if (block.linear_preds.size() > 1) {
+ for (unsigned pred : block.linear_preds)
+ check_block(program->blocks[pred].linear_succs.size() == 1, "linear critical edges are not allowed", &program->blocks[pred]);
+ for (unsigned pred : block.logical_preds)
+ check_block(program->blocks[pred].logical_succs.size() == 1, "logical critical edges are not allowed", &program->blocks[pred]);
+ }
+ }
+
assert(is_valid);
}