<div dir="ltr">Some ancient(ish) archaeology here.<div><br></div><div>This actually breaks the use of Type.h without DerivedType.h for two functions: getScalarType and isVectorTy.</div><div><br></div><div>You can have them used without defining them though they're marked inline. Options are: Reinstating them, moving everything that uses them also out of line, or something else I'm not thinking of right now.</div><div><br></div><div>Thoughts?</div><div><br></div><div>-eric</div><div><br></div><div>ps Found this with warnings in the new flang front end fwiw.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Apr 17, 2020 at 2:04 PM Christopher Tetreault via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: Christopher Tetreault<br>
Date: 2020-04-17T14:03:31-07:00<br>
New Revision: c858debebc1308e748de882c745e179b1a398fa0<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/c858debebc1308e748de882c745e179b1a398fa0" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/c858debebc1308e748de882c745e179b1a398fa0</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/c858debebc1308e748de882c745e179b1a398fa0.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/c858debebc1308e748de882c745e179b1a398fa0.diff</a><br>
<br>
LOG: Remove asserting getters from base Type<br>
<br>
Summary:<br>
Remove asserting vector getters from Type in preparation for the<br>
VectorType refactor. The existence of these functions complicates the<br>
refactor while adding little value.<br>
<br>
Reviewers: dexonsmith, sdesmalen, efriedma<br>
<br>
Reviewed By: efriedma<br>
<br>
Subscribers: cfe-commits, hiraditya, llvm-commits<br>
<br>
Tags: #llvm, #clang<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D77278" rel="noreferrer" target="_blank">https://reviews.llvm.org/D77278</a><br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
    clang/lib/CodeGen/CGBuiltin.cpp<br>
    llvm/include/llvm/IR/DerivedTypes.h<br>
    llvm/include/llvm/IR/Type.h<br>
    llvm/lib/CodeGen/CodeGenPrepare.cpp<br>
    llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp<br>
    llvm/unittests/IR/VPIntrinsicTest.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp<br>
index f4832ef4afb2..8ee69740f15c 100644<br>
--- a/clang/lib/CodeGen/CGBuiltin.cpp<br>
+++ b/clang/lib/CodeGen/CGBuiltin.cpp<br>
@@ -7573,8 +7573,7 @@ Value *CodeGenFunction::EmitSVEMaskedStore(const CallExpr *E,<br>
   // The vector type that is stored may be <br>
diff erent from the<br>
   // eventual type stored to memory.<br>
   auto VectorTy = cast<llvm::VectorType>(Ops.back()->getType());<br>
-  auto MemoryTy =<br>
-      llvm::VectorType::get(MemEltTy, VectorTy->getVectorElementCount());<br>
+  auto MemoryTy = llvm::VectorType::get(MemEltTy, VectorTy->getElementCount());<br>
<br>
   Value *Predicate = EmitSVEPredicateCast(Ops[0], MemoryTy);<br>
   Value *BasePtr = Builder.CreateBitCast(Ops[1], MemoryTy->getPointerTo());<br>
<br>
diff  --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h<br>
index 92017448fe0d..186430754303 100644<br>
--- a/llvm/include/llvm/IR/DerivedTypes.h<br>
+++ b/llvm/include/llvm/IR/DerivedTypes.h<br>
@@ -531,18 +531,6 @@ class VectorType : public Type {<br>
   }<br>
 };<br>
<br>
-unsigned Type::getVectorNumElements() const {<br>
-  return cast<VectorType>(this)->getNumElements();<br>
-}<br>
-<br>
-bool Type::getVectorIsScalable() const {<br>
-  return cast<VectorType>(this)->isScalable();<br>
-}<br>
-<br>
-ElementCount Type::getVectorElementCount() const {<br>
-  return cast<VectorType>(this)->getElementCount();<br>
-}<br>
-<br>
 bool Type::isVectorTy() const { return isa<VectorType>(this); }<br>
<br>
 /// Class to represent pointers.<br>
@@ -597,8 +585,8 @@ Type *Type::getWithNewBitWidth(unsigned NewBitWidth) const {<br>
       isIntOrIntVectorTy() &&<br>
       "Original type expected to be a vector of integers or a scalar integer.");<br>
   Type *NewType = getIntNTy(getContext(), NewBitWidth);<br>
-  if (isVectorTy())<br>
-    NewType = VectorType::get(NewType, getVectorElementCount());<br>
+  if (auto *VTy = dyn_cast<VectorType>(this))<br>
+    NewType = VectorType::get(NewType, VTy->getElementCount());<br>
   return NewType;<br>
 }<br>
<br>
@@ -606,6 +594,12 @@ unsigned Type::getPointerAddressSpace() const {<br>
   return cast<PointerType>(getScalarType())->getAddressSpace();<br>
 }<br>
