Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:56

0001 //===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file declares the Argument class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_IR_ARGUMENT_H
0014 #define LLVM_IR_ARGUMENT_H
0015 
0016 #include "llvm/ADT/Twine.h"
0017 #include "llvm/IR/Attributes.h"
0018 #include "llvm/IR/Value.h"
0019 #include <optional>
0020 
0021 namespace llvm {
0022 
0023 class ConstantRange;
0024 
0025 /// This class represents an incoming formal argument to a Function. A formal
0026 /// argument, since it is ``formal'', does not contain an actual value but
0027 /// instead represents the type, argument number, and attributes of an argument
0028 /// for a specific function. When used in the body of said function, the
0029 /// argument of course represents the value of the actual argument that the
0030 /// function was called with.
0031 class Argument final : public Value {
0032   Function *Parent;
0033   unsigned ArgNo;
0034 
0035   friend class Function;
0036   void setParent(Function *parent);
0037 
0038 public:
0039   /// Argument constructor.
0040   explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
0041                     unsigned ArgNo = 0);
0042 
0043   inline const Function *getParent() const { return Parent; }
0044   inline       Function *getParent()       { return Parent; }
0045 
0046   /// Return the index of this formal argument in its containing function.
0047   ///
0048   /// For example in "void foo(int a, float b)" a is 0 and b is 1.
0049   unsigned getArgNo() const {
0050     assert(Parent && "can't get number of unparented arg");
0051     return ArgNo;
0052   }
0053 
0054   /// Return true if this argument has the nonnull attribute. Also returns true
0055   /// if at least one byte is known to be dereferenceable and the pointer is in
0056   /// addrspace(0).
0057   /// If AllowUndefOrPoison is true, respect the semantics of nonnull attribute
0058   /// and return true even if the argument can be undef or poison.
0059   bool hasNonNullAttr(bool AllowUndefOrPoison = true) const;
0060 
0061   /// If this argument has the dereferenceable attribute, return the number of
0062   /// bytes known to be dereferenceable. Otherwise, zero is returned.
0063   uint64_t getDereferenceableBytes() const;
0064 
0065   /// If this argument has the dereferenceable_or_null attribute, return the
0066   /// number of bytes known to be dereferenceable. Otherwise, zero is returned.
0067   uint64_t getDereferenceableOrNullBytes() const;
0068 
0069   /// If this argument has nofpclass attribute, return the mask representing
0070   /// disallowed floating-point values. Otherwise, fcNone is returned.
0071   FPClassTest getNoFPClass() const;
0072 
0073   /// If this argument has a range attribute, return the value range of the
0074   /// argument. Otherwise, std::nullopt is returned.
0075   std::optional<ConstantRange> getRange() const;
0076 
0077   /// Return true if this argument has the byval attribute.
0078   bool hasByValAttr() const;
0079 
0080   /// Return true if this argument has the byref attribute.
0081   bool hasByRefAttr() const;
0082 
0083   /// Return true if this argument has the swiftself attribute.
0084   bool hasSwiftSelfAttr() const;
0085 
0086   /// Return true if this argument has the swifterror attribute.
0087   bool hasSwiftErrorAttr() const;
0088 
0089   /// Return true if this argument has the byval, inalloca, or preallocated
0090   /// attribute. These attributes represent arguments being passed by value,
0091   /// with an associated copy between the caller and callee
0092   bool hasPassPointeeByValueCopyAttr() const;
0093 
0094   /// If this argument satisfies has hasPassPointeeByValueAttr, return the
0095   /// in-memory ABI size copied to the stack for the call. Otherwise, return 0.
0096   uint64_t getPassPointeeByValueCopySize(const DataLayout &DL) const;
0097 
0098   /// Return true if this argument has the byval, sret, inalloca, preallocated,
0099   /// or byref attribute. These attributes represent arguments being passed by
0100   /// value (which may or may not involve a stack copy)
0101   bool hasPointeeInMemoryValueAttr() const;
0102 
0103   /// If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is
0104   /// returned. Otherwise, nullptr.
0105   Type *getPointeeInMemoryValueType() const;
0106 
0107   /// If this is a byval or inalloca argument, return its alignment.
0108   /// FIXME: Remove this function once transition to Align is over.
0109   /// Use getParamAlign() instead.
0110   LLVM_DEPRECATED("Use getParamAlign() instead", "getParamAlign")
0111   uint64_t getParamAlignment() const;
0112 
0113   /// If this is a byval or inalloca argument, return its alignment.
0114   MaybeAlign getParamAlign() const;
0115 
0116   MaybeAlign getParamStackAlign() const;
0117 
0118   /// If this is a byval argument, return its type.
0119   Type *getParamByValType() const;
0120 
0121   /// If this is an sret argument, return its type.
0122   Type *getParamStructRetType() const;
0123 
0124   /// If this is a byref argument, return its type.
0125   Type *getParamByRefType() const;
0126 
0127   /// If this is an inalloca argument, return its type.
0128   Type *getParamInAllocaType() const;
0129 
0130   /// Return true if this argument has the nest attribute.
0131   bool hasNestAttr() const;
0132 
0133   /// Return true if this argument has the noalias attribute.
0134   bool hasNoAliasAttr() const;
0135 
0136   /// Return true if this argument has the nocapture attribute.
0137   bool hasNoCaptureAttr() const;
0138 
0139   /// Return true if this argument has the nofree attribute.
0140   bool hasNoFreeAttr() const;
0141 
0142   /// Return true if this argument has the sret attribute.
0143   bool hasStructRetAttr() const;
0144 
0145   /// Return true if this argument has the inreg attribute.
0146   bool hasInRegAttr() const;
0147 
0148   /// Return true if this argument has the returned attribute.
0149   bool hasReturnedAttr() const;
0150 
0151   /// Return true if this argument has the readonly or readnone attribute.
0152   bool onlyReadsMemory() const;
0153 
0154   /// Return true if this argument has the inalloca attribute.
0155   bool hasInAllocaAttr() const;
0156 
0157   /// Return true if this argument has the preallocated attribute.
0158   bool hasPreallocatedAttr() const;
0159 
0160   /// Return true if this argument has the zext attribute.
0161   bool hasZExtAttr() const;
0162 
0163   /// Return true if this argument has the sext attribute.
0164   bool hasSExtAttr() const;
0165 
0166   /// Add attributes to an argument.
0167   void addAttrs(AttrBuilder &B);
0168 
0169   void addAttr(Attribute::AttrKind Kind);
0170 
0171   void addAttr(Attribute Attr);
0172 
0173   /// Remove attributes from an argument.
0174   void removeAttr(Attribute::AttrKind Kind);
0175 
0176   void removeAttrs(const AttributeMask &AM);
0177 
0178   /// Check if an argument has a given attribute.
0179   bool hasAttribute(Attribute::AttrKind Kind) const;
0180 
0181   bool hasAttribute(StringRef Kind) const;
0182 
0183   Attribute getAttribute(Attribute::AttrKind Kind) const;
0184 
0185   AttributeSet getAttributes() const;
0186 
0187   /// Method for support type inquiry through isa, cast, and dyn_cast.
0188   static bool classof(const Value *V) {
0189     return V->getValueID() == ArgumentVal;
0190   }
0191 };
0192 
0193 } // End llvm namespace
0194 
0195 #endif