Coverage Report

Created: 2020-02-25 14:32

/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.70M
  bool canHavePaddingType() const {
100
3.70M
    return isDirect() || 
isExtend()191k
||
isIndirect()83.8k
||
isExpand()65.3k
;
101
3.70M
  }
102
414k
  void setPaddingType(llvm::Type *T) {
103
414k
    assert(canHavePaddingType());
104
414k
    PaddingType = T;
105
414k
  }
106
107
1.08k
  void setUnpaddedCoerceToType(llvm::Type *T) {
108
1.08k
    assert(isCoerceAndExpand());
109
1.08k
    UnpaddedCoerceAndExpandType = T;
110
1.08k
  }
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
500k
        InReg(false), CanBeFlattened(false), SignExt(false) {}
118
119
  static ABIArgInfo getDirect(llvm::Type *T = nullptr, unsigned Offset = 0,
120
                              llvm::Type *Padding = nullptr,
121
395k
                              bool CanBeFlattened = true) {
122
395k
    auto AI = ABIArgInfo(Direct);
123
395k
    AI.setCoerceToType(T);
124
395k
    AI.setPaddingType(Padding);
125
395k
    AI.setDirectOffset(Offset);
126
395k
    AI.setCanBeFlattened(CanBeFlattened);
127
395k
    return AI;
128
395k
  }
129
306
  static ABIArgInfo getDirectInReg(llvm::Type *T = nullptr) {
130
306
    auto AI = getDirect(T);
131
306
    AI.setInReg(true);
132
306
    return AI;
133
306
  }
134
135
8.21k
  static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T = nullptr) {
136
8.21k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
137
8.21k
    auto AI = ABIArgInfo(Extend);
138
8.21k
    AI.setCoerceToType(T);
139
8.21k
    AI.setPaddingType(nullptr);
140
8.21k
    AI.setDirectOffset(0);
141
8.21k
    AI.setSignExt(true);
142
8.21k
    return AI;
143
8.21k
  }
144
145
6.51k
  static ABIArgInfo getZeroExtend(QualType Ty, llvm::Type *T = nullptr) {
146
6.51k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
147
6.51k
    auto AI = ABIArgInfo(Extend);
148
6.51k
    AI.setCoerceToType(T);
149
6.51k
    AI.setPaddingType(nullptr);
150
6.51k
    AI.setDirectOffset(0);
151
6.51k
    AI.setSignExt(false);
152
6.51k
    return AI;
153
6.51k
  }
154
155
  // ABIArgInfo will record the argument as being extended based on the sign
156
  // of its type.
157
14.6k
  static ABIArgInfo getExtend(QualType Ty, llvm::Type *T = nullptr) {
158
14.6k
    assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
159
14.6k
    if (Ty->hasSignedIntegerRepresentation())
160
8.17k
      return getSignExtend(Ty, T);
161
6.51k
    return getZeroExtend(Ty, T);
162
6.51k
  }
163
164
31
  static ABIArgInfo getExtendInReg(QualType Ty, llvm::Type *T = nullptr) {
165
31
    auto AI = getExtend(Ty, T);
166
31
    AI.setInReg(true);
167
31
    return AI;
168
31
  }
169
84.2k
  static ABIArgInfo getIgnore() {
170
84.2k
    return ABIArgInfo(Ignore);
171
84.2k
  }
172
  static ABIArgInfo getIndirect(CharUnits Alignment, bool ByVal = true,
173
                                bool Realign = false,
174
4.47k
                                llvm::Type *Padding = nullptr) {
175
4.47k
    auto AI = ABIArgInfo(Indirect);
176
4.47k
    AI.setIndirectAlign(Alignment);
177
4.47k
    AI.setIndirectByVal(ByVal);
178
4.47k
    AI.setIndirectRealign(Realign);
179
4.47k
    AI.setSRetAfterThis(false);
180
4.47k
    AI.setPaddingType(Padding);
181
4.47k
    return AI;
182
4.47k
  }
183
  static ABIArgInfo getIndirectInReg(CharUnits Alignment, bool ByVal = true,
184
25
                                     bool Realign = false) {
185
25
    auto AI = getIndirect(Alignment, ByVal, Realign);
186
25
    AI.setInReg(true);
187
25
    return AI;
188
25
  }
