Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/CodeGen/CGFunctionInfo.h
Line
Count
Source (jump to first uncovered line)
1
//==-- CGFunctionInfo.h - Representation of function argument/return types -==//
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
// Defines CGFunctionInfo and associated types used in representing the
11
// LLVM source types and ABI-coerced types for function arguments and
12
// return values.
13
//
14
//===----------------------------------------------------------------------===//
15
16
#ifndef LLVM_CLANG_CODEGEN_CGFUNCTIONINFO_H
17
#define LLVM_CLANG_CODEGEN_CGFUNCTIONINFO_H
18
19
#include "clang/AST/Attr.h"
20
#include "clang/AST/CanonicalType.h"
21
#include "clang/AST/CharUnits.h"
22
#include "clang/AST/Decl.h"
23
#include "clang/AST/Type.h"
24
#include "llvm/IR/DerivedTypes.h"
25
#include "llvm/ADT/FoldingSet.h"
26
#include "llvm/Support/TrailingObjects.h"
27
#include <cassert>
28
29
namespace clang {
30
namespace CodeGen {
31
32
/// ABIArgInfo - Helper class to encapsulate information about how a
33
/// specific C type should be passed to or returned from a function.
34
class ABIArgInfo {
35
public:
36
  enum Kind : uint8_t {
37
    /// Direct - Pass the argument directly using the normal converted LLVM
38
    /// type, or by coercing to another specified type stored in
39
    /// 'CoerceToType').  If an offset is specified (in UIntData), then the
40
    /// argument passed is offset by some number of bytes in the memory
41
    /// representation. A dummy argument is emitted before the real argument
42
    /// if the specified type stored in "PaddingType" is not zero.
43
    Direct,
44
45
    /// Extend - Valid only for integer argument types. Same as 'direct'
46
    /// but also emit a zero/sign extension attribute.
47
    Extend,
48
49
    /// Indirect - Pass the argument indirectly via a hidden pointer
50
    /// with the specified alignment (0 indicates default alignment).
51
    Indirect,
52
53
    /// Ignore - Ignore the argument (treat as void). Useful for void and
54
    /// empty structs.
55
    Ignore,
56
57
    /// Expand - Only valid for aggregate argument types. The structure should
58
    /// be expanded into consecutive arguments for its constituent fields.
59
    /// Currently expand is only allowed on structures whose fields
60
    /// are all scalar types or are themselves expandable types.
61
    Expand,
62
63
    /// CoerceAndExpand - Only valid for aggregate argument types. The
64
    /// structure should be expanded into consecutive arguments corresponding
65
    /// to the non-array elements of the type stored in CoerceToType.
66
    /// Array elements in the type are assumed to be padding and skipped.
67
    CoerceAndExpand,
68
69
    /// InAlloca - Pass the argument directly using the LLVM inalloca attribute.
70
    /// This is similar to indirect with byval, except it only applies to
71
    /// arguments stored in memory and forbids any implicit copies.  When
72
    /// applied to a return type, it means the value is returned indirectly via
73
    /// an implicit sret parameter stored in the argument struct.
74
    InAlloca,
75
    KindFirst = Direct,
76
    KindLast = InAlloca
77
  };
78
79
private:
80
  llvm::Type *TypeData; // canHaveCoerceToType()
81
  union {
82
    llvm::Type *PaddingType; // canHavePaddingType()
83
    llvm::Type *UnpaddedCoerceAndExpandType; // isCoerceAndExpand()
84
  };
85
  union {
86
    unsigned DirectOffset;     // isDirect() || isExtend()
87
    unsigned IndirectAlign;    // isIndirect()
88
    unsigned AllocaFieldIndex; // isInAlloca()
89
  };
90
  Kind TheKind;
91
  bool PaddingInReg : 1;
92
  bool InAllocaSRet : 1;    // isInAlloca()
93
  bool IndirectByVal : 1;   // isIndirect()
94
  bool IndirectRealign : 1; // isIndirect()
95
  bool SRetAfterThis : 1;   // isIndirect()
96
  bool InReg : 1;           // isDirect() || isExtend() || isIndirect()
97
  bool CanBeFlattened: 1;   // isDirect()
98
  bool SignExt : 1;         // isExtend()
99
  bool SuppressSRet : 1;    // isIndirect()
100
101
7.27M
  bool canHavePaddingType() const {
102
7.27M
    return isDirect() || 
isExtend()269k
||
isIndirect()60.7k
||
isExpand()38.6k
;
103
7.27M
  }
104
751k
  void setPaddingType(llvm::Type *T) {
105
751k
    assert(canHavePaddingType());
106
751k
    PaddingType = T;
107
751k
  }
108
109
877
  void setUnpaddedCoerceToType(llvm::Type *T) {
110
877
    assert(isCoerceAndExpand());
111
877
    UnpaddedCoerceAndExpandType = T;
112
877
  }
113
114
  ABIArgInfo(Kind K)
115
868k
      : TheKind(K), PaddingInReg(false), InReg(false), SuppressSRet(false) {
116
868k
  }
117
118
public:
119
  ABIArgInfo()
120
      : TypeData(nullptr), PaddingType(nullptr), DirectOffset(0),
121
        TheKind(Direct), PaddingInReg(false), InReg(false),
122
        SuppressSRet(false) {}
123
124
  static ABIArgInfo getDirect(llvm::Type *T = nullptr, unsigned Offset = 0,
125
                              llvm::Type *Padding = nullptr,
126
714k
                              bool CanBeFlattened = true) {
127
714k
    auto AI = ABIArgInfo(Direct);
128
714k
    AI.setCoerceToType(T);
129
714k
    AI.setPaddingType(Padding);
130
714k
    AI.setDirectOffset(Offset);
131
714k
    AI.setCanBeFlattened(CanBeFlattened);
132
714k
    return AI;
133
714k
  }
134
176
  static ABIArgInfo getDirectInReg(llvm::Type *T = nullptr) {
135
176
    auto AI = getDirect(T);
136
176
    AI.setInReg(true);
137
176
    return AI;
138
176
  }
139
140
8.19k
  static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T = nullptr) {
141
8.19k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
142
8.19k
    auto AI = ABIArgInfo(Extend);
143
8.19k
    AI.setCoerceToType(T);
144
8.19k
    AI.setPaddingType(nullptr);
145
8.19k
    AI.setDirectOffset(0);
146
8.19k
    AI.setSignExt(true);
147
8.19k
    return AI;
148
8.19k
  }
149
150
22.2k
  static ABIArgInfo getZeroExtend(QualType Ty, llvm::Type *T = nullptr) {
151
22.2k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
152
22.2k
    auto AI = ABIArgInfo(Extend);
153
22.2k
    AI.setCoerceToType(T);
154
22.2k
    AI.setPaddingType(nullptr);
155
22.2k
    AI.setDirectOffset(0);
156
22.2k
    AI.setSignExt(false);
157
22.2k
    return AI;
158
22.2k
  }
159
160
  // ABIArgInfo will record the argument as being extended based on the sign
161
  // of its type.
162
30.4k
  static ABIArgInfo getExtend(QualType Ty, llvm::Type *T = nullptr) {
163
30.4k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
164
30.4k
    if (Ty->hasSignedIntegerRepresentation())
165
8.15k
      return getSignExtend(Ty, T);
166
22.2k
    return getZeroExtend(Ty, T);
167
22.2k
  }
168
169
25
  static ABIArgInfo getExtendInReg(QualType Ty, llvm::Type *T = nullptr) {
170
25
    auto AI = getExtend(Ty, T);
171
25
    AI.setInReg(true);
172
25
    return AI;
173
25
  }
174
115k
  static ABIArgInfo getIgnore() {
175
115k
    return ABIArgInfo(Ignore);
176
115k
  }
177
  static ABIArgInfo getIndirect(CharUnits Alignment, bool ByVal = true,
178
                                bool Realign = false,
179
6.66k
                                llvm::Type *Padding = nullptr) {
180
6.66k
    auto AI = ABIArgInfo(Indirect);
181
6.66k
    AI.setIndirectAlign(Alignment);
182
6.66k
    AI.setIndirectByVal(ByVal);
183
6.66k
    AI.setIndirectRealign(Realign);
184
6.66k
    AI.setSRetAfterThis(false);
185
6.66k
    AI.setPaddingType(Padding);
186
6.66k
    return AI;
187
6.66k
  }
188
  static ABIArgInfo getIndirectInReg(CharUnits Alignment, bool ByVal = true,
189
21
                                     bool Realign = false) {
190
21
    auto AI = getIndirect(Alignment, ByVal, Realign);
191
21
    AI.setInReg(true);
192
21
    return AI;
193
21
  }
194
227
  static ABIArgInfo getInAlloca(unsigned FieldIndex) {
195
227
    auto AI = ABIArgInfo(InAlloca);
196
227
    AI.setInAllocaFieldIndex(FieldIndex);
197
227
    return AI;
198
227
  }
199
120
  static ABIArgInfo getExpand() {
200
120
    auto AI = ABIArgInfo(Expand);
201
120
    AI.setPaddingType(nullptr);
202
120
    return AI;
203
120
  }
204
  static ABIArgInfo getExpandWithPadding(bool PaddingInReg,
205
83
                                         llvm::Type *Padding) {
206
83
    auto AI = getExpand();
207
83
    AI.setPaddingInReg(PaddingInReg);
208
83
    AI.setPaddingType(Padding);
209
83
    return AI;
210
83
  }
211
212
  /// \param unpaddedCoerceToType The coerce-to type with padding elements
213
  ///   removed, canonicalized to a single element if it would otherwise
214
  ///   have exactly one element.
215
  static ABIArgInfo getCoerceAndExpand(llvm::StructType *coerceToType,
216
877
                                       llvm::Type *unpaddedCoerceToType) {
217
877
#ifndef NDEBUG
218
877
    // Sanity checks on unpaddedCoerceToType.
219
877
220
877
    // Assert that we only have a struct type if there are multiple elements.
221
877
    auto unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoerceToType);
222
877
    assert(!unpaddedStruct || unpaddedStruct->getNumElements() != 1);
223
877
224
877
    // Assert that all the non-padding elements have a corresponding element
225
877
    // in the unpadded type.
226
877
    unsigned unpaddedIndex = 0;
227
877
    for (auto eltType : coerceToType->elements()) {
228
877
      if (isPaddingForCoerceAndExpand(eltType)) continue;
229
877
      if (unpaddedStruct) {
230
877
        assert(unpaddedStruct->getElementType(unpaddedIndex) == eltType);
231
877
      } else {
232
877
        assert(unpaddedIndex == 0 && unpaddedCoerceToType == eltType);
233
877
      }
234
877
      unpaddedIndex++;
235
877
    }
236
877
237
877
    // Assert that there aren't extra elements in the unpadded type.
238
877
    if (unpaddedStruct) {
239
877
      assert(unpaddedStruct->getNumElements() == unpaddedIndex);
240
877
    } else {
241
877
      assert(unpaddedIndex == 1);
242
877
    }
243
877
#endif
244
877
245
877
    auto AI = ABIArgInfo(CoerceAndExpand);
246
877
    AI.setCoerceToType(coerceToType);
247
877
    AI.setUnpaddedCoerceToType(unpaddedCoerceToType);
248
877
    return AI;
249
877
  }
250
251
3.87k
  static bool isPaddingForCoerceAndExpand(llvm::Type *eltType) {
252
3.87k
    if (eltType->isArrayTy()) {
253
28
      assert(eltType->getArrayElementType()->isIntegerTy(8));
254
28
      return true;
255
3.84k
    } else {
256
3.84k
      return false;
257
3.84k
    }
258
3.87k
  }
259
260
23.0M
  Kind getKind() const { return TheKind; }
261
15.3M
  bool isDirect() const { return TheKind == Direct; }
262
875k
  bool isInAlloca() const { return TheKind == InAlloca; }
263
423k
  bool isExtend() const { return TheKind == Extend; }
264
0
  bool isIgnore() const { return TheKind == Ignore; }
265
1.01M
  bool isIndirect() const { return TheKind == Indirect; }
266
38.6k
  bool isExpand() const { return TheKind == Expand; }
267
994k
  bool isCoerceAndExpand() const { return TheKind == CoerceAndExpand; }
268
269
865k
  bool canHaveCoerceToType() const {
270
865k
    return isDirect() || 
isExtend()153k
||
isCoerceAndExpand()123k
;
271
865k
  }
272
273
  // Direct/Extend accessors
274
2.98M
  unsigned getDirectOffset() const {
275
2.98M
    assert((isDirect() || isExtend()) && "Not a direct or extend kind");
276
2.98M
    return DirectOffset;
277
2.98M
  }
278
744k
  void setDirectOffset(unsigned Offset) {
279
744k
    assert((isDirect() || isExtend()) && "Not a direct or extend kind");
280
744k
    DirectOffset = Offset;
281
744k
  }
282
283
136k
  bool isSignExt() const {
284
136k
    assert(isExtend() && "Invalid kind!");
285
136k
    return SignExt;
286
136k
  }
287
30.4k
  void setSignExt(bool SExt) {
288
30.4k
    assert(isExtend() && "Invalid kind!");
289
30.4k
    SignExt = SExt;
290
30.4k
  }
291
292
7.27M
  llvm::Type *getPaddingType() const {
293
7.27M
    return (canHavePaddingType() ? 
PaddingType7.24M
:
nullptr38.2k
);
294
7.27M
  }
295
296
47
  bool getPaddingInReg() const {
297
47
    return PaddingInReg;
298
47
  }
299
83
  void setPaddingInReg(bool PIR) {
300
83
    PaddingInReg = PIR;
301
83
  }
302
303
19.0M
  llvm::Type *getCoerceToType() const {
304
19.0M
    assert(canHaveCoerceToType() && "Invalid kind!");
305
19.0M
    return TypeData;
306
19.0M
  }
307
308
1.31M
  void setCoerceToType(llvm::Type *T) {
309
1.31M
    assert(canHaveCoerceToType() && "Invalid kind!");
310
1.31M
    TypeData = T;
311
1.31M
  }
312
313
1.76k
  llvm::StructType *getCoerceAndExpandType() const {
314
1.76k
    assert(isCoerceAndExpand());
315
1.76k
    return cast<llvm::StructType>(TypeData);
316
1.76k
  }
317
318
1.16k
  llvm::Type *getUnpaddedCoerceAndExpandType() const {
319
1.16k
    assert(isCoerceAndExpand());
320
1.16k
    return UnpaddedCoerceAndExpandType;
321
1.16k
  }
322
323
3.52k
  ArrayRef<llvm::Type *>getCoerceAndExpandTypeSequence() const {
324
3.52k
    assert(isCoerceAndExpand());
325
3.52k
    if (auto structTy =
326
2.27k
          dyn_cast<llvm::StructType>(UnpaddedCoerceAndExpandType)) {
327
2.27k
      return structTy->elements();
328
2.27k
    } else {
329
1.25k
      return llvm::makeArrayRef(&UnpaddedCoerceAndExpandType, 1);
330
1.25k
    }
331
3.52k
  }
332
333
3.18M
  bool getInReg() const {
334
3.18M
    assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
335
3.18M
    return InReg;
336
3.18M
  }
337
338
312
  void setInReg(bool IR) {
339
312
    assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
340
312
    InReg = IR;
341
312
  }
342
343
  // Indirect accessors
344
17.9k
  CharUnits getIndirectAlign() const {
345
17.9k
    assert(isIndirect() && "Invalid kind!");
346
17.9k
    return CharUnits::fromQuantity(IndirectAlign);
347
17.9k
  }
348
6.66k
  void setIndirectAlign(CharUnits IA) {
349
6.66k
    assert(isIndirect() && "Invalid kind!");
350
6.66k
    IndirectAlign = IA.getQuantity();
351
6.66k
  }
352
353
14.9k
  bool getIndirectByVal() const {
354
14.9k
    assert(isIndirect() && "Invalid kind!");
355
14.9k
    return IndirectByVal;
356
14.9k
  }
357
6.66k
  void setIndirectByVal(bool IBV) {
358
6.66k
    assert(isIndirect() && "Invalid kind!");
359
6.66k
    IndirectByVal = IBV;
360
6.66k
  }
361
362
2.45k
  bool getIndirectRealign() const {
363
2.45k
    assert(isIndirect() && "Invalid kind!");
364
2.45k
    return IndirectRealign;
365
2.45k
  }
366
6.66k
  void setIndirectRealign(bool IR) {
367
6.66k
    assert(isIndirect() && "Invalid kind!");
368
6.66k
    IndirectRealign = IR;
369
6.66k
  }
370
371
42.5k
  bool isSRetAfterThis() const {
372
42.5k
    assert(isIndirect() && "Invalid kind!");
373
42.5k
    return SRetAfterThis;
374
42.5k
  }
375
6.71k
  void setSRetAfterThis(bool AfterThis) {
376
6.71k
    assert(isIndirect() && "Invalid kind!");
377
6.71k
    SRetAfterThis = AfterThis;
378
6.71k
  }
379
380
217
  unsigned getInAllocaFieldIndex() const {
381
217
    assert(isInAlloca() && "Invalid kind!");
382
217
    return AllocaFieldIndex;
383
217
  }
384
227
  void setInAllocaFieldIndex(unsigned FieldIndex) {
385
227
    assert(isInAlloca() && "Invalid kind!");
386
227
    AllocaFieldIndex = FieldIndex;
387
227
  }
388
389
  /// Return true if this field of an inalloca struct should be returned
390
  /// to implement a struct return calling convention.
391
20
  bool getInAllocaSRet() const {
392
20
    assert(isInAlloca() && "Invalid kind!");
393
20
    return InAllocaSRet;
394
20
  }
395
396
8
  void setInAllocaSRet(bool SRet) {
397
8
    assert(isInAlloca() && "Invalid kind!");
398
8
    InAllocaSRet = SRet;
399
8
  }
400
401
7.02M
  bool getCanBeFlattened() const {
402
7.02M
    assert(isDirect() && "Invalid kind!");
403
7.02M
    return CanBeFlattened;
404
7.02M
  }
405
406
714k
  void setCanBeFlattened(bool Flatten) {
407
714k
    assert(isDirect() && "Invalid kind!");
408
714k
    CanBeFlattened = Flatten;
409
714k
  }
410
411
11.1k
  bool getSuppressSRet() const {
412
11.1k
    assert(isIndirect() && "Invalid kind!");
413
11.1k
    return SuppressSRet;
414
11.1k
  }
415
416
92
  void setSuppressSRet(bool Suppress) {
417
92
    assert(isIndirect() && "Invalid kind!");
418
92
    SuppressSRet = Suppress;
419
92
  }
420
421
  void dump() const;
422
};
423
424
/// A class for recording the number of arguments that a function
425
/// signature requires.
426
class RequiredArgs {
427
  /// The number of required arguments, or ~0 if the signature does
428
  /// not permit optional arguments.
429
  unsigned NumRequired;
430
public:
431
  enum All_t { All };
432
433
3.06M
  RequiredArgs(All_t _) : NumRequired(~0U) {}
434
117k
  explicit RequiredArgs(unsigned n) : NumRequired(n) {
435
117k
    assert(n != ~0U);
436
117k
  }
437
438
  /// Compute the arguments required by the given formal prototype,
439
  /// given that there may be some additional, non-formal arguments
440
  /// in play.
441
  ///
442
  /// If FD is not null, this will consider pass_object_size params in FD.
443
  static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype,
444
                                       unsigned additional,
445
1.87M
                                       const FunctionDecl *FD) {
446
1.87M
    if (!prototype->isVariadic()) 
return All1.81M
;
447
58.0k
    if (FD)
448
57.7k
      additional +=
449
77.1k
          llvm::count_if(FD->parameters(), [](const ParmVarDecl *PVD) {
450
77.1k
            return PVD->hasAttr<PassObjectSizeAttr>();
451
77.1k
          });
452
58.0k
    return RequiredArgs(prototype->getNumParams() + additional);
453
58.0k
  }