<br>
+Type *Type::getScalarType() const {<br>
+  if (isVectorTy())<br>
+    return cast<VectorType>(this)->getElementType();<br>
+  return const_cast<Type *>(this);<br>
+}<br>
+<br>
 } // end namespace llvm<br>
<br>
 #endif // LLVM_IR_DERIVEDTYPES_H<br>
<br>
diff  --git a/llvm/include/llvm/IR/Type.h b/llvm/include/llvm/IR/Type.h<br>
index 79d6964e3b3e..67be3ef480b7 100644<br>
--- a/llvm/include/llvm/IR/Type.h<br>
+++ b/llvm/include/llvm/IR/Type.h<br>
@@ -300,11 +300,7 @@ class Type {<br>
<br>
   /// If this is a vector type, return the element type, otherwise return<br>
   /// 'this'.<br>
-  Type *getScalarType() const {<br>
-    if (isVectorTy())<br>
-      return getVectorElementType();<br>
-    return const_cast<Type*>(this);<br>
-  }<br>
+  inline Type *getScalarType() const;<br>
<br>
   //===--------------------------------------------------------------------===//<br>
   // Type Iteration support.<br>
@@ -339,8 +335,8 @@ class Type {<br>
<br>
   //===--------------------------------------------------------------------===//<br>
   // Helper methods corresponding to subclass methods.  This forces a cast to<br>
-  // the specified subclass and calls its accessor.  "getVectorNumElements" (for<br>
-  // example) is shorthand for cast<VectorType>(Ty)->getNumElements().  This is<br>
+  // the specified subclass and calls its accessor.  "getArrayNumElements" (for<br>
+  // example) is shorthand for cast<ArrayType>(Ty)->getNumElements().  This is<br>
   // only intended to cover the core methods that are frequently used, helper<br>
   // methods should not be added here.<br>
<br>
@@ -361,14 +357,6 @@ class Type {<br>
     return ContainedTys[0];<br>
   }<br>
<br>
-  inline bool getVectorIsScalable() const;<br>
-  inline unsigned getVectorNumElements() const;<br>
-  inline ElementCount getVectorElementCount() const;<br>
-  Type *getVectorElementType() const {<br>
-    assert(getTypeID() == VectorTyID);<br>
-    return ContainedTys[0];<br>
-  }<br>
-<br>
   Type *getPointerElementType() const {<br>
     assert(getTypeID() == PointerTyID);<br>
     return ContainedTys[0];<br>
<br>
diff  --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp<br>
index 5eb772d12abf..d6a216f9f12c 100644<br>
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp<br>
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp<br>
@@ -5262,7 +5262,7 @@ bool CodeGenPrepare::optimizeGatherScatterInst(Instruction *MemoryInst,<br>
   if (!RewriteGEP && Ops.size() == 2)<br>
     return false;<br>
<br>
-  unsigned NumElts = Ptr->getType()->getVectorNumElements();<br>
+  unsigned NumElts = cast<VectorType>(Ptr->getType())->getNumElements();<br>
<br>
   IRBuilder<> Builder(MemoryInst);<br>
<br>
<br>
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp<br>
index f8c7f784bf11..a05b375d5279 100644<br>
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp<br>
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp<br>
@@ -4263,7 +4263,7 @@ static bool getUniformBase(const Value *Ptr, SDValue &Base, SDValue &Index,<br>
<br>
     Base = SDB->getValue(C);<br>
<br>
-    unsigned NumElts = Ptr->getType()->getVectorNumElements();<br>
+    unsigned NumElts = cast<VectorType>(Ptr->getType())->getNumElements();<br>
     EVT VT = EVT::getVectorVT(*DAG.getContext(), TLI.getPointerTy(DL), NumElts);<br>
     Index = DAG.getConstant(0, SDB->getCurSDLoc(), VT);<br>
     IndexType = ISD::SIGNED_SCALED;<br>
<br>
diff  --git a/llvm/unittests/IR/VPIntrinsicTest.cpp b/llvm/unittests/IR/VPIntrinsicTest.cpp<br>
index 919bac4ef266..35a1f3e9b4d7 100644<br>
--- a/llvm/unittests/IR/VPIntrinsicTest.cpp<br>
+++ b/llvm/unittests/IR/VPIntrinsicTest.cpp<br>
@@ -107,7 +107,7 @@ TEST_F(VPIntrinsicTest, GetParamPos) {<br>
     if (MaskParamPos.hasValue()) {<br>
       Type *MaskParamType = F.getArg(MaskParamPos.getValue())->getType();<br>
       ASSERT_TRUE(MaskParamType->isVectorTy());<br>
-      ASSERT_TRUE(MaskParamType->getVectorElementType()->isIntegerTy(1));<br>
+      ASSERT_TRUE(cast<VectorType>(MaskParamType)->getElementType()->isIntegerTy(1));<br>
     }<br>
<br>
     Optional<int> VecLenParamPos =<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>