Coverage Report

Created: 2018-07-21 08:31

/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
100
6.74M
  bool canHavePaddingType() const {
101
6.74M
    return isDirect() || 
isExtend()254k
||
isIndirect()52.4k
||
isExpand()33.1k
;
102
6.74M
  }
103
701k
  void setPaddingType(llvm::Type *T) {
104
701k
    assert(canHavePaddingType());
105
701k
    PaddingType = T;
106
701k
  }
107
108
877
  void setUnpaddedCoerceToType(llvm::Type *T) {
109
877
    assert(isCoerceAndExpand());
110
877
    UnpaddedCoerceAndExpandType = T;
111
877
  }
112
113
  ABIArgInfo(Kind K)
114
811k
      : TheKind(K), PaddingInReg(false), InReg(false) {
115
811k
  }
116
117
public:
118
  ABIArgInfo()
119
      : TypeData(nullptr), PaddingType(nullptr), DirectOffset(0),
120
        TheKind(Direct), PaddingInReg(false), InReg(false) {}
121
122
  static ABIArgInfo getDirect(llvm::Type *T = nullptr, unsigned Offset = 0,
123
                              llvm::Type *Padding = nullptr,
124
666k
                              bool CanBeFlattened = true) {
125
666k
    auto AI = ABIArgInfo(Direct);
126
666k
    AI.setCoerceToType(T);
127
666k
    AI.setPaddingType(Padding);
128
666k
    AI.setDirectOffset(Offset);
129
666k
    AI.setCanBeFlattened(CanBeFlattened);
130
666k
    return AI;
131
666k
  }
132
176
  static ABIArgInfo getDirectInReg(llvm::Type *T = nullptr) {
133
176
    auto AI = getDirect(T);
134
176
    AI.setInReg(true);
135
176
    return AI;
136
176
  }
137
138
7.77k
  static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T = nullptr) {
139
7.77k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
140
7.77k
    auto AI = ABIArgInfo(Extend);
141
7.77k
    AI.setCoerceToType(T);
142
7.77k
    AI.setPaddingType(nullptr);
143
7.77k
    AI.setDirectOffset(0);
144
7.77k
    AI.setSignExt(true);
145
7.77k
    return AI;
146
7.77k
  }
147
148
21.2k
  static ABIArgInfo getZeroExtend(QualType Ty, llvm::Type *T = nullptr) {
149
21.2k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
150
21.2k
    auto AI = ABIArgInfo(Extend);
151
21.2k
    AI.setCoerceToType(T);
152
21.2k
    AI.setPaddingType(nullptr);
153
21.2k
    AI.setDirectOffset(0);
154
21.2k
    AI.setSignExt(false);
155
21.2k
    return AI;
156
21.2k
  }
157
158
  // ABIArgInfo will record the argument as being extended based on the sign
159
  // of its type.
160
28.9k
  static ABIArgInfo getExtend(QualType Ty, llvm::Type *T = nullptr) {
161
28.9k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
162
28.9k
    if (Ty->hasSignedIntegerRepresentation())
163
7.76k
      return getSignExtend(Ty, T);
164
21.2k
    return getZeroExtend(Ty, T);
165
21.2k
  }
166
167
25
  static ABIArgInfo getExtendInReg(QualType Ty, llvm::Type *T = nullptr) {
168
25
    auto AI = getExtend(Ty, T);
169
25
    AI.setInReg(true);
170
25
    return AI;
171
25
  }
172
109k
  static ABIArgInfo getIgnore() {
173
109k
    return ABIArgInfo(Ignore);
174
109k
  }
175
  static ABIArgInfo getIndirect(CharUnits Alignment, bool ByVal = true,
176
                                bool Realign = false,
177
5.62k
                                llvm::Type *Padding = nullptr) {
178
5.62k
    auto AI = ABIArgInfo(Indirect);
179
5.62k
    AI.setIndirectAlign(Alignment);
180
5.62k
    AI.setIndirectByVal(ByVal);
181
5.62k
    AI.setIndirectRealign(Realign);
182
5.62k
    AI.setSRetAfterThis(false);
183
5.62k
    AI.setPaddingType(Padding);
184
5.62k
    return AI;
185
5.62k
  }
