Coverage Report

Created: 2020-07-11 14:00

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