[llvm] [SandboxIR] Add utility function to find the base Value for Mem instructions (PR #112030)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 11 11:20:39 PDT 2024


================
@@ -49,6 +49,16 @@ class Utils {
     return const_cast<Instruction *>(I);
   }
 
+  /// \Returns the base Value for load or store instruction \p LSI.
+  template <typename LoadOrStoreT>
+  static Value *getMemInstructionBase(const LoadOrStoreT *LSI) {
+    static_assert(std::is_same_v<LoadOrStoreT, LoadInst> ||
+                      std::is_same_v<LoadOrStoreT, StoreInst>,
+                  "Expected sandboxir::Load or sandboxir::Store!");
+    return LSI->Ctx.getOrCreateValue(
----------------
vporpo wrote:

Do we need `getOrCreateValue()` ? I assume that sandbox IR would have been generated for the whole function. That would remove the need for `friend class Utils` in Context.
```
auto *V = LSI->Ctx.getValue( getUnderlyingObject(LSI->getPointerOperand()->Val));
assert(V != nullptr && "Missing Sandbox IR value!");
return V;
```

https://github.com/llvm/llvm-project/pull/112030


More information about the llvm-commits mailing list