Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: src/IceCfgNode.cpp

Issue 1351433002: Subzero: Validate phi instructions after CFG construction. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Add the test provenance Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceCfgNode.h ('k') | src/IceTimerTree.def » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceCfgNode.cpp
diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp
index cb8d97e95ade4a9da16f91d828fe471885538945..0ccc6ea11268f5501cde38bddfc6a95e60f7a900 100644
--- a/src/IceCfgNode.cpp
+++ b/src/IceCfgNode.cpp
@@ -80,6 +80,46 @@ void CfgNode::computeSuccessors() {
OutEdges = Insts.rbegin()->getTerminatorEdges();
}
+// Validate each Phi instruction in the node with respect to control flow. For
+// every phi argument, its label must appear in the predecessor list. For each
+// predecessor, there must be a phi argument with that label. We don't check
+// that phi arguments with the same label have the same value.
+void CfgNode::validatePhis() {
+ for (Inst &Instr : Phis) {
+ auto *Phi = llvm::cast<InstPhi>(&Instr);
+ // We do a simple O(N^2) algorithm to check for consistency. Even so, it
+ // shows up as only about 0.2% of the total translation time. But if
+ // necessary, we could improve the complexity by using a hash table to count
+ // how many times each node is referenced in the Phi instruction, and how
+ // many times each node is referenced in the incoming edge list, and compare
+ // the two for equality.
+ for (SizeT i = 0; i < Phi->getSrcSize(); ++i) {
+ CfgNode *Label = Phi->getLabel(i);
+ bool Found = false;
+ for (CfgNode *InNode : getInEdges()) {
+ if (InNode == Label) {
+ Found = true;
+ break;
+ }
+ }
+ if (!Found)
+ llvm::report_fatal_error("Phi error: label for bad incoming edge");
+ }
+ for (CfgNode *InNode : getInEdges()) {
+ bool Found = false;
+ for (SizeT i = 0; i < Phi->getSrcSize(); ++i) {
+ CfgNode *Label = Phi->getLabel(i);
+ if (InNode == Label) {
+ Found = true;
+ break;
+ }
+ }
+ if (!Found)
+ llvm::report_fatal_error("Phi error: missing label for incoming edge");
+ }
+ }
+}
+
// This does part 1 of Phi lowering, by creating a new dest variable
// for each Phi instruction, replacing the Phi instruction's dest with
// that variable, and adding an explicit assignment of the old dest to
« no previous file with comments | « src/IceCfgNode.h ('k') | src/IceTimerTree.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698