Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 pmbaty 1
//===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file declares the Argument class.
10
//
11
//===----------------------------------------------------------------------===//
12
 
13
#ifndef LLVM_IR_ARGUMENT_H
14
#define LLVM_IR_ARGUMENT_H
15
 
16
#include "llvm/ADT/Twine.h"
17
#include "llvm/IR/Attributes.h"
18
#include "llvm/IR/Value.h"
19
 
20
namespace llvm {
21
 
22
/// This class represents an incoming formal argument to a Function. A formal
23
/// argument, since it is ``formal'', does not contain an actual value but
24
/// instead represents the type, argument number, and attributes of an argument
25
/// for a specific function. When used in the body of said function, the
26
/// argument of course represents the value of the actual argument that the
27
/// function was called with.
28
class Argument final : public Value {
29
  Function *Parent;
30
  unsigned ArgNo;
31
 
32
  friend class Function;
33
  void setParent(Function *parent);
34
 
35
public:
36
  /// Argument constructor.
37
  explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
38
                    unsigned ArgNo = 0);
39
 
40
  inline const Function *getParent() const { return Parent; }
41
  inline       Function *getParent()       { return Parent; }
42
 
43
  /// Return the index of this formal argument in its containing function.
44
  ///
45
  /// For example in "void foo(int a, float b)" a is 0 and b is 1.
46
  unsigned getArgNo() const {
47
    assert(Parent && "can't get number of unparented arg");
48
    return ArgNo;
49
  }
50
 
51
  /// Return true if this argument has the nonnull attribute. Also returns true
52
  /// if at least one byte is known to be dereferenceable and the pointer is in
53
  /// addrspace(0).
54
  /// If AllowUndefOrPoison is true, respect the semantics of nonnull attribute
55
  /// and return true even if the argument can be undef or poison.
56
  bool hasNonNullAttr(bool AllowUndefOrPoison = true) const;
57
 
58
  /// If this argument has the dereferenceable attribute, return the number of
59
  /// bytes known to be dereferenceable. Otherwise, zero is returned.
60
  uint64_t getDereferenceableBytes() const;
61
 
62
  /// If this argument has the dereferenceable_or_null attribute, return the
63
  /// number of bytes known to be dereferenceable. Otherwise, zero is returned.
64
  uint64_t getDereferenceableOrNullBytes() const;
65
 
66
  /// Return true if this argument has the byval attribute.
67
  bool hasByValAttr() const;
68
 
69
  /// Return true if this argument has the byref attribute.
70
  bool hasByRefAttr() const;
71
 
72
  /// Return true if this argument has the swiftself attribute.
73
  bool hasSwiftSelfAttr() const;
74
 
75
  /// Return true if this argument has the swifterror attribute.
76
  bool hasSwiftErrorAttr() const;
77
 
78
  /// Return true if this argument has the byval, inalloca, or preallocated
79
  /// attribute. These attributes represent arguments being passed by value,
80
  /// with an associated copy between the caller and callee
81
  bool hasPassPointeeByValueCopyAttr() const;
82
 
83
  /// If this argument satisfies has hasPassPointeeByValueAttr, return the
84
  /// in-memory ABI size copied to the stack for the call. Otherwise, return 0.
85
  uint64_t getPassPointeeByValueCopySize(const DataLayout &DL) const;
86
 
87
  /// Return true if this argument has the byval, sret, inalloca, preallocated,
88
  /// or byref attribute. These attributes represent arguments being passed by
89
  /// value (which may or may not involve a stack copy)
90
  bool hasPointeeInMemoryValueAttr() const;
91
 
92
  /// If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is
93
  /// returned. Otherwise, nullptr.
94
  Type *getPointeeInMemoryValueType() const;
95
 
96
  /// If this is a byval or inalloca argument, return its alignment.
97
  /// FIXME: Remove this function once transition to Align is over.
98
  /// Use getParamAlign() instead.
99
  LLVM_DEPRECATED("Use getParamAlign() instead", "getParamAlign")
100
  uint64_t getParamAlignment() const;
101
 
102
  /// If this is a byval or inalloca argument, return its alignment.
103
  MaybeAlign getParamAlign() const;
104
 
105
  MaybeAlign getParamStackAlign() const;
106
 
107
  /// If this is a byval argument, return its type.
108
  Type *getParamByValType() const;
109
 
110
  /// If this is an sret argument, return its type.
111
  Type *getParamStructRetType() const;
112
 
113
  /// If this is a byref argument, return its type.
114
  Type *getParamByRefType() const;
115
 
116
  /// If this is an inalloca argument, return its type.
117
  Type *getParamInAllocaType() const;
118
 
119
  /// Return true if this argument has the nest attribute.
120
  bool hasNestAttr() const;
121
 
122
  /// Return true if this argument has the noalias attribute.
123
  bool hasNoAliasAttr() const;
124
 
125
  /// Return true if this argument has the nocapture attribute.
126
  bool hasNoCaptureAttr() const;
127
 
128
  /// Return true if this argument has the nofree attribute.
129
  bool hasNoFreeAttr() const;
130
 
131
  /// Return true if this argument has the sret attribute.
132
  bool hasStructRetAttr() const;
133
 
134
  /// Return true if this argument has the inreg attribute.
135
  bool hasInRegAttr() const;
136
 
137
  /// Return true if this argument has the returned attribute.
138
  bool hasReturnedAttr() const;
139
 
140
  /// Return true if this argument has the readonly or readnone attribute.
141
  bool onlyReadsMemory() const;
142
 
143
  /// Return true if this argument has the inalloca attribute.
144
  bool hasInAllocaAttr() const;
145
 
146
  /// Return true if this argument has the preallocated attribute.
147
  bool hasPreallocatedAttr() const;
148
 
149
  /// Return true if this argument has the zext attribute.
150
  bool hasZExtAttr() const;
151
 
152
  /// Return true if this argument has the sext attribute.
153
  bool hasSExtAttr() const;
154
 
155
  /// Add attributes to an argument.
156
  void addAttrs(AttrBuilder &B);
157
 
158
  void addAttr(Attribute::AttrKind Kind);
159
 
160
  void addAttr(Attribute Attr);
161
 
162
  /// Remove attributes from an argument.
163
  void removeAttr(Attribute::AttrKind Kind);
164
 
165
  void removeAttrs(const AttributeMask &AM);
166
 
167
  /// Check if an argument has a given attribute.
168
  bool hasAttribute(Attribute::AttrKind Kind) const;
169
 
170
  Attribute getAttribute(Attribute::AttrKind Kind) const;
171
 
172
  /// Method for support type inquiry through isa, cast, and dyn_cast.
173
  static bool classof(const Value *V) {
174
    return V->getValueID() == ArgumentVal;
175
  }
176
};
177
 
178
} // End llvm namespace
179
 
180
#endif