189
244
  static ABIArgInfo getInAlloca(unsigned FieldIndex, bool Indirect = false) {
190
244
    auto AI = ABIArgInfo(InAlloca);
191
244
    AI.setInAllocaFieldIndex(FieldIndex);
192
244
    AI.setInAllocaIndirect(Indirect);
193
244
    return AI;
194
244
  }
195
124
  static ABIArgInfo getExpand() {
196
124
    auto AI = ABIArgInfo(Expand);
197
124
    AI.setPaddingType(nullptr);
198
124
    return AI;
199
124
  }
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.08k
                                       llvm::Type *unpaddedCoerceToType) {
213
1.08k
#ifndef NDEBUG
214
1.08k
    // Sanity checks on unpaddedCoerceToType.
215
1.08k
216
1.08k
    // Assert that we only have a struct type if there are multiple elements.
217
1.08k
    auto unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoerceToType);
218
1.08k
    assert(!unpaddedStruct || unpaddedStruct->getNumElements() != 1);
219
1.08k
220
1.08k
    // Assert that all the non-padding elements have a corresponding element
221
1.08k
    // in the unpadded type.
222
1.08k
    unsigned unpaddedIndex = 0;
223
2.29k
    for (auto eltType : coerceToType->elements()) {
224
2.29k
      if (isPaddingForCoerceAndExpand(eltType)) 
continue14
;
225
2.28k
      if (unpaddedStruct) {
226
1.92k
        assert(unpaddedStruct->getElementType(unpaddedIndex) == eltType);
227
1.92k
      } else {
228
361
        assert(unpaddedIndex == 0 && unpaddedCoerceToType == eltType);
229
361
      }
230
2.28k
      unpaddedIndex++;
231
2.28k
    }
232
1.08k
233
1.08k
    // Assert that there aren't extra elements in the unpadded type.
234
1.08k
    if (unpaddedStruct) {
235
723
      assert(unpaddedStruct->getNumElements() == unpaddedIndex);
236
723
    } else {
237
361
      assert(unpaddedIndex == 1);
238
361
    }
239
1.08k
#endif
240
1.08k
241
1.08k
    auto AI = ABIArgInfo(CoerceAndExpand);
242
1.08k
    AI.setCoerceToType(coerceToType);
243
1.08k
    AI.setUnpaddedCoerceToType(unpaddedCoerceToType);
244
1.08k
    return AI;
245
1.08k
  }
246
247
6.54k
  static bool isPaddingForCoerceAndExpand(llvm::Type *eltType) {
248
6.54k
    if (eltType->isArrayTy()) {
249
42
      assert(eltType->getArrayElementType()->isIntegerTy(8));
250
42
      return true;
251
6.49k
    } else {
252
6.49k
      return false;
253
6.49k
    }
254
6.54k
  }
255
256
10.7M
  Kind getKind() const { return TheKind; }
257
22.7M
  bool isDirect() const { return TheKind == Direct; }
258
326k
  bool isInAlloca() const { return TheKind == InAlloca; }
259
785k
  bool isExtend() const { return TheKind == Extend; }
260
0
  bool isIgnore() const { return TheKind == Ignore; }
261
612k
  bool isIndirect() const { return TheKind == Indirect; }
262
65.3k
  bool isExpand() const { return TheKind == Expand; }
263
406k
  bool isCoerceAndExpand() const { return TheKind == CoerceAndExpand; }
264
265
9.48M
  bool canHaveCoerceToType() const {
266
9.48M
    return isDirect() || 
isExtend()415k
||
isCoerceAndExpand()92.1k
;
267
9.48M
  }
268
269
  // Direct/Extend accessors
270
1.19M
  unsigned getDirectOffset() const {
271
1.19M
    assert((isDirect() || isExtend()) && "Not a direct or extend kind");
272
1.19M
    return DirectOffset;
273
1.19M
  }
274
409k
  void setDirectOffset(unsigned Offset) {
275
409k
    assert((isDirect() || isExtend()) && "Not a direct or extend kind");
276
409k
    DirectOffset = Offset;
277
409k
  }