454
455
  static RequiredArgs forPrototype(const FunctionProtoType *prototype,
456
                                   const FunctionDecl *FD) {
457
    return forPrototypePlus(prototype, 0, FD);
458
  }
459
460
  static RequiredArgs forPrototype(CanQual<FunctionProtoType> prototype,
461
                                   const FunctionDecl *FD) {
462
    return forPrototype(prototype.getTypePtr(), FD);
463
  }
464
465
  static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
466
                                       unsigned additional,
467
1.60M
                                       const FunctionDecl *FD) {
468
1.60M
    return forPrototypePlus(prototype.getTypePtr(), additional, FD);
469
1.60M
  }
470
471
6.32M
  bool allowsOptionalArgs() const { return NumRequired != ~0U; }
472
188k
  unsigned getNumRequiredArgs() const {
473
188k
    assert(allowsOptionalArgs());
474
188k
    return NumRequired;
475
188k
  }
476
477
6.49M
  unsigned getOpaqueData() const { return NumRequired; }
478
  static RequiredArgs getFromOpaqueData(unsigned value) {
479
    if (value == ~0U) return All;
480
    return RequiredArgs(value);
481
  }
482
};
483
484
// Implementation detail of CGFunctionInfo, factored out so it can be named
485
// in the TrailingObjects base class of CGFunctionInfo.
486
struct CGFunctionInfoArgInfo {
487
  CanQualType type;
488
  ABIArgInfo info;
489
};
490
491
/// CGFunctionInfo - Class to encapsulate the information about a
492
/// function definition.
493
class CGFunctionInfo final
494
    : public llvm::FoldingSetNode,
