summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/MachinePostDominators.cpp44
-rw-r--r--llvm/lib/Target/AMDGPU/SILowerI1Copies.cpp20
2 files changed, 38 insertions, 26 deletions
diff --git a/llvm/lib/CodeGen/MachinePostDominators.cpp b/llvm/lib/CodeGen/MachinePostDominators.cpp
index 7f220ed1fd8..f2fc9f814f8 100644
--- a/llvm/lib/CodeGen/MachinePostDominators.cpp
+++ b/llvm/lib/CodeGen/MachinePostDominators.cpp
@@ -13,6 +13,8 @@
#include "llvm/CodeGen/MachinePostDominators.h"
+#include "llvm/ADT/STLExtras.h"
+
using namespace llvm;
namespace llvm {
@@ -25,33 +27,43 @@ char MachinePostDominatorTree::ID = 0;
INITIALIZE_PASS(MachinePostDominatorTree, "machinepostdomtree",
"MachinePostDominator Tree Construction", true, true)
-MachinePostDominatorTree::MachinePostDominatorTree() : MachineFunctionPass(ID) {
+MachinePostDominatorTree::MachinePostDominatorTree()
+ : MachineFunctionPass(ID), PDT(nullptr) {
initializeMachinePostDominatorTreePass(*PassRegistry::getPassRegistry());
- DT = new PostDomTreeBase<MachineBasicBlock>();
}
-FunctionPass *
-MachinePostDominatorTree::createMachinePostDominatorTreePass() {
+FunctionPass *MachinePostDominatorTree::createMachinePostDominatorTreePass() {
return new MachinePostDominatorTree();
}
-bool
-MachinePostDominatorTree::runOnMachineFunction(MachineFunction &F) {
- DT->recalculate(F);
+bool MachinePostDominatorTree::runOnMachineFunction(MachineFunction &F) {
+ PDT = std::make_unique<PostDomTreeT>();
+ PDT->recalculate(F);
return false;
}
-MachinePostDominatorTree::~MachinePostDominatorTree() {
- delete DT;
-}
-
-void
-MachinePostDominatorTree::getAnalysisUsage(AnalysisUsage &AU) const {
+void MachinePostDominatorTree::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
MachineFunctionPass::getAnalysisUsage(AU);
}
-void
-MachinePostDominatorTree::print(llvm::raw_ostream &OS, const Module *M) const {
- DT->print(OS);
+MachineBasicBlock *MachinePostDominatorTree::findNearestCommonDominator(
+ ArrayRef<MachineBasicBlock *> Blocks) const {
+ assert(!Blocks.empty());
+
+ MachineBasicBlock *NCD = Blocks.front();
+ for (MachineBasicBlock *BB : Blocks.drop_front()) {
+ NCD = PDT->findNearestCommonDominator(NCD, BB);
+
+ // Stop when the root is reached.
+ if (PDT->isVirtualRoot(PDT->getNode(NCD)))
+ return nullptr;
+ }
+
+ return NCD;
+}
+
+void MachinePostDominatorTree::print(llvm::raw_ostream &OS,
+ const Module *M) const {
+ PDT->print(OS);
}
diff --git a/llvm/lib/Target/AMDGPU/SILowerI1Copies.cpp b/llvm/lib/Target/AMDGPU/SILowerI1Copies.cpp
index 86242f1fb64..b4541253635 100644
--- a/llvm/lib/Target/AMDGPU/SILowerI1Copies.cpp
+++ b/llvm/lib/Target/AMDGPU/SILowerI1Copies.cpp
@@ -589,12 +589,12 @@ void SILowerI1Copies::lowerPhis() {
// Phis in a loop that are observed outside the loop receive a simple but
// conservatively correct treatment.
- MachineBasicBlock *PostDomBound = &MBB;
- for (MachineInstr &Use : MRI->use_instructions(DstReg)) {
- PostDomBound =
- PDT->findNearestCommonDominator(PostDomBound, Use.getParent());
- }
+ std::vector<MachineBasicBlock *> DomBlocks = {&MBB};
+ for (MachineInstr &Use : MRI->use_instructions(DstReg))
+ DomBlocks.push_back(Use.getParent());
+ MachineBasicBlock *PostDomBound =
+ PDT->findNearestCommonDominator(DomBlocks);
unsigned FoundLoopLevel = LF.findLoop(PostDomBound);
SSAUpdater.Initialize(DstReg);
@@ -711,12 +711,12 @@ void SILowerI1Copies::lowerCopiesToI1() {
// Defs in a loop that are observed outside the loop must be transformed
// into appropriate bit manipulation.
- MachineBasicBlock *PostDomBound = &MBB;
- for (MachineInstr &Use : MRI->use_instructions(DstReg)) {
- PostDomBound =
- PDT->findNearestCommonDominator(PostDomBound, Use.getParent());
- }
+ std::vector<MachineBasicBlock *> DomBlocks = {&MBB};
+ for (MachineInstr &Use : MRI->use_instructions(DstReg))
+ DomBlocks.push_back(Use.getParent());
+ MachineBasicBlock *PostDomBound =
+ PDT->findNearestCommonDominator(DomBlocks);
unsigned FoundLoopLevel = LF.findLoop(PostDomBound);
if (FoundLoopLevel) {
SSAUpdater.Initialize(DstReg);
OpenPOWER on IntegriCloud