llvm.org GIT mirror llvm / 0b8c9a8
Move all of the header files which are involved in modelling the LLVM IR into their new header subdirectory: include/llvm/IR. This matches the directory structure of lib, and begins to correct a long standing point of file layout clutter in LLVM. There are still more header files to move here, but I wanted to handle them in separate commits to make tracking what files make sense at each layer easier. The only really questionable files here are the target intrinsic tablegen files. But that's a battle I'd rather not fight today. I've updated both CMake and Makefile build systems (I think, and my tests think, but I may have missed something). I've also re-sorted the includes throughout the project. I'll be committing updates to Clang, DragonEgg, and Polly momentarily. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171366 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
645 changed file(s) with 27305 addition(s) and 27304 deletion(s). Raw diff Collapse all Expand all
18131813 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
18141814 $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
18151815 $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1816 $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1816 $(wildcard $(LLVM_SRC_ROOT)/include/llvm/IR/Intrinsics*.td)
18171817
18181818 # All .inc.tmp files depend on the .td files.
18191819 $(INCTMPFiles) : $(TDFiles)
1515
1616 #include "llvm/ADT/DenseMap.h"
1717 #include "llvm/ADT/PostOrderIterator.h"
18 #include "llvm/BasicBlock.h"
1918 #include "llvm/CodeGen/MachineBasicBlock.h"
2019 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/IR/BasicBlock.h"
2121 #include "llvm/Support/BlockFrequency.h"
2222 #include "llvm/Support/BranchProbability.h"
2323 #include "llvm/Support/Debug.h"
1515 #define LLVM_ANALYSIS_CFGPRINTER_H
1616
1717 #include "llvm/Assembly/Writer.h"
18 #include "llvm/Constants.h"
19 #include "llvm/Function.h"
20 #include "llvm/Instructions.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/Instructions.h"
2121 #include "llvm/Support/CFG.h"
2222 #include "llvm/Support/GraphWriter.h"
2323
5252
5353 #include "llvm/ADT/GraphTraits.h"
5454 #include "llvm/ADT/STLExtras.h"
55 #include "llvm/Function.h"
55 #include "llvm/IR/Function.h"
5656 #include "llvm/Pass.h"
5757 #include "llvm/Support/CallSite.h"
5858 #include "llvm/Support/IncludeFile.h"
1414 #define LLVM_ANALYSIS_CAPTURETRACKING_H
1515
1616 #include "llvm/Analysis/AliasAnalysis.h"
17 #include "llvm/Constants.h"
18 #include "llvm/Instructions.h"
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/Instructions.h"
1919 #include "llvm/Support/CallSite.h"
2020
2121 namespace llvm {
4040 #define LLVM_ANALYSIS_DEPENDENCEANALYSIS_H
4141
4242 #include "llvm/ADT/SmallBitVector.h"
43 #include "llvm/Instructions.h"
43 #include "llvm/IR/Instructions.h"
4444 #include "llvm/Pass.h"
4545
4646 namespace llvm {
1919 #include "llvm/ADT/GraphTraits.h"
2020 #include "llvm/ADT/SmallPtrSet.h"
2121 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/Function.h"
22 #include "llvm/IR/Function.h"
2323 #include "llvm/Pass.h"
2424 #include "llvm/Support/CFG.h"
2525 #include "llvm/Support/Compiler.h"
1717 #include "llvm/ADT/SmallPtrSet.h"
1818 #include "llvm/ADT/ValueMap.h"
1919 #include "llvm/Analysis/CodeMetrics.h"
20 #include "llvm/Function.h"
20 #include "llvm/IR/Function.h"
2121 #include
2222 #include
2323 #include
1818 #ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
1919 #define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
2020
21 #include "llvm/User.h"
21 #include "llvm/IR/User.h"
2222
2323 namespace llvm {
2424 template
3333 #define LLVM_INTERVAL_ITERATOR_H
3434
3535 #include "llvm/Analysis/IntervalPartition.h"
36 #include "llvm/Function.h"
36 #include "llvm/IR/Function.h"
3737 #include "llvm/Support/CFG.h"
3838 #include
3939 #include
1313 #ifndef LLVM_ANALYSIS_LOADS_H
1414 #define LLVM_ANALYSIS_LOADS_H
1515
16 #include "llvm/BasicBlock.h"
16 #include "llvm/IR/BasicBlock.h"
1717
1818 namespace llvm {
1919
1515 #define LLVM_LOOP_PASS_H
1616
1717 #include "llvm/Analysis/LoopInfo.h"
18 #include "llvm/Function.h"
18 #include "llvm/IR/Function.h"
1919 #include "llvm/Pass.h"
2020 #include "llvm/PassManagers.h"
2121 #include
1616
1717 #include "llvm/ADT/DenseMap.h"
1818 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/IRBuilder.h"
19 #include "llvm/IR/IRBuilder.h"
20 #include "llvm/IR/Operator.h"
2021 #include "llvm/InstVisitor.h"
21 #include "llvm/Operator.h"
2222 #include "llvm/Support/DataTypes.h"
2323 #include "llvm/Support/TargetFolder.h"
2424 #include "llvm/Support/ValueHandle.h"
1818 #include "llvm/ADT/PointerIntPair.h"
1919 #include "llvm/ADT/SmallPtrSet.h"
2020 #include "llvm/Analysis/AliasAnalysis.h"
21 #include "llvm/BasicBlock.h"
21 #include "llvm/IR/BasicBlock.h"
2222 #include "llvm/Pass.h"
2323 #include "llvm/Support/ValueHandle.h"
2424
1414 #define LLVM_ANALYSIS_PHITRANSADDR_H
1515
1616 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/Instruction.h"
17 #include "llvm/IR/Instruction.h"
1818
1919 namespace llvm {
2020 class DominatorTree;
2626 #define LLVM_PATH_NUMBERING_H
2727
2828 #include "llvm/Analysis/ProfileInfoTypes.h"
29 #include "llvm/BasicBlock.h"
30 #include "llvm/Instructions.h"
29 #include "llvm/IR/BasicBlock.h"
30 #include "llvm/IR/Instructions.h"
3131 #include "llvm/Pass.h"
3232 #include "llvm/Support/CFG.h"
3333 #include
1414 #define LLVM_PATHPROFILEINFO_H
1515
1616 #include "llvm/Analysis/PathNumbering.h"
17 #include "llvm/BasicBlock.h"
17 #include "llvm/IR/BasicBlock.h"
1818
1919 namespace llvm {
2020
2424 #include "llvm/ADT/APInt.h"
2525 #include "llvm/ADT/SmallPtrSet.h"
2626 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/DataLayout.h"
27 #include "llvm/IR/DataLayout.h"
28 #include "llvm/IR/IntrinsicInst.h"
2829 #include "llvm/InstVisitor.h"
29 #include "llvm/IntrinsicInst.h"
3030 #include "llvm/Support/Compiler.h"
3131
3232 namespace llvm {
1616 #define LLVM_REGION_PASS_H
1717
1818 #include "llvm/Analysis/RegionInfo.h"
19 #include "llvm/Function.h"
19 #include "llvm/IR/Function.h"
2020 #include "llvm/Pass.h"
2121 #include "llvm/PassManagers.h"
2222 #include
2222
2323 #include "llvm/ADT/DenseSet.h"
2424 #include "llvm/ADT/FoldingSet.h"
25 #include "llvm/Function.h"
26 #include "llvm/Instructions.h"
27 #include "llvm/Operator.h"
25 #include "llvm/IR/Function.h"
26 #include "llvm/IR/Instructions.h"
27 #include "llvm/IR/Operator.h"
2828 #include "llvm/Pass.h"
2929 #include "llvm/Support/Allocator.h"
3030 #include "llvm/Support/ConstantRange.h"
1515
1616 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
1717 #include "llvm/Analysis/ScalarEvolutionNormalization.h"
18 #include "llvm/IRBuilder.h"
18 #include "llvm/IR/IRBuilder.h"
1919 #include "llvm/Support/TargetFolder.h"
2020 #include "llvm/Support/ValueHandle.h"
2121 #include
+0
-91
include/llvm/Argument.h less more
None //===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the Argument class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_ARGUMENT_H
14 #define LLVM_ARGUMENT_H
15
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/ADT/ilist_node.h"
18 #include "llvm/Attributes.h"
19 #include "llvm/Value.h"
20
21 namespace llvm {
22
23 template
24 class SymbolTableListTraits;
25
26 /// A class to represent an incoming formal argument to a Function. An argument
27 /// is a very simple Value. It is essentially a named (optional) type. When used
28 /// in the body of a function, it represents the value of the actual argument
29 /// the function was called with.
30 /// @brief LLVM Argument representation
31 class Argument : public Value, public ilist_node {
32 virtual void anchor();
33 Function *Parent;
34
35 friend class SymbolTableListTraits;
36 void setParent(Function *parent);
37
38 public:
39 /// Argument ctor - If Function argument is specified, this argument is
40 /// inserted at the end of the argument list for the function.
41 ///
42 explicit Argument(Type *Ty, const Twine &Name = "", Function *F = 0);
43
44 inline const Function *getParent() const { return Parent; }
45 inline Function *getParent() { return Parent; }
46
47 /// getArgNo - Return the index of this formal argument in its containing
48 /// function. For example in "void foo(int a, float b)" a is 0 and b is 1.
49 unsigned getArgNo() const;
50
51 /// hasByValAttr - Return true if this argument has the byval attribute on it
52 /// in its containing function.
53 bool hasByValAttr() const;
54
55 /// getParamAlignment - If this is a byval argument, return its alignment.
56 unsigned getParamAlignment() const;
57
58 /// hasNestAttr - Return true if this argument has the nest attribute on
59 /// it in its containing function.
60 bool hasNestAttr() const;
61
62 /// hasNoAliasAttr - Return true if this argument has the noalias attribute on
63 /// it in its containing function.
64 bool hasNoAliasAttr() const;
65
66 /// hasNoCaptureAttr - Return true if this argument has the nocapture
67 /// attribute on it in its containing function.
68 bool hasNoCaptureAttr() const;
69
70 /// hasStructRetAttr - Return true if this argument has the sret attribute on
71 /// it in its containing function.
72 bool hasStructRetAttr() const;
73
74 /// addAttr - Add a Attribute to an argument
75 void addAttr(Attribute);
76
77 /// removeAttr - Remove a Attribute from an argument
78 void removeAttr(Attribute);
79
80 /// classof - Methods for support type inquiry through isa, cast, and
81 /// dyn_cast:
82 ///
83 static inline bool classof(const Value *V) {
84 return V->getValueID() == ArgumentVal;
85 }
86 };
87
88 } // End llvm namespace
89
90 #endif
+0
-399
include/llvm/Attributes.h less more
None //===-- llvm/Attributes.h - Container for Attributes ------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file contains the simple types necessary to represent the
11 /// attributes associated with functions and their calls.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_ATTRIBUTES_H
16 #define LLVM_ATTRIBUTES_H
17
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/Support/MathExtras.h"
20 #include
21 #include
22
23 namespace llvm {
24
25 class AttrBuilder;
26 class AttributeImpl;
27 class LLVMContext;
28 class Type;
29
30 //===----------------------------------------------------------------------===//
31 /// \class
32 /// \brief Functions, function parameters, and return types can have attributes
33 /// to indicate how they should be treated by optimizations and code
34 /// generation. This class represents one of those attributes. It's light-weight
35 /// and should be passed around by-value.
36 class Attribute {
37 public:
38 /// This enumeration lists the attributes that can be associated with
39 /// parameters, function results or the function itself.
40 ///
41 /// Note: uwtable is about the ABI or the user mandating an entry in the
42 /// unwind table. The nounwind attribute is about an exception passing by the
43 /// function.
44 ///
45 /// In a theoretical system that uses tables for profiling and sjlj for
46 /// exceptions, they would be fully independent. In a normal system that uses
47 /// tables for both, the semantics are:
48 ///
49 /// nil = Needs an entry because an exception might pass by.
50 /// nounwind = No need for an entry
51 /// uwtable = Needs an entry because the ABI says so and because
52 /// an exception might pass by.
53 /// uwtable + nounwind = Needs an entry because the ABI says so.
54
55 enum AttrKind {
56 // IR-Level Attributes
57 None, ///< No attributes have been set
58 AddressSafety, ///< Address safety checking is on.
59 Alignment, ///< Alignment of parameter (5 bits)
60 ///< stored as log2 of alignment with +1 bias
61 ///< 0 means unaligned (different from align(1))
62 AlwaysInline, ///< inline=always
63 ByVal, ///< Pass structure by value
64 InlineHint, ///< Source said inlining was desirable
65 InReg, ///< Force argument to be passed in register
66 MinSize, ///< Function must be optimized for size first
67 Naked, ///< Naked function
68 Nest, ///< Nested function static chain
69 NoAlias, ///< Considered to not alias after call
70 NoCapture, ///< Function creates no aliases of pointer
71 NoDuplicate, ///< Call cannot be duplicated
72 NoImplicitFloat, ///< Disable implicit floating point insts
73 NoInline, ///< inline=never
74 NonLazyBind, ///< Function is called early and/or
75 ///< often, so lazy binding isn't worthwhile
76 NoRedZone, ///< Disable redzone
77 NoReturn, ///< Mark the function as not returning
78 NoUnwind, ///< Function doesn't unwind stack
79 OptimizeForSize, ///< opt_size
80 ReadNone, ///< Function does not access memory
81 ReadOnly, ///< Function only reads from memory
82 ReturnsTwice, ///< Function can return twice
83 SExt, ///< Sign extended before/after call
84 StackAlignment, ///< Alignment of stack for function (3 bits)
85 ///< stored as log2 of alignment with +1 bias 0
86 ///< means unaligned (different from
87 ///< alignstack=(1))
88 StackProtect, ///< Stack protection.
89 StackProtectReq, ///< Stack protection required.
90 StructRet, ///< Hidden pointer to structure to return
91 UWTable, ///< Function must be in a unwind table
92 ZExt ///< Zero extended before/after call
93 };
94 private:
95 AttributeImpl *pImpl;
96 Attribute(AttributeImpl *A) : pImpl(A) {}
97 public:
98 Attribute() : pImpl(0) {}
99
100 /// \brief Return a uniquified Attribute object. This takes the uniquified
101 /// value from the Builder and wraps it in the Attribute class.
102 static Attribute get(LLVMContext &Context, ArrayRef Vals);
103 static Attribute get(LLVMContext &Context, AttrBuilder &B);
104
105 /// \brief Return true if the attribute is present.
106 bool hasAttribute(AttrKind Val) const;
107
108 /// \brief Return true if attributes exist
109 bool hasAttributes() const;
110
111 /// \brief Return true if the attributes are a non-null intersection.
112 bool hasAttributes(const Attribute &A) const;
113
114 /// \brief Returns the alignment field of an attribute as a byte alignment
115 /// value.
116 unsigned getAlignment() const;
117
118 /// \brief Returns the stack alignment field of an attribute as a byte
119 /// alignment value.
120 unsigned getStackAlignment() const;
121
122 bool operator==(AttrKind K) const;
123 bool operator!=(AttrKind K) const;
124
125 // FIXME: Remove these 'operator' methods.
126 bool operator==(const Attribute &A) const {
127 return pImpl == A.pImpl;
128 }
129 bool operator!=(const Attribute &A) const {
130 return pImpl != A.pImpl;
131 }
132
133 uint64_t getBitMask() const;
134
135 /// \brief Which attributes cannot be applied to a type.
136 static Attribute typeIncompatible(Type *Ty);
137
138 /// \brief This returns an integer containing an encoding of all the LLVM
139 /// attributes found in the given attribute bitset. Any change to this
140 /// encoding is a breaking change to bitcode compatibility.
141 static uint64_t encodeLLVMAttributesForBitcode(Attribute Attrs);
142
143 /// \brief This returns an attribute bitset containing the LLVM attributes
144 /// that have been decoded from the given integer. This function must stay in
145 /// sync with 'encodeLLVMAttributesForBitcode'.
146 static Attribute decodeLLVMAttributesForBitcode(LLVMContext &C,
147 uint64_t EncodedAttrs);
148
149 /// \brief The Attribute is converted to a string of equivalent mnemonic. This
150 /// is, presumably, for writing out the mnemonics for the assembly writer.
151 std::string getAsString() const;
152 };
153
154 //===----------------------------------------------------------------------===//
155 /// \class
156 /// \brief This class is used in conjunction with the Attribute::get method to
157 /// create an Attribute object. The object itself is uniquified. The Builder's
158 /// value, however, is not. So this can be used as a quick way to test for
159 /// equality, presence of attributes, etc.
160 class AttrBuilder {
161 uint64_t Bits;
162 public:
163 AttrBuilder() : Bits(0) {}
164 explicit AttrBuilder(uint64_t B) : Bits(B) {}
165 AttrBuilder(const Attribute &A) : Bits(A.getBitMask()) {}
166
167 void clear() { Bits = 0; }
168
169 /// addAttribute - Add an attribute to the builder.
170 AttrBuilder &addAttribute(Attribute::AttrKind Val);
171
172 /// removeAttribute - Remove an attribute from the builder.
173 AttrBuilder &removeAttribute(Attribute::AttrKind Val);
174
175 /// addAttribute - Add the attributes from A to the builder.
176 AttrBuilder &addAttributes(const Attribute &A);
177
178 /// removeAttribute - Remove the attributes from A from the builder.
179 AttrBuilder &removeAttributes(const Attribute &A);
180
181 /// \brief Return true if the builder has the specified attribute.
182 bool contains(Attribute::AttrKind A) const;
183
184 /// hasAttributes - Return true if the builder has IR-level attributes.
185 bool hasAttributes() const;
186
187 /// hasAttributes - Return true if the builder has any attribute that's in the
188 /// specified attribute.
189 bool hasAttributes(const Attribute &A) const;
190
191 /// hasAlignmentAttr - Return true if the builder has an alignment attribute.
192 bool hasAlignmentAttr() const;
193
194 /// getAlignment - Retrieve the alignment attribute, if it exists.
195 uint64_t getAlignment() const;
196
197 /// getStackAlignment - Retrieve the stack alignment attribute, if it exists.
198 uint64_t getStackAlignment() const;
199
200 /// addAlignmentAttr - This turns an int alignment (which must be a power of
201 /// 2) into the form used internally in Attribute.
202 AttrBuilder &addAlignmentAttr(unsigned Align);
203
204 /// addStackAlignmentAttr - This turns an int stack alignment (which must be a
205 /// power of 2) into the form used internally in Attribute.
206 AttrBuilder &addStackAlignmentAttr(unsigned Align);
207
208 /// addRawValue - Add the raw value to the internal representation.
209 /// N.B. This should be used ONLY for decoding LLVM bitcode!
210 AttrBuilder &addRawValue(uint64_t Val);
211
212 /// @brief Remove attributes that are used on functions only.
213 void removeFunctionOnlyAttrs() {
214 removeAttribute(Attribute::NoReturn)
215 .removeAttribute(Attribute::NoUnwind)
216 .removeAttribute(Attribute::ReadNone)
217 .removeAttribute(Attribute::ReadOnly)
218 .removeAttribute(Attribute::NoInline)
219 .removeAttribute(Attribute::AlwaysInline)
220 .removeAttribute(Attribute::OptimizeForSize)
221 .removeAttribute(Attribute::StackProtect)
222 .removeAttribute(Attribute::StackProtectReq)
223 .removeAttribute(Attribute::NoRedZone)
224 .removeAttribute(Attribute::NoImplicitFloat)
225 .removeAttribute(Attribute::Naked)
226 .removeAttribute(Attribute::InlineHint)
227 .removeAttribute(Attribute::StackAlignment)
228 .removeAttribute(Attribute::UWTable)
229 .removeAttribute(Attribute::NonLazyBind)
230 .removeAttribute(Attribute::ReturnsTwice)
231 .removeAttribute(Attribute::AddressSafety)
232 .removeAttribute(Attribute::MinSize)
233 .removeAttribute(Attribute::NoDuplicate);
234 }
235
236 uint64_t getBitMask() const { return Bits; }
237
238 bool operator==(const AttrBuilder &B) {
239 return Bits == B.Bits;
240 }
241 bool operator!=(const AttrBuilder &B) {
242 return Bits != B.Bits;
243 }
244 };
245
246 //===----------------------------------------------------------------------===//
247 /// \class
248 /// \brief This is just a pair of values to associate a set of attributes with
249 /// an index.
250 struct AttributeWithIndex {
251 Attribute Attrs; ///< The attributes that are set, or'd together.
252 unsigned Index; ///< Index of the parameter for which the attributes apply.
253 ///< Index 0 is used for return value attributes.
254 ///< Index ~0U is used for function attributes.
255
256 static AttributeWithIndex get(LLVMContext &C, unsigned Idx,
257 ArrayRef Attrs) {
258 return get(Idx, Attribute::get(C, Attrs));
259 }
260 static AttributeWithIndex get(unsigned Idx, Attribute Attrs) {
261 AttributeWithIndex P;
262 P.Index = Idx;
263 P.Attrs = Attrs;
264 return P;
265 }
266 };
267
268 //===----------------------------------------------------------------------===//
269 // AttributeSet Smart Pointer
270 //===----------------------------------------------------------------------===//
271
272 class AttributeSetImpl;
273
274 //===----------------------------------------------------------------------===//
275 /// \class
276 /// \brief This class manages the ref count for the opaque AttributeSetImpl
277 /// object and provides accessors for it.
278 class AttributeSet {
279 public:
280 enum AttrIndex {
281 ReturnIndex = 0U,
282 FunctionIndex = ~0U
283 };
284 private:
285 /// \brief The attributes that we are managing. This can be null to represent
286 /// the empty attributes list.
287 AttributeSetImpl *AttrList;
288
289 /// \brief The attributes for the specified index are returned. Attributes
290 /// for the result are denoted with Idx = 0.
291 Attribute getAttributes(unsigned Idx) const;
292
293 explicit AttributeSet(AttributeSetImpl *LI) : AttrList(LI) {}
294 public:
295 AttributeSet() : AttrList(0) {}
296 AttributeSet(const AttributeSet &P) : AttrList(P.AttrList) {}
297 const AttributeSet &operator=(const AttributeSet &RHS);
298
299 //===--------------------------------------------------------------------===//
300 // Attribute List Construction and Mutation
301 //===--------------------------------------------------------------------===//
302
303 /// \brief Return an AttributeSet with the specified parameters in it.
304 static AttributeSet get(LLVMContext &C, ArrayRef Attrs);
305
306 /// \brief Add the specified attribute at the specified index to this
307 /// attribute list. Since attribute lists are immutable, this returns the new
308 /// list.
309 AttributeSet addAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const;
310
311 /// \brief Remove the specified attribute at the specified index from this
312 /// attribute list. Since attribute lists are immutable, this returns the new
313 /// list.
314 AttributeSet removeAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const;
315
316 //===--------------------------------------------------------------------===//
317 // Attribute List Accessors
318 //===--------------------------------------------------------------------===//
319
320 /// \brief The attributes for the specified index are returned.
321 Attribute getParamAttributes(unsigned Idx) const {
322 return getAttributes(Idx);
323 }
324
325 /// \brief The attributes for the ret value are returned.
326 Attribute getRetAttributes() const {
327 return getAttributes(ReturnIndex);
328 }
329
330 /// \brief The function attributes are returned.
331 Attribute getFnAttributes() const {
332 return getAttributes(FunctionIndex);
333 }
334
335 /// \brief Return the alignment for the specified function parameter.
336 unsigned getParamAlignment(unsigned Idx) const {
337 return getAttributes(Idx).getAlignment();
338 }
339
340 /// \brief Return true if the attribute exists at the given index.
341 bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const;
342
343 /// \brief Return true if attribute exists at the given index.
344 bool hasAttributes(unsigned Index) const;
345
346 /// \brief Get the stack alignment.
347 unsigned getStackAlignment(unsigned Index) const;
348
349 /// \brief Return the attributes at the index as a string.
350 std::string getAsString(unsigned Index) const;
351
352 uint64_t getBitMask(unsigned Index) const;
353
354 /// \brief Return true if the specified attribute is set for at least one
355 /// parameter or for the return value.
356 bool hasAttrSomewhere(Attribute::AttrKind Attr) const;
357
358 /// operator==/!= - Provide equality predicates.
359 bool operator==(const AttributeSet &RHS) const {
360 return AttrList == RHS.AttrList;
361 }
362 bool operator!=(const AttributeSet &RHS) const {
363 return AttrList != RHS.AttrList;
364 }
365
366 //===--------------------------------------------------------------------===//
367 // Attribute List Introspection
368 //===--------------------------------------------------------------------===//
369
370 /// \brief Return a raw pointer that uniquely identifies this attribute list.
371 void *getRawPointer() const {
372 return AttrList;
373 }
374
375 // Attributes are stored as a dense set of slots, where there is one slot for
376 // each argument that has an attribute. This allows walking over the dense
377 // set instead of walking the sparse list of attributes.
378
379 /// \brief Return true if there are no attributes.
380 bool isEmpty() const {
381 return AttrList == 0;
382 }
383
384 /// \brief Return the number of slots used in this attribute list. This is
385 /// the number of arguments that have an attribute set on them (including the
386 /// function itself).
387 unsigned getNumSlots() const;
388
389 /// \brief Return the AttributeWithIndex at the specified slot. This holds a
390 /// index number plus a set of attributes.
391 const AttributeWithIndex &getSlot(unsigned Slot) const;
392
393 void dump() const;
394 };
395
396 } // end llvm namespace
397
398 #endif
+0
-297
include/llvm/BasicBlock.h less more
None //===-- llvm/BasicBlock.h - Represent a basic block in the VM ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the declaration of the BasicBlock class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_BASICBLOCK_H
14 #define LLVM_BASICBLOCK_H
15
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/ADT/ilist.h"
18 #include "llvm/Instruction.h"
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/SymbolTableListTraits.h"
21
22 namespace llvm {
23
24 class LandingPadInst;
25 class TerminatorInst;
26 class LLVMContext;
27 class BlockAddress;
28
29 template<> struct ilist_traits
30 : public SymbolTableListTraits {
31 // createSentinel is used to get hold of a node that marks the end of
32 // the list...
33 // The sentinel is relative to this instance, so we use a non-static
34 // method.
35 Instruction *createSentinel() const {
36 // since i(p)lists always publicly derive from the corresponding
37 // traits, placing a data member in this class will augment i(p)list.
38 // But since the NodeTy is expected to publicly derive from
39 // ilist_node, there is a legal viable downcast from it
40 // to NodeTy. We use this trick to superpose i(p)list with a "ghostly"
41 // NodeTy, which becomes the sentinel. Dereferencing the sentinel is
42 // forbidden (save the ilist_node) so no one will ever notice
43 // the superposition.
44 return static_cast(&Sentinel);
45 }
46 static void destroySentinel(Instruction*) {}
47
48 Instruction *provideInitialHead() const { return createSentinel(); }
49 Instruction *ensureHead(Instruction*) const { return createSentinel(); }
50 static void noteHead(Instruction*, Instruction*) {}
51 private:
52 mutable ilist_half_node Sentinel;
53 };
54
55 /// This represents a single basic block in LLVM. A basic block is simply a
56 /// container of instructions that execute sequentially. Basic blocks are Values
57 /// because they are referenced by instructions such as branches and switch
58 /// tables. The type of a BasicBlock is "Type::LabelTy" because the basic block
59 /// represents a label to which a branch can jump.
60 ///
61 /// A well formed basic block is formed of a list of non-terminating
62 /// instructions followed by a single TerminatorInst instruction.
63 /// TerminatorInst's may not occur in the middle of basic blocks, and must
64 /// terminate the blocks. The BasicBlock class allows malformed basic blocks to
65 /// occur because it may be useful in the intermediate stage of constructing or
66 /// modifying a program. However, the verifier will ensure that basic blocks
67 /// are "well formed".
68 /// @brief LLVM Basic Block Representation
69 class BasicBlock : public Value, // Basic blocks are data objects also
70 public ilist_node {
71 friend class BlockAddress;
72 public:
73 typedef iplist InstListType;
74 private:
75 InstListType InstList;
76 Function *Parent;
77
78 void setParent(Function *parent);
79 friend class SymbolTableListTraits;
80
81 BasicBlock(const BasicBlock &) LLVM_DELETED_FUNCTION;
82 void operator=(const BasicBlock &) LLVM_DELETED_FUNCTION;
83
84 /// BasicBlock ctor - If the function parameter is specified, the basic block
85 /// is automatically inserted at either the end of the function (if
86 /// InsertBefore is null), or before the specified basic block.
87 ///
88 explicit BasicBlock(LLVMContext &C, const Twine &Name = "",
89 Function *Parent = 0, BasicBlock *InsertBefore = 0);
90 public:
91 /// getContext - Get the context in which this basic block lives.
92 LLVMContext &getContext() const;
93
94 /// Instruction iterators...
95 typedef InstListType::iterator iterator;
96 typedef InstListType::const_iterator const_iterator;
97 typedef InstListType::reverse_iterator reverse_iterator;
98 typedef InstListType::const_reverse_iterator const_reverse_iterator;
99
100 /// Create - Creates a new BasicBlock. If the Parent parameter is specified,
101 /// the basic block is automatically inserted at either the end of the
102 /// function (if InsertBefore is 0), or before the specified basic block.
103 static BasicBlock *Create(LLVMContext &Context, const Twine &Name = "",
104 Function *Parent = 0,BasicBlock *InsertBefore = 0) {
105 return new BasicBlock(Context, Name, Parent, InsertBefore);
106 }
107 ~BasicBlock();
108
109 /// getParent - Return the enclosing method, or null if none
110 ///
111 const Function *getParent() const { return Parent; }
112 Function *getParent() { return Parent; }
113
114 /// getTerminator() - If this is a well formed basic block, then this returns
115 /// a pointer to the terminator instruction. If it is not, then you get a
116 /// null pointer back.
117 ///
118 TerminatorInst *getTerminator();
119 const TerminatorInst *getTerminator() const;
120
121 /// Returns a pointer to the first instructon in this block that is not a
122 /// PHINode instruction. When adding instruction to the beginning of the
123 /// basic block, they should be added before the returned value, not before
124 /// the first instruction, which might be PHI.
125 /// Returns 0 is there's no non-PHI instruction.
126 Instruction* getFirstNonPHI();
127 const Instruction* getFirstNonPHI() const {
128 return const_cast(this)->getFirstNonPHI();
129 }
130
131 // Same as above, but also skip debug intrinsics.
132 Instruction* getFirstNonPHIOrDbg();
133 const Instruction* getFirstNonPHIOrDbg() const {
134 return const_cast(this)->getFirstNonPHIOrDbg();
135 }
136
137 // Same as above, but also skip lifetime intrinsics.
138 Instruction* getFirstNonPHIOrDbgOrLifetime();
139 const Instruction* getFirstNonPHIOrDbgOrLifetime() const {
140 return const_cast(this)->getFirstNonPHIOrDbgOrLifetime();
141 }
142
143 /// getFirstInsertionPt - Returns an iterator to the first instruction in this
144 /// block that is suitable for inserting a non-PHI instruction. In particular,
145 /// it skips all PHIs and LandingPad instructions.
146 iterator getFirstInsertionPt();
147 const_iterator getFirstInsertionPt() const {
148 return const_cast(this)->getFirstInsertionPt();
149 }
150
151 /// removeFromParent - This method unlinks 'this' from the containing
152 /// function, but does not delete it.
153 ///
154 void removeFromParent();
155
156 /// eraseFromParent - This method unlinks 'this' from the containing function
157 /// and deletes it.
158 ///
159 void eraseFromParent();
160
161 /// moveBefore - Unlink this basic block from its current function and
162 /// insert it into the function that MovePos lives in, right before MovePos.
163 void moveBefore(BasicBlock *MovePos);
164
165 /// moveAfter - Unlink this basic block from its current function and
166 /// insert it into the function that MovePos lives in, right after MovePos.
167 void moveAfter(BasicBlock *MovePos);
168
169
170 /// getSinglePredecessor - If this basic block has a single predecessor block,
171 /// return the block, otherwise return a null pointer.
172 BasicBlock *getSinglePredecessor();
173 const BasicBlock *getSinglePredecessor() const {
174 return const_cast(this)->getSinglePredecessor();
175 }
176
177 /// getUniquePredecessor - If this basic block has a unique predecessor block,
178 /// return the block, otherwise return a null pointer.
179 /// Note that unique predecessor doesn't mean single edge, there can be
180 /// multiple edges from the unique predecessor to this block (for example
181 /// a switch statement with multiple cases having the same destination).
182 BasicBlock *getUniquePredecessor();
183 const BasicBlock *getUniquePredecessor() const {
184 return const_cast(this)->getUniquePredecessor();
185 }
186
187 //===--------------------------------------------------------------------===//
188 /// Instruction iterator methods
189 ///
190 inline iterator begin() { return InstList.begin(); }
191 inline const_iterator begin() const { return InstList.begin(); }
192 inline iterator end () { return InstList.end(); }
193 inline const_iterator end () const { return InstList.end(); }
194
195 inline reverse_iterator rbegin() { return InstList.rbegin(); }
196 inline const_reverse_iterator rbegin() const { return InstList.rbegin(); }
197 inline reverse_iterator rend () { return InstList.rend(); }
198 inline const_reverse_iterator rend () const { return InstList.rend(); }
199
200 inline size_t size() const { return InstList.size(); }
201 inline bool empty() const { return InstList.empty(); }
202 inline const Instruction &front() const { return InstList.front(); }
203 inline Instruction &front() { return InstList.front(); }
204 inline const Instruction &back() const { return InstList.back(); }
205 inline Instruction &back() { return InstList.back(); }
206
207 /// getInstList() - Return the underlying instruction list container. You
208 /// need to access it directly if you want to modify it currently.
209 ///
210 const InstListType &getInstList() const { return InstList; }
211 InstListType &getInstList() { return InstList; }
212
213 /// getSublistAccess() - returns pointer to member of instruction list
214 static iplist BasicBlock::*getSublistAccess(Instruction*) {
215 return &BasicBlock::InstList;
216 }
217
218 /// getValueSymbolTable() - returns pointer to symbol table (if any)
219 ValueSymbolTable *getValueSymbolTable();
220
221 /// Methods for support type inquiry through isa, cast, and dyn_cast:
222 static inline bool classof(const Value *V) {
223 return V->getValueID() == Value::BasicBlockVal;
224 }
225
226 /// dropAllReferences() - This function causes all the subinstructions to "let
227 /// go" of all references that they are maintaining. This allows one to
228 /// 'delete' a whole class at a time, even though there may be circular
229 /// references... first all references are dropped, and all use counts go to
230 /// zero. Then everything is delete'd for real. Note that no operations are
231 /// valid on an object that has "dropped all references", except operator
232 /// delete.
233 ///
234 void dropAllReferences();
235
236 /// removePredecessor - This method is used to notify a BasicBlock that the
237 /// specified Predecessor of the block is no longer able to reach it. This is
238 /// actually not used to update the Predecessor list, but is actually used to
239 /// update the PHI nodes that reside in the block. Note that this should be
240 /// called while the predecessor still refers to this block.
241 ///
242 void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs = false);
243
244 /// splitBasicBlock - This splits a basic block into two at the specified
245 /// instruction. Note that all instructions BEFORE the specified iterator
246 /// stay as part of the original basic block, an unconditional branch is added
247 /// to the original BB, and the rest of the instructions in the BB are moved
248 /// to the new BB, including the old terminator. The newly formed BasicBlock
249 /// is returned. This function invalidates the specified iterator.
250 ///
251 /// Note that this only works on well formed basic blocks (must have a
252 /// terminator), and 'I' must not be the end of instruction list (which would
253 /// cause a degenerate basic block to be formed, having a terminator inside of
254 /// the basic block).
255 ///
256 /// Also note that this doesn't preserve any passes. To split blocks while
257 /// keeping loop information consistent, use the SplitBlock utility function.
258 ///
259 BasicBlock *splitBasicBlock(iterator I, const Twine &BBName = "");
260
261 /// hasAddressTaken - returns true if there are any uses of this basic block
262 /// other than direct branches, switches, etc. to it.
263 bool hasAddressTaken() const { return getSubclassDataFromValue() != 0; }
264
265 /// replaceSuccessorsPhiUsesWith - Update all phi nodes in all our successors
266 /// to refer to basic block New instead of to us.
267 void replaceSuccessorsPhiUsesWith(BasicBlock *New);
268
269 /// isLandingPad - Return true if this basic block is a landing pad. I.e.,
270 /// it's the destination of the 'unwind' edge of an invoke instruction.
271 bool isLandingPad() const;
272
273 /// getLandingPadInst() - Return the landingpad instruction associated with
274 /// the landing pad.
275 LandingPadInst *getLandingPadInst();
276 const LandingPadInst *getLandingPadInst() const;
277
278 private:
279 /// AdjustBlockAddressRefCount - BasicBlock stores the number of BlockAddress
280 /// objects using it. This is almost always 0, sometimes one, possibly but
281 /// almost never 2, and inconceivably 3 or more.
282 void AdjustBlockAddressRefCount(int Amt) {
283 setValueSubclassData(getSubclassDataFromValue()+Amt);
284 assert((int)(signed char)getSubclassDataFromValue() >= 0 &&
285 "Refcount wrap-around");
286 }
287 // Shadow Value::setValueSubclassData with a private forwarding method so that
288 // any future subclasses cannot accidentally use it.
289 void setValueSubclassData(unsigned short D) {
290 Value::setValueSubclassData(D);
291 }
292 };
293
294 } // End llvm namespace
295
296 #endif
None set(LLVM_TARGET_DEFINITIONS Intrinsics.td)
1
2 tablegen(LLVM Intrinsics.gen -gen-intrinsic)
3
4 add_custom_target(intrinsics_gen ALL
5 DEPENDS ${llvm_builded_incs_dir}/Intrinsics.gen)
6 set_target_properties(intrinsics_gen PROPERTIES FOLDER "Tablegenning")
0 add_subdirectory(IR)
71
82 if( MSVC_IDE OR XCODE )
93 # Creates a dummy target containing all headers for the benefit of
+0
-129
include/llvm/CallingConv.h less more
None //===-- llvm/CallingConv.h - LLVM Calling Conventions -----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines LLVM's set of calling conventions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CALLINGCONV_H
14 #define LLVM_CALLINGCONV_H
15
16 namespace llvm {
17
18 /// CallingConv Namespace - This namespace contains an enum with a value for
19 /// the well-known calling conventions.
20 ///
21 namespace CallingConv {
22 /// A set of enums which specify the assigned numeric values for known llvm
23 /// calling conventions.
24 /// @brief LLVM Calling Convention Representation
25 enum ID {
26 /// C - The default llvm calling convention, compatible with C. This
27 /// convention is the only calling convention that supports varargs calls.
28 /// As with typical C calling conventions, the callee/caller have to
29 /// tolerate certain amounts of prototype mismatch.
30 C = 0,
31
32 // Generic LLVM calling conventions. None of these calling conventions
33 // support varargs calls, and all assume that the caller and callee
34 // prototype exactly match.
35
36 /// Fast - This calling convention attempts to make calls as fast as
37 /// possible (e.g. by passing things in registers).
38 Fast = 8,
39
40 // Cold - This calling convention attempts to make code in the caller as
41 // efficient as possible under the assumption that the call is not commonly
42 // executed. As such, these calls often preserve all registers so that the
43 // call does not break any live ranges in the caller side.
44 Cold = 9,
45
46 // GHC - Calling convention used by the Glasgow Haskell Compiler (GHC).
47 GHC = 10,
48
49 // HiPE - Calling convention used by the High-Performance Erlang Compiler
50 // (HiPE).
51 HiPE = 11,
52
53 // Target - This is the start of the target-specific calling conventions,
54 // e.g. fastcall and thiscall on X86.
55 FirstTargetCC = 64,
56
57 /// X86_StdCall - stdcall is the calling conventions mostly used by the
58 /// Win32 API. It is basically the same as the C convention with the
59 /// difference in that the callee is responsible for popping the arguments
60 /// from the stack.
61 X86_StdCall = 64,
62
63 /// X86_FastCall - 'fast' analog of X86_StdCall. Passes first two arguments
64 /// in ECX:EDX registers, others - via stack. Callee is responsible for
65 /// stack cleaning.
66 X86_FastCall = 65,
67
68 /// ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete,
69 /// but still used on some targets).
70 ARM_APCS = 66,
71
72 /// ARM_AAPCS - ARM Architecture Procedure Calling Standard calling
73 /// convention (aka EABI). Soft float variant.
74 ARM_AAPCS = 67,
75
76 /// ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
77 ARM_AAPCS_VFP = 68,
78
79 /// MSP430_INTR - Calling convention used for MSP430 interrupt routines.
80 MSP430_INTR = 69,
81
82 /// X86_ThisCall - Similar to X86_StdCall. Passes first argument in ECX,
83 /// others via stack. Callee is responsible for stack cleaning. MSVC uses
84 /// this by default for methods in its ABI.
85 X86_ThisCall = 70,
86
87 /// PTX_Kernel - Call to a PTX kernel.
88 /// Passes all arguments in parameter space.
89 PTX_Kernel = 71,
90
91 /// PTX_Device - Call to a PTX device function.
92 /// Passes all arguments in register or parameter space.
93 PTX_Device = 72,
94
95 /// MBLAZE_INTR - Calling convention used for MBlaze interrupt routines.
96 MBLAZE_INTR = 73,
97
98 /// MBLAZE_INTR - Calling convention used for MBlaze interrupt support
99 /// routines (i.e. GCC's save_volatiles attribute).
100 MBLAZE_SVOL = 74,
101
102 /// SPIR_FUNC - Calling convention for SPIR non-kernel device functions.
103 /// No lowering or expansion of arguments.
104 /// Structures are passed as a pointer to a struct with the byval attribute.
105 /// Functions can only call SPIR_FUNC and SPIR_KERNEL functions.
106 /// Functions can only have zero or one return values.
107 /// Variable arguments are not allowed, except for printf.
108 /// How arguments/return values are lowered are not specified.
109 /// Functions are only visible to the devices.
110 SPIR_FUNC = 75,
111
112 /// SPIR_KERNEL - Calling convention for SPIR kernel functions.
113 /// Inherits the restrictions of SPIR_FUNC, except
114 /// Cannot have non-void return values.
115 /// Cannot have variable arguments.
116 /// Can also be called by the host.
117 /// Is externally visible.
118 SPIR_KERNEL = 76,
119
120 /// Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins
121 Intel_OCL_BI = 77
122
123 };
124 } // End CallingConv namespace
125
126 } // End llvm namespace
127
128 #endif
1717 #include "llvm/ADT/SmallVector.h"
1818 #include "llvm/CodeGen/ISDOpcodes.h"
1919 #include "llvm/CodeGen/ValueTypes.h"
20 #include "llvm/InlineAsm.h"
21 #include "llvm/Instructions.h"
20 #include "llvm/IR/InlineAsm.h"
21 #include "llvm/IR/Instructions.h"
2222 #include "llvm/Support/CallSite.h"
2323
2424 namespace llvm {
1616 #define LLVM_CODEGEN_ASMPRINTER_H
1717
1818 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/InlineAsm.h"
19 #include "llvm/IR/InlineAsm.h"
2020 #include "llvm/Support/DataTypes.h"
2121 #include "llvm/Support/ErrorHandling.h"
2222
1515 #define LLVM_CODEGEN_CALLINGCONVLOWER_H
1616
1717 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/CallingConv.h"
1918 #include "llvm/CodeGen/MachineFrameInfo.h"
2019 #include "llvm/CodeGen/MachineFunction.h"
2120 #include "llvm/CodeGen/ValueTypes.h"
21 #include "llvm/IR/CallingConv.h"
2222 #include "llvm/Target/TargetCallingConv.h"
2323
2424 namespace llvm {
2424 #include "llvm/CodeGen/ISDOpcodes.h"
2525 #include "llvm/CodeGen/MachineBasicBlock.h"
2626 #include "llvm/CodeGen/ValueTypes.h"
27 #include "llvm/InlineAsm.h"
28 #include "llvm/Instructions.h"
27 #include "llvm/IR/InlineAsm.h"
28 #include "llvm/IR/Instructions.h"
2929 #include "llvm/Support/CallSite.h"
3030 #include "llvm/Target/TargetRegisterInfo.h"
3131 #include
1515 #ifndef LLVM_CODEGEN_INTRINSICLOWERING_H
1616 #define LLVM_CODEGEN_INTRINSICLOWERING_H
1717
18 #include "llvm/Intrinsics.h"
18 #include "llvm/IR/Intrinsics.h"
1919
2020 namespace llvm {
2121 class CallInst;
2020 #include "llvm/ADT/DenseMap.h"
2121 #include "llvm/ADT/SmallPtrSet.h"
2222 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/Metadata.h"
23 #include "llvm/IR/Metadata.h"
2424 #include "llvm/Support/DebugLoc.h"
2525 #include "llvm/Support/ValueHandle.h"
2626 #include
2222 #include "llvm/ADT/ilist.h"
2323 #include "llvm/ADT/ilist_node.h"
2424 #include "llvm/CodeGen/MachineOperand.h"
25 #include "llvm/InlineAsm.h"
25 #include "llvm/IR/InlineAsm.h"
2626 #include "llvm/MC/MCInstrDesc.h"
2727 #include "llvm/Support/DebugLoc.h"
2828 #include "llvm/Target/TargetOpcodes.h"
3434 #include "llvm/ADT/PointerIntPair.h"
3535 #include "llvm/ADT/SmallPtrSet.h"
3636 #include "llvm/ADT/SmallVector.h"
37 #include "llvm/GlobalValue.h"
37 #include "llvm/IR/GlobalValue.h"
38 #include "llvm/IR/Metadata.h"
3839 #include "llvm/MC/MCContext.h"
3940 #include "llvm/MC/MachineLocation.h"
40 #include "llvm/Metadata.h"
4141 #include "llvm/Pass.h"
4242 #include "llvm/Support/DataTypes.h"
4343 #include "llvm/Support/DebugLoc.h"
1313 #ifndef LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
1414 #define LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
1515
16 #include "llvm/Value.h"
16 #include "llvm/IR/Value.h"
1717
1818 namespace llvm {
1919 class MachineFrameInfo;
1414 #ifndef LLVM_CODEGEN_SELECTIONDAG_ISEL_H
1515 #define LLVM_CODEGEN_SELECTIONDAG_ISEL_H
1616
17 #include "llvm/BasicBlock.h"
1817 #include "llvm/CodeGen/MachineFunctionPass.h"
1918 #include "llvm/CodeGen/SelectionDAG.h"
19 #include "llvm/IR/BasicBlock.h"
2020 #include "llvm/Pass.h"
2121
2222 namespace llvm {
2727 #include "llvm/CodeGen/ISDOpcodes.h"
2828 #include "llvm/CodeGen/MachineMemOperand.h"
2929 #include "llvm/CodeGen/ValueTypes.h"
30 #include "llvm/Constants.h"
31 #include "llvm/Instructions.h"
30 #include "llvm/IR/Constants.h"
31 #include "llvm/IR/Instructions.h"
3232 #include "llvm/Support/DataTypes.h"
3333 #include "llvm/Support/DebugLoc.h"
3434 #include "llvm/Support/MathExtras.h"
+0
-167
include/llvm/Constant.h less more
None //===-- llvm/Constant.h - Constant class definition -------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the declaration of the Constant class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CONSTANT_H
14 #define LLVM_CONSTANT_H
15
16 #include "llvm/User.h"
17
18 namespace llvm {
19 class APInt;
20
21 template class SmallVectorImpl;
22
23 /// This is an important base class in LLVM. It provides the common facilities
24 /// of all constant values in an LLVM program. A constant is a value that is
25 /// immutable at runtime. Functions are constants because their address is
26 /// immutable. Same with global variables.
27 ///
28 /// All constants share the capabilities provided in this class. All constants
29 /// can have a null value. They can have an operand list. Constants can be
30 /// simple (integer and floating point values), complex (arrays and structures),
31 /// or expression based (computations yielding a constant value composed of
32 /// only certain operators and other constant values).
33 ///
34 /// Note that Constants are immutable (once created they never change)
35 /// and are fully shared by structural equivalence. This means that two
36 /// structurally equivalent constants will always have the same address.
37 /// Constants are created on demand as needed and never deleted: thus clients
38 /// don't have to worry about the lifetime of the objects.
39 /// @brief LLVM Constant Representation
40 class Constant : public User {
41 void operator=(const Constant &) LLVM_DELETED_FUNCTION;
42 Constant(const Constant &) LLVM_DELETED_FUNCTION;
43 virtual void anchor();
44
45 protected:
46 Constant(Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
47 : User(ty, vty, Ops, NumOps) {}
48
49 void destroyConstantImpl();
50 public:
51 /// isNullValue - Return true if this is the value that would be returned by
52 /// getNullValue.
53 bool isNullValue() const;
54
55 /// isAllOnesValue - Return true if this is the value that would be returned by
56 /// getAllOnesValue.
57 bool isAllOnesValue() const;
58
59 /// isNegativeZeroValue - Return true if the value is what would be returned
60 /// by getZeroValueForNegation.
61 bool isNegativeZeroValue() const;
62
63 /// canTrap - Return true if evaluation of this constant could trap. This is
64 /// true for things like constant expressions that could divide by zero.
65 bool canTrap() const;
66
67 /// isThreadDependent - Return true if the value can vary between threads.
68 bool isThreadDependent() const;
69
70 /// isConstantUsed - Return true if the constant has users other than constant
71 /// exprs and other dangling things.
72 bool isConstantUsed() const;
73
74 enum PossibleRelocationsTy {
75 NoRelocation = 0,
76 LocalRelocation = 1,
77 GlobalRelocations = 2
78 };
79
80 /// getRelocationInfo - This method classifies the entry according to
81 /// whether or not it may generate a relocation entry. This must be
82 /// conservative, so if it might codegen to a relocatable entry, it should say
83 /// so. The return values are:
84 ///
85 /// NoRelocation: This constant pool entry is guaranteed to never have a
86 /// relocation applied to it (because it holds a simple constant like
87 /// '4').
88 /// LocalRelocation: This entry has relocations, but the entries are
89 /// guaranteed to be resolvable by the static linker, so the dynamic
90 /// linker will never see them.
91 /// GlobalRelocations: This entry may have arbitrary relocations.
92 ///
93 /// FIXME: This really should not be in VMCore.
94 PossibleRelocationsTy getRelocationInfo() const;
95
96 /// getAggregateElement - For aggregates (struct/array/vector) return the
97 /// constant that corresponds to the specified element if possible, or null if
98 /// not. This can return null if the element index is a ConstantExpr, or if
99 /// 'this' is a constant expr.
100 Constant *getAggregateElement(unsigned Elt) const;
101 Constant *getAggregateElement(Constant *Elt) const;
102
103 /// getSplatValue - If this is a splat vector constant, meaning that all of
104 /// the elements have the same value, return that value. Otherwise return 0.
105 Constant *getSplatValue() const;
106
107 /// If C is a constant integer then return its value, otherwise C must be a
108 /// vector of constant integers, all equal, and the common value is returned.
109 const APInt &getUniqueInteger() const;
110
111 /// destroyConstant - Called if some element of this constant is no longer
112 /// valid. At this point only other constants may be on the use_list for this
113 /// constant. Any constants on our Use list must also be destroy'd. The
114 /// implementation must be sure to remove the constant from the list of
115 /// available cached constants. Implementations should call
116 /// destroyConstantImpl as the last thing they do, to destroy all users and
117 /// delete this.
118 virtual void destroyConstant() { llvm_unreachable("Not reached!"); }
119
120 //// Methods for support type inquiry through isa, cast, and dyn_cast:
121 static inline bool classof(const Value *V) {
122 return V->getValueID() >= ConstantFirstVal &&
123 V->getValueID() <= ConstantLastVal;
124 }
125
126 /// replaceUsesOfWithOnConstant - This method is a special form of
127 /// User::replaceUsesOfWith (which does not work on constants) that does work
128 /// on constants. Basically this method goes through the trouble of building
129 /// a new constant that is equivalent to the current one, with all uses of
130 /// From replaced with uses of To. After this construction is completed, all
131 /// of the users of 'this' are replaced to use the new constant, and then
132 /// 'this' is deleted. In general, you should not call this method, instead,
133 /// use Value::replaceAllUsesWith, which automatically dispatches to this
134 /// method as needed.
135 ///
136 virtual void replaceUsesOfWithOnConstant(Value *, Value *, Use *) {
137 // Provide a default implementation for constants (like integers) that
138 // cannot use any other values. This cannot be called at runtime, but needs
139 // to be here to avoid link errors.
140 assert(getNumOperands() == 0 && "replaceUsesOfWithOnConstant must be "
141 "implemented for all constants that have operands!");
142 llvm_unreachable("Constants that do not have operands cannot be using "
143 "'From'!");
144 }
145
146 static Constant *getNullValue(Type* Ty);
147
148 /// @returns the value for an integer or vector of integer constant of the
149 /// given type that has all its bits set to true.
150 /// @brief Get the all ones value
151 static Constant *getAllOnesValue(Type* Ty);
152
153 /// getIntegerValue - Return the value for an integer or pointer constant,
154 /// or a vector thereof, with the given scalar value.
155 static Constant *getIntegerValue(Type* Ty, const APInt &V);
156
157 /// removeDeadConstantUsers - If there are any dead constant users dangling
158 /// off of this constant, remove them. This method is useful for clients
159 /// that want to check to see if a global is unused, but don't want to deal
160 /// with potentially dead constants hanging off of the globals.
161 void removeDeadConstantUsers() const;
162 };
163
164 } // End llvm namespace
165
166 #endif
+0
-1163
include/llvm/Constants.h less more
None //===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// @file
10 /// This file contains the declarations for the subclasses of Constant,
11 /// which represent the different flavors of constant values that live in LLVM.
12 /// Note that Constants are immutable (once created they never change) and are
13 /// fully shared by structural equivalence. This means that two structurally
14 /// equivalent constants will always have the same address. Constant's are
15 /// created on demand as needed and never deleted: thus clients don't have to
16 /// worry about the lifetime of the objects.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_CONSTANTS_H
21 #define LLVM_CONSTANTS_H
22
23 #include "llvm/ADT/APFloat.h"
24 #include "llvm/ADT/APInt.h"
25 #include "llvm/ADT/ArrayRef.h"
26 #include "llvm/Constant.h"
27 #include "llvm/OperandTraits.h"
28
29 namespace llvm {
30
31 class ArrayType;
32 class IntegerType;
33 class StructType;
34 class PointerType;
35 class VectorType;
36 class SequentialType;
37
38 template
39 struct ConstantCreator;
40 template
41 struct ConstantArrayCreator;
42 template
43 struct ConvertConstantType;
44
45 //===----------------------------------------------------------------------===//
46 /// This is the shared class of boolean and integer constants. This class
47 /// represents both boolean and integral constants.
48 /// @brief Class for constant integers.
49 class ConstantInt : public Constant {
50 virtual void anchor();
51 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
52 ConstantInt(const ConstantInt &) LLVM_DELETED_FUNCTION;
53 ConstantInt(IntegerType *Ty, const APInt& V);
54 APInt Val;
55 protected:
56 // allocate space for exactly zero operands
57 void *operator new(size_t s) {
58 return User::operator new(s, 0);
59 }
60 public:
61 static ConstantInt *getTrue(LLVMContext &Context);
62 static ConstantInt *getFalse(LLVMContext &Context);
63 static Constant *getTrue(Type *Ty);
64 static Constant *getFalse(Type *Ty);
65
66 /// If Ty is a vector type, return a Constant with a splat of the given
67 /// value. Otherwise return a ConstantInt for the given value.
68 static Constant *get(Type *Ty, uint64_t V, bool isSigned = false);
69
70 /// Return a ConstantInt with the specified integer value for the specified
71 /// type. If the type is wider than 64 bits, the value will be zero-extended
72 /// to fit the type, unless isSigned is true, in which case the value will
73 /// be interpreted as a 64-bit signed integer and sign-extended to fit
74 /// the type.
75 /// @brief Get a ConstantInt for a specific value.
76 static ConstantInt *get(IntegerType *Ty, uint64_t V,
77 bool isSigned = false);
78
79 /// Return a ConstantInt with the specified value for the specified type. The
80 /// value V will be canonicalized to a an unsigned APInt. Accessing it with
81 /// either getSExtValue() or getZExtValue() will yield a correctly sized and
82 /// signed value for the type Ty.
83 /// @brief Get a ConstantInt for a specific signed value.
84 static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
85 static Constant *getSigned(Type *Ty, int64_t V);
86
87 /// Return a ConstantInt with the specified value and an implied Type. The
88 /// type is the integer type that corresponds to the bit width of the value.
89 static ConstantInt *get(LLVMContext &Context, const APInt &V);
90
91 /// Return a ConstantInt constructed from the string strStart with the given
92 /// radix.
93 static ConstantInt *get(IntegerType *Ty, StringRef Str,
94 uint8_t radix);
95
96 /// If Ty is a vector type, return a Constant with a splat of the given
97 /// value. Otherwise return a ConstantInt for the given value.
98 static Constant *get(Type* Ty, const APInt& V);
99
100 /// Return the constant as an APInt value reference. This allows clients to
101 /// obtain a copy of the value, with all its precision in tact.
102 /// @brief Return the constant's value.
103 inline const APInt &getValue() const {
104 return Val;
105 }
106
107 /// getBitWidth - Return the bitwidth of this constant.
108 unsigned getBitWidth() const { return Val.getBitWidth(); }
109
110 /// Return the constant as a 64-bit unsigned integer value after it
111 /// has been zero extended as appropriate for the type of this constant. Note
112 /// that this method can assert if the value does not fit in 64 bits.
113 /// @deprecated
114 /// @brief Return the zero extended value.
115 inline uint64_t getZExtValue() const {
116 return Val.getZExtValue();
117 }
118
119 /// Return the constant as a 64-bit integer value after it has been sign
120 /// extended as appropriate for the type of this constant. Note that
121 /// this method can assert if the value does not fit in 64 bits.
122 /// @deprecated
123 /// @brief Return the sign extended value.
124 inline int64_t getSExtValue() const {
125 return Val.getSExtValue();
126 }
127
128 /// A helper method that can be used to determine if the constant contained
129 /// within is equal to a constant. This only works for very small values,
130 /// because this is all that can be represented with all types.
131 /// @brief Determine if this constant's value is same as an unsigned char.
132 bool equalsInt(uint64_t V) const {
133 return Val == V;
134 }
135
136 /// getType - Specialize the getType() method to always return an IntegerType,
137 /// which reduces the amount of casting needed in parts of the compiler.
138 ///
139 inline IntegerType *getType() const {
140 return reinterpret_cast(Value::getType());
141 }
142
143 /// This static method returns true if the type Ty is big enough to
144 /// represent the value V. This can be used to avoid having the get method
145 /// assert when V is larger than Ty can represent. Note that there are two
146 /// versions of this method, one for unsigned and one for signed integers.
147 /// Although ConstantInt canonicalizes everything to an unsigned integer,
148 /// the signed version avoids callers having to convert a signed quantity
149 /// to the appropriate unsigned type before calling the method.
150 /// @returns true if V is a valid value for type Ty
151 /// @brief Determine if the value is in range for the given type.
152 static bool isValueValidForType(Type *Ty, uint64_t V);
153 static bool isValueValidForType(Type *Ty, int64_t V);
154
155 bool isNegative() const { return Val.isNegative(); }
156
157 /// This is just a convenience method to make client code smaller for a
158 /// common code. It also correctly performs the comparison without the
159 /// potential for an assertion from getZExtValue().
160 bool isZero() const {
161 return Val == 0;
162 }
163
164 /// This is just a convenience method to make client code smaller for a
165 /// common case. It also correctly performs the comparison without the
166 /// potential for an assertion from getZExtValue().
167 /// @brief Determine if the value is one.
168 bool isOne() const {
169 return Val == 1;
170 }
171
172 /// This function will return true iff every bit in this constant is set
173 /// to true.
174 /// @returns true iff this constant's bits are all set to true.
175 /// @brief Determine if the value is all ones.
176 bool isMinusOne() const {
177 return Val.isAllOnesValue();
178 }
179
180 /// This function will return true iff this constant represents the largest
181 /// value that may be represented by the constant's type.
182 /// @returns true iff this is the largest value that may be represented
183 /// by this type.
184 /// @brief Determine if the value is maximal.
185 bool isMaxValue(bool isSigned) const {
186 if (isSigned)
187 return Val.isMaxSignedValue();
188 else
189 return Val.isMaxValue();
190 }
191
192 /// This function will return true iff this constant represents the smallest
193 /// value that may be represented by this constant's type.
194 /// @returns true if this is the smallest value that may be represented by
195 /// this type.
196 /// @brief Determine if the value is minimal.
197 bool isMinValue(bool isSigned) const {
198 if (isSigned)
199 return Val.isMinSignedValue();
200 else
201 return Val.isMinValue();
202 }
203
204 /// This function will return true iff this constant represents a value with
205 /// active bits bigger than 64 bits or a value greater than the given uint64_t
206 /// value.
207 /// @returns true iff this constant is greater or equal to the given number.
208 /// @brief Determine if the value is greater or equal to the given number.
209 bool uge(uint64_t Num) const {
210 return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
211 }
212
213 /// getLimitedValue - If the value is smaller than the specified limit,
214 /// return it, otherwise return the limit value. This causes the value
215 /// to saturate to the limit.
216 /// @returns the min of the value of the constant and the specified value
217 /// @brief Get the constant's value with a saturation limit
218 uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
219 return Val.getLimitedValue(Limit);
220 }
221
222 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
223 static bool classof(const Value *V) {
224 return V->getValueID() == ConstantIntVal;
225 }
226 };
227
228
229 //===----------------------------------------------------------------------===//
230 /// ConstantFP - Floating Point Values [float, double]
231 ///
232 class ConstantFP : public Constant {
233 APFloat Val;
234 virtual void anchor();
235 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
236 ConstantFP(const ConstantFP &) LLVM_DELETED_FUNCTION;
237 friend class LLVMContextImpl;
238 protected:
239 ConstantFP(Type *Ty, const APFloat& V);
240 protected:
241 // allocate space for exactly zero operands
242 void *operator new(size_t s) {
243 return User::operator new(s, 0);
244 }
245 public:
246 /// Floating point negation must be implemented with f(x) = -0.0 - x. This
247 /// method returns the negative zero constant for floating point or vector
248 /// floating point types; for all other types, it returns the null value.
249 static Constant *getZeroValueForNegation(Type *Ty);
250
251 /// get() - This returns a ConstantFP, or a vector containing a splat of a
252 /// ConstantFP, for the specified value in the specified type. This should
253 /// only be used for simple constant values like 2.0/1.0 etc, that are
254 /// known-valid both as host double and as the target format.
255 static Constant *get(Type* Ty, double V);
256 static Constant *get(Type* Ty, StringRef Str);
257 static ConstantFP *get(LLVMContext &Context, const APFloat &V);
258 static ConstantFP *getNegativeZero(Type* Ty);
259 static ConstantFP *getInfinity(Type *Ty, bool Negative = false);
260
261 /// isValueValidForType - return true if Ty is big enough to represent V.
262 static bool isValueValidForType(Type *Ty, const APFloat &V);
263 inline const APFloat &getValueAPF() const { return Val; }
264
265 /// isZero - Return true if the value is positive or negative zero.
266 bool isZero() const { return Val.isZero(); }
267
268 /// isNegative - Return true if the sign bit is set.
269 bool isNegative() const { return Val.isNegative(); }
270
271 /// isNaN - Return true if the value is a NaN.
272 bool isNaN() const { return Val.isNaN(); }
273
274 /// isExactlyValue - We don't rely on operator== working on double values, as
275 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
276 /// As such, this method can be used to do an exact bit-for-bit comparison of
277 /// two floating point values. The version with a double operand is retained
278 /// because it's so convenient to write isExactlyValue(2.0), but please use
279 /// it only for simple constants.
280 bool isExactlyValue(const APFloat &V) const;
281
282 bool isExactlyValue(double V) const {
283 bool ignored;
284 APFloat FV(V);
285 FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
286 return isExactlyValue(FV);
287 }
288 /// Methods for support type inquiry through isa, cast, and dyn_cast:
289 static bool classof(const Value *V) {
290 return V->getValueID() == ConstantFPVal;
291 }
292 };
293
294 //===----------------------------------------------------------------------===//
295 /// ConstantAggregateZero - All zero aggregate value
296 ///
297 class ConstantAggregateZero : public Constant {
298 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
299 ConstantAggregateZero(const ConstantAggregateZero &) LLVM_DELETED_FUNCTION;
300 protected:
301 explicit ConstantAggregateZero(Type *ty)
302 : Constant(ty, ConstantAggregateZeroVal, 0, 0) {}
303 protected:
304 // allocate space for exactly zero operands
305 void *operator new(size_t s) {
306 return User::operator new(s, 0);
307 }
308 public:
309 static ConstantAggregateZero *get(Type *Ty);
310
311 virtual void destroyConstant();
312
313 /// getSequentialElement - If this CAZ has array or vector type, return a zero
314 /// with the right element type.
315 Constant *getSequentialElement() const;
316
317 /// getStructElement - If this CAZ has struct type, return a zero with the
318 /// right element type for the specified element.
319 Constant *getStructElement(unsigned Elt) const;
320
321 /// getElementValue - Return a zero of the right value for the specified GEP
322 /// index.
323 Constant *getElementValue(Constant *C) const;
324
325 /// getElementValue - Return a zero of the right value for the specified GEP
326 /// index.
327 Constant *getElementValue(unsigned Idx) const;
328
329 /// Methods for support type inquiry through isa, cast, and dyn_cast:
330 ///
331 static bool classof(const Value *V) {
332 return V->getValueID() == ConstantAggregateZeroVal;
333 }
334 };
335
336
337 //===----------------------------------------------------------------------===//
338 /// ConstantArray - Constant Array Declarations
339 ///
340 class ConstantArray : public Constant {
341 friend struct ConstantArrayCreator;
342 ConstantArray(const ConstantArray &) LLVM_DELETED_FUNCTION;
343 protected:
344 ConstantArray(ArrayType *T, ArrayRef Val);
345 public:
346 // ConstantArray accessors
347 static Constant *get(ArrayType *T, ArrayRef V);
348
349 /// Transparently provide more efficient getOperand methods.
350 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
351
352 /// getType - Specialize the getType() method to always return an ArrayType,
353 /// which reduces the amount of casting needed in parts of the compiler.
354 ///
355 inline ArrayType *getType() const {
356 return reinterpret_cast(Value::getType());
357 }
358
359 virtual void destroyConstant();
360 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
361
362 /// Methods for support type inquiry through isa, cast, and dyn_cast:
363 static bool classof(const Value *V) {
364 return V->getValueID() == ConstantArrayVal;
365 }
366 };
367
368 template <>
369 struct OperandTraits :
370 public VariadicOperandTraits {
371 };
372
373 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Constant)
374
375 //===----------------------------------------------------------------------===//
376 // ConstantStruct - Constant Struct Declarations
377 //
378 class ConstantStruct : public Constant {
379 friend struct ConstantArrayCreator;
380 ConstantStruct(const ConstantStruct &) LLVM_DELETED_FUNCTION;
381 protected:
382 ConstantStruct(StructType *T, ArrayRef Val);
383 public:
384 // ConstantStruct accessors
385 static Constant *get(StructType *T, ArrayRef V);
386 static Constant *get(StructType *T, ...) END_WITH_NULL;
387
388 /// getAnon - Return an anonymous struct that has the specified
389 /// elements. If the struct is possibly empty, then you must specify a
390 /// context.
391 static Constant *getAnon(ArrayRef V, bool Packed = false) {
392 return get(getTypeForElements(V, Packed), V);
393 }
394 static Constant *getAnon(LLVMContext &Ctx,
395 ArrayRef V, bool Packed = false) {
396 return get(getTypeForElements(Ctx, V, Packed), V);
397 }
398
399 /// getTypeForElements - Return an anonymous struct type to use for a constant
400 /// with the specified set of elements. The list must not be empty.
401 static StructType *getTypeForElements(ArrayRef V,
402 bool Packed = false);
403 /// getTypeForElements - This version of the method allows an empty list.
404 static StructType *getTypeForElements(LLVMContext &Ctx,
405 ArrayRef V,
406 bool Packed = false);
407
408 /// Transparently provide more efficient getOperand methods.
409 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
410
411 /// getType() specialization - Reduce amount of casting...
412 ///
413 inline StructType *getType() const {
414 return reinterpret_cast(Value::getType());
415 }
416
417 virtual void destroyConstant();
418 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
419
420 /// Methods for support type inquiry through isa, cast, and dyn_cast:
421 static bool classof(const Value *V) {
422 return V->getValueID() == ConstantStructVal;
423 }
424 };
425
426 template <>
427 struct OperandTraits :
428 public VariadicOperandTraits {
429 };
430
431 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Constant)
432
433
434 //===----------------------------------------------------------------------===//
435 /// ConstantVector - Constant Vector Declarations
436 ///
437 class ConstantVector : public Constant {
438 friend struct ConstantArrayCreator;
439 ConstantVector(const ConstantVector &) LLVM_DELETED_FUNCTION;
440 protected:
441 ConstantVector(VectorType *T, ArrayRef Val);
442 public:
443 // ConstantVector accessors
444 static Constant *get(ArrayRef V);
445
446 /// getSplat - Return a ConstantVector with the specified constant in each
447 /// element.
448 static Constant *getSplat(unsigned NumElts, Constant *Elt);
449
450 /// Transparently provide more efficient getOperand methods.
451 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
452
453 /// getType - Specialize the getType() method to always return a VectorType,
454 /// which reduces the amount of casting needed in parts of the compiler.
455 ///
456 inline VectorType *getType() const {
457 return reinterpret_cast(Value::getType());
458 }
459
460 /// getSplatValue - If this is a splat constant, meaning that all of the
461 /// elements have the same value, return that value. Otherwise return NULL.
462 Constant *getSplatValue() const;
463
464 virtual void destroyConstant();
465 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
466
467 /// Methods for support type inquiry through isa, cast, and dyn_cast:
468 static bool classof(const Value *V) {
469 return V->getValueID() == ConstantVectorVal;
470 }
471 };
472
473 template <>
474 struct OperandTraits :
475 public VariadicOperandTraits {
476 };
477
478 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Constant)
479
480 //===----------------------------------------------------------------------===//
481 /// ConstantPointerNull - a constant pointer value that points to null
482 ///
483 class ConstantPointerNull : public Constant {
484 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
485 ConstantPointerNull(const ConstantPointerNull &) LLVM_DELETED_FUNCTION;
486 protected:
487 explicit ConstantPointerNull(PointerType *T)
488 : Constant(reinterpret_cast(T),
489 Value::ConstantPointerNullVal, 0, 0) {}
490
491 protected:
492 // allocate space for exactly zero operands
493 void *operator new(size_t s) {
494 return User::operator new(s, 0);
495 }
496 public:
497 /// get() - Static factory methods - Return objects of the specified value
498 static ConstantPointerNull *get(PointerType *T);
499
500 virtual void destroyConstant();
501
502 /// getType - Specialize the getType() method to always return an PointerType,
503 /// which reduces the amount of casting needed in parts of the compiler.
504 ///
505 inline PointerType *getType() const {
506 return reinterpret_cast(Value::getType());
507 }
508
509 /// Methods for support type inquiry through isa, cast, and dyn_cast:
510 static bool classof(const Value *V) {
511 return V->getValueID() == ConstantPointerNullVal;
512 }
513 };
514
515 //===----------------------------------------------------------------------===//
516 /// ConstantDataSequential - A vector or array constant whose element type is a
517 /// simple 1/2/4/8-byte integer or float/double, and whose elements are just
518 /// simple data values (i.e. ConstantInt/ConstantFP). This Constant node has no
519 /// operands because it stores all of the elements of the constant as densely
520 /// packed data, instead of as Value*'s.
521 ///
522 /// This is the common base class of ConstantDataArray and ConstantDataVector.
523 ///
524 class ConstantDataSequential : public Constant {
525 friend class LLVMContextImpl;
526 /// DataElements - A pointer to the bytes underlying this constant (which is
527 /// owned by the uniquing StringMap).
528 const char *DataElements;
529
530 /// Next - This forms a link list of ConstantDataSequential nodes that have
531 /// the same value but different type. For example, 0,0,0,1 could be a 4
532 /// element array of i8, or a 1-element array of i32. They'll both end up in
533 /// the same StringMap bucket, linked up.
534 ConstantDataSequential *Next;
535 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
536 ConstantDataSequential(const ConstantDataSequential &) LLVM_DELETED_FUNCTION;
537 protected:
538 explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
539 : Constant(ty, VT, 0, 0), DataElements(Data), Next(0) {}
540 ~ConstantDataSequential() { delete Next; }
541
542 static Constant *getImpl(StringRef Bytes, Type *Ty);
543
544 protected:
545 // allocate space for exactly zero operands.
546 void *operator new(size_t s) {
547 return User::operator new(s, 0);
548 }
549 public:
550
551 /// isElementTypeCompatible - Return true if a ConstantDataSequential can be
552 /// formed with a vector or array of the specified element type.
553 /// ConstantDataArray only works with normal float and int types that are
554 /// stored densely in memory, not with things like i42 or x86_f80.
555 static bool isElementTypeCompatible(const Type *Ty);
556
557 /// getElementAsInteger - If this is a sequential container of integers (of
558 /// any size), return the specified element in the low bits of a uint64_t.
559 uint64_t getElementAsInteger(unsigned i) const;
560
561 /// getElementAsAPFloat - If this is a sequential container of floating point
562 /// type, return the specified element as an APFloat.
563 APFloat getElementAsAPFloat(unsigned i) const;
564
565 /// getElementAsFloat - If this is an sequential container of floats, return
566 /// the specified element as a float.
567 float getElementAsFloat(unsigned i) const;
568
569 /// getElementAsDouble - If this is an sequential container of doubles, return
570 /// the specified element as a double.
571 double getElementAsDouble(unsigned i) const;
572
573 /// getElementAsConstant - Return a Constant for a specified index's element.
574 /// Note that this has to compute a new constant to return, so it isn't as
575 /// efficient as getElementAsInteger/Float/Double.
576 Constant *getElementAsConstant(unsigned i) const;
577
578 /// getType - Specialize the getType() method to always return a
579 /// SequentialType, which reduces the amount of casting needed in parts of the
580 /// compiler.
581 inline SequentialType *getType() const {
582 return reinterpret_cast(Value::getType());
583 }
584
585 /// getElementType - Return the element type of the array/vector.
586 Type *getElementType() const;
587
588 /// getNumElements - Return the number of elements in the array or vector.
589 unsigned getNumElements() const;
590
591 /// getElementByteSize - Return the size (in bytes) of each element in the
592 /// array/vector. The size of the elements is known to be a multiple of one
593 /// byte.
594 uint64_t getElementByteSize() const;
595
596
597 /// isString - This method returns true if this is an array of i8.
598 bool isString() const;
599
600 /// isCString - This method returns true if the array "isString", ends with a
601 /// nul byte, and does not contains any other nul bytes.
602 bool isCString() const;
603
604 /// getAsString - If this array is isString(), then this method returns the
605 /// array as a StringRef. Otherwise, it asserts out.
606 ///
607 StringRef getAsString() const {
608 assert(isString() && "Not a string");
609 return getRawDataValues();
610 }
611
612 /// getAsCString - If this array is isCString(), then this method returns the
613 /// array (without the trailing null byte) as a StringRef. Otherwise, it
614 /// asserts out.
615 ///
616 StringRef getAsCString() const {
617 assert(isCString() && "Isn't a C string");
618 StringRef Str = getAsString();
619 return Str.substr(0, Str.size()-1);
620 }
621
622 /// getRawDataValues - Return the raw, underlying, bytes of this data. Note
623 /// that this is an extremely tricky thing to work with, as it exposes the
624 /// host endianness of the data elements.
625 StringRef getRawDataValues() const;
626
627 virtual void destroyConstant();
628
629 /// Methods for support type inquiry through isa, cast, and dyn_cast:
630 ///
631 static bool classof(const Value *V) {
632 return V->getValueID() == ConstantDataArrayVal ||
633 V->getValueID() == ConstantDataVectorVal;
634 }
635 private:
636 const char *getElementPointer(unsigned Elt) const;
637 };
638
639 //===----------------------------------------------------------------------===//
640 /// ConstantDataArray - An array constant whose element type is a simple
641 /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
642 /// data values (i.e. ConstantInt/ConstantFP). This Constant node has no
643 /// operands because it stores all of the elements of the constant as densely
644 /// packed data, instead of as Value*'s.
645 class ConstantDataArray : public ConstantDataSequential {
646 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
647 ConstantDataArray(const ConstantDataArray &) LLVM_DELETED_FUNCTION;
648 virtual void anchor();
649 friend class ConstantDataSequential;
650 explicit ConstantDataArray(Type *ty, const char *Data)
651 : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {}
652 protected:
653 // allocate space for exactly zero operands.
654 void *operator new(size_t s) {
655 return User::operator new(s, 0);
656 }
657 public:
658
659 /// get() constructors - Return a constant with array type with an element
660 /// count and element type matching the ArrayRef passed in. Note that this
661 /// can return a ConstantAggregateZero object.
662 static Constant *get(LLVMContext &Context, ArrayRef Elts);
663 static Constant *get(LLVMContext &Context, ArrayRef Elts);
664 static Constant *get(LLVMContext &Context, ArrayRef Elts);
665 static Constant *get(LLVMContext &Context, ArrayRef Elts);
666 static Constant *get(LLVMContext &Context, ArrayRef Elts);
667 static Constant *get(LLVMContext &Context, ArrayRef Elts);
668
669 /// getString - This method constructs a CDS and initializes it with a text
670 /// string. The default behavior (AddNull==true) causes a null terminator to
671 /// be placed at the end of the array (increasing the length of the string by
672 /// one more than the StringRef would normally indicate. Pass AddNull=false
673 /// to disable this behavior.
674 static Constant *getString(LLVMContext &Context, StringRef Initializer,
675 bool AddNull = true);
676
677 /// getType - Specialize the getType() method to always return an ArrayType,
678 /// which reduces the amount of casting needed in parts of the compiler.
679 ///
680 inline ArrayType *getType() const {
681 return reinterpret_cast(Value::getType());
682 }
683
684 /// Methods for support type inquiry through isa, cast, and dyn_cast:
685 ///
686 static bool classof(const Value *V) {
687 return V->getValueID() == ConstantDataArrayVal;
688 }
689 };
690
691 //===----------------------------------------------------------------------===//
692 /// ConstantDataVector - A vector constant whose element type is a simple
693 /// 1/2/4/8-byte integer or float/double, and whose elements are just simple
694 /// data values (i.e. ConstantInt/ConstantFP). This Constant node has no
695 /// operands because it stores all of the elements of the constant as densely
696 /// packed data, instead of as Value*'s.
697 class ConstantDataVector : public ConstantDataSequential {
698 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
699 ConstantDataVector(const ConstantDataVector &) LLVM_DELETED_FUNCTION;
700 virtual void anchor();
701 friend class ConstantDataSequential;
702 explicit ConstantDataVector(Type *ty, const char *Data)
703 : ConstantDataSequential(ty, ConstantDataVectorVal, Data) {}
704 protected:
705 // allocate space for exactly zero operands.
706 void *operator new(size_t s) {
707 return User::operator new(s, 0);
708 }
709 public:
710
711 /// get() constructors - Return a constant with vector type with an element
712 /// count and element type matching the ArrayRef passed in. Note that this
713 /// can return a ConstantAggregateZero object.
714 static Constant *get(LLVMContext &Context, ArrayRef Elts);
715 static Constant *get(LLVMContext &Context, ArrayRef Elts);
716 static Constant *get(LLVMContext &Context, ArrayRef Elts);
717 static Constant *get(LLVMContext &Context, ArrayRef Elts);
718 static Constant *get(LLVMContext &Context, ArrayRef Elts);
719 static Constant *get(LLVMContext &Context, ArrayRef Elts);
720
721 /// getSplat - Return a ConstantVector with the specified constant in each
722 /// element. The specified constant has to be a of a compatible type (i8/i16/
723 /// i32/i64/float/double) and must be a ConstantFP or ConstantInt.
724 static Constant *getSplat(unsigned NumElts, Constant *Elt);
725
726 /// getSplatValue - If this is a splat constant, meaning that all of the
727 /// elements have the same value, return that value. Otherwise return NULL.
728 Constant *getSplatValue() const;
729
730 /// getType - Specialize the getType() method to always return a VectorType,
731 /// which reduces the amount of casting needed in parts of the compiler.
732 ///
733 inline VectorType *getType() const {
734 return reinterpret_cast(Value::getType());
735 }
736
737 /// Methods for support type inquiry through isa, cast, and dyn_cast:
738 ///
739 static bool classof(const Value *V) {
740 return V->getValueID() == ConstantDataVectorVal;
741 }
742 };
743
744
745
746 /// BlockAddress - The address of a basic block.
747 ///
748 class BlockAddress : public Constant {
749 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
750 void *operator new(size_t s) { return User::operator new(s, 2); }
751 BlockAddress(Function *F, BasicBlock *BB);
752 public:
753 /// get - Return a BlockAddress for the specified function and basic block.
754 static BlockAddress *get(Function *F, BasicBlock *BB);
755
756 /// get - Return a BlockAddress for the specified basic block. The basic
757 /// block must be embedded into a function.
758 static BlockAddress *get(BasicBlock *BB);
759
760 /// Transparently provide more efficient getOperand methods.
761 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
762
763 Function *getFunction() const { return (Function*)Op<0>().get(); }
764 BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
765
766 virtual void destroyConstant();
767 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
768
769 /// Methods for support type inquiry through isa, cast, and dyn_cast:
770 static inline bool classof(const Value *V) {
771 return V->getValueID() == BlockAddressVal;
772 }
773 };
774
775 template <>
776 struct OperandTraits :
777 public FixedNumOperandTraits {
778 };
779
780 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value)
781
782
783 //===----------------------------------------------------------------------===//
784 /// ConstantExpr - a constant value that is initialized with an expression using
785 /// other constant values.
786 ///
787 /// This class uses the standard Instruction opcodes to define the various
788 /// constant expressions. The Opcode field for the ConstantExpr class is
789 /// maintained in the Value::SubclassData field.
790 class ConstantExpr : public Constant {
791 friend struct ConstantCreator
792 std::pair > >;
793 friend struct ConvertConstantType;
794
795 protected:
796 ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
797 : Constant(ty, ConstantExprVal, Ops, NumOps) {
798 // Operation type (an Instruction opcode) is stored as the SubclassData.
799 setValueSubclassData(Opcode);
800 }
801
802 public:
803 // Static methods to construct a ConstantExpr of different kinds. Note that
804 // these methods may return a object that is not an instance of the
805 // ConstantExpr class, because they will attempt to fold the constant
806 // expression into something simpler if possible.
807
808 /// getAlignOf constant expr - computes the alignment of a type in a target
809 /// independent way (Note: the return type is an i64).
810 static Constant *getAlignOf(Type *Ty);
811
812 /// getSizeOf constant expr - computes the (alloc) size of a type (in
813 /// address-units, not bits) in a target independent way (Note: the return
814 /// type is an i64).
815 ///
816 static Constant *getSizeOf(Type *Ty);
817
818 /// getOffsetOf constant expr - computes the offset of a struct field in a
819 /// target independent way (Note: the return type is an i64).
820 ///
821 static Constant *getOffsetOf(StructType *STy, unsigned FieldNo);
822
823 /// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
824 /// which supports any aggregate type, and any Constant index.
825 ///
826 static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
827
828 static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false);
829 static Constant *getFNeg(Constant *C);
830 static Constant *getNot(Constant *C);
831 static Constant *getAdd(Constant *C1, Constant *C2,
832 bool HasNUW = false, bool HasNSW = false);
833 static Constant *getFAdd(Constant *C1, Constant *C2);
834 static Constant *getSub(Constant *C1, Constant *C2,
835 bool HasNUW = false, bool HasNSW = false);
836 static Constant *getFSub(Constant *C1, Constant *C2);
837 static Constant *getMul(Constant *C1, Constant *C2,
838 bool HasNUW = false, bool HasNSW = false);
839 static Constant *getFMul(Constant *C1, Constant *C2);
840 static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false);
841 static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false);
842 static Constant *getFDiv(Constant *C1, Constant *C2);
843 static Constant *getURem(Constant *C1, Constant *C2);
844 static Constant *getSRem(Constant *C1, Constant *C2);
845 static Constant *getFRem(Constant *C1, Constant *C2);
846 static Constant *getAnd(Constant *C1, Constant *C2);
847 static Constant *getOr(Constant *C1, Constant *C2);
848 static Constant *getXor(Constant *C1, Constant *C2);
849 static Constant *getShl(Constant *C1, Constant *C2,
850 bool HasNUW = false, bool HasNSW = false);
851 static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
852 static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
853 static Constant *getTrunc (Constant *C, Type *Ty);
854 static Constant *getSExt (Constant *C, Type *Ty);
855 static Constant *getZExt (Constant *C, Type *Ty);
856 static Constant *getFPTrunc (Constant *C, Type *Ty);
857 static Constant *getFPExtend(Constant *C, Type *Ty);
858 static Constant *getUIToFP (Constant *C, Type *Ty);
859 static Constant *getSIToFP (Constant *C, Type *Ty);
860 static Constant *getFPToUI (Constant *C, Type *Ty);
861 static Constant *getFPToSI (Constant *C, Type *Ty);
862 static Constant *getPtrToInt(Constant *C, Type *Ty);
863 static Constant *getIntToPtr(Constant *C, Type *Ty);
864 static Constant *getBitCast (Constant *C, Type *Ty);
865
866 static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); }
867 static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); }
868 static Constant *getNSWAdd(Constant *C1, Constant *C2) {
869 return getAdd(C1, C2, false, true);
870 }
871 static Constant *getNUWAdd(Constant *C1, Constant *C2) {
872 return getAdd(C1, C2, true, false);
873 }
874 static Constant *getNSWSub(Constant *C1, Constant *C2) {
875 return getSub(C1, C2, false, true);
876 }
877 static Constant *getNUWSub(Constant *C1, Constant *C2) {
878 return getSub(C1, C2, true, false);
879 }
880 static Constant *getNSWMul(Constant *C1, Constant *C2) {
881 return getMul(C1, C2, false, true);
882 }
883 static Constant *getNUWMul(Constant *C1, Constant *C2) {
884 return getMul(C1, C2, true, false);
885 }
886 static Constant *getNSWShl(Constant *C1, Constant *C2) {
887 return getShl(C1, C2, false, true);
888 }
889 static Constant *getNUWShl(Constant *C1, Constant *C2) {
890 return getShl(C1, C2, true, false);
891 }
892 static Constant *getExactSDiv(Constant *C1, Constant *C2) {
893 return getSDiv(C1, C2, true);
894 }
895 static Constant *getExactUDiv(Constant *C1, Constant *C2) {
896 return getUDiv(C1, C2, true);
897 }
898 static Constant *getExactAShr(Constant *C1, Constant *C2) {
899 return getAShr(C1, C2, true);
900 }
901 static Constant *getExactLShr(Constant *C1, Constant *C2) {
902 return getLShr(C1, C2, true);
903 }
904
905 /// getBinOpIdentity - Return the identity for the given binary operation,
906 /// i.e. a constant C such that X op C = X and C op X = X for every X. It
907 /// returns null if the operator doesn't have an identity.
908 static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty);
909
910 /// getBinOpAbsorber - Return the absorbing element for the given binary
911 /// operation, i.e. a constant C such that X op C = C and C op X = C for
912 /// every X. For example, this returns zero for integer multiplication.
913 /// It returns null if the operator doesn't have an absorbing element.
914 static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty);
915
916 /// Transparently provide more efficient getOperand methods.
917 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
918
919 // @brief Convenience function for getting one of the casting operations
920 // using a CastOps opcode.
921 static Constant *getCast(
922 unsigned ops, ///< The opcode for the conversion
923 Constant *C, ///< The constant to be converted
924 Type *Ty ///< The type to which the constant is converted
925 );
926
927 // @brief Create a ZExt or BitCast cast constant expression
928 static Constant *getZExtOrBitCast(
929 Constant *C, ///< The constant to zext or bitcast
930 Type *Ty ///< The type to zext or bitcast C to
931 );
932
933 // @brief Create a SExt or BitCast cast constant expression
934 static Constant *getSExtOrBitCast(
935 Constant *C, ///< The constant to sext or bitcast
936 Type *Ty ///< The type to sext or bitcast C to
937 );
938
939 // @brief Create a Trunc or BitCast cast constant expression
940 static Constant *getTruncOrBitCast(
941 Constant *C, ///< The constant to trunc or bitcast
942 Type *Ty ///< The type to trunc or bitcast C to
943 );
944
945 /// @brief Create a BitCast or a PtrToInt cast constant expression
946 static Constant *getPointerCast(
947 Constant *C, ///< The pointer value to be casted (operand 0)
948 Type *Ty ///< The type to which cast should be made
949 );
950
951 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
952 static Constant *getIntegerCast(
953 Constant *C, ///< The integer constant to be casted
954 Type *Ty, ///< The integer type to cast to
955 bool isSigned ///< Whether C should be treated as signed or not
956 );
957
958 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
959 static Constant *getFPCast(
960 Constant *C, ///< The integer constant to be casted
961 Type *Ty ///< The integer type to cast to
962 );
963
964 /// @brief Return true if this is a convert constant expression
965 bool isCast() const;
966
967 /// @brief Return true if this is a compare constant expression
968 bool isCompare() const;
969
970 /// @brief Return true if this is an insertvalue or extractvalue expression,
971 /// and the getIndices() method may be used.
972 bool hasIndices() const;
973
974 /// @brief Return true if this is a getelementptr expression and all
975 /// the index operands are compile-time known integers within the
976 /// corresponding notional static array extents. Note that this is
977 /// not equivalant to, a subset of, or a superset of the "inbounds"
978 /// property.
979 bool isGEPWithNoNotionalOverIndexing() const;
980
981 /// Select constant expr
982 ///
983 static Constant *getSelect(Constant *C, Constant *V1, Constant *V2);
984
985 /// get - Return a binary or shift operator constant expression,
986 /// folding if possible.
987 ///
988 static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
989 unsigned Flags = 0);
990
991 /// @brief Return an ICmp or FCmp comparison operator constant expression.
992 static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
993
994 /// get* - Return some common constants without having to
995 /// specify the full Instruction::OPCODE identifier.
996 ///
997 static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
998 static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
999
1000 /// Getelementptr form. Value* is only accepted for convenience;
1001 /// all elements must be Constant's.
1002 ///
1003 static Constant *getGetElementPtr(Constant *C,
1004 ArrayRef IdxList,
1005 bool InBounds = false) {
1006 return getGetElementPtr(C, makeArrayRef((Value * const *)IdxList.data(),
1007 IdxList.size()),
1008 InBounds);
1009 }
1010 static Constant *getGetElementPtr(Constant *C,
1011 Constant *Idx,
1012 bool InBounds = false) {
1013 // This form of the function only exists to avoid ambiguous overload
1014 // warnings about whether to convert Idx to ArrayRef or
1015 // ArrayRef.
1016 return getGetElementPtr(C, cast(Idx), InBounds);
1017 }
1018 static Constant *getGetElementPtr(Constant *C,
1019 ArrayRef IdxList,
1020 bool InBounds = false);
1021
1022 /// Create an "inbounds" getelementptr. See the documentation for the
1023 /// "inbounds" flag in LangRef.html for details.
1024 static Constant *getInBoundsGetElementPtr(Constant *C,
1025 ArrayRef IdxList) {
1026 return getGetElementPtr(C, IdxList, true);
1027 }
1028 static Constant *getInBoundsGetElementPtr(Constant *C,
1029 Constant *Idx) {
1030 // This form of the function only exists to avoid ambiguous overload
1031 // warnings about whether to convert Idx to ArrayRef or
1032 // ArrayRef.
1033 return getGetElementPtr(C, Idx, true);
1034 }
1035 static Constant *getInBoundsGetElementPtr(Constant *C,
1036 ArrayRef IdxList) {
1037 return getGetElementPtr(C, IdxList, true);
1038 }
1039
1040 static Constant *getExtractElement(Constant *Vec, Constant *Idx);
1041 static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
1042 static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
1043 static Constant *getExtractValue(Constant *Agg, ArrayRef Idxs);
1044 static Constant *getInsertValue(Constant *Agg, Constant *Val,
1045 ArrayRef Idxs);
1046
1047 /// getOpcode - Return the opcode at the root of this constant expression
1048 unsigned getOpcode() const { return getSubclassDataFromValue(); }
1049
1050 /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
1051 /// not an ICMP or FCMP constant expression.
1052 unsigned getPredicate() const;
1053
1054 /// getIndices - Assert that this is an insertvalue or exactvalue
1055 /// expression and return the list of indices.
1056 ArrayRef getIndices() const;
1057
1058 /// getOpcodeName - Return a string representation for an opcode.
1059 const char *getOpcodeName() const;
1060
1061 /// getWithOperandReplaced - Return a constant expression identical to this
1062 /// one, but with the specified operand set to the specified value.
1063 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
1064
1065 /// getWithOperands - This returns the current constant expression with the
1066 /// operands replaced with the specified values. The specified array must
1067 /// have the same number of operands as our current one.
1068 Constant *getWithOperands(ArrayRef Ops) const {
1069 return getWithOperands(Ops, getType());
1070 }
1071
1072 /// getWithOperands - This returns the current constant expression with the
1073 /// operands replaced with the specified values and with the specified result
1074 /// type. The specified array must have the same number of operands as our
1075 /// current one.
1076 Constant *getWithOperands(ArrayRef Ops, Type *Ty) const;
1077
1078 /// getAsInstruction - Returns an Instruction which implements the same operation
1079 /// as this ConstantExpr. The instruction is not linked to any basic block.
1080 ///
1081 /// A better approach to this could be to have a constructor for Instruction
1082 /// which would take a ConstantExpr parameter, but that would have spread
1083 /// implementation details of ConstantExpr outside of Constants.cpp, which
1084 /// would make it harder to remove ConstantExprs altogether.
1085 Instruction *getAsInstruction();
1086
1087 virtual void destroyConstant();
1088 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
1089
1090 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1091 static inline bool classof(const Value *V) {
1092 return V->getValueID() == ConstantExprVal;
1093 }
1094
1095 private:
1096 // Shadow Value::setValueSubclassData with a private forwarding method so that
1097 // subclasses cannot accidentally use it.
1098 void setValueSubclassData(unsigned short D) {
1099 Value::setValueSubclassData(D);
1100 }
1101 };
1102
1103 template <>
1104 struct OperandTraits :
1105 public VariadicOperandTraits {
1106 };
1107
1108 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
1109
1110 //===----------------------------------------------------------------------===//
1111 /// UndefValue - 'undef' values are things that do not have specified contents.
1112 /// These are used for a variety of purposes, including global variable
1113 /// initializers and operands to instructions. 'undef' values can occur with
1114 /// any first-class type.
1115 ///
1116 /// Undef values aren't exactly constants; if they have multiple uses, they
1117 /// can appear to have different bit patterns at each use. See
1118 /// LangRef.html#undefvalues for details.
1119 ///
1120 class UndefValue : public Constant {
1121 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1122 UndefValue(const UndefValue &) LLVM_DELETED_FUNCTION;
1123 protected:
1124 explicit UndefValue(Type *T) : Constant(T, UndefValueVal, 0, 0) {}
1125 protected:
1126 // allocate space for exactly zero operands
1127 void *operator new(size_t s) {
1128 return User::operator new(s, 0);
1129 }
1130 public:
1131 /// get() - Static factory methods - Return an 'undef' object of the specified
1132 /// type.
1133 ///
1134 static UndefValue *get(Type *T);
1135
1136 /// getSequentialElement - If this Undef has array or vector type, return a
1137 /// undef with the right element type.
1138 UndefValue *getSequentialElement() const;
1139
1140 /// getStructElement - If this undef has struct type, return a undef with the
1141 /// right element type for the specified element.
1142 UndefValue *getStructElement(unsigned Elt) const;
1143
1144 /// getElementValue - Return an undef of the right value for the specified GEP
1145 /// index.
1146 UndefValue *getElementValue(Constant *C) const;
1147
1148 /// getElementValue - Return an undef of the right value for the specified GEP
1149 /// index.
1150 UndefValue *getElementValue(unsigned Idx) const;
1151
1152 virtual void destroyConstant();
1153
1154 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1155 static bool classof(const Value *V) {
1156 return V->getValueID() == UndefValueVal;
1157 }
1158 };
1159
1160 } // End llvm namespace
1161
1162 #endif
+0
-427
include/llvm/DataLayout.h less more
None //===--------- llvm/DataLayout.h - Data size & alignment info ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines layout properties related to datatype size/offset/alignment
10 // information. It uses lazy annotations to cache information about how
11 // structure types are laid out and used.
12 //
13 // This structure should be created once, filled in if the defaults are not
14 // correct and then passed around by const&. None of the members functions
15 // require modification to the object.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_DATALAYOUT_H
20 #define LLVM_DATALAYOUT_H
21
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/Pass.h"
25 #include "llvm/Support/DataTypes.h"
26
27 namespace llvm {
28
29 class Value;
30 class Type;
31 class IntegerType;
32 class StructType;
33 class StructLayout;
34 class GlobalVariable;
35 class LLVMContext;
36 template
37 class ArrayRef;
38
39 /// Enum used to categorize the alignment types stored by LayoutAlignElem
40 enum AlignTypeEnum {
41 INVALID_ALIGN = 0, ///< An invalid alignment
42 INTEGER_ALIGN = 'i', ///< Integer type alignment
43 VECTOR_ALIGN = 'v', ///< Vector type alignment
44 FLOAT_ALIGN = 'f', ///< Floating point type alignment
45 AGGREGATE_ALIGN = 'a', ///< Aggregate alignment
46 STACK_ALIGN = 's' ///< Stack objects alignment
47 };
48
49 /// Layout alignment element.
50 ///
51 /// Stores the alignment data associated with a given alignment type (integer,
52 /// vector, float) and type bit width.
53 ///
54 /// @note The unusual order of elements in the structure attempts to reduce
55 /// padding and make the structure slightly more cache friendly.
56 struct LayoutAlignElem {
57 unsigned AlignType : 8; ///< Alignment type (AlignTypeEnum)
58 unsigned TypeBitWidth : 24; ///< Type bit width
59 unsigned ABIAlign : 16; ///< ABI alignment for this type/bitw
60 unsigned PrefAlign : 16; ///< Pref. alignment for this type/bitw
61
62 /// Initializer
63 static LayoutAlignElem get(AlignTypeEnum align_type, unsigned abi_align,
64 unsigned pref_align, uint32_t bit_width);
65 /// Equality predicate
66 bool operator==(const LayoutAlignElem &rhs) const;
67 };
68
69 /// Layout pointer alignment element.
70 ///
71 /// Stores the alignment data associated with a given pointer and address space.
72 ///
73 /// @note The unusual order of elements in the structure attempts to reduce
74 /// padding and make the structure slightly more cache friendly.
75 struct PointerAlignElem {
76 unsigned ABIAlign; ///< ABI alignment for this type/bitw
77 unsigned PrefAlign; ///< Pref. alignment for this type/bitw
78 uint32_t TypeBitWidth; ///< Type bit width
79 uint32_t AddressSpace; ///< Address space for the pointer type
80
81 /// Initializer
82 static PointerAlignElem get(uint32_t addr_space, unsigned abi_align,
83 unsigned pref_align, uint32_t bit_width);
84 /// Equality predicate
85 bool operator==(const PointerAlignElem &rhs) const;
86 };
87
88
89 /// DataLayout - This class holds a parsed version of the target data layout
90 /// string in a module and provides methods for querying it. The target data
91 /// layout string is specified *by the target* - a frontend generating LLVM IR
92 /// is required to generate the right target data for the target being codegen'd
93 /// to. If some measure of portability is desired, an empty string may be
94 /// specified in the module.
95 class DataLayout : public ImmutablePass {
96 private:
97 bool LittleEndian; ///< Defaults to false
98 unsigned StackNaturalAlign; ///< Stack natural alignment
99
100 SmallVector LegalIntWidths; ///< Legal Integers.
101
102 /// Alignments- Where the primitive type alignment data is stored.
103 ///
104 /// @sa init().
105 /// @note Could support multiple size pointer alignments, e.g., 32-bit
106 /// pointers vs. 64-bit pointers by extending LayoutAlignment, but for now,
107 /// we don't.
108 SmallVector Alignments;
109 DenseMap Pointers;
110
111 /// InvalidAlignmentElem - This member is a signal that a requested alignment
112 /// type and bit width were not found in the SmallVector.
113 static const LayoutAlignElem InvalidAlignmentElem;
114
115 /// InvalidPointerElem - This member is a signal that a requested pointer
116 /// type and bit width were not found in the DenseSet.
117 static const PointerAlignElem InvalidPointerElem;
118
119 // The StructType -> StructLayout map.
120 mutable void *LayoutMap;
121
122 //! Set/initialize target alignments
123 void setAlignment(AlignTypeEnum align_type, unsigned abi_align,
124 unsigned pref_align, uint32_t bit_width);
125 unsigned getAlignmentInfo(AlignTypeEnum align_type, uint32_t bit_width,
126 bool ABIAlign, Type *Ty) const;
127
128 //! Set/initialize pointer alignments
129 void setPointerAlignment(uint32_t addr_space, unsigned abi_align,
130 unsigned pref_align, uint32_t bit_width);
131
132 //! Internal helper method that returns requested alignment for type.
133 unsigned getAlignment(Type *Ty, bool abi_or_pref) const;
134
135 /// Valid alignment predicate.
136 ///
137 /// Predicate that tests a LayoutAlignElem reference returned by get() against
138 /// InvalidAlignmentElem.
139 bool validAlignment(const LayoutAlignElem &align) const {
140 return &align != &InvalidAlignmentElem;
141 }
142
143 /// Valid pointer predicate.
144 ///
145 /// Predicate that tests a PointerAlignElem reference returned by get() against
146 /// InvalidPointerElem.
147 bool validPointer(const PointerAlignElem &align) const {
148 return &align != &InvalidPointerElem;
149 }
150
151 /// Parses a target data specification string. Assert if the string is
152 /// malformed.
153 void parseSpecifier(StringRef LayoutDescription);
154
155 public:
156 /// Default ctor.
157 ///
158 /// @note This has to exist, because this is a pass, but it should never be
159 /// used.
160 DataLayout();
161
162 /// Constructs a DataLayout from a specification string. See init().
163 explicit DataLayout(StringRef LayoutDescription)
164 : ImmutablePass(ID) {
165 init(LayoutDescription);
166 }
167
168 /// Initialize target data from properties stored in the module.
169 explicit DataLayout(const Module *M);
170
171 DataLayout(const DataLayout &TD) :
172 ImmutablePass(ID),
173 LittleEndian(TD.isLittleEndian()),
174 LegalIntWidths(TD.LegalIntWidths),
175 Alignments(TD.Alignments),
176 Pointers(TD.Pointers),
177 LayoutMap(0)
178 { }
179
180 ~DataLayout(); // Not virtual, do not subclass this class
181
182 /// Parse a data layout string (with fallback to default values). Ensure that
183 /// the data layout pass is registered.
184 void init(StringRef LayoutDescription);
185
186 /// Layout endianness...
187 bool isLittleEndian() const { return LittleEndian; }
188 bool isBigEndian() const { return !LittleEndian; }
189
190 /// getStringRepresentation - Return the string representation of the
191 /// DataLayout. This representation is in the same format accepted by the
192 /// string constructor above.
193 std::string getStringRepresentation() const;
194
195 /// isLegalInteger - This function returns true if the specified type is
196 /// known to be a native integer type supported by the CPU. For example,
197 /// i64 is not native on most 32-bit CPUs and i37 is not native on any known
198 /// one. This returns false if the integer width is not legal.
199 ///
200 /// The width is specified in bits.
201 ///
202 bool isLegalInteger(unsigned Width) const {
203 for (unsigned i = 0, e = (unsigned)LegalIntWidths.size(); i != e; ++i)
204 if (LegalIntWidths[i] == Width)
205 return true;
206 return false;
207 }
208
209 bool isIllegalInteger(unsigned Width) const {
210 return !isLegalInteger(Width);
211 }
212
213 /// Returns true if the given alignment exceeds the natural stack alignment.
214 bool exceedsNaturalStackAlignment(unsigned Align) const {
215 return (StackNaturalAlign != 0) && (Align > StackNaturalAlign);
216 }
217
218 /// fitsInLegalInteger - This function returns true if the specified type fits
219 /// in a native integer type supported by the CPU. For example, if the CPU
220 /// only supports i32 as a native integer type, then i27 fits in a legal
221 // integer type but i45 does not.
222 bool fitsInLegalInteger(unsigned Width) const {
223 for (unsigned i = 0, e = (unsigned)LegalIntWidths.size(); i != e; ++i)
224 if (Width <= LegalIntWidths[i])
225 return true;
226 return false;
227 }
228
229 /// Layout pointer alignment
230 /// FIXME: The defaults need to be removed once all of
231 /// the backends/clients are updated.
232 unsigned getPointerABIAlignment(unsigned AS = 0) const {
233 DenseMap::const_iterator val = Pointers.find(AS);
234 if (val == Pointers.end()) {
235 val = Pointers.find(0);
236 }
237 return val->second.ABIAlign;
238 }
239 /// Return target's alignment for stack-based pointers
240 /// FIXME: The defaults need to be removed once all of
241 /// the backends/clients are updated.
242 unsigned getPointerPrefAlignment(unsigned AS = 0) const {
243 DenseMap::const_iterator val = Pointers.find(AS);
244 if (val == Pointers.end()) {
245 val = Pointers.find(0);
246 }
247 return val->second.PrefAlign;
248 }
249 /// Layout pointer size
250 /// FIXME: The defaults need to be removed once all of
251 /// the backends/clients are updated.
252 unsigned getPointerSize(unsigned AS = 0) const {
253 DenseMap::const_iterator val = Pointers.find(AS);
254 if (val == Pointers.end()) {
255 val = Pointers.find(0);
256 }
257 return val->second.TypeBitWidth;
258 }
259 /// Layout pointer size, in bits
260 /// FIXME: The defaults need to be removed once all of
261 /// the backends/clients are updated.
262 unsigned getPointerSizeInBits(unsigned AS = 0) const {
263 return getPointerSize(AS) * 8;
264 }
265 /// Size examples:
266 ///
267 /// Type SizeInBits StoreSizeInBits AllocSizeInBits[*]
268 /// ---- ---------- --------------- ---------------
269 /// i1 1 8 8
270 /// i8 8 8 8
271 /// i19 19 24 32
272 /// i32 32 32 32
273 /// i100 100 104 128
274 /// i128 128 128 128
275 /// Float 32 32 32
276 /// Double 64 64 64
277 /// X86_FP80 80 80 96
278 ///
279 /// [*] The alloc size depends on the alignment, and thus on the target.
280 /// These values are for x86-32 linux.
281
282 /// getTypeSizeInBits - Return the number of bits necessary to hold the
283 /// specified type. For example, returns 36 for i36 and 80 for x86_fp80.
284 /// The type passed must have a size (Type::isSized() must return true).
285 uint64_t getTypeSizeInBits(Type* Ty) const;
286
287 /// getTypeStoreSize - Return the maximum number of bytes that may be
288 /// overwritten by storing the specified type. For example, returns 5
289 /// for i36 and 10 for x86_fp80.
290 uint64_t getTypeStoreSize(Type *Ty) const {
291 return (getTypeSizeInBits(Ty)+7)/8;
292 }
293
294 /// getTypeStoreSizeInBits - Return the maximum number of bits that may be
295 /// overwritten by storing the specified type; always a multiple of 8. For
296 /// example, returns 40 for i36 and 80 for x86_fp80.
297 uint64_t getTypeStoreSizeInBits(Type *Ty) const {
298 return 8*getTypeStoreSize(Ty);
299 }
300
301 /// getTypeAllocSize - Return the offset in bytes between successive objects
302 /// of the specified type, including alignment padding. This is the amount
303 /// that alloca reserves for this type. For example, returns 12 or 16 for
304 /// x86_fp80, depending on alignment.
305 uint64_t getTypeAllocSize(Type* Ty) const {
306 // Round up to the next alignment boundary.
307 return RoundUpAlignment(getTypeStoreSize(Ty), getABITypeAlignment(Ty));
308 }
309
310 /// getTypeAllocSizeInBits - Return the offset in bits between successive
311 /// objects of the specified type, including alignment padding; always a
312 /// multiple of 8. This is the amount that alloca reserves for this type.
313 /// For example, returns 96 or 128 for x86_fp80, depending on alignment.
314 uint64_t getTypeAllocSizeInBits(Type* Ty) const {
315 return 8*getTypeAllocSize(Ty);
316 }
317
318 /// getABITypeAlignment - Return the minimum ABI-required alignment for the
319 /// specified type.
320 unsigned getABITypeAlignment(Type *Ty) const;
321
322 /// getABIIntegerTypeAlignment - Return the minimum ABI-required alignment for
323 /// an integer type of the specified bitwidth.
324 unsigned getABIIntegerTypeAlignment(unsigned BitWidth) const;
325
326
327 /// getCallFrameTypeAlignment - Return the minimum ABI-required alignment
328 /// for the specified type when it is part of a call frame.
329 unsigned getCallFrameTypeAlignment(Type *Ty) const;
330
331
332 /// getPrefTypeAlignment - Return the preferred stack/global alignment for
333 /// the specified type. This is always at least as good as the ABI alignment.
334 unsigned getPrefTypeAlignment(Type *Ty) const;
335
336 /// getPreferredTypeAlignmentShift - Return the preferred alignment for the
337 /// specified type, returned as log2 of the value (a shift amount).
338 ///
339 unsigned getPreferredTypeAlignmentShift(Type *Ty) const;
340
341 /// getIntPtrType - Return an integer type with size at least as big as that
342 /// of a pointer in the given address space.
343 IntegerType *getIntPtrType(LLVMContext &C, unsigned AddressSpace = 0) const;
344
345 /// getIntPtrType - Return an integer (vector of integer) type with size at
346 /// least as big as that of a pointer of the given pointer (vector of pointer)
347 /// type.
348 Type *getIntPtrType(Type *) const;
349
350 /// getIndexedOffset - return the offset from the beginning of the type for
351 /// the specified indices. This is used to implement getelementptr.
352 ///
353 uint64_t getIndexedOffset(Type *Ty, ArrayRef Indices) const;
354
355 /// getStructLayout - Return a StructLayout object, indicating the alignment
356 /// of the struct, its size, and the offsets of its fields. Note that this
357 /// information is lazily cached.
358 const StructLayout *getStructLayout(StructType *Ty) const;
359
360 /// getPreferredAlignment - Return the preferred alignment of the specified
361 /// global. This includes an explicitly requested alignment (if the global
362 /// has one).
363 unsigned getPreferredAlignment(const GlobalVariable *GV) const;
364
365 /// getPreferredAlignmentLog - Return the preferred alignment of the
366 /// specified global, returned in log form. This includes an explicitly
367 /// requested alignment (if the global has one).
368 unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const;
369
370 /// RoundUpAlignment - Round the specified value up to the next alignment
371 /// boundary specified by Alignment. For example, 7 rounded up to an
372 /// alignment boundary of 4 is 8. 8 rounded up to the alignment boundary of 4
373 /// is 8 because it is already aligned.
374 template
375 static UIntTy RoundUpAlignment(UIntTy Val, unsigned Alignment) {
376 assert((Alignment & (Alignment-1)) == 0 && "Alignment must be power of 2!");
377 return (Val + (Alignment-1)) & ~UIntTy(Alignment-1);
378 }
379
380 static char ID; // Pass identification, replacement for typeid
381 };
382
383 /// StructLayout - used to lazily calculate structure layout information for a
384 /// target machine, based on the DataLayout structure.
385 ///
386 class StructLayout {
387 uint64_t StructSize;
388 unsigned StructAlignment;
389 unsigned NumElements;
390 uint64_t MemberOffsets[1]; // variable sized array!
391 public:
392
393 uint64_t getSizeInBytes() const {
394 return StructSize;
395 }
396
397 uint64_t getSizeInBits() const {
398 return 8*StructSize;
399 }
400
401 unsigned getAlignment() const {
402 return StructAlignment;
403 }
404
405 /// getElementContainingOffset - Given a valid byte offset into the structure,
406 /// return the structure index that contains it.
407 ///
408 unsigned getElementContainingOffset(uint64_t Offset) const;
409
410 uint64_t getElementOffset(unsigned Idx) const {
411 assert(Idx < NumElements && "Invalid element idx!");
412 return MemberOffsets[Idx];
413 }
414
415 uint64_t getElementOffsetInBits(unsigned Idx) const {
416 return getElementOffset(Idx)*8;
417 }
418
419 private:
420 friend class DataLayout; // Only DataLayout can create this class
421 StructLayout(StructType *ST, const DataLayout &TD);
422 };
423
424 } // End llvm namespace
425
426 #endif
+0
-455
include/llvm/DerivedTypes.h less more
None //===-- llvm/DerivedTypes.h - Classes for handling data types ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the declarations of classes that represent "derived
10 // types". These are things like "arrays of x" or "structure of x, y, z" or
11 // "function returning x taking (y,z) as parameters", etc...
12 //
13 // The implementations of these classes live in the Type.cpp file.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_DERIVED_TYPES_H
18 #define LLVM_DERIVED_TYPES_H
19
20 #include "llvm/Support/Compiler.h"
21 #include "llvm/Support/DataTypes.h"
22 #include "llvm/Type.h"
23
24 namespace llvm {
25
26 class Value;
27 class APInt;
28 class LLVMContext;
29 template class ArrayRef;
30 class StringRef;
31
32 /// Class to represent integer types. Note that this class is also used to
33 /// represent the built-in integer types: Int1Ty, Int8Ty, Int16Ty, Int32Ty and
34 /// Int64Ty.
35 /// @brief Integer representation type
36 class IntegerType : public Type {
37 friend class LLVMContextImpl;
38
39 protected:
40 explicit IntegerType(LLVMContext &C, unsigned NumBits) : Type(C, IntegerTyID){
41 setSubclassData(NumBits);
42 }
43 public:
44 /// This enum is just used to hold constants we need for IntegerType.
45 enum {
46 MIN_INT_BITS = 1, ///< Minimum number of bits that can be specified
47 MAX_INT_BITS = (1<<23)-1 ///< Maximum number of bits that can be specified
48 ///< Note that bit width is stored in the Type classes SubclassData field
49 ///< which has 23 bits. This yields a maximum bit width of 8,388,607 bits.
50 };
51
52 /// This static method is the primary way of constructing an IntegerType.
53 /// If an IntegerType with the same NumBits value was previously instantiated,
54 /// that instance will be returned. Otherwise a new one will be created. Only
55 /// one instance with a given NumBits value is ever created.
56 /// @brief Get or create an IntegerType instance.
57 static IntegerType *get(LLVMContext &C, unsigned NumBits);
58
59 /// @brief Get the number of bits in this IntegerType
60 unsigned getBitWidth() const { return getSubclassData(); }
61
62 /// getBitMask - Return a bitmask with ones set for all of the bits
63 /// that can be set by an unsigned version of this type. This is 0xFF for
64 /// i8, 0xFFFF for i16, etc.
65 uint64_t getBitMask() const {
66 return ~uint64_t(0UL) >> (64-getBitWidth());
67 }
68
69 /// getSignBit - Return a uint64_t with just the most significant bit set (the
70 /// sign bit, if the value is treated as a signed number).
71 uint64_t getSignBit() const {
72 return 1ULL << (getBitWidth()-1);
73 }
74
75 /// For example, this is 0xFF for an 8 bit integer, 0xFFFF for i16, etc.
76 /// @returns a bit mask with ones set for all the bits of this type.
77 /// @brief Get a bit mask for this type.
78 APInt getMask() const;
79
80 /// This method determines if the width of this IntegerType is a power-of-2
81 /// in terms of 8 bit bytes.
82 /// @returns true if this is a power-of-2 byte width.
83 /// @brief Is this a power-of-2 byte-width IntegerType ?
84 bool isPowerOf2ByteWidth() const;
85
86 // Methods for support type inquiry through isa, cast, and dyn_cast.
87 static inline bool classof(const Type *T) {
88 return T->getTypeID() == IntegerTyID;
89 }
90 };
91
92
93 /// FunctionType - Class to represent function types
94 ///
95 class FunctionType : public Type {
96 FunctionType(const FunctionType &) LLVM_DELETED_FUNCTION;
97 const FunctionType &operator=(const FunctionType &) LLVM_DELETED_FUNCTION;
98 FunctionType(Type *Result, ArrayRef Params, bool IsVarArgs);
99
100 public:
101 /// FunctionType::get - This static method is the primary way of constructing
102 /// a FunctionType.
103 ///
104 static FunctionType *get(Type *Result,
105 ArrayRef Params, bool isVarArg);
106
107 /// FunctionType::get - Create a FunctionType taking no parameters.
108 ///
109 static FunctionType *get(Type *Result, bool isVarArg);
110
111 /// isValidReturnType - Return true if the specified type is valid as a return
112 /// type.
113 static bool isValidReturnType(Type *RetTy);
114
115 /// isValidArgumentType - Return true if the specified type is valid as an
116 /// argument type.
117 static bool isValidArgumentType(Type *ArgTy);
118
119 bool isVarArg() const { return getSubclassData(); }
120 Type *getReturnType() const { return ContainedTys[0]; }
121
122 typedef Type::subtype_iterator param_iterator;
123 param_iterator param_begin() const { return ContainedTys + 1; }
124 param_iterator param_end() const { return &ContainedTys[NumContainedTys]; }
125
126 // Parameter type accessors.
127 Type *getParamType(unsigned i) const { return ContainedTys[i+1]; }
128
129 /// getNumParams - Return the number of fixed parameters this function type
130 /// requires. This does not consider varargs.
131 ///
132 unsigned getNumParams() const { return NumContainedTys - 1; }
133
134 // Methods for support type inquiry through isa, cast, and dyn_cast.
135 static inline bool classof(const Type *T) {
136 return T->getTypeID() == FunctionTyID;
137 }
138 };
139
140
141 /// CompositeType - Common super class of ArrayType, StructType, PointerType
142 /// and VectorType.
143 class CompositeType : public Type {
144 protected:
145 explicit CompositeType(LLVMContext &C, TypeID tid) : Type(C, tid) { }
146 public:
147
148 /// getTypeAtIndex - Given an index value into the type, return the type of
149 /// the element.
150 ///
151 Type *getTypeAtIndex(const Value *V);
152 Type *getTypeAtIndex(unsigned Idx);
153 bool indexValid(const Value *V) const;
154 bool indexValid(unsigned Idx) const;
155
156 // Methods for support type inquiry through isa, cast, and dyn_cast.
157 static inline bool classof(const Type *T) {
158 return T->getTypeID() == ArrayTyID ||
159 T->getTypeID() == StructTyID ||
160 T->getTypeID() == PointerTyID ||
161 T->getTypeID() == VectorTyID;
162 }
163 };
164
165
166 /// StructType - Class to represent struct types. There are two different kinds
167 /// of struct types: Literal structs and Identified structs.
168 ///
169 /// Literal struct types (e.g. { i32, i32 }) are uniqued structurally, and must
170 /// always have a body when created. You can get one of these by using one of
171 /// the StructType::get() forms.
172 ///
173 /// Identified structs (e.g. %foo or %42) may optionally have a name and are not
174 /// uniqued. The names for identified structs are managed at the LLVMContext
175 /// level, so there can only be a single identified struct with a given name in
176 /// a particular LLVMContext. Identified structs may also optionally be opaque
177 /// (have no body specified). You get one of these by using one of the
178 /// StructType::create() forms.
179 ///
180 /// Independent of what kind of struct you have, the body of a struct type are
181 /// laid out in memory consequtively with the elements directly one after the
182 /// other (if the struct is packed) or (if not packed) with padding between the
183 /// elements as defined by DataLayout (which is required to match what the code
184 /// generator for a target expects).
185 ///
186 class StructType : public CompositeType {
187 StructType(const StructType &) LLVM_DELETED_FUNCTION;
188 const StructType &operator=(const StructType &) LLVM_DELETED_FUNCTION;
189 StructType(LLVMContext &C)
190 : CompositeType(C, StructTyID), SymbolTableEntry(0) {}
191 enum {
192 // This is the contents of the SubClassData field.
193 SCDB_HasBody = 1,
194 SCDB_Packed = 2,
195 SCDB_IsLiteral = 4,
196 SCDB_IsSized = 8
197 };
198
199 /// SymbolTableEntry - For a named struct that actually has a name, this is a
200 /// pointer to the symbol table entry (maintained by LLVMContext) for the
201 /// struct. This is null if the type is an literal struct or if it is
202 /// a identified type that has an empty name.
203 ///
204 void *SymbolTableEntry;
205 public:
206 ~StructType() {
207 delete [] ContainedTys; // Delete the body.
208 }
209
210 /// StructType::create - This creates an identified struct.
211 static StructType *create(LLVMContext &Context, StringRef Name);
212 static StructType *create(LLVMContext &Context);
213
214 static StructType *create(ArrayRef Elements,
215 StringRef Name,
216 bool isPacked = false);
217 static StructType *create(ArrayRef Elements);
218 static StructType *create(LLVMContext &Context,
219 ArrayRef Elements,
220 StringRef Name,
221 bool isPacked = false);
222 static StructType *create(LLVMContext &Context, ArrayRef Elements);
223 static StructType *create(StringRef Name, Type *elt1, ...) END_WITH_NULL;
224
225 /// StructType::get - This static method is the primary way to create a
226 /// literal StructType.
227 static StructType *get(LLVMContext &Context, ArrayRef Elements,
228 bool isPacked = false);
229
230 /// StructType::get - Create an empty structure type.
231 ///
232 static StructType *get(LLVMContext &Context, bool isPacked = false);
233
234 /// StructType::get - This static method is a convenience method for creating
235 /// structure types by specifying the elements as arguments. Note that this
236 /// method always returns a non-packed struct, and requires at least one
237 /// element type.
238 static StructType *get(Type *elt1, ...) END_WITH_NULL;
239
240 bool isPacked() const { return (getSubclassData() & SCDB_Packed) != 0; }
241
242 /// isLiteral - Return true if this type is uniqued by structural
243 /// equivalence, false if it is a struct definition.
244 bool isLiteral() const { return (getSubclassData() & SCDB_IsLiteral) != 0; }
245
246 /// isOpaque - Return true if this is a type with an identity that has no body
247 /// specified yet. These prints as 'opaque' in .ll files.
248 bool isOpaque() const { return (getSubclassData() & SCDB_HasBody) == 0; }
249
250 /// isSized - Return true if this is a sized type.
251 bool isSized() const;
252
253 /// hasName - Return true if this is a named struct that has a non-empty name.
254 bool hasName() const { return SymbolTableEntry != 0; }
255
256 /// getName - Return the name for this struct type if it has an identity.
257 /// This may return an empty string for an unnamed struct type. Do not call
258 /// this on an literal type.
259 StringRef getName() const;
260
261 /// setName - Change the name of this type to the specified name, or to a name
262 /// with a suffix if there is a collision. Do not call this on an literal
263 /// type.
264 void setName(StringRef Name);
265
266 /// setBody - Specify a body for an opaque identified type.
267 void setBody(ArrayRef Elements, bool isPacked = false);
268 void setBody(Type *elt1, ...) END_WITH_NULL;
269
270 /// isValidElementType - Return true if the specified type is valid as a
271 /// element type.
272 static bool isValidElementType(Type *ElemTy);
273
274
275 // Iterator access to the elements.
276 typedef Type::subtype_iterator element_iterator;
277 element_iterator element_begin() const { return ContainedTys; }
278 element_iterator element_end() const { return &ContainedTys[NumContainedTys];}
279
280 /// isLayoutIdentical - Return true if this is layout identical to the
281 /// specified struct.
282 bool isLayoutIdentical(StructType *Other) const;
283
284 // Random access to the elements
285 unsigned getNumElements() const { return NumContainedTys; }
286 Type *getElementType(unsigned N) const {
287 assert(N < NumContainedTys && "Element number out of range!");
288 return ContainedTys[N];
289 }
290
291 // Methods for support type inquiry through isa, cast, and dyn_cast.
292 static inline bool classof(const Type *T) {
293 return T->getTypeID() == StructTyID;
294 }
295 };
296
297 /// SequentialType - This is the superclass of the array, pointer and vector
298 /// type classes. All of these represent "arrays" in memory. The array type
299 /// represents a specifically sized array, pointer types are unsized/unknown
300 /// size arrays, vector types represent specifically sized arrays that
301 /// allow for use of SIMD instructions. SequentialType holds the common
302 /// features of all, which stem from the fact that all three lay their
303 /// components out in memory identically.
304 ///
305 class SequentialType : public CompositeType {
306 Type *ContainedType; ///< Storage for the single contained type.
307 SequentialType(const SequentialType &) LLVM_DELETED_FUNCTION;
308 const SequentialType &operator=(const SequentialType &) LLVM_DELETED_FUNCTION;
309
310 protected:
311 SequentialType(TypeID TID, Type *ElType)
312 : CompositeType(ElType->getContext(), TID), ContainedType(ElType) {
313 ContainedTys = &ContainedType;
314 NumContainedTys = 1;
315 }
316
317 public:
318 Type *getElementType() const { return ContainedTys[0]; }
319
320 // Methods for support type inquiry through isa, cast, and dyn_cast.
321 static inline bool classof(const Type *T) {
322 return T->getTypeID() == ArrayTyID ||
323 T->getTypeID() == PointerTyID ||
324 T->getTypeID() == VectorTyID;
325 }
326 };
327
328
329 /// ArrayType - Class to represent array types.
330 ///
331 class ArrayType : public SequentialType {
332 uint64_t NumElements;
333
334 ArrayType(const ArrayType &) LLVM_DELETED_FUNCTION;
335 const ArrayType &operator=(const ArrayType &) LLVM_DELETED_FUNCTION;
336 ArrayType(Type *ElType, uint64_t NumEl);
337 public:
338 /// ArrayType::get - This static method is the primary way to construct an
339 /// ArrayType
340 ///
341 static ArrayType *get(Type *ElementType, uint64_t NumElements);
342
343 /// isValidElementType - Return true if the specified type is valid as a
344 /// element type.
345 static bool isValidElementType(Type *ElemTy);
346
347 uint64_t getNumElements() const { return NumElements; }
348
349 // Methods for support type inquiry through isa, cast, and dyn_cast.
350 static inline bool classof(const Type *T) {
351 return T->getTypeID() == ArrayTyID;
352 }
353 };
354
355 /// VectorType - Class to represent vector types.
356 ///
357 class VectorType : public SequentialType {
358 unsigned NumElements;
359
360 VectorType(const VectorType &) LLVM_DELETED_FUNCTION;
361 const VectorType &operator=(const VectorType &) LLVM_DELETED_FUNCTION;
362 VectorType(Type *ElType, unsigned NumEl);
363 public:
364 /// VectorType::get - This static method is the primary way to construct an
365 /// VectorType.
366 ///
367 static VectorType *get(Type *ElementType, unsigned NumElements);
368
369 /// VectorType::getInteger - This static method gets a VectorType with the
370 /// same number of elements as the input type, and the element type is an
371 /// integer type of the same width as the input element type.
372 ///
373 static VectorType *getInteger(VectorType *VTy) {
374 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
375 assert(EltBits && "Element size must be of a non-zero size");
376 Type *EltTy = IntegerType::get(VTy->getContext(), EltBits);
377 return VectorType::get(EltTy, VTy->getNumElements());
378 }
379
380 /// VectorType::getExtendedElementVectorType - This static method is like
381 /// getInteger except that the element types are twice as wide as the
382 /// elements in the input type.
383 ///
384 static VectorType *getExtendedElementVectorType(VectorType *VTy) {
385 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
386 Type *EltTy = IntegerType::get(VTy->getContext(), EltBits * 2);
387 return VectorType::get(EltTy, VTy->getNumElements());
388 }
389
390 /// VectorType::getTruncatedElementVectorType - This static method is like
391 /// getInteger except that the element types are half as wide as the
392 /// elements in the input type.
393 ///
394 static VectorType *getTruncatedElementVectorType(VectorType *VTy) {
395 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
396 assert((EltBits & 1) == 0 &&
397 "Cannot truncate vector element with odd bit-width");
398 Type *EltTy = IntegerType::get(VTy->getContext(), EltBits / 2);
399 return VectorType::get(EltTy, VTy->getNumElements());
400 }
401
402 /// isValidElementType - Return true if the specified type is valid as a
403 /// element type.
404 static bool isValidElementType(Type *ElemTy);
405
406 /// @brief Return the number of elements in the Vector type.
407 unsigned getNumElements() const { return NumElements; }
408
409 /// @brief Return the number of bits in the Vector type.
410 /// Returns zero when the vector is a vector of pointers.
411 unsigned getBitWidth() const {
412 return NumElements * getElementType()->getPrimitiveSizeInBits();
413 }
414
415 // Methods for support type inquiry through isa, cast, and dyn_cast.
416 static inline bool classof(const Type *T) {
417 return T->getTypeID() == VectorTyID;
418 }
419 };
420
421
422 /// PointerType - Class to represent pointers.
423 ///
424 class PointerType : public SequentialType {
425 PointerType(const PointerType &) LLVM_DELETED_FUNCTION;
426 const PointerType &operator=(const PointerType &) LLVM_DELETED_FUNCTION;
427 explicit PointerType(Type *ElType, unsigned AddrSpace);
428 public:
429 /// PointerType::get - This constructs a pointer to an object of the specified
430 /// type in a numbered address space.
431 static PointerType *get(Type *ElementType, unsigned AddressSpace);
432
433 /// PointerType::getUnqual - This constructs a pointer to an object of the
434 /// specified type in the generic address space (address space zero).
435 static PointerType *getUnqual(Type *ElementType) {
436 return PointerType::get(ElementType, 0);
437 }
438
439 /// isValidElementType - Return true if the specified type is valid as a
440 /// element type.
441 static bool isValidElementType(Type *ElemTy);
442
443 /// @brief Return the address space of the Pointer type.
444 inline unsigned getAddressSpace() const { return getSubclassData(); }
445
446 // Implement support type inquiry through isa, cast, and dyn_cast.
447 static inline bool classof(const Type *T) {
448 return T->getTypeID() == PointerTyID;
449 }
450 };
451
452 } // End llvm namespace
453
454 #endif
+0
-452
include/llvm/Function.h less more
None //===-- llvm/Function.h - Class to represent a single function --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the declaration of the Function class, which represents a
10 // single function/procedure in LLVM.
11 //
12 // A function basically consists of a list of basic blocks, a list of arguments,
13 // and a symbol table.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_FUNCTION_H
18 #define LLVM_FUNCTION_H
19
20 #include "llvm/Argument.h"
21 #include "llvm/Attributes.h"
22 #include "llvm/BasicBlock.h"
23 #include "llvm/CallingConv.h"
24 #include "llvm/GlobalValue.h"
25 #include "llvm/Support/Compiler.h"
26
27 namespace llvm {
28
29 class FunctionType;
30 class LLVMContext;
31
32 // Traits for intrusive list of basic blocks...
33 template<> struct ilist_traits
34 : public SymbolTableListTraits {
35
36 // createSentinel is used to get hold of the node that marks the end of the
37 // list... (same trick used here as in ilist_traits)
38 BasicBlock *createSentinel() const {
39 return static_cast(&Sentinel);
40 }
41 static void destroySentinel(BasicBlock*) {}
42
43 BasicBlock *provideInitialHead() const { return createSentinel(); }
44 BasicBlock *ensureHead(BasicBlock*) const { return createSentinel(); }
45 static void noteHead(BasicBlock*, BasicBlock*) {}
46
47 static ValueSymbolTable *getSymTab(Function *ItemParent);
48 private:
49 mutable ilist_half_node Sentinel;
50 };
51
52 template<> struct ilist_traits
53 : public SymbolTableListTraits {
54
55 Argument *createSentinel() const {
56 return static_cast(&Sentinel);