495
      private llvm::TrailingObjects<CGFunctionInfo, CGFunctionInfoArgInfo,
496
                                    FunctionProtoType::ExtParameterInfo> {
497
  typedef CGFunctionInfoArgInfo ArgInfo;
498
  typedef FunctionProtoType::ExtParameterInfo ExtParameterInfo;
499
500
  /// The LLVM::CallingConv to use for this function (as specified by the
501
  /// user).
502
  unsigned CallingConvention : 8;
503
504
  /// The LLVM::CallingConv to actually use for this function, which may
505
  /// depend on the ABI.
506
  unsigned EffectiveCallingConvention : 8;
507
508
  /// The clang::CallingConv that this was originally created with.
509
  unsigned ASTCallingConvention : 6;
510
511
  /// Whether this is an instance method.
512
  unsigned InstanceMethod : 1;
513
514
  /// Whether this is a chain call.
515
  unsigned ChainCall : 1;
516
517
  /// Whether this function is noreturn.
518
  unsigned NoReturn : 1;
519
520
  /// Whether this function is returns-retained.
521
  unsigned ReturnsRetained : 1;
522
523
  /// Whether this function saved caller registers.
524
  unsigned NoCallerSavedRegs : 1;
525
526
  /// How many arguments to pass inreg.
527
  unsigned HasRegParm : 1;
528
  unsigned RegParm : 3;
529
530
  /// Whether this function has nocf_check attribute.
531
  unsigned NoCfCheck : 1;
532
533
  RequiredArgs Required;
534
535
  /// The struct representing all arguments passed in memory.  Only used when
536
  /// passing non-trivial types with inalloca.  Not part of the profile.
537
  llvm::StructType *ArgStruct;
538
  unsigned ArgStructAlign : 31;
539
  unsigned HasExtParameterInfos : 1;
540
541
  unsigned NumArgs;
542
543
10.0M
  ArgInfo *getArgsBuffer() {
544
10.0M
    return getTrailingObjects<ArgInfo>();
545
10.0M
  }
546
25.1M
  const ArgInfo *getArgsBuffer() const {
547
25.1M
    return getTrailingObjects<ArgInfo>();
548
25.1M
  }
549
550
4.84k
  ExtParameterInfo *getExtParameterInfosBuffer() {
551
4.84k
    return getTrailingObjects<ExtParameterInfo>();
552
4.84k
  }
553
26.6k
  const ExtParameterInfo *getExtParameterInfosBuffer() const{
554
26.6k
    return getTrailingObjects<ExtParameterInfo>();
555
26.6k
  }
556
557
295k
  CGFunctionInfo() : Required(RequiredArgs::All) {}
558
559
public:
560
  static CGFunctionInfo *create(unsigned llvmCC,
561
                                bool instanceMethod,
562
                                bool chainCall,
563
                                const FunctionType::ExtInfo &extInfo,
564
                                ArrayRef<ExtParameterInfo> paramInfos,
565
                                CanQualType resultType,
566
                                ArrayRef<CanQualType> argTypes,
567
                                RequiredArgs required);
568
295k
  void operator delete(void *p) { ::operator delete(p); }
569
570
  // Friending class TrailingObjects is apparently not good enough for MSVC,
571
  // so these have to be public.
572
  friend class TrailingObjects;
573
31.4k
  size_t numTrailingObjects(OverloadToken<ArgInfo>) const {
574
31.4k
    return NumArgs + 1;
575
31.4k
  }
576
0
  size_t numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
577
0
    return (HasExtParameterInfos ? NumArgs : 0);
578
0
  }
