Skip to content

Commit 0fa07f4

Browse files
committed
[LegacyPassManager] Deprecate the BasicBlockPass/Manager.
Summary: The BasicBlockManager is potentially broken and should not be used. Replace all uses of the BasicBlockPass with a FunctionBlockPass+loop on blocks. Reviewers: chandlerc Subscribers: jholewinski, sanjoy.google, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68234 llvm-svn: 373254
1 parent 9567940 commit 0fa07f4

File tree

4 files changed

+70
-61
lines changed

4 files changed

+70
-61
lines changed

llvm/include/llvm/Pass.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class FunctionPass : public Pass {
306306
};
307307

308308
//===----------------------------------------------------------------------===//
309+
/// Deprecated - do not create new passes as BasicBlockPasses. Use FunctionPass
310+
/// with a loop over the BasicBlocks instead.
311+
//
309312
/// BasicBlockPass class - This class is used to implement most local
310313
/// optimizations. Optimizations should subclass this class if they
311314
/// meet the following constraints:

llvm/lib/Target/NVPTX/NVPTX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ MachineFunctionPass *createNVPTXPrologEpilogPass();
4444
MachineFunctionPass *createNVPTXReplaceImageHandlesPass();
4545
FunctionPass *createNVPTXImageOptimizerPass();
4646
FunctionPass *createNVPTXLowerArgsPass(const NVPTXTargetMachine *TM);
47-
BasicBlockPass *createNVPTXLowerAllocaPass();
47+
FunctionPass *createNVPTXLowerAllocaPass();
4848
MachineFunctionPass *createNVPTXPeephole();
4949
MachineFunctionPass *createNVPTXProxyRegErasurePass();
5050

llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ void initializeNVPTXLowerAllocaPass(PassRegistry &);
4141
}
4242

