[llvm] [SandboxIR] Functions to find vectorizor-relevant properties (PR #109221)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 19 16:34:57 PDT 2024


================
@@ -4019,6 +4019,42 @@ class Function : public Constant {
 #endif
 };
 
+// Collector for SandboxIR related convenience functions that don't belong in
+// other classes.
+class SandboxIRUtils {
+public:
+  /// \Returns the expected type of \p Value V. For most Values this is
+  /// equivalent to getType, but for stores returns the stored type, rather
+  /// than void, and for ReturnInsts returns the returned type.
+  static Type *getExpectedType(const Value *V) {
+    if (auto *I = dyn_cast<Instruction>(V)) {
+      // A Return's value operand can be null if it returns void.
+      if (auto *RI = dyn_cast<ReturnInst>(I)) {
+        if (RI->getReturnValue() == nullptr)
+          return RI->getType();
+      }
+      return getExpectedValue(I)->getType();
+    }
+    return V->getType();
+  }
+
+  /// \Returns the expected Value for this instruction. For most instructions,
+  /// this is the instruction it self, but for stores returns the stored
+  /// operand, and for ReturnInstructions returns the returned value.
+  static Value *getExpectedValue(const Instruction *I) {
+    if (auto *SI = dyn_cast<StoreInst>(I))
+      return SI->getValueOperand();
+    if (auto *RI = dyn_cast<ReturnInst>(I))
+      return RI->getReturnValue();
+    return const_cast<Instruction *>(I);
+  }
+
+  /// \Returns the number of bits required to represent \p SBV in \p DL.
+  static unsigned getNumBits(sandboxir::Value *SBV, const DataLayout &DL) {
----------------
vporpo wrote:

I think we can drop `sandboxir::` from `sandboxir::Value`

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


More information about the llvm-commits mailing list