[Object][ELF] Range-based loop simplification.
[oota-llvm.git] / include / llvm / IR / Argument.h
1 //===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the Argument class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_IR_ARGUMENT_H
15 #define LLVM_IR_ARGUMENT_H
16
17 #include "llvm/ADT/Twine.h"
18 #include "llvm/ADT/ilist_node.h"
19 #include "llvm/IR/Attributes.h"
20 #include "llvm/IR/Value.h"
21
22 namespace llvm {
23
24 template<typename ValueSubClass, typename ItemParentClass>
25   class SymbolTableListTraits;
26
27 /// \brief LLVM Argument representation
28 ///
29 /// This class represents an incoming formal argument to a Function. A formal
30 /// argument, since it is ``formal'', does not contain an actual value but
31 /// instead represents the type, argument number, and attributes of an argument
32 /// for a specific function. When used in the body of said function, the
33 /// argument of course represents the value of the actual argument that the
34 /// function was called with.
35 class Argument : public Value, public ilist_node<Argument> {
36   virtual void anchor();
37   Function *Parent;
38
39   friend class SymbolTableListTraits<Argument, Function>;
40   void setParent(Function *parent);
41
42 public:
43   /// \brief Constructor.
44   ///
45   /// If \p F is specified, the argument is inserted at the end of the argument
46   /// list for \p F.
47   explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr);
48
49   inline const Function *getParent() const { return Parent; }
50   inline       Function *getParent()       { return Parent; }
51
52   /// \brief Return the index of this formal argument in its containing
53   /// function.
54   ///
55   /// For example in "void foo(int a, float b)" a is 0 and b is 1.
56   unsigned getArgNo() const;
57
58   /// \brief Return true if this argument has the nonnull attribute on it in
59   /// its containing function.
60   bool hasNonNullAttr() const;
61
62   /// \brief Return true if this argument has the byval attribute on it in its
63   /// containing function.
64   bool hasByValAttr() const;
65
66   /// \brief Return true if this argument has the byval attribute or inalloca
67   /// attribute on it in its containing function.  These attributes both
68   /// represent arguments being passed by value.
69   bool hasByValOrInAllocaAttr() const;
70
71   /// \brief If this is a byval or inalloca argument, return its alignment.
72   unsigned getParamAlignment() const;
73
74   /// \brief Return true if this argument has the nest attribute on it in its
75   /// containing function.
76   bool hasNestAttr() const;
77
78   /// \brief Return true if this argument has the noalias attribute on it in its
79   /// containing function.
80   bool hasNoAliasAttr() const;
81
82   /// \brief Return true if this argument has the nocapture attribute on it in
83   /// its containing function.
84   bool hasNoCaptureAttr() const;
85
86   /// \brief Return true if this argument has the sret attribute on it in its
87   /// containing function.
88   bool hasStructRetAttr() const;
89
90   /// \brief Return true if this argument has the returned attribute on it in
91   /// its containing function.
92   bool hasReturnedAttr() const;
93
94   /// \brief Return true if this argument has the readonly or readnone attribute
95   /// on it in its containing function.
96   bool onlyReadsMemory() const;
97
98   /// \brief Return true if this argument has the inalloca attribute on it in
99   /// its containing function.
100   bool hasInAllocaAttr() const;
101
102   /// \brief Add a Attribute to an argument.
103   void addAttr(AttributeSet AS);
104
105   /// \brief Remove a Attribute from an argument.
106   void removeAttr(AttributeSet AS);
107
108   /// \brief Method for support type inquiry through isa, cast, and
109   /// dyn_cast.
110   static inline bool classof(const Value *V) {
111     return V->getValueID() == ArgumentVal;
112   }
113 };
114
115 } // End llvm namespace
116
117 #endif