[llvm] [CodeGen] Forbid passing a PointerType to MVT::getVT and EVT::getEVT (PR #92671)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 21 15:24:16 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: Jessica Clarke (jrtc27)
<details>
<summary>Changes</summary>
There is the expectation throughout CodeGen that, for types representing "real" values, the MVT or EVT is self-contained. However, MVT::iPTR is challenging, because it has no address space, and even if it did, there often is no DataLayout immediately accessible to determine what actually is the underlying type.
Historically it was documented as being TableGen-only, but that was lost in 631bfdbee5b45eda9f99dff6a716d63c5698e4bd's conversion to using the generated defines. Let's preserve that intent by not allowing it to originate through accidental calls to get(E)VT with a PointerType. If you need to support that, be sure to use something like TargetLowering's getValueType, which takes a DataLayout and can map pointers to their concrete MVTs.
---
Full diff: https://github.com/llvm/llvm-project/pull/92671.diff
3 Files Affected:
- (modified) llvm/include/llvm/CodeGen/ValueTypes.h (+2-2)
- (modified) llvm/include/llvm/CodeGenTypes/MachineValueType.h (+3-3)
- (modified) llvm/lib/CodeGen/ValueTypes.cpp (+6-7)
``````````diff
diff --git a/llvm/include/llvm/CodeGen/ValueTypes.h b/llvm/include/llvm/CodeGen/ValueTypes.h
index b66c66d1bfc45..a4d57fba7a7a0 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.h
+++ b/llvm/include/llvm/CodeGen/ValueTypes.h
@@ -488,8 +488,8 @@ namespace llvm {
Type *getTypeForEVT(LLVMContext &Context) const;
/// Return the value type corresponding to the specified type.
- /// This returns all pointers as iPTR. If HandleUnknown is true, unknown
- /// types are returned as Other, otherwise they are invalid.
+ /// If HandleUnknown is true, unknown types are returned as Other,
+ /// otherwise they are invalid.
static EVT getEVT(Type *Ty, bool HandleUnknown = false);
intptr_t getRawBits() const {
diff --git a/llvm/include/llvm/CodeGenTypes/MachineValueType.h b/llvm/include/llvm/CodeGenTypes/MachineValueType.h
index 9aceb9896021c..f3280d0276399 100644
--- a/llvm/include/llvm/CodeGenTypes/MachineValueType.h
+++ b/llvm/include/llvm/CodeGenTypes/MachineValueType.h
@@ -476,9 +476,9 @@ namespace llvm {
return getVectorVT(VT, EC.getKnownMinValue());
}
- /// Return the value type corresponding to the specified type. This returns
- /// all pointers as iPTR. If HandleUnknown is true, unknown types are
- /// returned as Other, otherwise they are invalid.
+ /// Return the value type corresponding to the specified type.
+ /// If HandleUnknown is true, unknown types are returned as Other,
+ /// otherwise they are invalid.
static MVT getVT(Type *Ty, bool HandleUnknown = false);
public:
diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp
index 58db686ec7d57..38d2438f76b9d 100644
--- a/llvm/lib/CodeGen/ValueTypes.cpp
+++ b/llvm/lib/CodeGen/ValueTypes.cpp
@@ -579,9 +579,9 @@ Type *EVT::getTypeForEVT(LLVMContext &Context) const {
// clang-format on
}
-/// Return the value type corresponding to the specified type. This returns all
-/// pointers as MVT::iPTR. If HandleUnknown is true, unknown types are returned
-/// as Other, otherwise they are invalid.
+/// Return the value type corresponding to the specified type.
+/// If HandleUnknown is true, unknown types are returned as Other, otherwise
+/// they are invalid.
MVT MVT::getVT(Type *Ty, bool HandleUnknown){
assert(Ty != nullptr && "Invalid type");
switch (Ty->getTypeID()) {
@@ -611,7 +611,6 @@ MVT MVT::getVT(Type *Ty, bool HandleUnknown){
case Type::X86_AMXTyID: return MVT(MVT::x86amx);
case Type::FP128TyID: return MVT(MVT::f128);
case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
- case Type::PointerTyID: return MVT(MVT::iPTR);
case Type::FixedVectorTyID:
case Type::ScalableVectorTyID: {
VectorType *VTy = cast<VectorType>(Ty);
@@ -622,9 +621,9 @@ MVT MVT::getVT(Type *Ty, bool HandleUnknown){
}
}
-/// getEVT - Return the value type corresponding to the specified type. This
-/// returns all pointers as MVT::iPTR. If HandleUnknown is true, unknown types
-/// are returned as Other, otherwise they are invalid.
+/// getEVT - Return the value type corresponding to the specified type.
+/// If HandleUnknown is true, unknown types are returned as Other, otherwise
+/// they are invalid.
EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
switch (Ty->getTypeID()) {
default:
``````````
</details>
https://github.com/llvm/llvm-project/pull/92671
More information about the llvm-commits
mailing list