278
279
47.2k
  bool isSignExt() const {
280
47.2k
    assert(isExtend() && "Invalid kind!");
281
47.2k
    return SignExt;
282
47.2k
  }
283
14.7k
  void setSignExt(bool SExt) {
284
14.7k
    assert(isExtend() && "Invalid kind!");
285
14.7k
    SignExt = SExt;
286
14.7k
  }
287
288
3.29M
  llvm::Type *getPaddingType() const {
289
3.29M
    return (canHavePaddingType() ? 
PaddingType3.22M
:
nullptr64.7k
);
290
3.29M
  }
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
8.47M
  llvm::Type *getCoerceToType() const {
300
8.47M
    assert(canHaveCoerceToType() && "Invalid kind!");
301
8.47M
    return TypeData;
302
8.47M
  }
303
304
515k
  void setCoerceToType(llvm::Type *T) {
305
515k
    assert(canHaveCoerceToType() && "Invalid kind!");
306
515k
    TypeData = T;
307
515k
  }
308
309
1.96k
  llvm::StructType *getCoerceAndExpandType() const {
310
1.96k
    assert(isCoerceAndExpand());
311
1.96k
    return cast<llvm::StructType>(TypeData);
312
1.96k
  }
313
314
2.22k
  llvm::Type *getUnpaddedCoerceAndExpandType() const {
315
2.22k
    assert(isCoerceAndExpand());
316
2.22k
    return UnpaddedCoerceAndExpandType;
317
2.22k
  }
318
319
4.81k
  ArrayRef<llvm::Type *>getCoerceAndExpandTypeSequence() const {
320
4.81k
    assert(isCoerceAndExpand());
321
4.81k
    if (auto structTy =
322
3.15k
          dyn_cast<llvm::StructType>(UnpaddedCoerceAndExpandType)) {
323
3.15k
      return structTy->elements();
324
3.15k
    } else {
325
1.66k
      return llvm::makeArrayRef(&UnpaddedCoerceAndExpandType, 1);
326
1.66k
    }
327
4.81k
  }
328
329
1.24M
  bool getInReg() const {
330
1.24M
    assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
331
1.24M
    return InReg;
332
1.24M
  }
333
334
570
  void setInReg(bool IR) {
335
570
    assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
336
570
    InReg = IR;
337
570
  }
338
339
  // Indirect accessors
340
10.4k
  CharUnits getIndirectAlign() const {
341
10.4k
    assert(isIndirect() && "Invalid kind!");
342
10.4k
    return CharUnits::fromQuantity(IndirectAlign);
343
10.4k
  }
344
4.47k
  void setIndirectAlign(CharUnits IA) {
345
4.47k
    assert(isIndirect() && "Invalid kind!");
346
4.47k
    IndirectAlign = IA.getQuantity();
347
4.47k
  }
348
349
11.4k
  bool getIndirectByVal() const {
350
11.4k
    assert(isIndirect() && "Invalid kind!");
351
11.4k
    return IndirectByVal;
352
11.4k
  }
353
4.47k
  void setIndirectByVal(bool IBV) {
354
4.47k
    assert(isIndirect() && "Invalid kind!");
355
4.47k
    IndirectByVal = IBV;
356
4.47k
  }
357
358
1.78k
  bool getIndirectRealign() const {
359
1.78k
    assert(isIndirect() && "Invalid kind!");
360
1.78k
    return IndirectRealign;
361
1.78k
  }
362
4.47k
  void setIndirectRealign(bool IR) {
363
4.47k
    assert(isIndirect() && "Invalid kind!");
364
4.47k
    IndirectRealign = IR;
365
4.47k
  }
366
367
17.2k
  bool isSRetAfterThis() const {
368
17.2k
    assert(isIndirect() && "Invalid kind!");
369
17.2k
    return SRetAfterThis;
370
17.2k
  }
371
4.59k
  void setSRetAfterThis(bool AfterThis) {
372
4.59k
    assert(isIndirect() && "Invalid kind!");
373
4.59k
    SRetAfterThis = AfterThis;
374
4.59k
  }
375
376
234
  unsigned getInAllocaFieldIndex() const {
377
234
    assert(isInAlloca() && "Invalid kind!");
378
234
    return AllocaFieldIndex;
379
234
  }