579
580
  typedef const ArgInfo *const_arg_iterator;
581
  typedef ArgInfo *arg_iterator;
582
583
  typedef llvm::iterator_range<arg_iterator> arg_range;
584
  typedef llvm::iterator_range<const_arg_iterator> const_arg_range;
585
586
4.17M
  arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
587
0
  const_arg_range arguments() const {
588
0
    return const_arg_range(arg_begin(), arg_end());
589
0
  }
590
591
8.21M
  const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }
592
1.32M
  const_arg_iterator arg_end() const { return getArgsBuffer() + 1 + NumArgs; }
593
4.25M
  arg_iterator arg_begin() { return getArgsBuffer() + 1; }
594
4.25M
  arg_iterator arg_end() { return getArgsBuffer() + 1 + NumArgs; }
595
596
9.64M
  unsigned  arg_size() const { return NumArgs; }
597
598
6.32M
  bool isVariadic() const { return Required.allowsOptionalArgs(); }
599
188k
  RequiredArgs getRequiredArgs() const { return Required; }
600
4.70M
  unsigned getNumRequiredArgs() const {
601
4.70M
    return isVariadic() ? 
getRequiredArgs().getNumRequiredArgs()188k
:
arg_size()4.51M
;
602
4.70M
  }
603
604
209
  bool isInstanceMethod() const { return InstanceMethod; }
