clang  3.9.0
SwiftCallingConv.h
Go to the documentation of this file.
1 //==-- SwiftCallingConv.h - Swift ABI lowering -----------------------------==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Defines constants and types related to Swift ABI lowering.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_CODEGEN_SWIFTCALLINGCONV_H
15 #define LLVM_CLANG_CODEGEN_SWIFTCALLINGCONV_H
16 
18 #include "clang/AST/CharUnits.h"
19 #include "clang/AST/Type.h"
20 #include "llvm/ADT/FoldingSet.h"
21 #include "llvm/Support/TrailingObjects.h"
22 #include <cassert>
23 
24 namespace llvm {
25  class IntegerType;
26  class Type;
27  class StructType;
28  class VectorType;
29 }
30 
31 namespace clang {
32 class Decl;
33 class FieldDecl;
34 class ASTRecordLayout;
35 
36 namespace CodeGen {
37 class ABIArgInfo;
38 class CodeGenModule;
39 class CGFunctionInfo;
40 
41 namespace swiftcall {
42 
44  CodeGenModule &CGM;
45 
46  struct StorageEntry {
47  CharUnits Begin;
48  CharUnits End;
50 
51  CharUnits getWidth() const {
52  return End - Begin;
53  }
54  };
56  bool Finished = false;
57 
58 public:
59  SwiftAggLowering(CodeGenModule &CGM) : CGM(CGM) {}
60 
62  addEntry(nullptr, begin, end);
63  }
64 
66  void addTypedData(const RecordDecl *record, CharUnits begin);
67  void addTypedData(const RecordDecl *record, CharUnits begin,
68  const ASTRecordLayout &layout);
71 
72  void finish();
73 
74  /// Does this lowering require passing any data?
75  bool empty() const {
76  assert(Finished && "didn't finish lowering before calling empty()");
77  return Entries.empty();
78  }
79 
80  /// According to the target Swift ABI, should a value with this lowering
81  /// be passed indirectly?
82  ///
83  /// Note that this decision is based purely on the data layout of the
84  /// value and does not consider whether the type is address-only,
85  /// must be passed indirectly to match a function abstraction pattern, or
86  /// anything else that is expected to be handled by high-level lowering.
87  ///
88  /// \param asReturnValue - if true, answer whether it should be passed
89  /// indirectly as a return value; if false, answer whether it should be
90  /// passed indirectly as an argument
91  bool shouldPassIndirectly(bool asReturnValue) const;
92 
93  using EnumerationCallback =
94  llvm::function_ref<void(CharUnits offset, llvm::Type *type)>;
95 
96  /// Enumerate the expanded components of this type.
97  ///
98  /// The component types will always be legal vector, floating-point,
99  /// integer, or pointer types.
100  void enumerateComponents(EnumerationCallback callback) const;
101 
102  /// Return the types for a coerce-and-expand operation.
103  ///
104  /// The first type matches the memory layout of the data that's been
105  /// added to this structure, including explicit [N x i8] arrays for any
106  /// internal padding.
107  ///
108  /// The second type removes any internal padding members and, if only
109  /// one element remains, is simply that element type.
110  std::pair<llvm::StructType*, llvm::Type*> getCoerceAndExpandTypes() const;
111 
112 private:
113  void addBitFieldData(const FieldDecl *field, CharUnits begin,
114  uint64_t bitOffset);
115  void addLegalTypedData(llvm::Type *type, CharUnits begin, CharUnits end);
116  void addEntry(llvm::Type *type, CharUnits begin, CharUnits end);
117  void splitVectorEntry(unsigned index);
118 };
119 
120 /// Return the maximum voluntary integer size for the current target.
122 
123 /// Return the Swift CC's notion of the natural alignment of a type.
125 
126 /// Is the given integer type "legal" for Swift's perspective on the
127 /// current platform?
128 bool isLegalIntegerType(CodeGenModule &CGM, llvm::IntegerType *type);
129 
130 /// Is the given vector type "legal" for Swift's perspective on the
131 /// current platform?
132 bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,
133  llvm::VectorType *vectorTy);
134 bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,
135  llvm::Type *eltTy, unsigned numElts);
136 
137 /// Minimally split a legal vector type.
138 std::pair<llvm::Type*, unsigned>
140  llvm::VectorType *vectorTy);
141 
142 /// Turn a vector type in a sequence of legal component vector types.
143 ///
144 /// The caller may assume that the sum of the data sizes of the resulting
145 /// types will equal the data size of the vector type.
146 void legalizeVectorType(CodeGenModule &CGM, CharUnits vectorSize,
147  llvm::VectorType *vectorTy,
149 
150 /// Should a C++ record type be passed and returned indirectly?
152  const CXXRecordDecl *record);
153 
154 /// Classify the rules for how to return a particular type.
156 
157 /// Classify the rules for how to pass a particular type.
159 
160 /// Compute the ABI information of a swiftcall function. This is a
161 /// private interface for Clang.
163 
164 } // end namespace swiftcall
165 } // end namespace CodeGen
166 } // end namespace clang
167 
168 #endif
A (possibly-)qualified type.
Definition: Type.h:598
bool empty() const
Does this lowering require passing any data?
C Language Family Type Representation.
bool shouldPassIndirectly(bool asReturnValue) const
According to the target Swift ABI, should a value with this lowering be passed indirectly?
The base class of the type hierarchy.
Definition: Type.h:1281
void enumerateComponents(EnumerationCallback callback) const
Enumerate the expanded components of this type.
std::pair< llvm::Type *, unsigned > splitLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize, llvm::VectorType *vectorTy)
Minimally split a legal vector type.
iterator begin() const
Definition: Type.h:4235
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3253
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to pass a particular type.
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2293
ABIArgInfo classifyReturnType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to return a particular type.
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
iterator end() const
CharUnits getNaturalAlignment(CodeGenModule &CGM, llvm::Type *type)
Return the Swift CC's notion of the natural alignment of a type.
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Definition: RecordLayout.h:34
void addOpaqueData(CharUnits begin, CharUnits end)
void legalizeVectorType(CodeGenModule &CGM, CharUnits vectorSize, llvm::VectorType *vectorTy, llvm::SmallVectorImpl< llvm::Type * > &types)
Turn a vector type in a sequence of legal component vector types.
The l-value was considered opaque, so the alignment was determined from a type.
void addTypedData(QualType type, CharUnits begin)
void computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI)
Compute the ABI information of a swiftcall function.
bool shouldPassCXXRecordIndirectly(CodeGenModule &CGM, const CXXRecordDecl *record)
Should a C++ record type be passed and returned indirectly?
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
std::pair< llvm::StructType *, llvm::Type * > getCoerceAndExpandTypes() const
Return the types for a coerce-and-expand operation.
bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize, llvm::VectorType *vectorTy)
Is the given vector type "legal" for Swift's perspective on the current platform?
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:1983
llvm::function_ref< void(CharUnits offset, llvm::Type *type)> EnumerationCallback
Represents a C++ struct/union/class.
Definition: DeclCXX.h:263
bool isLegalIntegerType(CodeGenModule &CGM, llvm::IntegerType *type)
Is the given integer type "legal" for Swift's perspective on the current platform?
CharUnits getMaximumVoluntaryIntegerSize(CodeGenModule &CGM)
Return the maximum voluntary integer size for the current target.