380
244
  void setInAllocaFieldIndex(unsigned FieldIndex) {
381
244
    assert(isInAlloca() && "Invalid kind!");
382
244
    AllocaFieldIndex = FieldIndex;
383
244
  }
384
385
220
  unsigned getInAllocaIndirect() const {
386
220
    assert(isInAlloca() && "Invalid kind!");
387
220
    return InAllocaIndirect;
388
220
  }
389
244
  void setInAllocaIndirect(bool Indirect) {
390
244
    assert(isInAlloca() && "Invalid kind!");
391
244
    InAllocaIndirect = Indirect;
392
244
  }
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.12M
  bool getCanBeFlattened() const {
407
3.12M
    assert(isDirect() && "Invalid kind!");
408
3.12M
    return CanBeFlattened;
409
3.12M
  }
410
411
395k
  void setCanBeFlattened(bool Flatten) {
412
395k
    assert(isDirect() && "Invalid kind!");
413
395k
    CanBeFlattened = Flatten;
414
395k
  }
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.33M
  RequiredArgs(All_t _) : NumRequired(~0U) {}
429
51.5k
  explicit RequiredArgs(unsigned n) : NumRequired(n) {
430
51.5k
    assert(n != ~0U);
431
51.5k
  }
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
732k
                                       unsigned additional) {
440
732k
    if (!prototype->isVariadic()) 
return All683k
;
441
49.2k
442
49.2k
    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
49.2k
449
49.2k
    return RequiredArgs(prototype->getNumParams() + additional);
450
49.2k
  }
451
452
  static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
453
600k
                                       unsigned additional) {
454
600k
    return forPrototypePlus(prototype.getTypePtr(), additional);
455
600k
  }
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.42M
  bool allowsOptionalArgs() const { return NumRequired != ~0U; }
466
182k
  unsigned getNumRequiredArgs() const {
467
182k
    assert(allowsOptionalArgs());
468
182k
    return NumRequired;
469
182k
  }
470
471
2.39M
  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 noreturn.
512
  unsigned NoReturn : 1;
513
514
  /// Whether this function is returns-retained.
515
  unsigned ReturnsRetained : 1;
516
517
  /// Whether this function saved caller registers.
518
  unsigned NoCallerSavedRegs : 1;
519
520
  /// How many arguments to pass inreg.
521
  unsigned HasRegParm : 1;
522
  unsigned RegParm : 3;
523
524
  /// Whether this function has nocf_check attribute.
525
  unsigned NoCfCheck : 1;
526
527
  RequiredArgs Required;
528
529
  /// The struct representing all arguments passed in memory.  Only used when
530
  /// passing non-trivial types with inalloca.  Not part of the profile.
531
  llvm::StructType *ArgStruct;
532
  unsigned ArgStructAlign : 31;
533
  unsigned HasExtParameterInfos : 1;
534
535
  unsigned NumArgs;
536
537
2.74M
  ArgInfo *getArgsBuffer() {
538
2.74M
    return getTrailingObjects<ArgInfo>();
539
2.74M
  }
540
14.8M
  const ArgInfo *getArgsBuffer() const {
541
14.8M
    return getTrailingObjects<ArgInfo>();
542
14.8M
  }
543
544
20.5k
  ExtParameterInfo *getExtParameterInfosBuffer() {
545
20.5k
    return getTrailingObjects<ExtParameterInfo>();
546
20.5k
  }
547
147k
  const ExtParameterInfo *getExtParameterInfosBuffer() const{
548
147k
    return getTrailingObjects<ExtParameterInfo>();
549
147k
  }
550
551
180k
  CGFunctionInfo() : Required(RequiredArgs::All) {}
552
553
public:
554
  static CGFunctionInfo *create(unsigned llvmCC,
555
                                bool instanceMethod,
556
                                bool chainCall,
557
                                const FunctionType::ExtInfo &extInfo,
558
                                ArrayRef<ExtParameterInfo> paramInfos,
559
                                CanQualType resultType,
560
                                ArrayRef<CanQualType> argTypes,
561
                                RequiredArgs required);
562
180k
  void operator delete(void *p) { ::operator delete(p); }
563
564
  // Friending class TrailingObjects is apparently not good enough for MSVC,
