162162using namespace llvm ;
163163
164164namespace llvm {
165- void initializeNVPTXLowerArgsPass (PassRegistry &);
165+ void initializeNVPTXLowerArgsLegacyPassPass (PassRegistry &);
166166}
167167
168168namespace {
169- class NVPTXLowerArgs : public FunctionPass {
169+ class NVPTXLowerArgsLegacyPass : public FunctionPass {
170170 bool runOnFunction (Function &F) override ;
171171
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-
183172public:
184173 static char ID; // Pass identification, replacement for typeid
185- NVPTXLowerArgs () : FunctionPass(ID) {}
174+ NVPTXLowerArgsLegacyPass () : FunctionPass(ID) {}
186175 StringRef getPassName () const override {
187176 return " Lower pointer arguments of CUDA kernels" ;
188177 }
@@ -192,12 +181,12 @@ class NVPTXLowerArgs : public FunctionPass {
192181};
193182} // namespace
194183
195- char NVPTXLowerArgs ::ID = 1 ;
184+ char NVPTXLowerArgsLegacyPass ::ID = 1 ;
196185
197- INITIALIZE_PASS_BEGIN (NVPTXLowerArgs , " nvptx-lower-args" ,
186+ INITIALIZE_PASS_BEGIN (NVPTXLowerArgsLegacyPass , " nvptx-lower-args" ,
198187 " Lower arguments (NVPTX)" , false , false )
199188INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
200- INITIALIZE_PASS_END(NVPTXLowerArgs , " nvptx-lower-args" ,
189+ INITIALIZE_PASS_END(NVPTXLowerArgsLegacyPass , " nvptx-lower-args" ,
201190 " Lower arguments (NVPTX)" , false , false )
202191
203192// =============================================================================
@@ -552,8 +541,7 @@ void copyByValParam(Function &F, Argument &Arg) {
552541}
553542} // namespace
554543
555- void NVPTXLowerArgs::handleByValParam (const NVPTXTargetMachine &TM,
556- Argument *Arg) {
544+ static void handleByValParam (const NVPTXTargetMachine &TM, Argument *Arg) {
557545 Function *Func = Arg->getParent ();
558546 bool HasCvtaParam =
559547 TM.getSubtargetImpl (*Func)->hasCvtaParam () && isKernelFunction (*Func);
@@ -647,20 +635,19 @@ static void markPointerAsAS(Value *Ptr, const unsigned AS) {
647635 PtrInGlobal->setOperand (0 , Ptr);
648636}
649637
650- void NVPTXLowerArgs:: markPointerAsGlobal (Value *Ptr) {
638+ static void markPointerAsGlobal (Value *Ptr) {
651639 markPointerAsAS (Ptr, ADDRESS_SPACE_GLOBAL);
652640}
653641
654642// =============================================================================
655643// Main function for this pass.
656644// =============================================================================
657- bool NVPTXLowerArgs::runOnKernelFunction (const NVPTXTargetMachine &TM,
658- Function &F) {
645+ static bool runOnKernelFunction (const NVPTXTargetMachine &TM, Function &F) {
659646 // Copying of byval aggregates + SROA may result in pointers being loaded as
660647 // integers, followed by intotoptr. We may want to mark those as global, too,
661648 // but only if the loaded integer is used exclusively for conversion to a
662649 // pointer with inttoptr.
663- auto HandleIntToPtr = [this ](Value &V) {
650+ auto HandleIntToPtr = [](Value &V) {
664651 if (llvm::all_of (V.users (), [](User *U) { return isa<IntToPtrInst>(U); })) {
665652 SmallVector<User *, 16 > UsersToUpdate (V.users ());
666653 for (User *U : UsersToUpdate)
@@ -705,8 +692,7 @@ bool NVPTXLowerArgs::runOnKernelFunction(const NVPTXTargetMachine &TM,
705692}
706693
707694// 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) {
710696 LLVM_DEBUG (dbgs () << " Lowering function args of " << F.getName () << " \n " );
711697
712698 const auto *TLI =
@@ -720,14 +706,18 @@ bool NVPTXLowerArgs::runOnDeviceFunction(const NVPTXTargetMachine &TM,
720706 return true ;
721707}
722708
723- bool NVPTXLowerArgs::runOnFunction (Function &F) {
724- auto &TM = getAnalysis<TargetPassConfig>().getTM <NVPTXTargetMachine>();
725-
709+ static bool processFunction (Function &F, NVPTXTargetMachine &TM) {
726710 return isKernelFunction (F) ? runOnKernelFunction (TM, F)
727711 : runOnDeviceFunction (TM, F);
728712}
729713
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+ }
731721
732722static bool copyFunctionByValArgs (Function &F) {
733723 LLVM_DEBUG (dbgs () << " Creating a copy of byval args of " << F.getName ()
@@ -747,3 +737,10 @@ PreservedAnalyses NVPTXCopyByValArgsPass::run(Function &F,
747737 return copyFunctionByValArgs (F) ? PreservedAnalyses::none ()
748738 : PreservedAnalyses::all ();
749739}
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