Coverage Report

Created: 2020-09-19 12:23

/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.09M
  bool canHavePaddingType() const {
114
4.09M
    return isDirect() || 
isExtend()203k
||
isIndirect()86.3k
||
isIndirectAliased()66.6k
||
115
66.6k
           isExpand();
116
4.09M
  }
117
478k
  void setPaddingType(llvm::Type *T) {
118
478k
    assert(canHavePaddingType());
119
478k
    PaddingType = T;
120
478k
  }
121
122
1.10k
  void setUnpaddedCoerceToType(llvm::Type *T) {
123
1.10k
    assert(isCoerceAndExpand());
124
1.10k
    UnpaddedCoerceAndExpandType = T;
125
1.10k
  }
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
573k
        SignExt(false) {}
134
135
  static ABIArgInfo getDirect(llvm::Type *T = nullptr, unsigned Offset = 0,
136
                              llvm::Type *Padding = nullptr,
137
456k
                              bool CanBeFlattened = true) {
138
456k
    auto AI = ABIArgInfo(Direct);
139
456k
    AI.setCoerceToType(T);
140
456k
    AI.setPaddingType(Padding);
141
456k
    AI.setDirectOffset(Offset);
142
456k
    AI.setCanBeFlattened(CanBeFlattened);
143
456k
    return AI;
144
456k
  }
145
320
  static ABIArgInfo getDirectInReg(llvm::Type *T = nullptr) {
146
320
    auto AI = getDirect(T);
147
320
    AI.setInReg(true);
148
320
    return AI;
149
320
  }
150
151
9.37k
  static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T = nullptr) {
152
9.37k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
153
9.37k
    auto AI = ABIArgInfo(Extend);
154
9.37k
    AI.setCoerceToType(T);
155
9.37k
    AI.setPaddingType(nullptr);
156
9.37k
    AI.setDirectOffset(0);
157
9.37k
    AI.setSignExt(true);
158
9.37k
    return AI;
159
9.37k
  }
160
161
7.05k
  static ABIArgInfo getZeroExtend(QualType Ty, llvm::Type *T = nullptr) {
162
7.05k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
163
7.05k
    auto AI = ABIArgInfo(Extend);
164
7.05k
    AI.setCoerceToType(T);
165
7.05k
    AI.setPaddingType(nullptr);
166
7.05k
    AI.setDirectOffset(0);
167
7.05k
    AI.setSignExt(false);
168
7.05k
    return AI;
169
7.05k
  }
170
171
  // ABIArgInfo will record the argument as being extended based on the sign
172
  // of its type.
173
16.3k
  static ABIArgInfo getExtend(QualType Ty, llvm::Type *T = nullptr) {
174
16.3k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
175
16.3k
    if (Ty->hasSignedIntegerRepresentation())
176
9.33k
      return getSignExtend(Ty, T);
177
7.05k
    return getZeroExtend(Ty, T);
178
7.05k
  }
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
93.8k
  static ABIArgInfo getIgnore() {
186
93.8k
    return ABIArgInfo(Ignore);
187
93.8k
  }
188
  static ABIArgInfo getIndirect(CharUnits Alignment, bool ByVal = true,
189
                                bool Realign = false,
190
4.92k
                                llvm::Type *Padding = nullptr) {
191
4.92k
    auto AI = ABIArgInfo(Indirect);
192
4.92k
    AI.setIndirectAlign(Alignment);
193
4.92k
    AI.setIndirectByVal(ByVal);
194
4.92k
    AI.setIndirectRealign(Realign);
195
4.92k
    AI.setSRetAfterThis(false);
196
4.92k
    AI.setPaddingType(Padding);
197
4.92k
    return AI;
198
4.92k
  }
199
200
  /// Pass this in memory using the IR byref attribute.
