aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
diff options
context:
space:
mode:
authorSharmaRithik <rithiksh02@gmail.com>2020-07-10 11:16:06 +0530
committerSharmaRithik <rithiksh02@gmail.com>2020-07-10 11:22:43 +0530
commite71c7b593a2d1b7d60dc8aaa4b8ede03de7bbd00 (patch)
tree4dda2ba1c56ebb500818127235cdeb705583383b /llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
parent760bbda2d8200481d03a46a74587035059dd12cc (diff)
downloadllvm-e71c7b593a2d1b7d60dc8aaa4b8ede03de7bbd00.zip
llvm-e71c7b593a2d1b7d60dc8aaa4b8ede03de7bbd00.tar.gz
llvm-e71c7b593a2d1b7d60dc8aaa4b8ede03de7bbd00.tar.bz2
[CodeMoverUtils] Move OrderedInstructions to CodeMoverUtils
Summary: This patch moves OrderedInstructions to CodeMoverUtils as It was the only place where OrderedInstructions is required. Authored By: RithikSharma Reviewer: Whitney, bmahjour, etiotto, fhahn, nikic Reviewed By: Whitney, nikic Subscribers: mgorny, hiraditya, llvm-commits Tag: LLVM Differential Revision: https://reviews.llvm.org/D80643
Diffstat (limited to 'llvm/lib/Transforms/Utils/CodeMoverUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/CodeMoverUtils.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp b/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
index 11a740f..08047dc 100644
--- a/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
@@ -15,7 +15,6 @@
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/DependenceAnalysis.h"
-#include "llvm/Analysis/OrderedInstructions.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Dominators.h"
@@ -94,6 +93,18 @@ private:
};
} // namespace
+static bool domTreeLevelBefore(DominatorTree *DT, const Instruction *InstA,
+ const Instruction *InstB) {
+ // Use ordered basic block in case the 2 instructions are in the same
+ // block.
+ if (InstA->getParent() == InstB->getParent())
+ return InstA->comesBefore(InstB);
+
+ DomTreeNode *DA = DT->getNode(InstA->getParent());
+ DomTreeNode *DB = DT->getNode(InstB->getParent());
+ return DA->getLevel() < DB->getLevel();
+}
+
const Optional<ControlConditions> ControlConditions::collectControlConditions(
const BasicBlock &BB, const BasicBlock &Dominator, const DominatorTree &DT,
const PostDominatorTree &PDT, unsigned MaxLookup) {
@@ -332,9 +343,8 @@ bool llvm::isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint,
if (&InsertPoint == OpInst || !DT.dominates(OpInst, &InsertPoint))
return false;
- OrderedInstructions OI(&DT);
DT.updateDFSNumbers();
- const bool MoveForward = OI.domTreeLevelBefore(&I, &InsertPoint);
+ const bool MoveForward = domTreeLevelBefore(&DT, &I, &InsertPoint);
Instruction &StartInst = (MoveForward ? I : InsertPoint);
Instruction &EndInst = (MoveForward ? InsertPoint : I);
SmallPtrSet<Instruction *, 10> InstsToCheck;