[PATCH] D76748: [llvm][Support] Add isZero method for TypeSize. [NFC]

Francesco Petrogalli via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 24 19:42:25 PDT 2020


fpetrogalli created this revision.
fpetrogalli added a reviewer: sdesmalen.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

The method is used where TypeSize is implicitly cast to integer for
being checked against 0.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76748

Files:
  llvm/include/llvm/Support/TypeSize.h
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/CodeGen/LowLevelType.cpp
  llvm/lib/Target/AArch64/AArch64CallLowering.cpp


Index: llvm/lib/Target/AArch64/AArch64CallLowering.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64CallLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64CallLowering.cpp
@@ -420,7 +420,7 @@
   SmallVector<ArgInfo, 8> SplitArgs;
   unsigned i = 0;
   for (auto &Arg : F.args()) {
-    if (DL.getTypeStoreSize(Arg.getType()) == 0)
+    if (DL.getTypeStoreSize(Arg.getType()).isZero())
       continue;
 
     ArgInfo OrigArg{VRegs[i], Arg.getType()};
Index: llvm/lib/CodeGen/LowLevelType.cpp
===================================================================
--- llvm/lib/CodeGen/LowLevelType.cpp
+++ llvm/lib/CodeGen/LowLevelType.cpp
@@ -34,9 +34,10 @@
   if (Ty.isSized()) {
     // Aggregates are no different from real scalars as far as GlobalISel is
     // concerned.
-    auto SizeInBits = DL.getTypeSizeInBits(&Ty);
-    assert(SizeInBits != 0 && "invalid zero-sized type");
-    return LLT::scalar(SizeInBits);
+    TypeSize SizeInBits = DL.getTypeSizeInBits(&Ty);
+    assert(SizeInBits.isNonZero() && "invalid zero-sized type");
+    assert(!SizeInBits.isScalable() && "Invalid TypeSize.");
+    return LLT::scalar(SizeInBits.getKnownMinSize());
   }
 
   return LLT();
Index: llvm/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/lib/Analysis/ConstantFolding.cpp
+++ llvm/lib/Analysis/ConstantFolding.cpp
@@ -363,7 +363,7 @@
       Constant *ElemC;
       do {
         ElemC = C->getAggregateElement(Elem++);
-      } while (ElemC && DL.getTypeSizeInBits(ElemC->getType()) == 0);
+      } while (ElemC && DL.getTypeSizeInBits(ElemC->getType()).isZero());
       C = ElemC;
     } else {
       C = C->getAggregateElement(0u);
Index: llvm/include/llvm/Support/TypeSize.h
===================================================================
--- llvm/include/llvm/Support/TypeSize.h
+++ llvm/include/llvm/Support/TypeSize.h
@@ -149,6 +149,9 @@
   // Returns true if the type size is non-zero.
   bool isNonZero() const { return MinSize != 0; }
 
+  // Returns true if the type size is zero.
+  bool isZero() const { return MinSize == 0; }
+
   // Casts to a uint64_t if this is a fixed-width size.
   //
   // This interface is deprecated and will be removed in a future version


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76748.252480.patch
Type: text/x-patch
Size: 2305 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200325/3d01dcc4/attachment-0001.bin>


More information about the llvm-commits mailing list