[PATCH] D155375: [wip/help] Access TargetMachine without crashing

Jon Chesterfield via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 15 10:24:42 PDT 2023


JonChesterfield created this revision.
JonChesterfield added reviewers: arsenm, foad, aeubanks, pateldeev, jdoerfert, tra.
Herald added subscribers: StephenFan, kerbowa, hiraditya, jvesely.
Herald added a project: All.
JonChesterfield requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, wdng.
Herald added a project: LLVM.

Cargo culting is not working. What other state do I need to set?
Tagging various people. I miss the mailing list.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155375

Files:
  llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp


Index: llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -186,6 +186,7 @@
 #include "llvm/ADT/SetOperations.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/Analysis/CallGraph.h"
+#include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/IRBuilder.h"
@@ -199,6 +200,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/OptimizedStructLayout.h"
+#include "llvm/Target/TargetMachine.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 
@@ -333,7 +335,20 @@
 public:
   static char ID;
 
-  AMDGPULowerModuleLDS() : ModulePass(ID) {
+  AMDGPULowerModuleLDS()
+      : ModulePass(ID)
+
+  {
+    // Asserts
+    // assert(PI && "getAnalysis for unregistered pass!");
+    // Can cayhnge to getAnalysisIfAvailable, which asserts
+    // assert(Resolver && "Pass not resident in a PassManager object!");
+    // Thus... how do I get at the TargetMachine from a ModulePass?
+
+    TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
+    const TargetMachine &TM = TPC.getTM<TargetMachine>();
+    (void)TM;
+
     initializeAMDGPULowerModuleLDSPass(*PassRegistry::getPassRegistry());
   }
 
@@ -1268,6 +1283,10 @@
     return Changed;
   }
 
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+    AU.addRequired<TargetPassConfig>();
+  }
+
 private:
   // Increase the alignment of LDS globals if necessary to maximise the chance
   // that we can use aligned LDS instructions to access them.
@@ -1533,9 +1552,13 @@
 
 char &llvm::AMDGPULowerModuleLDSID = AMDGPULowerModuleLDS::ID;
 
-INITIALIZE_PASS(AMDGPULowerModuleLDS, DEBUG_TYPE,
-                "Lower uses of LDS variables from non-kernel functions", false,
-                false)
+INITIALIZE_PASS_BEGIN(AMDGPULowerModuleLDS, DEBUG_TYPE,
+                      "Lower uses of LDS variables from non-kernel functions",
+                      false, false)
+INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
+INITIALIZE_PASS_END(AMDGPULowerModuleLDS, DEBUG_TYPE,
+                    "Lower uses of LDS variables from non-kernel functions",
+                    false, false)
 
 ModulePass *llvm::createAMDGPULowerModuleLDSPass() {
   return new AMDGPULowerModuleLDS();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155375.540703.patch
Type: text/x-patch
Size: 2490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230715/088f01e0/attachment.bin>


More information about the llvm-commits mailing list