summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils
diff options
context:
space:
mode:
authorFlorian Hahn <florian.hahn@arm.com>2018-06-20 17:42:01 +0000
committerFlorian Hahn <florian.hahn@arm.com>2018-06-20 17:42:01 +0000
commit5ac2629823d689309ba000ab624ab667b9f123dd (patch)
tree458dad826771a040a05268f1e700ba70a8cb16d6 /llvm/lib/Transforms/Utils
parent0583d7a56cb5f14ce57183d13269c13390acfada (diff)
downloadbcm5719-llvm-5ac2629823d689309ba000ab624ab667b9f123dd.tar.gz
bcm5719-llvm-5ac2629823d689309ba000ab624ab667b9f123dd.zip
[PredicateInfo] Order instructions in different BBs by DFSNumIn.
Using OrderedInstructions::dominates as comparator for instructions in BBs without dominance relation can cause a non-deterministic order between such instructions. That in turn can cause us to materialize copies in a non-deterministic order. While this does not effect correctness, it causes some minor non-determinism in the final generated code, because values have slightly different labels. Without this patch, running -print-predicateinfo on a reasonably large module produces slightly different output on each run. This patch uses the dominator trees DFSInNum to order instruction from different BBs, which should enforce a deterministic ordering and guarantee that dominated instructions come after the instructions that dominate them. Reviewers: dberlin, efriedma, davide Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D48230 llvm-svn: 335150
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r--llvm/lib/Transforms/Utils/OrderedInstructions.cpp33
-rw-r--r--llvm/lib/Transforms/Utils/PredicateInfo.cpp3
2 files changed, 28 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Utils/OrderedInstructions.cpp b/llvm/lib/Transforms/Utils/OrderedInstructions.cpp
index dc780542ce6..6d0b96f6aa8 100644
--- a/llvm/lib/Transforms/Utils/OrderedInstructions.cpp
+++ b/llvm/lib/Transforms/Utils/OrderedInstructions.cpp
@@ -14,19 +14,38 @@
#include "llvm/Transforms/Utils/OrderedInstructions.h"
using namespace llvm;
+bool OrderedInstructions::localDominates(const Instruction *InstA,
+ const Instruction *InstB) const {
+ assert(InstA->getParent() == InstB->getParent() &&
+ "Instructions must be in the same basic block");
+
+ const BasicBlock *IBB = InstA->getParent();
+ auto OBB = OBBMap.find(IBB);
+ if (OBB == OBBMap.end())
+ OBB = OBBMap.insert({IBB, make_unique<OrderedBasicBlock>(IBB)}).first;
+ return OBB->second->dominates(InstA, InstB);
+}
+
/// Given 2 instructions, use OrderedBasicBlock to check for dominance relation
/// if the instructions are in the same basic block, Otherwise, use dominator
/// tree.
bool OrderedInstructions::dominates(const Instruction *InstA,
const Instruction *InstB) const {
- const BasicBlock *IBB = InstA->getParent();
// Use ordered basic block to do dominance check in case the 2 instructions
// are in the same basic block.
- if (IBB == InstB->getParent()) {
- auto OBB = OBBMap.find(IBB);
- if (OBB == OBBMap.end())
- OBB = OBBMap.insert({IBB, make_unique<OrderedBasicBlock>(IBB)}).first;
- return OBB->second->dominates(InstA, InstB);
- }
+ if (InstA->getParent() == InstB->getParent())
+ return localDominates(InstA, InstB);
return DT->dominates(InstA->getParent(), InstB->getParent());
}
+
+bool OrderedInstructions::dfsBefore(const Instruction *InstA,
+ const Instruction *InstB) const {
+ // Use ordered basic block in case the 2 instructions are in the same basic
+ // block.
+ if (InstA->getParent() == InstB->getParent())
+ return localDominates(InstA, InstB);
+
+ DomTreeNode *DA = DT->getNode(InstA->getParent());
+ DomTreeNode *DB = DT->getNode(InstB->getParent());
+ return DA->getDFSNumIn() < DB->getDFSNumIn();
+}
diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
index 6da3c7a90b6..38cada8cb06 100644
--- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp
+++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
@@ -118,7 +118,7 @@ static bool valueComesBefore(OrderedInstructions &OI, const Value *A,
return false;
if (ArgA && ArgB)
return ArgA->getArgNo() < ArgB->getArgNo();
- return OI.dominates(cast<Instruction>(A), cast<Instruction>(B));
+ return OI.dfsBefore(cast<Instruction>(A), cast<Instruction>(B));
}
// This compares ValueDFS structures, creating OrderedBasicBlocks where
@@ -557,6 +557,7 @@ void PredicateInfo::renameUses(SmallPtrSetImpl<Value *> &OpSet) {
ValueDFS_Compare Compare(OI);
// Compute liveness, and rename in O(uses) per Op.
for (auto *Op : OpsToRename) {
+ LLVM_DEBUG(dbgs() << "Visiting " << *Op << "\n");
unsigned Counter = 0;
SmallVector<ValueDFS, 16> OrderedUses;
const auto &ValueInfo = getValueInfo(Op);
OpenPOWER on IntegriCloud