186
  static ABIArgInfo getIndirectInReg(CharUnits Alignment, bool ByVal = true,
187
21
                                     bool Realign = false) {
188
21
    auto AI = getIndirect(Alignment, ByVal, Realign);
189
21
    AI.setInReg(true);
190
21
    return AI;
191
21
  }
192
225
  static ABIArgInfo getInAlloca(unsigned FieldIndex) {
193
225
    auto AI = ABIArgInfo(InAlloca);
194
225
    AI.setInAllocaFieldIndex(FieldIndex);
195
225
    return AI;
196
225
  }
197
120
  static ABIArgInfo getExpand() {
198
120
    auto AI = ABIArgInfo(Expand);
199
120
    AI.setPaddingType(nullptr);
200
120
    return AI;
201
120
  }
202
  static ABIArgInfo getExpandWithPadding(bool PaddingInReg,
203
83
                                         llvm::Type *Padding) {
204
83
    auto AI = getExpand();
205
83
    AI.setPaddingInReg(PaddingInReg);
206
83
    AI.setPaddingType(Padding);
207
83
    return AI;
208
83
  }
209
210
  /// \param unpaddedCoerceToType The coerce-to type with padding elements
211
  ///   removed, canonicalized to a single element if it would otherwise
212
  ///   have exactly one element.
213
  static ABIArgInfo getCoerceAndExpand(llvm::StructType *coerceToType,
214
877
                                       llvm::Type *unpaddedCoerceToType) {
215
877
#ifndef NDEBUG
216
877
    // Sanity checks on unpaddedCoerceToType.
217
877
218
877
    // Assert that we only have a struct type if there are multiple elements.
219
877
    auto unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoerceToType);
220
877
    assert(!unpaddedStruct || unpaddedStruct->getNumElements() != 1);
221
877
222
877
    // Assert that all the non-padding elements have a corresponding element
223
877
    // in the unpadded type.
224
877
    unsigned unpaddedIndex = 0;
225
877
    for (auto eltType : coerceToType->elements()) {
226
877
      if (isPaddingForCoerceAndExpand(eltType)) continue;
227
877
      if (unpaddedStruct) {
228
877
        assert(unpaddedStruct->getElementType(unpaddedIndex) == eltType);
229
877
      } else {
230
877
        assert(unpaddedIndex == 0 && unpaddedCoerceToType == eltType);
231
877
      }
232
877
      unpaddedIndex++;
233
877
    }
234
877
235
877
    // Assert that there aren't extra elements in the unpadded type.
236
877
    if (unpaddedStruct) {
237
877
      assert(unpaddedStruct->getNumElements() == unpaddedIndex);
238
877
    } else {
239
877
      assert(unpaddedIndex == 1);
240
877
    }
241
877
#endif
242
877
243
877
    auto AI = ABIArgInfo(CoerceAndExpand);
244
877
    AI.setCoerceToType(coerceToType);
245
877
    AI.setUnpaddedCoerceToType(unpaddedCoerceToType);
246
877
    return AI;
247
877
  }
248
249
3.73k
  static bool isPaddingForCoerceAndExpand(llvm::Type *eltType) {
250
3.73k
    if (eltType->isArrayTy()) {
251
28
      assert(eltType->getArrayElementType()->isIntegerTy(8));
252
28
      return true;
253
3.70k
    } else {
254
3.70k
      return false;
255
3.70k
    }
256
3.73k
  }
257
258
21.3M
  Kind getKind() const { return TheKind; }
259
14.2M
  bool isDirect() const { return TheKind == Direct; }
260
811k
  bool isInAlloca() const { return TheKind == InAlloca; }
261
399k
  bool isExtend() const { return TheKind == Extend; }
262
0
  bool isIgnore() const { return TheKind == Ignore; }
263
942k
  bool isIndirect() const { return TheKind == Indirect; }
264
33.1k
  bool isExpand() const { return TheKind == Expand; }
265
923k
  bool isCoerceAndExpand() const { return TheKind == CoerceAndExpand; }
266
267
808k
  bool canHaveCoerceToType() const {
268
808k
    return isDirect() || 
isExtend()144k
||
isCoerceAndExpand()116k
;
269
808k
  }
