/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/include/llvm/IR/Function.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- llvm/Function.h - Class to represent a single function ---*- C++ -*-===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file contains the declaration of the Function class, which represents a |
11 | | // single function/procedure in LLVM. |
12 | | // |
13 | | // A function basically consists of a list of basic blocks, a list of arguments, |
14 | | // and a symbol table. |
15 | | // |
16 | | //===----------------------------------------------------------------------===// |
17 | | |
18 | | #ifndef LLVM_IR_FUNCTION_H |
19 | | #define LLVM_IR_FUNCTION_H |
20 | | |
21 | | #include "llvm/ADT/DenseSet.h" |
22 | | #include "llvm/ADT/StringRef.h" |
23 | | #include "llvm/ADT/Twine.h" |
24 | | #include "llvm/ADT/ilist_node.h" |
25 | | #include "llvm/ADT/iterator_range.h" |
26 | | #include "llvm/IR/Argument.h" |
27 | | #include "llvm/IR/Attributes.h" |
28 | | #include "llvm/IR/BasicBlock.h" |
29 | | #include "llvm/IR/CallingConv.h" |
30 | | #include "llvm/IR/DerivedTypes.h" |
31 | | #include "llvm/IR/GlobalObject.h" |
32 | | #include "llvm/IR/GlobalValue.h" |
33 | | #include "llvm/IR/OperandTraits.h" |
34 | | #include "llvm/IR/SymbolTableListTraits.h" |
35 | | #include "llvm/IR/Value.h" |
36 | | #include "llvm/Support/Casting.h" |
37 | | #include "llvm/Support/Compiler.h" |
38 | | #include <cassert> |
39 | | #include <cstddef> |
40 | | #include <cstdint> |
41 | | #include <memory> |
42 | | #include <string> |
43 | | |
44 | | namespace llvm { |
45 | | |
46 | | namespace Intrinsic { |
47 | | enum ID : unsigned; |
48 | | } |
49 | | |
50 | | class AssemblyAnnotationWriter; |
51 | | class Constant; |
52 | | class DISubprogram; |
53 | | class LLVMContext; |
54 | | class Module; |
55 | | template <typename T> class Optional; |
56 | | class raw_ostream; |
57 | | class Type; |
58 | | class User; |
59 | | |
60 | | class Function : public GlobalObject, public ilist_node<Function> { |
61 | | public: |
62 | | using BasicBlockListType = SymbolTableList<BasicBlock>; |
63 | | |
64 | | // BasicBlock iterators... |
65 | | using iterator = BasicBlockListType::iterator; |
66 | | using const_iterator = BasicBlockListType::const_iterator; |
67 | | |
68 | | using arg_iterator = Argument *; |
69 | | using const_arg_iterator = const Argument *; |
70 | | |
71 | | private: |
72 | | // Important things that make up a function! |
73 | | BasicBlockListType BasicBlocks; ///< The basic blocks |
74 | | mutable Argument *Arguments = nullptr; ///< The formal arguments |
75 | | size_t NumArgs; |
76 | | std::unique_ptr<ValueSymbolTable> |
77 | | SymTab; ///< Symbol table of args/instructions |
78 | | AttributeList AttributeSets; ///< Parameter attributes |
79 | | |
80 | | /* |
81 | | * Value::SubclassData |
82 | | * |
83 | | * bit 0 : HasLazyArguments |
84 | | * bit 1 : HasPrefixData |
85 | | * bit 2 : HasPrologueData |
86 | | * bit 3 : HasPersonalityFn |
87 | | * bits 4-13 : CallingConvention |
88 | | * bits 14 : HasGC |
89 | | * bits 15 : [reserved] |
90 | | */ |
91 | | |
92 | | /// Bits from GlobalObject::GlobalObjectSubclassData. |
93 | | enum { |
94 | | /// Whether this function is materializable. |
95 | | IsMaterializableBit = 0, |
96 | | }; |
97 | | |
98 | | friend class SymbolTableListTraits<Function>; |
99 | | |
100 | | /// hasLazyArguments/CheckLazyArguments - The argument list of a function is |
101 | | /// built on demand, so that the list isn't allocated until the first client |
102 | | /// needs it. The hasLazyArguments predicate returns true if the arg list |
103 | | /// hasn't been set up yet. |
104 | | public: |
105 | 170M | bool hasLazyArguments() const { |
106 | 170M | return getSubclassDataFromValue() & (1<<0); |
107 | 170M | } |
108 | | |
109 | | private: |
110 | 170M | void CheckLazyArguments() const { |
111 | 170M | if (hasLazyArguments()) |
112 | 1.11M | BuildLazyArguments(); |
113 | 170M | } |
114 | | |
115 | | void BuildLazyArguments() const; |
116 | | |
117 | | void clearArguments(); |
118 | | |
119 | | /// Function ctor - If the (optional) Module argument is specified, the |
120 | | /// function is automatically inserted into the end of the function list for |
121 | | /// the module. |
122 | | /// |
123 | | Function(FunctionType *Ty, LinkageTypes Linkage, |
124 | | const Twine &N = "", Module *M = nullptr); |
125 | | |
126 | | public: |
127 | | Function(const Function&) = delete; |
128 | | void operator=(const Function&) = delete; |
129 | | ~Function(); |
130 | | |
131 | | // This is here to help easily convert from FunctionT * (Function * or |
132 | | // MachineFunction *) in BlockFrequencyInfoImpl to Function * by calling |
133 | | // FunctionT->getFunction(). |
134 | 435 | const Function *getFunction() const { return this; } |
135 | | |
136 | | static Function *Create(FunctionType *Ty, LinkageTypes Linkage, |
137 | 2.84M | const Twine &N = "", Module *M = nullptr) { |
138 | 2.84M | return new Function(Ty, Linkage, N, M); |
139 | 2.84M | } |
140 | | |
141 | | // Provide fast operand accessors. |
142 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
143 | | |
144 | | /// Returns the FunctionType for me. |
145 | 46.1M | FunctionType *getFunctionType() const { |
146 | 46.1M | return cast<FunctionType>(getValueType()); |
147 | 46.1M | } |
148 | | |
149 | | /// Returns the type of the ret val. |
150 | 17.1M | Type *getReturnType() const { return getFunctionType()->getReturnType(); } |
151 | | |
152 | | /// getContext - Return a reference to the LLVMContext associated with this |
153 | | /// function. |
154 | | LLVMContext &getContext() const; |
155 | | |
156 | | /// isVarArg - Return true if this function takes a variable number of |
157 | | /// arguments. |
158 | 5.12M | bool isVarArg() const { return getFunctionType()->isVarArg(); } |
159 | | |
160 | 53.3M | bool isMaterializable() const { |
161 | 53.3M | return getGlobalObjectSubClassData() & (1 << IsMaterializableBit); |
162 | 53.3M | } |
163 | 3.81M | void setIsMaterializable(bool V) { |
164 | 3.81M | unsigned Mask = 1 << IsMaterializableBit; |
165 | 3.81M | setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) | |
166 | 3.81M | (V ? Mask655k : 0u3.16M )); |
167 | 3.81M | } |
168 | | |
169 | | /// getIntrinsicID - This method returns the ID number of the specified |
170 | | /// function, or Intrinsic::not_intrinsic if the function is not an |
171 | | /// intrinsic, or if the pointer is null. This value is always defined to be |
172 | | /// zero to allow easy checking for whether a function is intrinsic or not. |
173 | | /// The particular intrinsic functions which correspond to this value are |
174 | | /// defined in llvm/Intrinsics.h. |
175 | 267M | Intrinsic::ID getIntrinsicID() const LLVM_READONLY { return IntID; } |
176 | | |
177 | | /// isIntrinsic - Returns true if the function's name starts with "llvm.". |
178 | | /// It's possible for this function to return true while getIntrinsicID() |
179 | | /// returns Intrinsic::not_intrinsic! |
180 | 704M | bool isIntrinsic() const { return HasLLVMReservedName; } |
181 | | |
182 | | static Intrinsic::ID lookupIntrinsicID(StringRef Name); |
183 | | |
184 | | /// \brief Recalculate the ID for this function if it is an Intrinsic defined |
185 | | /// in llvm/Intrinsics.h. Sets the intrinsic ID to Intrinsic::not_intrinsic |
186 | | /// if the name of this function does not match an intrinsic in that header. |
187 | | /// Note, this method does not need to be called directly, as it is called |
188 | | /// from Value::setName() whenever the name of this function changes. |
189 | | void recalculateIntrinsicID(); |
190 | | |
191 | | /// getCallingConv()/setCallingConv(CC) - These method get and set the |
192 | | /// calling convention of this function. The enum values for the known |
193 | | /// calling conventions are defined in CallingConv.h. |
194 | 68.0M | CallingConv::ID getCallingConv() const { |
195 | 68.0M | return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) & |
196 | 68.0M | CallingConv::MaxID); |
197 | 68.0M | } |
198 | 2.77M | void setCallingConv(CallingConv::ID CC) { |
199 | 2.77M | auto ID = static_cast<unsigned>(CC); |
200 | 2.77M | assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention"); |
201 | 2.77M | setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (ID << 4)); |
202 | 2.77M | } |
203 | | |
204 | | /// @brief Return the attribute list for this Function. |
205 | 1.19G | AttributeList getAttributes() const { return AttributeSets; } |
206 | | |
207 | | /// @brief Set the attribute list for this Function. |
208 | 5.50M | void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; } |
209 | | |
210 | | /// @brief Add function attributes to this function. |
211 | 444k | void addFnAttr(Attribute::AttrKind Kind) { |
212 | 444k | addAttribute(AttributeList::FunctionIndex, Kind); |
213 | 444k | } |
214 | | |
215 | | /// @brief Add function attributes to this function. |
216 | 188k | void addFnAttr(StringRef Kind, StringRef Val = StringRef()) { |
217 | 188k | addAttribute(AttributeList::FunctionIndex, |
218 | 188k | Attribute::get(getContext(), Kind, Val)); |
219 | 188k | } |
220 | | |
221 | 4 | void addFnAttr(Attribute Attr) { |
222 | 4 | addAttribute(AttributeList::FunctionIndex, Attr); |
223 | 4 | } |
224 | | |
225 | | /// @brief Remove function attributes from this function. |
226 | 140k | void removeFnAttr(Attribute::AttrKind Kind) { |
227 | 140k | removeAttribute(AttributeList::FunctionIndex, Kind); |
228 | 140k | } |
229 | | |
230 | | /// @brief Remove function attribute from this function. |
231 | 29 | void removeFnAttr(StringRef Kind) { |
232 | 29 | setAttributes(getAttributes().removeAttribute( |
233 | 29 | getContext(), AttributeList::FunctionIndex, Kind)); |
234 | 29 | } |
235 | | |
236 | | /// \brief Set the entry count for this function. |
237 | | /// |
238 | | /// Entry count is the number of times this function was executed based on |
239 | | /// pgo data. \p Imports points to a set of GUIDs that needs to be imported |
240 | | /// by the function for sample PGO, to enable the same inlines as the |
241 | | /// profiled optimized binary. |
242 | | void setEntryCount(uint64_t Count, |
243 | | const DenseSet<GlobalValue::GUID> *Imports = nullptr); |
244 | | |
245 | | /// \brief Get the entry count for this function. |
246 | | /// |
247 | | /// Entry count is the number of times the function was executed based on |
248 | | /// pgo data. |
249 | | Optional<uint64_t> getEntryCount() const; |
250 | | |
251 | | /// Returns the set of GUIDs that needs to be imported to the function for |
252 | | /// sample PGO, to enable the same inlines as the profiled optimized binary. |
253 | | DenseSet<GlobalValue::GUID> getImportGUIDs() const; |
254 | | |
255 | | /// Set the section prefix for this function. |
256 | | void setSectionPrefix(StringRef Prefix); |
257 | | |
258 | | /// Get the section prefix for this function. |
259 | | Optional<StringRef> getSectionPrefix() const; |
260 | | |
261 | | /// @brief Return true if the function has the attribute. |
262 | 372M | bool hasFnAttribute(Attribute::AttrKind Kind) const { |
263 | 372M | return AttributeSets.hasFnAttribute(Kind); |
264 | 372M | } |
265 | 15.0M | bool hasFnAttribute(StringRef Kind) const { |
266 | 15.0M | return AttributeSets.hasFnAttribute(Kind); |
267 | 15.0M | } |
268 | | |
269 | | /// @brief Return the attribute for the given attribute kind. |
270 | 16.9M | Attribute getFnAttribute(Attribute::AttrKind Kind) const { |
271 | 16.9M | return getAttribute(AttributeList::FunctionIndex, Kind); |
272 | 16.9M | } |
273 | 68.0M | Attribute getFnAttribute(StringRef Kind) const { |
274 | 68.0M | return getAttribute(AttributeList::FunctionIndex, Kind); |
275 | 68.0M | } |
276 | | |
277 | | /// \brief Return the stack alignment for the function. |
278 | 60 | unsigned getFnStackAlignment() const { |
279 | 60 | if (!hasFnAttribute(Attribute::StackAlignment)) |
280 | 0 | return 0; |
281 | 60 | return AttributeSets.getStackAlignment(AttributeList::FunctionIndex); |
282 | 60 | } |
283 | | |
284 | | /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm |
285 | | /// to use during code generation. |
286 | 6.21M | bool hasGC() const { |
287 | 6.21M | return getSubclassDataFromValue() & (1<<14); |
288 | 6.21M | } |
289 | | const std::string &getGC() const; |
290 | | void setGC(std::string Str); |
291 | | void clearGC(); |
292 | | |
293 | | /// @brief adds the attribute to the list of attributes. |
294 | | void addAttribute(unsigned i, Attribute::AttrKind Kind); |
295 | | |
296 | | /// @brief adds the attribute to the list of attributes. |
297 | | void addAttribute(unsigned i, Attribute Attr); |
298 | | |
299 | | /// @brief adds the attributes to the list of attributes. |
300 | | void addAttributes(unsigned i, const AttrBuilder &Attrs); |
301 | | |
302 | | /// @brief adds the attribute to the list of attributes for the given arg. |
303 | | void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind); |
304 | | |
305 | | /// @brief adds the attribute to the list of attributes for the given arg. |
306 | | void addParamAttr(unsigned ArgNo, Attribute Attr); |
307 | | |
308 | | /// @brief adds the attributes to the list of attributes for the given arg. |
309 | | void addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs); |
310 | | |
311 | | /// @brief removes the attribute from the list of attributes. |
312 | | void removeAttribute(unsigned i, Attribute::AttrKind Kind); |
313 | | |
314 | | /// @brief removes the attribute from the list of attributes. |
315 | | void removeAttribute(unsigned i, StringRef Kind); |
316 | | |
317 | | /// @brief removes the attributes from the list of attributes. |
318 | | void removeAttributes(unsigned i, const AttrBuilder &Attrs); |
319 | | |
320 | | /// @brief removes the attribute from the list of attributes. |
321 | | void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind); |
322 | | |
323 | | /// @brief removes the attribute from the list of attributes. |
324 | | void removeParamAttr(unsigned ArgNo, StringRef Kind); |
325 | | |
326 | | /// @brief removes the attribute from the list of attributes. |
327 | | void removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs); |
328 | | |
329 | | /// @brief check if an attributes is in the list of attributes. |
330 | 7.69k | bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const { |
331 | 7.69k | return getAttributes().hasAttribute(i, Kind); |
332 | 7.69k | } |
333 | | |
334 | | /// @brief check if an attributes is in the list of attributes. |
335 | 259M | bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const { |
336 | 259M | return getAttributes().hasParamAttribute(ArgNo, Kind); |
337 | 259M | } |
338 | | |
339 | 16.9M | Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const { |
340 | 16.9M | return AttributeSets.getAttribute(i, Kind); |
341 | 16.9M | } |
342 | | |
343 | 68.0M | Attribute getAttribute(unsigned i, StringRef Kind) const { |
344 | 68.0M | return AttributeSets.getAttribute(i, Kind); |
345 | 68.0M | } |
346 | | |
347 | | /// @brief adds the dereferenceable attribute to the list of attributes. |
348 | | void addDereferenceableAttr(unsigned i, uint64_t Bytes); |
349 | | |
350 | | /// @brief adds the dereferenceable attribute to the list of attributes for |
351 | | /// the given arg. |
352 | | void addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes); |
353 | | |
354 | | /// @brief adds the dereferenceable_or_null attribute to the list of |
355 | | /// attributes. |
356 | | void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes); |
357 | | |
358 | | /// @brief adds the dereferenceable_or_null attribute to the list of |
359 | | /// attributes for the given arg. |
360 | | void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes); |
361 | | |
362 | | /// @brief Extract the alignment for a call or parameter (0=unknown). |
363 | 33.6M | unsigned getParamAlignment(unsigned ArgNo) const { |
364 | 33.6M | return AttributeSets.getParamAlignment(ArgNo); |
365 | 33.6M | } |
366 | | |
367 | | /// @brief Extract the number of dereferenceable bytes for a call or |
368 | | /// parameter (0=unknown). |
369 | | /// @param i AttributeList index, referring to a return value or argument. |
370 | 0 | uint64_t getDereferenceableBytes(unsigned i) const { |
371 | 0 | return AttributeSets.getDereferenceableBytes(i); |
372 | 0 | } |
373 | | |
374 | | /// @brief Extract the number of dereferenceable bytes for a parameter. |
375 | | /// @param ArgNo Index of an argument, with 0 being the first function arg. |
376 | 92.4M | uint64_t getParamDereferenceableBytes(unsigned ArgNo) const { |
377 | 92.4M | return AttributeSets.getParamDereferenceableBytes(ArgNo); |
378 | 92.4M | } |
379 | | |
380 | | /// @brief Extract the number of dereferenceable_or_null bytes for a call or |
381 | | /// parameter (0=unknown). |
382 | | /// @param i AttributeList index, referring to a return value or argument. |
383 | 0 | uint64_t getDereferenceableOrNullBytes(unsigned i) const { |
384 | 0 | return AttributeSets.getDereferenceableOrNullBytes(i); |
385 | 0 | } |
386 | | |
387 | | /// @brief Extract the number of dereferenceable_or_null bytes for a |
388 | | /// parameter. |
389 | | /// @param ArgNo AttributeList ArgNo, referring to an argument. |
390 | 1.36M | uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const { |
391 | 1.36M | return AttributeSets.getParamDereferenceableOrNullBytes(ArgNo); |
392 | 1.36M | } |
393 | | |
394 | | /// @brief Determine if the function does not access memory. |
395 | 67.2M | bool doesNotAccessMemory() const { |
396 | 67.2M | return hasFnAttribute(Attribute::ReadNone); |
397 | 67.2M | } |
398 | 1 | void setDoesNotAccessMemory() { |
399 | 1 | addFnAttr(Attribute::ReadNone); |
400 | 1 | } |
401 | | |
402 | | /// @brief Determine if the function does not access or only reads memory. |
403 | 22.8M | bool onlyReadsMemory() const { |
404 | 22.8M | return doesNotAccessMemory() || hasFnAttribute(Attribute::ReadOnly); |
405 | 22.8M | } |
406 | 13.2k | void setOnlyReadsMemory() { |
407 | 13.2k | addFnAttr(Attribute::ReadOnly); |
408 | 13.2k | } |
409 | | |
410 | | /// @brief Determine if the function does not access or only writes memory. |
411 | 21.6M | bool doesNotReadMemory() const { |
412 | 21.6M | return doesNotAccessMemory() || hasFnAttribute(Attribute::WriteOnly); |
413 | 21.6M | } |
414 | 0 | void setDoesNotReadMemory() { |
415 | 0 | addFnAttr(Attribute::WriteOnly); |
416 | 0 | } |
417 | | |
418 | | /// @brief Determine if the call can access memmory only using pointers based |
419 | | /// on its arguments. |
420 | 22.2M | bool onlyAccessesArgMemory() const { |
421 | 22.2M | return hasFnAttribute(Attribute::ArgMemOnly); |
422 | 22.2M | } |
423 | 3.55k | void setOnlyAccessesArgMemory() { addFnAttr(Attribute::ArgMemOnly); } |
424 | | |
425 | | /// @brief Determine if the function may only access memory that is |
426 | | /// inaccessible from the IR. |
427 | 19.5M | bool onlyAccessesInaccessibleMemory() const { |
428 | 19.5M | return hasFnAttribute(Attribute::InaccessibleMemOnly); |
429 | 19.5M | } |
430 | 0 | void setOnlyAccessesInaccessibleMemory() { |
431 | 0 | addFnAttr(Attribute::InaccessibleMemOnly); |
432 | 0 | } |
433 | | |
434 | | /// @brief Determine if the function may only access memory that is |
435 | | /// either inaccessible from the IR or pointed to by its arguments. |
436 | 19.5M | bool onlyAccessesInaccessibleMemOrArgMem() const { |
437 | 19.5M | return hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly); |
438 | 19.5M | } |
439 | 0 | void setOnlyAccessesInaccessibleMemOrArgMem() { |
440 | 0 | addFnAttr(Attribute::InaccessibleMemOrArgMemOnly); |
441 | 0 | } |
442 | | |
443 | | /// @brief Determine if the function cannot return. |
444 | 726k | bool doesNotReturn() const { |
445 | 726k | return hasFnAttribute(Attribute::NoReturn); |
446 | 726k | } |
447 | 414 | void setDoesNotReturn() { |
448 | 414 | addFnAttr(Attribute::NoReturn); |
449 | 414 | } |
450 | | |
451 | | /// @brief Determine if the function cannot unwind. |
452 | 30.1M | bool doesNotThrow() const { |
453 | 30.1M | return hasFnAttribute(Attribute::NoUnwind); |
454 | 30.1M | } |
455 | 127k | void setDoesNotThrow() { |
456 | 127k | addFnAttr(Attribute::NoUnwind); |
457 | 127k | } |
458 | | |
459 | | /// @brief Determine if the call cannot be duplicated. |
460 | 0 | bool cannotDuplicate() const { |
461 | 0 | return hasFnAttribute(Attribute::NoDuplicate); |
462 | 0 | } |
463 | 0 | void setCannotDuplicate() { |
464 | 0 | addFnAttr(Attribute::NoDuplicate); |
465 | 0 | } |
466 | | |
467 | | /// @brief Determine if the call is convergent. |
468 | 728k | bool isConvergent() const { |
469 | 728k | return hasFnAttribute(Attribute::Convergent); |
470 | 728k | } |
471 | 0 | void setConvergent() { |
472 | 0 | addFnAttr(Attribute::Convergent); |
473 | 0 | } |
474 | 5 | void setNotConvergent() { |
475 | 5 | removeFnAttr(Attribute::Convergent); |
476 | 5 | } |
477 | | |
478 | | /// @brief Determine if the call has sideeffects. |
479 | 3.07M | bool isSpeculatable() const { |
480 | 3.07M | return hasFnAttribute(Attribute::Speculatable); |
481 | 3.07M | } |
482 | 0 | void setSpeculatable() { |
483 | 0 | addFnAttr(Attribute::Speculatable); |
484 | 0 | } |
485 | | |
486 | | /// Determine if the function is known not to recurse, directly or |
487 | | /// indirectly. |
488 | 1.44M | bool doesNotRecurse() const { |
489 | 1.44M | return hasFnAttribute(Attribute::NoRecurse); |
490 | 1.44M | } |
491 | 47.5k | void setDoesNotRecurse() { |
492 | 47.5k | addFnAttr(Attribute::NoRecurse); |
493 | 47.5k | } |
494 | | |
495 | | /// @brief True if the ABI mandates (or the user requested) that this |
496 | | /// function be in a unwind table. |
497 | 1.91M | bool hasUWTable() const { |
498 | 1.91M | return hasFnAttribute(Attribute::UWTable); |
499 | 1.91M | } |
500 | 18 | void setHasUWTable() { |
501 | 18 | addFnAttr(Attribute::UWTable); |
502 | 18 | } |
503 | | |
504 | | /// @brief True if this function needs an unwind table. |
505 | 1.91M | bool needsUnwindTableEntry() const { |
506 | 1.49M | return hasUWTable() || !doesNotThrow(); |
507 | 1.91M | } |
508 | | |
509 | | /// @brief Determine if the function returns a structure through first |
510 | | /// or second pointer argument. |
511 | 866k | bool hasStructRetAttr() const { |
512 | 866k | return AttributeSets.hasParamAttribute(0, Attribute::StructRet) || |
513 | 863k | AttributeSets.hasParamAttribute(1, Attribute::StructRet); |
514 | 866k | } |
515 | | |
516 | | /// @brief Determine if the parameter or return value is marked with NoAlias |
517 | | /// attribute. |
518 | 820k | bool returnDoesNotAlias() const { |
519 | 820k | return AttributeSets.hasAttribute(AttributeList::ReturnIndex, |
520 | 820k | Attribute::NoAlias); |
521 | 820k | } |
522 | 946 | void setReturnDoesNotAlias() { |
523 | 946 | addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias); |
524 | 946 | } |
525 | | |
526 | | /// Optimize this function for minimum size (-Oz). |
527 | 38.0M | bool optForMinSize() const { return hasFnAttribute(Attribute::MinSize); } |
528 | | |
529 | | /// Optimize this function for size (-Os) or minimum size (-Oz). |
530 | 29.5M | bool optForSize() const { |
531 | 29.4M | return hasFnAttribute(Attribute::OptimizeForSize) || optForMinSize(); |
532 | 29.5M | } |
533 | | |
534 | | /// copyAttributesFrom - copy all additional attributes (those not needed to |
535 | | /// create a Function) from the Function Src to this one. |
536 | | void copyAttributesFrom(const Function *Src); |
537 | | |
538 | | /// deleteBody - This method deletes the body of the function, and converts |
539 | | /// the linkage to external. |
540 | | /// |
541 | 2.19k | void deleteBody() { |
542 | 2.19k | dropAllReferences(); |
543 | 2.19k | setLinkage(ExternalLinkage); |
544 | 2.19k | } |
545 | | |
546 | | /// removeFromParent - This method unlinks 'this' from the containing module, |
547 | | /// but does not delete it. |
548 | | /// |
549 | | void removeFromParent(); |
550 | | |
551 | | /// eraseFromParent - This method unlinks 'this' from the containing module |
552 | | /// and deletes it. |
553 | | /// |
554 | | void eraseFromParent(); |
555 | | |
556 | | /// Steal arguments from another function. |
557 | | /// |
558 | | /// Drop this function's arguments and splice in the ones from \c Src. |
559 | | /// Requires that this has no function body. |
560 | | void stealArgumentListFrom(Function &Src); |
561 | | |
562 | | /// Get the underlying elements of the Function... the basic block list is |
563 | | /// empty for external functions. |
564 | | /// |
565 | 1.90M | const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; } |
566 | 29.3M | BasicBlockListType &getBasicBlockList() { return BasicBlocks; } |
567 | | |
568 | 10.3M | static BasicBlockListType Function::*getSublistAccess(BasicBlock*) { |
569 | 10.3M | return &Function::BasicBlocks; |
570 | 10.3M | } |
571 | | |
572 | 12.0M | const BasicBlock &getEntryBlock() const { return front(); } |
573 | 78.9M | BasicBlock &getEntryBlock() { return front(); } |
574 | | |
575 | | //===--------------------------------------------------------------------===// |
576 | | // Symbol Table Accessing functions... |
577 | | |
578 | | /// getSymbolTable() - Return the symbol table if any, otherwise nullptr. |
579 | | /// |
580 | 49.0M | inline ValueSymbolTable *getValueSymbolTable() { return SymTab.get(); } |
581 | 7.87k | inline const ValueSymbolTable *getValueSymbolTable() const { |
582 | 7.87k | return SymTab.get(); |
583 | 7.87k | } |
584 | | |
585 | | //===--------------------------------------------------------------------===// |
586 | | // BasicBlock iterator forwarding functions |
587 | | // |
588 | 51.7M | iterator begin() { return BasicBlocks.begin(); } |
589 | 6.27M | const_iterator begin() const { return BasicBlocks.begin(); } |
590 | 118M | iterator end () { return BasicBlocks.end(); } |
591 | 6.27M | const_iterator end () const { return BasicBlocks.end(); } |
592 | | |
593 | 11.2M | size_t size() const { return BasicBlocks.size(); } |
594 | 134M | bool empty() const { return BasicBlocks.empty(); } |
595 | 16.3M | const BasicBlock &front() const { return BasicBlocks.front(); } |
596 | 97.0M | BasicBlock &front() { return BasicBlocks.front(); } |
597 | 0 | const BasicBlock &back() const { return BasicBlocks.back(); } |
598 | 0 | BasicBlock &back() { return BasicBlocks.back(); } |
599 | | |
600 | | /// @name Function Argument Iteration |
601 | | /// @{ |
602 | | |
603 | 6.69M | arg_iterator arg_begin() { |
604 | 6.69M | CheckLazyArguments(); |
605 | 6.69M | return Arguments; |
606 | 6.69M | } |
607 | 78.7M | const_arg_iterator arg_begin() const { |
608 | 78.7M | CheckLazyArguments(); |
609 | 78.7M | return Arguments; |
610 | 78.7M | } |
611 | | |
612 | 6.34M | arg_iterator arg_end() { |
613 | 6.34M | CheckLazyArguments(); |
614 | 6.34M | return Arguments + NumArgs; |
615 | 6.34M | } |
616 | 78.3M | const_arg_iterator arg_end() const { |
617 | 78.3M | CheckLazyArguments(); |
618 | 78.3M | return Arguments + NumArgs; |
619 | 78.3M | } |
620 | | |
621 | 4.31M | iterator_range<arg_iterator> args() { |
622 | 4.31M | return make_range(arg_begin(), arg_end()); |
623 | 4.31M | } |
624 | 76.5M | iterator_range<const_arg_iterator> args() const { |
625 | 76.5M | return make_range(arg_begin(), arg_end()); |
626 | 76.5M | } |
627 | | |
628 | | /// @} |
629 | | |
630 | 2.05M | size_t arg_size() const { return NumArgs; } |
631 | 16.1k | bool arg_empty() const { return arg_size() == 0; } |
632 | | |
633 | | /// \brief Check whether this function has a personality function. |
634 | 6.37M | bool hasPersonalityFn() const { |
635 | 6.37M | return getSubclassDataFromValue() & (1<<3); |
636 | 6.37M | } |
637 | | |
638 | | /// \brief Get the personality function associated with this function. |
639 | | Constant *getPersonalityFn() const; |
640 | | void setPersonalityFn(Constant *Fn); |
641 | | |
642 | | /// \brief Check whether this function has prefix data. |
643 | 767k | bool hasPrefixData() const { |
644 | 767k | return getSubclassDataFromValue() & (1<<1); |
645 | 767k | } |
646 | | |
647 | | /// \brief Get the prefix data associated with this function. |
648 | | Constant *getPrefixData() const; |
649 | | void setPrefixData(Constant *PrefixData); |
650 | | |
651 | | /// \brief Check whether this function has prologue data. |
652 | 767k | bool hasPrologueData() const { |
653 | 767k | return getSubclassDataFromValue() & (1<<2); |
654 | 767k | } |
655 | | |
656 | | /// \brief Get the prologue data associated with this function. |
657 | | Constant *getPrologueData() const; |
658 | | void setPrologueData(Constant *PrologueData); |
659 | | |
660 | | /// Print the function to an output stream with an optional |
661 | | /// AssemblyAnnotationWriter. |
662 | | void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW = nullptr, |
663 | | bool ShouldPreserveUseListOrder = false, |
664 | | bool IsForDebug = false) const; |
665 | | |
666 | | /// viewCFG - This function is meant for use from the debugger. You can just |
667 | | /// say 'call F->viewCFG()' and a ghostview window should pop up from the |
668 | | /// program, displaying the CFG of the current function with the code for each |
669 | | /// basic block inside. This depends on there being a 'dot' and 'gv' program |
670 | | /// in your path. |
671 | | /// |
672 | | void viewCFG() const; |
673 | | |
674 | | /// viewCFGOnly - This function is meant for use from the debugger. It works |
675 | | /// just like viewCFG, but it does not include the contents of basic blocks |
676 | | /// into the nodes, just the label. If you are only interested in the CFG |
677 | | /// this can make the graph smaller. |
678 | | /// |
679 | | void viewCFGOnly() const; |
680 | | |
681 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
682 | 370M | static bool classof(const Value *V) { |
683 | 370M | return V->getValueID() == Value::FunctionVal; |
684 | 370M | } |
685 | | |
686 | | /// dropAllReferences() - This method causes all the subinstructions to "let |
687 | | /// go" of all references that they are maintaining. This allows one to |
688 | | /// 'delete' a whole module at a time, even though there may be circular |
689 | | /// references... first all references are dropped, and all use counts go to |
690 | | /// zero. Then everything is deleted for real. Note that no operations are |
691 | | /// valid on an object that has "dropped all references", except operator |
692 | | /// delete. |
693 | | /// |
694 | | /// Since no other object in the module can have references into the body of a |
695 | | /// function, dropping all references deletes the entire body of the function, |
696 | | /// including any contained basic blocks. |
697 | | /// |
698 | | void dropAllReferences(); |
699 | | |
700 | | /// hasAddressTaken - returns true if there are any uses of this function |
701 | | /// other than direct calls or invokes to it, or blockaddress expressions. |
702 | | /// Optionally passes back an offending user for diagnostic purposes. |
703 | | /// |
704 | | bool hasAddressTaken(const User** = nullptr) const; |
705 | | |
706 | | /// isDefTriviallyDead - Return true if it is trivially safe to remove |
707 | | /// this function definition from the module (because it isn't externally |
708 | | /// visible, does not have its address taken, and has no callers). To make |
709 | | /// this more accurate, call removeDeadConstantUsers first. |
710 | | bool isDefTriviallyDead() const; |
711 | | |
712 | | /// callsFunctionThatReturnsTwice - Return true if the function has a call to |
713 | | /// setjmp or other function that gcc recognizes as "returning twice". |
714 | | bool callsFunctionThatReturnsTwice() const; |
715 | | |
716 | | /// \brief Set the attached subprogram. |
717 | | /// |
718 | | /// Calls \a setMetadata() with \a LLVMContext::MD_dbg. |
719 | | void setSubprogram(DISubprogram *SP); |
720 | | |
721 | | /// \brief Get the attached subprogram. |
722 | | /// |
723 | | /// Calls \a getMetadata() with \a LLVMContext::MD_dbg and casts the result |
724 | | /// to \a DISubprogram. |
725 | | DISubprogram *getSubprogram() const; |
726 | | |
727 | | /// Returns true if we should emit debug info for profiling. |
728 | | bool isDebugInfoForProfiling() const; |
729 | | |
730 | | private: |
731 | | void allocHungoffUselist(); |
732 | | template<int Idx> void setHungoffOperand(Constant *C); |
733 | | |
734 | | /// Shadow Value::setValueSubclassData with a private forwarding method so |
735 | | /// that subclasses cannot accidentally use it. |
736 | 7.21M | void setValueSubclassData(unsigned short D) { |
737 | 7.21M | Value::setValueSubclassData(D); |
738 | 7.21M | } |
739 | | void setValueSubclassDataBit(unsigned Bit, bool On); |
740 | | }; |
741 | | |
742 | | template <> |
743 | | struct OperandTraits<Function> : public HungoffOperandTraits<3> {}; |
744 | | |
745 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(Function, Value) |
746 | | |
747 | | } // end namespace llvm |
748 | | |
749 | | #endif // LLVM_IR_FUNCTION_H |