Coverage Report

Created: 2021-01-26 06:56

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