@@ -41,12 +41,12 @@ void initializeNVPTXLowerAllocaPass(PassRegistry &);
41
41
}
42
42
43
43
namespace {
44
- class NVPTXLowerAlloca : public BasicBlockPass {
45
- bool runOnBasicBlock (BasicBlock &BB ) override ;
44
+ class NVPTXLowerAlloca : public FunctionPass {
45
+ bool runOnFunction (Function &F ) override ;
46
46
47
47
public:
48
48
static char ID; // Pass identification, replacement for typeid
49
- NVPTXLowerAlloca () : BasicBlockPass (ID) {}
49
+ NVPTXLowerAlloca () : FunctionPass (ID) {}
50
50
StringRef getPassName () const override {
51
51
return " convert address space of alloca'ed memory to local" ;
52
52
}
@@ -61,58 +61,61 @@ INITIALIZE_PASS(NVPTXLowerAlloca, "nvptx-lower-alloca",
61
61
// =============================================================================
62
62
// Main function for this pass.
63
63
// =============================================================================
64
- bool NVPTXLowerAlloca::runOnBasicBlock(BasicBlock &BB ) {
65
- if (skipBasicBlock (BB ))
64
+ bool NVPTXLowerAlloca::runOnFunction(Function &F ) {
65
+ if (skipFunction (F ))
66
66
return false ;
67
67
68
68
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
+ }
109
113
}
110
114
}
111
115
}
112
- }
113
116
return Changed;
114
117
}
115
118
116
- BasicBlockPass *llvm::createNVPTXLowerAllocaPass () {
119
+ FunctionPass *llvm::createNVPTXLowerAllocaPass () {
117
120
return new NVPTXLowerAlloca ();
118
121
}
0 commit comments