605
606
1.27M
  bool isChainCall() const { return ChainCall; }
607
608
1.68M
  bool isNoReturn() const { return NoReturn; }
609
610
  /// In ARC, whether this function retains its return value.  This
611
  /// is not always reliable for call sites.
612
330
  bool isReturnsRetained() const { return ReturnsRetained; }
613
614
  /// Whether this function no longer saves caller registers.
615
16
  bool isNoCallerSavedRegs() const { return NoCallerSavedRegs; }
616
617
  /// Whether this function has nocf_check attribute.
618
16
  bool isNoCfCheck() const { return NoCfCheck; }
619
620
  /// getASTCallingConvention() - Return the AST-specified calling
621
  /// convention.
622
3.66M
  CallingConv getASTCallingConvention() const {
623
3.66M
    return CallingConv(ASTCallingConvention);
624
3.66M
  }
625
626
  /// getCallingConvention - Return the user specified calling
627
  /// convention, which has been translated into an LLVM CC.
628
138k
  unsigned getCallingConvention() const { return CallingConvention; }
629
630
  /// getEffectiveCallingConvention - Return the actual calling convention to
631
  /// use, which may depend on the ABI.
632
1.32M
  unsigned getEffectiveCallingConvention() const {
633
1.32M
    return EffectiveCallingConvention;
634
1.32M
  }
