[llvm] [SandboxIR] Add pointer-diff utility function (PR #110176)

Thorsten Schütt via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 22:21:37 PDT 2024


================
@@ -57,6 +61,38 @@ class Utils {
   memoryLocationGetOrNone(const Instruction *I) {
     return llvm::MemoryLocation::getOrNone(cast<llvm::Instruction>(I->Val));
   }
+
+  /// \Returns the number of bytes between the memory locations accessed by \p
+  /// I0 and \p I1 in bytes.
+  template <typename LoadOrStoreT>
+  static std::optional<int>
+  getPointerDiffInBytes(LoadOrStoreT *I0, LoadOrStoreT *I1, ScalarEvolution &SE,
+                        const DataLayout &DL) {
+    static_assert(std::is_same<LoadOrStoreT, LoadInst>::value ||
----------------
tschuett wrote:

You can use `std::is_same_v<LoadOrStoreT, LoadInst>` to make it briefer.

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


More information about the llvm-commits mailing list