201
  static ABIArgInfo getIndirectAliased(CharUnits Alignment, unsigned AddrSpace,
202
                                       bool Realign = false,
203
5
                                       llvm::Type *Padding = nullptr) {
204
5
    auto AI = ABIArgInfo(IndirectAliased);
205
5
    AI.setIndirectAlign(Alignment);
206
5
    AI.setIndirectRealign(Realign);
207
5
    AI.setPaddingType(Padding);
208
5
    AI.setIndirectAddrSpace(AddrSpace);
209
5
    return AI;
210
5
  }
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
246
  static ABIArgInfo getInAlloca(unsigned FieldIndex, bool Indirect = false) {
219
246
    auto AI = ABIArgInfo(InAlloca);
220
246
    AI.setInAllocaFieldIndex(FieldIndex);
221
246
    AI.setInAllocaIndirect(Indirect);
222
246
    return AI;
223
246
  }
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.10k
                                       llvm::Type *unpaddedCoerceToType) {
242
1.10k
#ifndef NDEBUG
243
    // Sanity checks on unpaddedCoerceToType.
244
1.10k
245
    // Assert that we only have a struct type if there are multiple elements.
246
1.10k
    auto unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoerceToType);
247
1.10k
    assert(!unpaddedStruct || unpaddedStruct->getNumElements() != 1);
248
1.10k
249
    // Assert that all the non-padding elements have a corresponding element
250
    // in the unpadded type.
251
1.10k
    unsigned unpaddedIndex = 0;
252
2.34k
    for (auto eltType : coerceToType->elements()) {
253
2.34k
      if (isPaddingForCoerceAndExpand(eltType)) 
continue14
;
254
2.32k
      if (unpaddedStruct) {
255
1.96k
        assert(unpaddedStruct->getElementType(unpaddedIndex) == eltType);
256
361
      } else {
257
361
        assert(unpaddedIndex == 0 && unpaddedCoerceToType == eltType);
258
361
      }
259
2.32k
      unpaddedIndex++;
260
2.32k
    }
261
1.10k
262
    // Assert that there aren't extra elements in the unpadded type.
263
1.10k
    if (unpaddedStruct) {
264
745
      assert(unpaddedStruct->getNumElements() == unpaddedIndex);
265
361
    } else {
266
361
      assert(unpaddedIndex == 1);
267
361
    }
268
1.10k
#endif
269
1.10k
270
1.10k
    auto AI = ABIArgInfo(CoerceAndExpand);
271
1.10k
    AI.setCoerceToType(coerceToType);
272
1.10k
    AI.setUnpaddedCoerceToType(unpaddedCoerceToType);
273
1.10k
    return AI;
274
1.10k
  }
275
276
6.62k
  static bool isPaddingForCoerceAndExpand(llvm::Type *eltType) {
277
6.62k
    if (eltType->isArrayTy()) {
278
42
      assert(eltType->getArrayElementType()->isIntegerTy(8));
279
42
      return true;
280
6.58k
    } else {
281
6.58k
      return false;
282
6.58k
    }
283
6.62k
  }
284
285
11.8M
  Kind getKind() const { return TheKind; }
286
25.9M
  bool isDirect() const { return TheKind == Direct; }
287
340k
  bool isInAlloca() const { return TheKind == InAlloca; }
288
873k
  bool isExtend() const { return TheKind == Extend; }
289
0
  bool isIgnore() const { return TheKind == Ignore; }
290
643k
  bool isIndirect() const { return TheKind == Indirect; }
291
68.5k
  bool isIndirectAliased() const { return TheKind == IndirectAliased; }
292
66.6k
  bool isExpand() const { return TheKind == Expand; }
293
431k
  bool isCoerceAndExpand() const { return TheKind == CoerceAndExpand; }
294
295
10.8M
  bool canHaveCoerceToType() const {
296
10.8M
    return isDirect() || 
isExtend()455k
||
isCoerceAndExpand()102k
;
297
10.8M
  }
298
299
  // Direct/Extend accessors
300
1.78M
  unsigned getDirectOffset() const {
301
1.78M
    assert((isDirect() || isExtend()) && "Not a direct or extend kind");
302
1.78M
    return DirectOffset;
303
1.78M
  }
304
473k
  void setDirectOffset(unsigned Offset) {
305
473k
    assert((isDirect() || isExtend()) && "Not a direct or extend kind");
306
473k
    DirectOffset = Offset;
307
473k
  }
308
309
51.6k
  bool isSignExt() const {
310
51.6k
    assert(isExtend() && "Invalid kind!");
311
51.6k
    return SignExt;
312
51.6k
  }
313
16.4k
  void setSignExt(bool SExt) {
314
16.4k
    assert(isExtend() && "Invalid kind!");
315
16.4k
    SignExt = SExt;
316
16.4k
  }