635
2.86k
  void setEffectiveCallingConvention(unsigned Value) {
636
2.86k
    EffectiveCallingConvention = Value;
637
2.86k
  }
638
639
29.7k
  bool getHasRegParm() const { return HasRegParm; }
640
49
  unsigned getRegParm() const { return RegParm; }
641
642
16
  FunctionType::ExtInfo getExtInfo() const {
643
16
    return FunctionType::ExtInfo(isNoReturn(), getHasRegParm(), getRegParm(),
644
16
                                 getASTCallingConvention(), isReturnsRetained(),
645
16
                                 isNoCallerSavedRegs(), isNoCfCheck());
646
16
  }
647
648
7.10M
  CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
649
650
666k
  ABIArgInfo &getReturnInfo() { return getArgsBuffer()[0].info; }
651
8.51M
  const ABIArgInfo &getReturnInfo() const { return getArgsBuffer()[0].info; }
652
653
26.6k
  ArrayRef<ExtParameterInfo> getExtParameterInfos() const {
654
26.6k
    if (!HasExtParameterInfos) 
return {}0
;
655
26.6k
    return llvm::makeArrayRef(getExtParameterInfosBuffer(), NumArgs);
656
26.6k
  }
657
6.93M
  ExtParameterInfo getExtParameterInfo(unsigned argIndex) const {
658
6.93M
    assert(argIndex <= NumArgs);
659
6.93M
    if (!HasExtParameterInfos) 
return ExtParameterInfo()6.90M
;
660
22.6k
    return getExtParameterInfos()[argIndex];
661
22.6k
  }
