[llvm] [SandboxIR] Implement UndefValue (PR #107628)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 6 13:12:06 PDT 2024
================
@@ -1020,10 +1021,61 @@ class ConstantPointerNull final : public Constant {
#endif
};
-// TODO: Inherit from UndefValue.
-class PoisonValue final : public Constant {
+// TODO: Inherit from ConstantData.
+class UndefValue : public Constant {
+protected:
+ UndefValue(llvm::UndefValue *C, Context &Ctx)
+ : Constant(ClassID::UndefValue, C, Ctx) {}
+ UndefValue(ClassID ID, llvm::Constant *C, Context &Ctx)
+ : Constant(ID, C, Ctx) {}
+ friend class Context; // For constructor.
+
+public:
+ /// Static factory methods - Return an 'undef' object of the specified type.
+ static UndefValue *get(Type *T);
+
+ /// If this Undef has array or vector type, return a undef with the right
+ /// element type.
+ UndefValue *getSequentialElement() const;
+
+ /// If this undef has struct type, return a undef with the right element type
+ /// for the specified element.
+ UndefValue *getStructElement(unsigned Elt) const;
+
+ /// Return an undef of the right value for the specified GEP index if we can,
+ /// otherwise return null (e.g. if C is a ConstantExpr).
+ UndefValue *getElementValue(Constant *C) const;
+
+ /// Return an undef of the right value for the specified GEP index.
+ UndefValue *getElementValue(unsigned Idx) const;
+
+ /// Return the number of elements in the array, vector, or struct.
+ unsigned getNumElements() const {
+ return cast<llvm::UndefValue>(Val)->getNumElements();
+ }
+
+ /// For isa/dyn_cast.
+ static bool classof(const sandboxir::Value *From) {
+ return From->getSubclassID() == ClassID::UndefValue ||
+ From->getSubclassID() == ClassID::PoisonValue;
----------------
vporpo wrote:
> isa<PoisonValue>(Undef) should/must be false.
We are already testing that: ` EXPECT_FALSE(isa<sandboxir::PoisonValue>(Val: Undef)); // Undef is not Poison `
https://github.com/llvm/llvm-project/pull/107628
More information about the llvm-commits
mailing list