Coverage Report

Created: 2019-07-24 05:18

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