317
318
3.61M
  llvm::Type *getPaddingType() const {
319
3.55M
    return (canHavePaddingType() ? PaddingType : 
nullptr65.9k
);
320
3.61M
  }
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.60M
  llvm::Type *getCoerceToType() const {
330
9.60M
    assert(canHaveCoerceToType() && "Invalid kind!");
331
9.60M
    return TypeData;
332
9.60M
  }
333
334
633k
  void setCoerceToType(llvm::Type *T) {
335
633k
    assert(canHaveCoerceToType() && "Invalid kind!");
336
633k
    TypeData = T;
337
633k
  }
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.90k
  ArrayRef<llvm::Type *>getCoerceAndExpandTypeSequence() const {
350
4.90k
    assert(isCoerceAndExpand());
351
4.90k
    if (auto structTy =
352
3.24k
          dyn_cast<llvm::StructType>(UnpaddedCoerceAndExpandType)) {
353
3.24k
      return structTy->elements();
354
1.66k
    } else {
355
1.66k
      return llvm::makeArrayRef(&UnpaddedCoerceAndExpandType, 1);
356
1.66k
    }
357
4.90k
  }
358
359
1.37M
  bool getInReg() const {
360
1.37M
    assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
361
1.37M
    return InReg;
362
1.37M
  }
363
364
590
  void setInReg(bool IR) {
365
590
    assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
366
590
    InReg = IR;
367
590
  }
368
369
  // Indirect accessors
370
15.3k
  CharUnits getIndirectAlign() const {
371
15.3k
    assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
372
15.3k
    return CharUnits::fromQuantity(IndirectAlign);
373
15.3k
  }
374
4.93k
  void setIndirectAlign(CharUnits IA) {
375
4.93k
    assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
376
4.93k
    IndirectAlign = IA.getQuantity();
377
4.93k
  }
378
379
12.1k
  bool getIndirectByVal() const {
380
12.1k
    assert(isIndirect() && "Invalid kind!");
381
12.1k
    return IndirectByVal;
382
12.1k
  }
383
4.92k
  void setIndirectByVal(bool IBV) {
384
4.92k
    assert(isIndirect() && "Invalid kind!");
385
4.92k
    IndirectByVal = IBV;
386
4.92k
  }
387
388
15
  unsigned getIndirectAddrSpace() const {
389
15
    assert(isIndirectAliased() && "Invalid kind!");
390
15
    return IndirectAddrSpace;
391
15
  }
392
393
5
  void setIndirectAddrSpace(unsigned AddrSpace) {
394
5
    assert(isIndirectAliased() && "Invalid kind!");
395
5
    IndirectAddrSpace = AddrSpace;
396
5
  }
397
398
1.85k
  bool getIndirectRealign() const {
399
1.85k
    assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
400
1.85k
    return IndirectRealign;
401
1.85k
  }
402
4.93k
  void setIndirectRealign(bool IR) {
403
4.93k
    assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
404
4.93k
    IndirectRealign = IR;
405
4.93k
  }
406
407
18.6k
  bool isSRetAfterThis() const {
408
18.6k
    assert(isIndirect() && "Invalid kind!");
409
18.6k
    return SRetAfterThis;
410
18.6k
  }
411
5.04k
  void setSRetAfterThis(bool AfterThis) {
412
5.04k
    assert(isIndirect() && "Invalid kind!");
413
5.04k
    SRetAfterThis = AfterThis;
414
5.04k
  }
415
416
235
  unsigned getInAllocaFieldIndex() const {
417
235
    assert(isInAlloca() && "Invalid kind!");
418
235
    return AllocaFieldIndex;
419
235
  }
420
246
  void setInAllocaFieldIndex(unsigned FieldIndex) {
421
246
    assert(isInAlloca() && "Invalid kind!");
422
246
    AllocaFieldIndex = FieldIndex;
423
246
  }
424
425
221
  unsigned getInAllocaIndirect() const {
426
221
    assert(isInAlloca() && "Invalid kind!");
427
221
    return InAllocaIndirect;
428
221
  }
