]> granicus.if.org Git - llvm/commitdiff
IR: make getParamByValType Just Work. NFC.
authorTim Northover <tnorthover@apple.com>
Wed, 5 Jun 2019 20:37:47 +0000 (20:37 +0000)
committerTim Northover <tnorthover@apple.com>
Wed, 5 Jun 2019 20:37:47 +0000 (20:37 +0000)
Most parts of LLVM don't care whether the byval type is derived from an
explicit Attribute or from the parameter's pointee type, so it makes
sense for the main access function to just return the right value.

The very few users who do care (only BitcodeReader so far) can find out
how it's specified by accessing the Attribute directly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362642 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Argument.h
include/llvm/IR/Function.h
include/llvm/IR/InstrTypes.h
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/ValueEnumerator.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/CodeGen/SelectionDAG/TargetLowering.cpp
lib/IR/Function.cpp

index 952fbcdffb1426833c3612a882c140bd24aae2ea..5f514b9c47d291215602d8363c5d43cce76ed509 100644 (file)
@@ -124,6 +124,8 @@ public:
   /// Check if an argument has a given attribute.
   bool hasAttribute(Attribute::AttrKind Kind) const;
 
+  Attribute getAttribute(Attribute::AttrKind Kind) const;
+
   /// Method for support type inquiry through isa, cast, and dyn_cast.
   static bool classof(const Value *V) {
     return V->getValueID() == ArgumentVal;
index 896c2189eb824601637ae070ce229aea7c1bdb28..b93541cbb16b7aa4a3e6171fdaa02cd39e7ee489 100644 (file)
@@ -401,6 +401,11 @@ public:
     return getAttributes().hasParamAttribute(ArgNo, Kind);
   }
 
+  /// gets the specified attribute from the list of attributes.
+  Attribute getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const {
+    return getAttributes().getParamAttr(ArgNo, Kind);
+  }
+
   /// gets the attribute from the list of attributes.
   Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
     return AttributeSets.getAttribute(i, Kind);
@@ -431,9 +436,10 @@ public:
     return AttributeSets.getParamAlignment(ArgNo);
   }
 
-  /// Extract the byval type for a parameter (nullptr=unknown).
+  /// Extract the byval type for a parameter.
   Type *getParamByValType(unsigned ArgNo) const {
-    return AttributeSets.getParamByValType(ArgNo);
+    Type *Ty = AttributeSets.getParamByValType(ArgNo);
+    return Ty ? Ty : (arg_begin() + ArgNo)->getType()->getPointerElementType();
   }
 
   /// Extract the number of dereferenceable bytes for a call or
index 6ce76811c0e669b9313118b50100756933b5fe42..237929f5e609d75e1e7a40095b506ba339d5d453 100644 (file)
@@ -1560,9 +1560,10 @@ public:
     return Attrs.getParamAlignment(ArgNo);
   }
 
-  /// Extract the byval type for a call or parameter (nullptr=unknown).
+  /// Extract the byval type for a call or parameter.
   Type *getParamByValType(unsigned ArgNo) const {
-    return Attrs.getParamByValType(ArgNo);
+    Type *Ty = Attrs.getParamByValType(ArgNo);
+    return Ty ? Ty : getArgOperand(ArgNo)->getType()->getPointerElementType();
   }
 
   /// Extract the number of dereferenceable bytes for a call or
index 9f562ba82db93c633bc2b58fc226111a2f7076cd..c33fc568abe852c70392dcd10925bb4f56b6c698 100644 (file)
@@ -3049,7 +3049,8 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef<uint64_t> Record) {
   // pointee type. There should be no opaque pointers where the byval type is
   // implicit.
   for (auto &Arg : Func->args()) {
-    if (Arg.hasByValAttr() && !Arg.getParamByValType()) {
+    if (Arg.hasByValAttr() &&
+        !Arg.getAttribute(Attribute::ByVal).getValueAsType()) {
       Arg.removeAttr(Attribute::ByVal);
       Arg.addAttr(Attribute::getWithByValType(
           Context, Arg.getType()->getPointerElementType()));
index 143570fb20a8cf329301f230f89a9bb44e1be6ff..f59c906c7b75779c82bf2a38682b67400ab1660e 100644 (file)
@@ -951,7 +951,7 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
   // Adding function arguments to the value table.
   for (const auto &I : F.args()) {
     EnumerateValue(&I);
-    if (I.hasAttribute(Attribute::ByVal) && I.getParamByValType())
+    if (I.hasAttribute(Attribute::ByVal))
       EnumerateType(I.getParamByValType());
   }
   FirstFuncConstantID = Values.size();
index 4f7257d4a151d66acdc76312738c3541649eec69..07d6ac83e03b1b0272b6b13771197abec76f37ae 100644 (file)
@@ -9584,8 +9584,7 @@ void SelectionDAGISel::LowerArguments(const Function &F) {
         // For ByVal, size and alignment should be passed from FE.  BE will
         // guess if this info is not there but there are cases it cannot get
         // right.
-        unsigned FrameSize = DL.getTypeAllocSize(
-            Arg.getParamByValType() ? Arg.getParamByValType() : ElementTy);
+        unsigned FrameSize = DL.getTypeAllocSize(Arg.getParamByValType());
         Flags.setByValSize(FrameSize);
 
         unsigned FrameAlign;
index 6e6917b39b6d56aa862f07b1ba3dabaee88a5bf8..c2123dbfdd95fd60be80d2eae1c8d5f50aaa9305 100644 (file)
@@ -112,7 +112,9 @@ void TargetLoweringBase::ArgListEntry::setAttributes(const CallBase *Call,
   IsSwiftSelf = Call->paramHasAttr(ArgIdx, Attribute::SwiftSelf);
   IsSwiftError = Call->paramHasAttr(ArgIdx, Attribute::SwiftError);
   Alignment = Call->getParamAlignment(ArgIdx);
-  ByValType = Call->getParamByValType(ArgIdx);
+  ByValType = nullptr;
+  if (Call->paramHasAttr(ArgIdx, Attribute::ByVal))
+    ByValType = Call->getParamByValType(ArgIdx);
 }
 
 /// Generate a libcall taking the given operands as arguments and returning a
index a4a78ca4deb96afffe042bbdf626609c4fc27e77..c88fd1a82cd3b0f750cef5b70674e58055ea8214 100644 (file)
@@ -194,6 +194,10 @@ bool Argument::hasAttribute(Attribute::AttrKind Kind) const {
   return getParent()->hasParamAttribute(getArgNo(), Kind);
 }
 
+Attribute Argument::getAttribute(Attribute::AttrKind Kind) const {
+  return getParent()->getParamAttribute(getArgNo(), Kind);
+}
+
 //===----------------------------------------------------------------------===//
 // Helper Methods in Function
 //===----------------------------------------------------------------------===//