Coverage Report

Created: 2019-07-24 05:18

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