270
271
  // Direct/Extend accessors
272
2.76M
  unsigned getDirectOffset() const {
273
2.76M
    assert((isDirect() || isExtend()) && "Not a direct or extend kind");
274
2.76M
    return DirectOffset;
275
2.76M
  }
276
695k
  void setDirectOffset(unsigned Offset) {
277
695k
    assert((isDirect() || isExtend()) && "Not a direct or extend kind");
278
695k
    DirectOffset = Offset;
279
695k
  }
280
281
130k
  bool isSignExt() const {
282
130k
    assert(isExtend() && "Invalid kind!");
283
130k
    return SignExt;
284
130k
  }
285
29.0k
  void setSignExt(bool SExt) {
286
29.0k
    assert(isExtend() && "Invalid kind!");
287
29.0k
    SignExt = SExt;
288
29.0k
  }
289
290
6.74M
  llvm::Type *getPaddingType() const {
291
6.74M
    return (canHavePaddingType() ? 
PaddingType6.70M
:
nullptr32.7k
);
292
6.74M
  }
293
294
47
  bool getPaddingInReg() const {
295
47
    return PaddingInReg;
296
47
  }
297
83
  void setPaddingInReg(bool PIR) {
298
83
    PaddingInReg = PIR;
299
83
  }
300
301
17.6M
  llvm::Type *getCoerceToType() const {
302
17.6M
    assert(canHaveCoerceToType() && "Invalid kind!");
303
17.6M
    return TypeData;
304
17.6M
  }
305
306
1.21M
  void setCoerceToType(llvm::Type *T) {
307
1.21M
    assert(canHaveCoerceToType() && "Invalid kind!");
308
1.21M
    TypeData = T;
309
1.21M
  }
310
311
1.76k
  llvm::StructType *getCoerceAndExpandType() const {
312
1.76k
    assert(isCoerceAndExpand());
313
1.76k
    return cast<llvm::StructType>(TypeData);
314
1.76k
  }
315
316
1.15k
  llvm::Type *getUnpaddedCoerceAndExpandType() const {
317
1.15k
    assert(isCoerceAndExpand());
318
1.15k
    return UnpaddedCoerceAndExpandType;
319
1.15k
  }
320
321
3.52k
  ArrayRef<llvm::Type *>getCoerceAndExpandTypeSequence() const {
322
3.52k
    assert(isCoerceAndExpand());
323
3.52k
    if (auto structTy =
324
2.24k
          dyn_cast<llvm::StructType>(UnpaddedCoerceAndExpandType)) {
325
2.24k
      return structTy->elements();
326
2.24k
    } else {
327
1.28k
      return llvm::makeArrayRef(&UnpaddedCoerceAndExpandType, 1);
328
1.28k
    }
329
3.52k
  }
330
331
2.95M
  bool getInReg() const {
332
2.95M
    assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
333
2.95M
    return InReg;
334
2.95M
  }
335
336
312
  void setInReg(bool IR) {
337
312
    assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
338
312
    InReg = IR;
339
312
  }
340
341
  // Indirect accessors
342
15.2k
  CharUnits getIndirectAlign() const {
343
15.2k
    assert(isIndirect() && "Invalid kind!");
344
15.2k
    return CharUnits::fromQuantity(IndirectAlign);
345
15.2k
  }
346
5.62k
  void setIndirectAlign(CharUnits IA) {
347
5.62k
    assert(isIndirect() && "Invalid kind!");
348
5.62k
    IndirectAlign = IA.getQuantity();
349
5.62k
  }
350
351
13.1k
  bool getIndirectByVal() const {
352
13.1k
    assert(isIndirect() && "Invalid kind!");
353
13.1k
    return IndirectByVal;
354
13.1k
  }
355
5.62k
  void setIndirectByVal(bool IBV) {
356
5.62k
    assert(isIndirect() && "Invalid kind!");
357
5.62k
    IndirectByVal = IBV;
358
5.62k
  }
359
360
2.19k
  bool getIndirectRealign() const {
361
2.19k
    assert(isIndirect() && "Invalid kind!");
362
2.19k
    return IndirectRealign;
363
2.19k
  }