662
663
  /// Return true if this function uses inalloca arguments.
664
4.10M
  bool usesInAlloca() const { return ArgStruct; }
665
666
  /// Get the struct type used to represent all the arguments in memory.
667
878k
  llvm::StructType *getArgStruct() const { return ArgStruct; }
668
99
  CharUnits getArgStructAlignment() const {
669
99
    return CharUnits::fromQuantity(ArgStructAlign);
670
99
  }
671
64
  void setArgStruct(llvm::StructType *Ty, CharUnits Align) {
672
64
    ArgStruct = Ty;
673
64
    ArgStructAlign = Align.getQuantity();
674
64
  }
675
676
3.66M
  void Profile(llvm::FoldingSetNodeID &ID) {
677
3.66M
    ID.AddInteger(getASTCallingConvention());
678
3.66M
    ID.AddBoolean(InstanceMethod);
679
3.66M
    ID.AddBoolean(ChainCall);
680
3.66M
    ID.AddBoolean(NoReturn);
681
3.66M
    ID.AddBoolean(ReturnsRetained);
682
3.66M
    ID.AddBoolean(NoCallerSavedRegs);
683
3.66M
    ID.AddBoolean(HasRegParm);
684
3.66M
    ID.AddInteger(RegParm);
685
3.66M
    ID.AddBoolean(NoCfCheck);
686
3.66M
    ID.AddInteger(Required.getOpaqueData());
687
3.66M
    ID.AddBoolean(HasExtParameterInfos);
688
3.66M
    if (HasExtParameterInfos) {
689
3.99k
      for (auto paramInfo : getExtParameterInfos())
690
10.1k
        ID.AddInteger(paramInfo.getOpaqueValue());
691
3.99k
    }
692
3.66M
    getReturnType().Profile(ID);
693
3.66M
    for (const auto &I : arguments())
694
6.63M
      I.type.Profile(ID);
695
3.66M
  }