4343
namespace {
44-
class NVPTXLowerAlloca : public BasicBlockPass {
45-
bool runOnBasicBlock(BasicBlock &BB) override;
44+
class NVPTXLowerAlloca : public FunctionPass {
45+
bool runOnFunction(Function &F) override;
4646

4747
public:
4848
static char ID; // Pass identification, replacement for typeid
49-
NVPTXLowerAlloca() : BasicBlockPass(ID) {}
49+
NVPTXLowerAlloca() : FunctionPass(ID) {}
5050
StringRef getPassName() const override {
5151
return "convert address space of alloca'ed memory to local";
5252
}
@@ -61,58 +61,61 @@ INITIALIZE_PASS(NVPTXLowerAlloca, "nvptx-lower-alloca",
6161
// =============================================================================
6262
// Main function for this pass.
6363
// =============================================================================
64-
bool NVPTXLowerAlloca::runOnBasicBlock(BasicBlock &BB) {
65-
if (skipBasicBlock(BB))
64+
bool NVPTXLowerAlloca::runOnFunction(Function &F) {
65+
if (skipFunction(F))
6666
return false;
6767

6868
bool Changed = false;
69-
for (auto &I : BB) {
70-
if (auto allocaInst = dyn_cast<AllocaInst>(&I)) {
71-
Changed = true;
72-
auto PTy = dyn_cast<PointerType>(allocaInst->getType());
73-
auto ETy = PTy->getElementType();
74-
auto LocalAddrTy = PointerType::get(ETy, ADDRESS_SPACE_LOCAL);
75-
auto NewASCToLocal = new AddrSpaceCastInst(allocaInst, LocalAddrTy, "");
76-
auto GenericAddrTy = PointerType::get(ETy, ADDRESS_SPACE_GENERIC);
77-
auto NewASCToGeneric = new AddrSpaceCastInst(NewASCToLocal,
78-
GenericAddrTy, "");
79-
NewASCToLocal->insertAfter(allocaInst);
80-
NewASCToGeneric->insertAfter(NewASCToLocal);
81-
for (Value::use_iterator UI = allocaInst->use_begin(),
82-
UE = allocaInst->use_end();
83-
UI != UE; ) {
84-
// Check Load, Store, GEP, and BitCast Uses on alloca and make them
85-
// use the converted generic address, in order to expose non-generic
86-
// addrspacecast to NVPTXInferAddressSpaces. For other types
87-
// of instructions this is unnecessary and may introduce redundant
88-
// address cast.
89-
const auto &AllocaUse = *UI++;
90-
auto LI = dyn_cast<LoadInst>(AllocaUse.getUser());
91-
if (LI && LI->getPointerOperand() == allocaInst && !LI->isVolatile()) {
92-
LI->setOperand(LI->getPointerOperandIndex(), NewASCToGeneric);
93-
continue;
94-
}
95-
auto SI = dyn_cast<StoreInst>(AllocaUse.getUser());
96-
if (SI && SI->getPointerOperand() == allocaInst && !SI->isVolatile()) {
97-
SI->setOperand(SI->getPointerOperandIndex(), NewASCToGeneric);
98-
continue;
99-
}
100-
auto GI = dyn_cast<GetElementPtrInst>(AllocaUse.getUser());
101-
if (GI && GI->getPointerOperand() == allocaInst) {
102-
GI->setOperand(GI->getPointerOperandIndex(), NewASCToGeneric);
103-
continue;
104-
}
105-
auto BI = dyn_cast<BitCastInst>(AllocaUse.getUser());
106-
if (BI && BI->getOperand(0) == allocaInst) {
107-
BI->setOperand(0, NewASCToGeneric);
108-
continue;
69+
for (auto &BB : F)
70+
for (auto &I : BB) {
71+
if (auto allocaInst = dyn_cast<AllocaInst>(&I)) {
72+
Changed = true;
73+
auto PTy = dyn_cast<PointerType>(allocaInst->getType());
74+
auto ETy = PTy->getElementType();
75+
auto LocalAddrTy = PointerType::get(ETy, ADDRESS_SPACE_LOCAL);
76+
auto NewASCToLocal = new AddrSpaceCastInst(allocaInst, LocalAddrTy, "");
77+
auto GenericAddrTy = PointerType::get(ETy, ADDRESS_SPACE_GENERIC);
78+
auto NewASCToGeneric =
79+
new AddrSpaceCastInst(NewASCToLocal, GenericAddrTy, "");
80+
NewASCToLocal->insertAfter(allocaInst);
81+
NewASCToGeneric->insertAfter(NewASCToLocal);
82+
for (Value::use_iterator UI = allocaInst->use_begin(),
83+
UE = allocaInst->use_end();
84+
UI != UE;) {
85+
// Check Load, Store, GEP, and BitCast Uses on alloca and make them
86+
// use the converted generic address, in order to expose non-generic
87+
// addrspacecast to NVPTXInferAddressSpaces. For other types
88+
// of instructions this is unnecessary and may introduce redundant
89+
// address cast.
90+
const auto &AllocaUse = *UI++;
91+
auto LI = dyn_cast<LoadInst>(AllocaUse.getUser());
92+
if (LI && LI->getPointerOperand() == allocaInst &&
93+
!LI->isVolatile()) {
94+
LI->setOperand(LI->getPointerOperandIndex(), NewASCToGeneric);
95+
continue;
96+
}
97+
auto SI = dyn_cast<StoreInst>(AllocaUse.getUser());
98+
if (SI && SI->getPointerOperand() == allocaInst &&
99+
!SI->isVolatile()) {
100+
SI->setOperand(SI->getPointerOperandIndex(), NewASCToGeneric);
101+
continue;
102+
}
103+
auto GI = dyn_cast<GetElementPtrInst>(AllocaUse.getUser());
104+
if (GI && GI->getPointerOperand() == allocaInst) {
105+
GI->setOperand(GI->getPointerOperandIndex(), NewASCToGeneric);
106+
continue;
107+
}
108+
auto BI = dyn_cast<BitCastInst>(AllocaUse.getUser());
109+
if (BI && BI->getOperand(0) == allocaInst) {
110+
BI->setOperand(0, NewASCToGeneric);
111+
continue;
112+
}
109113
}
110114
}
111115
}
112-
}
113116
return Changed;
114117
}
115118

116-
BasicBlockPass *llvm::createNVPTXLowerAllocaPass() {
119+
FunctionPass *llvm::createNVPTXLowerAllocaPass() {
117120
return new NVPTXLowerAlloca();
118121
}

llvm/lib/Transforms/Scalar/DCE.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,19 @@ namespace {
3838
//===--------------------------------------------------------------------===//
3939
// DeadInstElimination pass implementation
4040
//
41-
struct DeadInstElimination : public BasicBlockPass {
42-
static char ID; // Pass identification, replacement for typeid
43-
DeadInstElimination() : BasicBlockPass(ID) {
44-
initializeDeadInstEliminationPass(*PassRegistry::getPassRegistry());
45-
}
46-
bool runOnBasicBlock(BasicBlock &BB) override {
47-
if (skipBasicBlock(BB))
48-
return false;
49-
auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
50-
TargetLibraryInfo *TLI = TLIP ? &TLIP->getTLI(*BB.getParent()) : nullptr;
51-
bool Changed = false;
41+
struct DeadInstElimination : public FunctionPass {
42+
static char ID; // Pass identification, replacement for typeid
43+
DeadInstElimination() : FunctionPass(ID) {
44+
initializeDeadInstEliminationPass(*PassRegistry::getPassRegistry());
45+
}
46+
bool runOnFunction(Function &F) override {
47+
if (skipFunction(F))
48+
return false;
49+
auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
50+
TargetLibraryInfo *TLI = TLIP ? &TLIP->getTLI(F) : nullptr;
51+
52+
bool Changed = false;
53+
for (auto &BB : F) {
5254
for (BasicBlock::iterator DI = BB.begin(); DI != BB.end(); ) {
5355
Instruction *Inst = &*DI++;
5456
if (isInstructionTriviallyDead(Inst, TLI)) {
@@ -60,13 +62,14 @@ namespace {
6062
++DIEEliminated;
6163
}
6264
}
63-
return Changed;
6465
}
66+
return Changed;
67+
}
6568

6669
void getAnalysisUsage(AnalysisUsage &AU) const override {
6770
AU.setPreservesCFG();
6871
}
69-
};
72+
};
7073
}
7174

7275
char DeadInstElimination::ID = 0;

0 commit comments

Comments
 (0)