364
5.62k
  void setIndirectRealign(bool IR) {
365
5.62k
    assert(isIndirect() && "Invalid kind!");
366
5.62k
    IndirectRealign = IR;
367
5.62k
  }
368
369
27.6k
  bool isSRetAfterThis() const {
370
27.6k
    assert(isIndirect() && "Invalid kind!");
371
27.6k
    return SRetAfterThis;
372
27.6k
  }
373
5.66k
  void setSRetAfterThis(bool AfterThis) {
374
5.66k
    assert(isIndirect() && "Invalid kind!");
375
5.66k
    SRetAfterThis = AfterThis;
376
5.66k
  }
377
378
213
  unsigned getInAllocaFieldIndex() const {
379
213
    assert(isInAlloca() && "Invalid kind!");
380
213
    return AllocaFieldIndex;
381
213
  }
382
225
  void setInAllocaFieldIndex(unsigned FieldIndex) {
383
225
    assert(isInAlloca() && "Invalid kind!");
384
225
    AllocaFieldIndex = FieldIndex;
385
225
  }
386
387
  /// Return true if this field of an inalloca struct should be returned
388
  /// to implement a struct return calling convention.
389
20
  bool getInAllocaSRet() const {
390
20
    assert(isInAlloca() && "Invalid kind!");
391
20
    return InAllocaSRet;
392
20
  }
393
394
8
  void setInAllocaSRet(bool SRet) {
395
8
    assert(isInAlloca() && "Invalid kind!");
396
8
    InAllocaSRet = SRet;
397
8
  }
398
399
6.49M
  bool getCanBeFlattened() const {
400
6.49M
    assert(isDirect() && "Invalid kind!");
401
6.49M
    return CanBeFlattened;
402
6.49M
  }
403
404
666k
  void setCanBeFlattened(bool Flatten) {
405
666k
    assert(isDirect() && "Invalid kind!");
406
666k
    CanBeFlattened = Flatten;
407
666k
  }
408
409
  void dump() const;
410
};
411
412
/// A class for recording the number of arguments that a function
413
/// signature requires.
414
class RequiredArgs {
415
  /// The number of required arguments, or ~0 if the signature does
416
  /// not permit optional arguments.
417
  unsigned NumRequired;
418
public:
419
  enum All_t { All };
420
421
2.83M
  RequiredArgs(All_t _) : NumRequired(~0U) {}
422
117k
  explicit RequiredArgs(unsigned n) : NumRequired(n) {
423
117k
    assert(n != ~0U);
424
117k
  }
425
426
  /// Compute the arguments required by the given formal prototype,
427
  /// given that there may be some additional, non-formal arguments
428
  /// in play.
429
  ///
430
  /// If FD is not null, this will consider pass_object_size params in FD.
431
  static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype,
432
                                       unsigned additional,
433
1.72M
                                       const FunctionDecl *FD) {
434
1.72M
    if (!prototype->isVariadic()) 
return All1.66M
;
435
57.7k
    if (FD)
436
57.3k
      additional +=
437
76.7k
          llvm::count_if(FD->parameters(), [](const ParmVarDecl *PVD) {
438
76.7k
            return PVD->hasAttr<PassObjectSizeAttr>();
439
76.7k
          });
440
57.7k
    return RequiredArgs(prototype->getNumParams() + additional);
441
57.7k
  }
442
443
  static RequiredArgs forPrototype(const FunctionProtoType *prototype,
444
                                   const FunctionDecl *FD) {
445
    return forPrototypePlus(prototype, 0, FD);
446
  }
447
448
  static RequiredArgs forPrototype(CanQual<FunctionProtoType> prototype,
449
                                   const FunctionDecl *FD) {
450
    return forPrototype(prototype.getTypePtr(), FD);
451
  }
452
453
  static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
454
                                       unsigned additional,
455
1.49M
                                       const FunctionDecl *FD) {
456
1.49M
    return forPrototypePlus(prototype.getTypePtr(), additional, FD);
457
1.49M
  }
458
459
5.84M
  bool allowsOptionalArgs() const { return NumRequired != ~0U; }