429
246
  void setInAllocaIndirect(bool Indirect) {
430
246
    assert(isInAlloca() && "Invalid kind!");
431
246
    InAllocaIndirect = Indirect;
432
246
  }
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.44M
  bool getCanBeFlattened() const {
447
3.44M
    assert(isDirect() && "Invalid kind!");
448
3.44M
    return CanBeFlattened;
449
3.44M
  }
450
451
456k
  void setCanBeFlattened(bool Flatten) {
452
456k
    assert(isDirect() && "Invalid kind!");
453
456k
    CanBeFlattened = Flatten;
454
456k
  }
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.47M
  RequiredArgs(All_t _) : NumRequired(~0U) {}
469
53.3k
  explicit RequiredArgs(unsigned n) : NumRequired(n) {
470
53.3k
    assert(n != ~0U);
471
53.3k
  }
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
807k
                                       unsigned additional) {
480
807k
    if (!prototype->isVariadic()) 
return All756k
;
481
51.0k
482
51.0k
    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
51.0k
489
51.0k
    return RequiredArgs(prototype->getNumParams() + additional);
490
51.0k
  }
491
492
  static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
493
670k
                                       unsigned additional) {
494
670k
    return forPrototypePlus(prototype.getTypePtr(), additional);
495
670k
  }
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.80M
  bool allowsOptionalArgs() const { return NumRequired != ~0U; }
506
189k
  unsigned getNumRequiredArgs() const {
507
189k
    assert(allowsOptionalArgs());
508
189k
    return NumRequired;
509
189k
  }
510
511
2.61M
  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.01M
  ArgInfo *getArgsBuffer() {
581
3.01M
    return getTrailingObjects<ArgInfo>();
582
3.01M
  }
583
16.3M
  const ArgInfo *getArgsBuffer() const {
584
16.3M
    return getTrailingObjects<ArgInfo>();
585
16.3M
  }
586
587
20.4k
  ExtParameterInfo *getExtParameterInfosBuffer() {
588
20.4k
    return getTrailingObjects<ExtParameterInfo>();
589
20.4k
  }
590
147k
  const ExtParameterInfo *getExtParameterInfosBuffer() const{
591
147k
    return getTrailingObjects<ExtParameterInfo>();
592
147k
  }
593
594
204k
  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
204k
  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.62M
  MutableArrayRef<ArgInfo> arguments() {
621
1.62M
    return MutableArrayRef<ArgInfo>(arg_begin(), NumArgs);
622
1.62M
  }
623
0
  ArrayRef<ArgInfo> arguments() const {
624
0
    return ArrayRef<ArgInfo>(arg_begin(), NumArgs);
625
0
  }
626
627
4.44M
  const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }
628
4.25M
  const_arg_iterator arg_end() const { return getArgsBuffer() + 1 + NumArgs; }
629
1.76M
  arg_iterator arg_begin() { return getArgsBuffer() + 1; }
630
137k
  arg_iterator arg_end() { return getArgsBuffer() + 1 + NumArgs; }
631
632
6.67M
  unsigned  arg_size() const { return NumArgs; }
633
634
4.40M
  bool isVariadic() const { return Required.allowsOptionalArgs(); }
635
173k
  RequiredArgs getRequiredArgs() const { return Required; }
636
3.07M
  unsigned getNumRequiredArgs() const {
637
2.90M
    return isVariadic() ? 
getRequiredArgs().getNumRequiredArgs()171k
: arg_size();
638
3.07M
  }
639
640
1.09k
  bool isInstanceMethod() const { return InstanceMethod; }
641
642
724k
  bool isChainCall() const { return ChainCall; }
643
644
640k
  bool isCmseNSCall() const { return CmseNSCall; }
645
646
925k
  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.39k
  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.35M
  CallingConv getASTCallingConvention() const {
661
1.35M
    return CallingConv(ASTCallingConvention);
662
1.35M
  }
663
664
  /// getCallingConvention - Return the user specified calling
665
  /// convention, which has been translated into an LLVM CC.
666
185k
  unsigned getCallingConvention() const { return CallingConvention; }
667
668
  /// getEffectiveCallingConvention - Return the actual calling convention to
669
  /// use, which may depend on the ABI.
670
636k
  unsigned getEffectiveCallingConvention() const {
671
636k
    return EffectiveCallingConvention;
672
636k
  }
