162
162
using namespace llvm ;
163
163
164
164
namespace llvm {
165
- void initializeNVPTXLowerArgsPass (PassRegistry &);
165
+ void initializeNVPTXLowerArgsLegacyPassPass (PassRegistry &);
166
166
}
167
167
168
168
namespace {
169
- class NVPTXLowerArgs : public FunctionPass {
169
+ class NVPTXLowerArgsLegacyPass : public FunctionPass {
170
170
bool runOnFunction (Function &F) override ;
171
171
172
- bool runOnKernelFunction (const NVPTXTargetMachine &TM, Function &F);
173
- bool runOnDeviceFunction (const NVPTXTargetMachine &TM, Function &F);
174
-
175
- // handle byval parameters
176
- void handleByValParam (const NVPTXTargetMachine &TM, Argument *Arg);
177
- // Knowing Ptr must point to the global address space, this function
178
- // addrspacecasts Ptr to global and then back to generic. This allows
179
- // NVPTXInferAddressSpaces to fold the global-to-generic cast into
180
- // loads/stores that appear later.
181
- void markPointerAsGlobal (Value *Ptr);
182
-
183
172
public:
184
173
static char ID; // Pass identification, replacement for typeid
185
- NVPTXLowerArgs () : FunctionPass(ID) {}
174
+ NVPTXLowerArgsLegacyPass () : FunctionPass(ID) {}
186
175
StringRef getPassName () const override {
187
176
return " Lower pointer arguments of CUDA kernels" ;
188
177
}
@@ -192,12 +181,12 @@ class NVPTXLowerArgs : public FunctionPass {
192
181
};
193
182
} // namespace
194
183
195
- char NVPTXLowerArgs ::ID = 1 ;
184
+ char NVPTXLowerArgsLegacyPass ::ID = 1 ;
196
185
197
- INITIALIZE_PASS_BEGIN (NVPTXLowerArgs , " nvptx-lower-args" ,
186
+ INITIALIZE_PASS_BEGIN (NVPTXLowerArgsLegacyPass , " nvptx-lower-args" ,
198
187
" Lower arguments (NVPTX)" , false , false )
199
188
INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
200
- INITIALIZE_PASS_END(NVPTXLowerArgs , " nvptx-lower-args" ,
189
+ INITIALIZE_PASS_END(NVPTXLowerArgsLegacyPass , " nvptx-lower-args" ,
201
190
" Lower arguments (NVPTX)" , false , false )
202
191
203
192
// =============================================================================
@@ -552,8 +541,7 @@ void copyByValParam(Function &F, Argument &Arg) {
552
541
}
553
542
} // namespace
554
543
555
- void NVPTXLowerArgs::handleByValParam (const NVPTXTargetMachine &TM,
556
- Argument *Arg) {
544
+ static void handleByValParam (const NVPTXTargetMachine &TM, Argument *Arg) {
557
545
Function *Func = Arg->getParent ();
558
546
bool HasCvtaParam =
559
547
TM.getSubtargetImpl (*Func)->hasCvtaParam () && isKernelFunction (*Func);
@@ -647,20 +635,19 @@ static void markPointerAsAS(Value *Ptr, const unsigned AS) {
647
635
PtrInGlobal->setOperand (0 , Ptr);
648
636
}
649
637
650
- void NVPTXLowerArgs:: markPointerAsGlobal (Value *Ptr) {
638
+ static void markPointerAsGlobal (Value *Ptr) {
651
639
markPointerAsAS (Ptr, ADDRESS_SPACE_GLOBAL);
652
640
}
653
641
654
642
// =============================================================================
655
643
// Main function for this pass.
656
644
// =============================================================================
657
- bool NVPTXLowerArgs::runOnKernelFunction (const NVPTXTargetMachine &TM,
658
- Function &F) {
645
+ static bool runOnKernelFunction (const NVPTXTargetMachine &TM, Function &F) {
659
646
// Copying of byval aggregates + SROA may result in pointers being loaded as
660
647
// integers, followed by intotoptr. We may want to mark those as global, too,
661
648
// but only if the loaded integer is used exclusively for conversion to a
662
649
// pointer with inttoptr.
663
- auto HandleIntToPtr = [this ](Value &V) {
650
+ auto HandleIntToPtr = [](Value &V) {
664
651
if (llvm::all_of (V.users (), [](User *U) { return isa<IntToPtrInst>(U); })) {
665
652
SmallVector<User *, 16 > UsersToUpdate (V.users ());
666
653
for (User *U : UsersToUpdate)
@@ -705,8 +692,7 @@ bool NVPTXLowerArgs::runOnKernelFunction(const NVPTXTargetMachine &TM,
705
692
}
706
693
707
694
// Device functions only need to copy byval args into local memory.
708
- bool NVPTXLowerArgs::runOnDeviceFunction (const NVPTXTargetMachine &TM,
709
- Function &F) {
695
+ static bool runOnDeviceFunction (const NVPTXTargetMachine &TM, Function &F) {
710
696
LLVM_DEBUG (dbgs () << " Lowering function args of " << F.getName () << " \n " );
711
697
712
698
const auto *TLI =
@@ -720,14 +706,18 @@ bool NVPTXLowerArgs::runOnDeviceFunction(const NVPTXTargetMachine &TM,
720
706
return true ;
721
707
}
722
708
723
- bool NVPTXLowerArgs::runOnFunction (Function &F) {
724
- auto &TM = getAnalysis<TargetPassConfig>().getTM <NVPTXTargetMachine>();
725
-
709
+ static bool processFunction (Function &F, NVPTXTargetMachine &TM) {
726
710
return isKernelFunction (F) ? runOnKernelFunction (TM, F)
727
711
: runOnDeviceFunction (TM, F);
728
712
}
729
713
730
- FunctionPass *llvm::createNVPTXLowerArgsPass () { return new NVPTXLowerArgs (); }
714
+ bool NVPTXLowerArgsLegacyPass::runOnFunction (Function &F) {
715
+ auto &TM = getAnalysis<TargetPassConfig>().getTM <NVPTXTargetMachine>();
716
+ return processFunction (F, TM);
717
+ }
718
+ FunctionPass *llvm::createNVPTXLowerArgsPass () {
719
+ return new NVPTXLowerArgsLegacyPass ();
720
+ }
731
721
732
722
static bool copyFunctionByValArgs (Function &F) {
733
723
LLVM_DEBUG (dbgs () << " Creating a copy of byval args of " << F.getName ()
@@ -747,3 +737,10 @@ PreservedAnalyses NVPTXCopyByValArgsPass::run(Function &F,
747
737
return copyFunctionByValArgs (F) ? PreservedAnalyses::none ()
748
738
: PreservedAnalyses::all ();
749
739
}
740
+
741
+ PreservedAnalyses NVPTXLowerArgsPass::run (Function &F,
742
+ FunctionAnalysisManager &AM) {
743
+ auto &NTM = static_cast <NVPTXTargetMachine &>(TM);
744
+ bool Changed = processFunction (F, NTM);
745
+ return Changed ? PreservedAnalyses::none () : PreservedAnalyses::all ();
746
+ }
0 commit comments