460
187k
  unsigned getNumRequiredArgs() const {
461
187k
    assert(allowsOptionalArgs());
462
187k
    return NumRequired;
463
187k
  }
464
465
5.96M
  unsigned getOpaqueData() const { return NumRequired; }
466
  static RequiredArgs getFromOpaqueData(unsigned value) {
467
    if (value == ~0U) return All;
468
    return RequiredArgs(value);
469
  }
470
};
471
472
// Implementation detail of CGFunctionInfo, factored out so it can be named
473
// in the TrailingObjects base class of CGFunctionInfo.
474
struct CGFunctionInfoArgInfo {
475
  CanQualType type;
476
  ABIArgInfo info;
477
};
478
479
/// CGFunctionInfo - Class to encapsulate the information about a
480
/// function definition.
481
class CGFunctionInfo final
482
    : public llvm::FoldingSetNode,
483
      private llvm::TrailingObjects<CGFunctionInfo, CGFunctionInfoArgInfo,
484
                                    FunctionProtoType::ExtParameterInfo> {
485
  typedef CGFunctionInfoArgInfo ArgInfo;
486
  typedef FunctionProtoType::ExtParameterInfo ExtParameterInfo;
487
488
  /// The LLVM::CallingConv to use for this function (as specified by the
489
  /// user).
490
  unsigned CallingConvention : 8;
491
492
  /// The LLVM::CallingConv to actually use for this function, which may
493
  /// depend on the ABI.
494
  unsigned EffectiveCallingConvention : 8;
495
496
  /// The clang::CallingConv that this was originally created with.
497
  unsigned ASTCallingConvention : 6;
498
499
  /// Whether this is an instance method.
500
  unsigned InstanceMethod : 1;
501
502
  /// Whether this is a chain call.
503
  unsigned ChainCall : 1;
504
505
  /// Whether this function is noreturn.
506
  unsigned NoReturn : 1;
507
508
  /// Whether this function is returns-retained.
509
  unsigned ReturnsRetained : 1;
510
511
  /// Whether this function saved caller registers.
512
  unsigned NoCallerSavedRegs : 1;
513
514
  /// How many arguments to pass inreg.
515
  unsigned HasRegParm : 1;
516
  unsigned RegParm : 3;
517
518
  /// Whether this function has nocf_check attribute.
519
  unsigned NoCfCheck : 1;
520
521
  RequiredArgs Required;
522
523
  /// The struct representing all arguments passed in memory.  Only used when
524
  /// passing non-trivial types with inalloca.  Not part of the profile.
525
  llvm::StructType *ArgStruct;
526
  unsigned ArgStructAlign : 31;
527
  unsigned HasExtParameterInfos : 1;
528
529
  unsigned NumArgs;
530
531
9.21M
  ArgInfo *getArgsBuffer() {
532
9.21M
    return getTrailingObjects<ArgInfo>();
533
9.21M
  }
534
23.2M
  const ArgInfo *getArgsBuffer() const {
535
23.2M
    return getTrailingObjects<ArgInfo>();
536
23.2M
  }
537
538
4.83k
  ExtParameterInfo *getExtParameterInfosBuffer() {
539
4.83k
    return getTrailingObjects<ExtParameterInfo>();
540
4.83k
  }
541
26.8k
  const ExtParameterInfo *getExtParameterInfosBuffer() const{
542
26.8k
    return getTrailingObjects<ExtParameterInfo>();
543
26.8k
  }
544
545
275k
  CGFunctionInfo() : Required(RequiredArgs::All) {}
546
547
public:
548
  static CGFunctionInfo *create(unsigned llvmCC,
549
                                bool instanceMethod,
550
                                bool chainCall,
551
                                const FunctionType::ExtInfo &extInfo,
552
                                ArrayRef<ExtParameterInfo> paramInfos,
553
                                CanQualType resultType,
554
                                ArrayRef<CanQualType> argTypes,
555
                                RequiredArgs required);
556
275k
  void operator delete(void *p) { ::operator delete(p); }
557
558
  // Friending class TrailingObjects is apparently not good enough for MSVC,
559
  // so these have to be public.
560
  friend class TrailingObjects;
561
31.6k
  size_t numTrailingObjects(OverloadToken<ArgInfo>) const {
562
31.6k
    return NumArgs + 1;
563
31.6k
  }
564
0
  size_t numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
565
0
    return (HasExtParameterInfos ? NumArgs : 0);
566
0
  }