565
  // so these have to be public.
566
  friend class TrailingObjects;
567
167k
  size_t numTrailingObjects(OverloadToken<ArgInfo>) const {
568
167k
    return NumArgs + 1;
569
167k
  }
570
0
  size_t numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
571
0
    return (HasExtParameterInfos ? NumArgs : 0);
572
0
  }
573
574
  typedef const ArgInfo *const_arg_iterator;
575
  typedef ArgInfo *arg_iterator;
576
577
1.48M
  MutableArrayRef<ArgInfo> arguments() {
578
1.48M
    return MutableArrayRef<ArgInfo>(arg_begin(), NumArgs);
579
1.48M
  }
580
0
  ArrayRef<ArgInfo> arguments() const {
581
0
    return ArrayRef<ArgInfo>(arg_begin(), NumArgs);
582
0
  }
583
584
4.05M
  const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }
585
3.86M
  const_arg_iterator arg_end() const { return getArgsBuffer() + 1 + NumArgs; }
586
1.61M
  arg_iterator arg_begin() { return getArgsBuffer() + 1; }
587
133k
  arg_iterator arg_end() { return getArgsBuffer() + 1 + NumArgs; }
588
589
6.08M
  unsigned  arg_size() const { return NumArgs; }
590
591
4.05M
  bool isVariadic() const { return Required.allowsOptionalArgs(); }
592
167k
  RequiredArgs getRequiredArgs() const { return Required; }
593
2.83M
  unsigned getNumRequiredArgs() const {
594
2.83M
    return isVariadic() ? 
getRequiredArgs().getNumRequiredArgs()165k
:
arg_size()2.66M
;
595
2.83M
  }
596
597
1.08k
  bool isInstanceMethod() const { return InstanceMethod; }
598
599
665k
  bool isChainCall() const { return ChainCall; }
600
601
820k
  bool isNoReturn() const { return NoReturn; }
602
603
  /// In ARC, whether this function retains its return value.  This
604
  /// is not always reliable for call sites.
605
1.36k
  bool isReturnsRetained() const { return ReturnsRetained; }
606
607
  /// Whether this function no longer saves caller registers.
608
906
  bool isNoCallerSavedRegs() const { return NoCallerSavedRegs; }
609
610
  /// Whether this function has nocf_check attribute.
611
906
  bool isNoCfCheck() const { return NoCfCheck; }
612
613
  /// getASTCallingConvention() - Return the AST-specified calling
614
  /// convention.
615
1.25M
  CallingConv getASTCallingConvention() const {
616
1.25M
    return CallingConv(ASTCallingConvention);
617
1.25M
  }
618
619
  /// getCallingConvention - Return the user specified calling
620
  /// convention, which has been translated into an LLVM CC.
621
174k
  unsigned getCallingConvention() const { return CallingConvention; }
622
623
  /// getEffectiveCallingConvention - Return the actual calling convention to
624
  /// use, which may depend on the ABI.
625
575k
  unsigned getEffectiveCallingConvention() const {
626
575k
    return EffectiveCallingConvention;
627
575k
  }
628
3.61k
  void setEffectiveCallingConvention(unsigned Value) {
629
3.61k
    EffectiveCallingConvention = Value;
630
3.61k
  }
631
632
16.1k
  bool getHasRegParm() const { return HasRegParm; }
633
2.06k
  unsigned getRegParm() const { return RegParm; }
634
635
906
  FunctionType::ExtInfo getExtInfo() const {
636
906
    return FunctionType::ExtInfo(isNoReturn(), getHasRegParm(), getRegParm(),
637
906
                                 getASTCallingConvention(), isReturnsRetained(),
638
906
                                 isNoCallerSavedRegs(), isNoCfCheck());
639
906
  }
640
641
2.80M
  CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
642
643
494k
  ABIArgInfo &getReturnInfo() { return getArgsBuffer()[0].info; }
644
4.18M
  const ABIArgInfo &getReturnInfo() const { return getArgsBuffer()[0].info; }
645
646
147k
  ArrayRef<ExtParameterInfo> getExtParameterInfos() const {
647
147k
    if (!HasExtParameterInfos) 
return {}0
;
648
147k
    return llvm::makeArrayRef(getExtParameterInfosBuffer(), NumArgs);
649
147k
  }