696
  static void Profile(llvm::FoldingSetNodeID &ID,
697
                      bool InstanceMethod,
698
                      bool ChainCall,
699
                      const FunctionType::ExtInfo &info,
700
                      ArrayRef<ExtParameterInfo> paramInfos,
701
                      RequiredArgs required,
702
                      CanQualType resultType,
703
2.83M
                      ArrayRef<CanQualType> argTypes) {
704
2.83M
    ID.AddInteger(info.getCC());
705
2.83M
    ID.AddBoolean(InstanceMethod);
706
2.83M
    ID.AddBoolean(ChainCall);
707
2.83M
    ID.AddBoolean(info.getNoReturn());
708
2.83M
    ID.AddBoolean(info.getProducesResult());
709
2.83M
    ID.AddBoolean(info.getNoCallerSavedRegs());
710
2.83M
    ID.AddBoolean(info.getHasRegParm());
711
2.83M
    ID.AddInteger(info.getRegParm());
712
2.83M
    ID.AddBoolean(info.getNoCfCheck());
713
2.83M
    ID.AddInteger(required.getOpaqueData());
714
2.83M
    ID.AddBoolean(!paramInfos.empty());
715
2.83M
    if (!paramInfos.empty()) {
716
4.80k
      for (auto paramInfo : paramInfos)
717
12.2k
        ID.AddInteger(paramInfo.getOpaqueValue());
718
4.80k
    }
719
2.83M
    resultType.Profile(ID);
720
2.83M
    for (ArrayRef<CanQualType>::iterator
721
7.81M
           i = argTypes.begin(), e = argTypes.end(); i != e; 
++i4.97M
) {
722
4.97M
      i->Profile(ID);
723
4.97M
    }
724
2.83M
  }
725
};
726
727
}  // end namespace CodeGen
728
}  // end namespace clang
729
730
#endif