567
568
  typedef const ArgInfo *const_arg_iterator;
569
  typedef ArgInfo *arg_iterator;
570
571
  typedef llvm::iterator_range<arg_iterator> arg_range;
572
  typedef llvm::iterator_range<const_arg_iterator> arg_const_range;
573
574
3.81M
  arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
575
0
  arg_const_range arguments() const {
576
0
    return arg_const_range(arg_begin(), arg_end());
577
0
  }
578
579
7.59M
  const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }
580
1.22M
  const_arg_iterator arg_end() const { return getArgsBuffer() + 1 + NumArgs; }
581
3.89M
  arg_iterator arg_begin() { return getArgsBuffer() + 1; }
582
3.89M
  arg_iterator arg_end() { return getArgsBuffer() + 1 + NumArgs; }
583
584
8.90M
  unsigned  arg_size() const { return NumArgs; }
585
586
5.84M
  bool isVariadic() const { return Required.allowsOptionalArgs(); }
587
187k
  RequiredArgs getRequiredArgs() const { return Required; }
588
4.34M
  unsigned getNumRequiredArgs() const {
589
4.34M
    return isVariadic() ? 
getRequiredArgs().getNumRequiredArgs()187k
:
arg_size()4.15M
;
590
4.34M
  }
591
592
190
  bool isInstanceMethod() const { return InstanceMethod; }
593
594
1.18M
  bool isChainCall() const { return ChainCall; }
595
596
1.56M
  bool isNoReturn() const { return NoReturn; }
597
598
  /// In ARC, whether this function retains its return value.  This
599
  /// is not always reliable for call sites.
600
328
  bool isReturnsRetained() const { return ReturnsRetained; }
601
602
  /// Whether this function no longer saves caller registers.
603
16
  bool isNoCallerSavedRegs() const { return NoCallerSavedRegs; }
604
605
  /// Whether this function has nocf_check attribute.
606
16
  bool isNoCfCheck() const { return NoCfCheck; }
607
608
  /// getASTCallingConvention() - Return the AST-specified calling
609
  /// convention.
610
3.34M
  CallingConv getASTCallingConvention() const {
611
3.34M
    return CallingConv(ASTCallingConvention);
612
3.34M
  }
613
614
  /// getCallingConvention - Return the user specified calling
615
  /// convention, which has been translated into an LLVM CC.
616
135k
  unsigned getCallingConvention() const { return CallingConvention; }
617
618
  /// getEffectiveCallingConvention - Return the actual calling convention to
619
  /// use, which may depend on the ABI.
620
1.22M
  unsigned getEffectiveCallingConvention() const {
621
1.22M
    return EffectiveCallingConvention;
622
1.22M
  }
623
2.67k
  void setEffectiveCallingConvention(unsigned Value) {
624
2.67k
    EffectiveCallingConvention = Value;
625
2.67k
  }
626
627
29.6k
  bool getHasRegParm() const { return HasRegParm; }
628
49
  unsigned getRegParm() const { return RegParm; }
629
630
16
  FunctionType::ExtInfo getExtInfo() const {
631
16
    return FunctionType::ExtInfo(isNoReturn(), getHasRegParm(), getRegParm(),
632
16
                                 getASTCallingConvention(), isReturnsRetained(),
633
16
                                 isNoCallerSavedRegs(), isNoCfCheck());
634
16
  }
635
636
6.52M
  CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
637
638
625k
  ABIArgInfo &getReturnInfo() { return getArgsBuffer()[0].info; }
639
7.85M
  const ABIArgInfo &getReturnInfo() const { return getArgsBuffer()[0].info; }
640
641
26.8k
  ArrayRef<ExtParameterInfo> getExtParameterInfos() const {
642
26.8k
    if (!HasExtParameterInfos) 
return {}0
;
643
26.8k
    return llvm::makeArrayRef(getExtParameterInfosBuffer(), NumArgs);
644
26.8k
  }