650
2.77M
  ExtParameterInfo getExtParameterInfo(unsigned argIndex) const {
651
2.77M
    assert(argIndex <= NumArgs);
652
2.77M
    if (!HasExtParameterInfos) 
return ExtParameterInfo()2.63M
;
653
130k
    return getExtParameterInfos()[argIndex];
654
130k
  }
655
656
  /// Return true if this function uses inalloca arguments.
657
2.02M
  bool usesInAlloca() const { return ArgStruct; }
658
659
  /// Get the struct type used to represent all the arguments in memory.
660
349k
  llvm::StructType *getArgStruct() const { return ArgStruct; }
661
108
  CharUnits getArgStructAlignment() const {
662
108
    return CharUnits::fromQuantity(ArgStructAlign);
663
108
  }
664
70
  void setArgStruct(llvm::StructType *Ty, CharUnits Align) {
665
70
    ArgStruct = Ty;
666
70
    ArgStructAlign = Align.getQuantity();
667
70
  }
668
669
1.25M
  void Profile(llvm::FoldingSetNodeID &ID) {
670
1.25M
    ID.AddInteger(getASTCallingConvention());
671
1.25M
    ID.AddBoolean(InstanceMethod);
672
1.25M
    ID.AddBoolean(ChainCall);
673
1.25M
    ID.AddBoolean(NoReturn);
674
1.25M
    ID.AddBoolean(ReturnsRetained);
675
1.25M
    ID.AddBoolean(NoCallerSavedRegs);
676
1.25M
    ID.AddBoolean(HasRegParm);
677
1.25M
    ID.AddInteger(RegParm);
678
1.25M
    ID.AddBoolean(NoCfCheck);
679
1.25M
    ID.AddInteger(Required.getOpaqueData());
680
1.25M
    ID.AddBoolean(HasExtParameterInfos);
681
1.25M
    if (HasExtParameterInfos) {
682
15.4k
      for (auto paramInfo : getExtParameterInfos())
683
46.8k
        ID.AddInteger(paramInfo.getOpaqueValue());
684
15.4k
    }
685
1.25M
    getReturnType().Profile(ID);
686
1.25M
    for (const auto &I : arguments())
687
2.03M
      I.type.Profile(ID);
688
1.25M
  }
689
  static void Profile(llvm::FoldingSetNodeID &ID,
690
                      bool InstanceMethod,
691
                      bool ChainCall,
692
                      const FunctionType::ExtInfo &info,
693
                      ArrayRef<ExtParameterInfo> paramInfos,
694
                      RequiredArgs required,
695
                      CanQualType resultType,
696
1.13M
                      ArrayRef<CanQualType> argTypes) {
697
1.13M
    ID.AddInteger(info.getCC());
698
1.13M
    ID.AddBoolean(InstanceMethod);
699
1.13M
    ID.AddBoolean(ChainCall);
700
1.13M
    ID.AddBoolean(info.getNoReturn());
701
1.13M
    ID.AddBoolean(info.getProducesResult());
702
1.13M
    ID.AddBoolean(info.getNoCallerSavedRegs());
703
1.13M
    ID.AddBoolean(info.getHasRegParm());
704
1.13M
    ID.AddInteger(info.getRegParm());
705
1.13M
    ID.AddBoolean(info.getNoCfCheck());
706
1.13M
    ID.AddInteger(required.getOpaqueData());
707
1.13M
    ID.AddBoolean(!paramInfos.empty());
708
1.13M
    if (!paramInfos.empty()) {
709
18.2k
      for (auto paramInfo : paramInfos)
710
54.0k
        ID.AddInteger(paramInfo.getOpaqueValue());
711
18.2k
    }
712
1.13M
    resultType.Profile(ID);
713
1.13M
    for (ArrayRef<CanQualType>::iterator
714
2.95M
           i = argTypes.begin(), e = argTypes.end(); i != e; 
++i1.81M
) {
715
1.81M
      i->Profile(ID);
716
1.81M
    }
717
1.13M
  }
718
};
719
720
}  // end namespace CodeGen
721
}  // end namespace clang
722
723
#endif