673
5.08k
  void setEffectiveCallingConvention(unsigned Value) {
674
5.08k
    EffectiveCallingConvention = Value;
675
5.08k
  }
676
677
18.7k
  bool getHasRegParm() const { return HasRegParm; }
678
2.09k
  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.07M
  CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
688
689
547k
  ABIArgInfo &getReturnInfo() { return getArgsBuffer()[0].info; }
690
4.60M
  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.07M
  ExtParameterInfo getExtParameterInfo(unsigned argIndex) const {
697
3.07M
    assert(argIndex <= NumArgs);
698
3.07M
    if (!HasExtParameterInfos) 
return ExtParameterInfo()2.94M
;
699
131k
    return getExtParameterInfos()[argIndex];
700
131k
  }
701
702
  /// Return true if this function uses inalloca arguments.
703
2.22M
  bool usesInAlloca() const { return ArgStruct; }
704
705
  /// Get the struct type used to represent all the arguments in memory.
706
365k
  llvm::StructType *getArgStruct() const { return ArgStruct; }
707
109
  CharUnits getArgStructAlignment() const {
708
109
    return CharUnits::fromQuantity(ArgStructAlign);
709
109
  }
710
71
  void setArgStruct(llvm::StructType *Ty, CharUnits Align) {
711
71
    ArgStruct = Ty;
712
71
    ArgStructAlign = Align.getQuantity();
713
71
  }
714
715
1.35M
  void Profile(llvm::FoldingSetNodeID &ID) {
716
1.35M
    ID.AddInteger(getASTCallingConvention());
717
1.35M
    ID.AddBoolean(InstanceMethod);
718
1.35M
    ID.AddBoolean(ChainCall);
719
1.35M
    ID.AddBoolean(NoReturn);
720
1.35M
    ID.AddBoolean(ReturnsRetained);
721
1.35M
    ID.AddBoolean(NoCallerSavedRegs);
722
1.35M
    ID.AddBoolean(HasRegParm);
723
1.35M
    ID.AddInteger(RegParm);
724
1.35M
    ID.AddBoolean(NoCfCheck);
725
1.35M
    ID.AddBoolean(CmseNSCall);
726
1.35M
    ID.AddInteger(Required.getOpaqueData());
727
1.35M
    ID.AddBoolean(HasExtParameterInfos);
728
1.35M
    if (HasExtParameterInfos) {
729
15.4k
      for (auto paramInfo : getExtParameterInfos())
730
47.3k
        ID.AddInteger(paramInfo.getOpaqueValue());
731
15.4k
    }
732
1.35M
    getReturnType().Profile(ID);
733
1.35M
    for (const auto &I : arguments())
734
2.18M
      I.type.Profile(ID);
735
1.35M
  }
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.25M
                      ArrayRef<CanQualType> argTypes) {
744
1.25M
    ID.AddInteger(info.getCC());
745
1.25M
    ID.AddBoolean(InstanceMethod);
746
1.25M
    ID.AddBoolean(ChainCall);
747
1.25M
    ID.AddBoolean(info.getNoReturn());
748
1.25M
    ID.AddBoolean(info.getProducesResult());
749
1.25M
    ID.AddBoolean(info.getNoCallerSavedRegs());
750
1.25M
    ID.AddBoolean(info.getHasRegParm());
751
1.25M
    ID.AddInteger(info.getRegParm());
752
1.25M
    ID.AddBoolean(info.getNoCfCheck());
753
1.25M
    ID.AddBoolean(info.getCmseNSCall());
754
1.25M
    ID.AddInteger(required.getOpaqueData());
755
1.25M
    ID.AddBoolean(!paramInfos.empty());
756
1.25M
    if (!paramInfos.empty()) {
757
18.2k
      for (auto paramInfo : paramInfos)
758
54.2k
        ID.AddInteger(paramInfo.getOpaqueValue());
759
18.2k
    }
760
1.25M
    resultType.Profile(ID);
761
1.25M
    for (ArrayRef<CanQualType>::iterator
762
3.26M
           i = argTypes.begin(), e = argTypes.end(); i != e; 
++i2.00M
) {
763
2.00M
      i->Profile(ID);
764
2.00M
    }
765
1.25M
  }
766
};
767
768
}  // end namespace CodeGen
769
}  // end namespace clang
770
771
#endif