645
6.44M
  ExtParameterInfo getExtParameterInfo(unsigned argIndex) const {
646
6.44M
    assert(argIndex <= NumArgs);
647
6.44M
    if (!HasExtParameterInfos) 
return ExtParameterInfo()6.41M
;
648
22.5k
    return getExtParameterInfos()[argIndex];
649
22.5k
  }
650
651
  /// Return true if this function uses inalloca arguments.
652
3.79M
  bool usesInAlloca() const { return ArgStruct; }
653
654
  /// Get the struct type used to represent all the arguments in memory.
655
811k
  llvm::StructType *getArgStruct() const { return ArgStruct; }
656
95
  CharUnits getArgStructAlignment() const {
657
95
    return CharUnits::fromQuantity(ArgStructAlign);
658
95
  }
659
63
  void setArgStruct(llvm::StructType *Ty, CharUnits Align) {
660
63
    ArgStruct = Ty;
661
63
    ArgStructAlign = Align.getQuantity();
662
63
  }
663
664
3.34M
  void Profile(llvm::FoldingSetNodeID &ID) {
665
3.34M
    ID.AddInteger(getASTCallingConvention());
666
3.34M
    ID.AddBoolean(InstanceMethod);
667
3.34M
    ID.AddBoolean(ChainCall);
668
3.34M
    ID.AddBoolean(NoReturn);
669
3.34M
    ID.AddBoolean(ReturnsRetained);
670
3.34M
    ID.AddBoolean(NoCallerSavedRegs);
671
3.34M
    ID.AddBoolean(HasRegParm);
672
3.34M
    ID.AddInteger(RegParm);
673
3.34M
    ID.AddBoolean(NoCfCheck);
674
3.34M
    ID.AddInteger(Required.getOpaqueData());
675
3.34M
    ID.AddBoolean(HasExtParameterInfos);
676
3.34M
    if (HasExtParameterInfos) {
677
4.23k
      for (auto paramInfo : getExtParameterInfos())
678
10.5k
        ID.AddInteger(paramInfo.getOpaqueValue());
679
4.23k
    }
680
3.34M
    getReturnType().Profile(ID);
681
3.34M
    for (const auto &I : arguments())
682
6.06M
      I.type.Profile(ID);
683
3.34M
  }
684
  static void Profile(llvm::FoldingSetNodeID &ID,
685
                      bool InstanceMethod,
686
                      bool ChainCall,
687
                      const FunctionType::ExtInfo &info,
688
                      ArrayRef<ExtParameterInfo> paramInfos,
689
                      RequiredArgs required,
690
                      CanQualType resultType,
691
2.62M
                      ArrayRef<CanQualType> argTypes) {
692
2.62M
    ID.AddInteger(info.getCC());
693
2.62M
    ID.AddBoolean(InstanceMethod);
694
2.62M
    ID.AddBoolean(ChainCall);
695
2.62M
    ID.AddBoolean(info.getNoReturn());
696
2.62M
    ID.AddBoolean(info.getProducesResult());
697
2.62M
    ID.AddBoolean(info.getNoCallerSavedRegs());
698
2.62M
    ID.AddBoolean(info.getHasRegParm());
699
2.62M
    ID.AddInteger(info.getRegParm());
700
2.62M
    ID.AddBoolean(info.getNoCfCheck());
701
2.62M
    ID.AddInteger(required.getOpaqueData());
702
2.62M
    ID.AddBoolean(!paramInfos.empty());
703
2.62M
    if (!paramInfos.empty()) {
704
4.78k
      for (auto paramInfo : paramInfos)
705
12.2k
        ID.AddInteger(paramInfo.getOpaqueValue());
706
4.78k
    }
707
2.62M
    resultType.Profile(ID);
708
2.62M
    for (ArrayRef<CanQualType>::iterator
709
7.22M
           i = argTypes.begin(), e = argTypes.end(); i != e; 
++i4.60M
) {
710
4.60M
      i->Profile(ID);
711
4.60M
    }
712
2.62M
  }
713
};
714
715
}  // end namespace CodeGen
716
}  // end namespace clang
717
718
#endif