File indexing completed on 2026-05-10 08:36:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_CODEGEN_SWIFTCALLINGCONV_H
0015 #define LLVM_CLANG_CODEGEN_SWIFTCALLINGCONV_H
0016
0017 #include "clang/AST/CanonicalType.h"
0018 #include "clang/AST/CharUnits.h"
0019 #include "clang/AST/Type.h"
0020 #include "llvm/Support/TrailingObjects.h"
0021 #include <cassert>
0022
0023 namespace llvm {
0024 class IntegerType;
0025 class Type;
0026 class StructType;
0027 class VectorType;
0028 }
0029
0030 namespace clang {
0031 class FieldDecl;
0032 class ASTRecordLayout;
0033
0034 namespace CodeGen {
0035 class ABIArgInfo;
0036 class CodeGenModule;
0037 class CGFunctionInfo;
0038
0039 namespace swiftcall {
0040
0041 class SwiftAggLowering {
0042 CodeGenModule &CGM;
0043
0044 struct StorageEntry {
0045 CharUnits Begin;
0046 CharUnits End;
0047 llvm::Type *Type;
0048
0049 CharUnits getWidth() const {
0050 return End - Begin;
0051 }
0052 };
0053 SmallVector<StorageEntry, 4> Entries;
0054 bool Finished = false;
0055
0056 public:
0057 SwiftAggLowering(CodeGenModule &CGM) : CGM(CGM) {}
0058
0059 void addOpaqueData(CharUnits begin, CharUnits end) {
0060 addEntry(nullptr, begin, end);
0061 }
0062
0063 void addTypedData(QualType type, CharUnits begin);
0064 void addTypedData(const RecordDecl *record, CharUnits begin);
0065 void addTypedData(const RecordDecl *record, CharUnits begin,
0066 const ASTRecordLayout &layout);
0067 void addTypedData(llvm::Type *type, CharUnits begin);
0068 void addTypedData(llvm::Type *type, CharUnits begin, CharUnits end);
0069
0070 void finish();
0071
0072
0073 bool empty() const {
0074 assert(Finished && "didn't finish lowering before calling empty()");
0075 return Entries.empty();
0076 }
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 bool shouldPassIndirectly(bool asReturnValue) const;
0090
0091 using EnumerationCallback =
0092 llvm::function_ref<void(CharUnits offset, CharUnits end, llvm::Type *type)>;
0093
0094
0095
0096
0097
0098 void enumerateComponents(EnumerationCallback callback) const;
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 std::pair<llvm::StructType*, llvm::Type*> getCoerceAndExpandTypes() const;
0109
0110 private:
0111 void addBitFieldData(const FieldDecl *field, CharUnits begin,
0112 uint64_t bitOffset);
0113 void addLegalTypedData(llvm::Type *type, CharUnits begin, CharUnits end);
0114 void addEntry(llvm::Type *type, CharUnits begin, CharUnits end);
0115 void splitVectorEntry(unsigned index);
0116 static bool shouldMergeEntries(const StorageEntry &first,
0117 const StorageEntry &second,
0118 CharUnits chunkSize);
0119 };
0120
0121
0122
0123 bool shouldPassIndirectly(CodeGenModule &CGM,
0124 ArrayRef<llvm::Type*> types,
0125 bool asReturnValue);
0126
0127
0128 CharUnits getMaximumVoluntaryIntegerSize(CodeGenModule &CGM);
0129
0130
0131 CharUnits getNaturalAlignment(CodeGenModule &CGM, llvm::Type *type);
0132
0133
0134
0135 bool isLegalIntegerType(CodeGenModule &CGM, llvm::IntegerType *type);
0136
0137
0138
0139 bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,
0140 llvm::VectorType *vectorTy);
0141 bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,
0142 llvm::Type *eltTy, unsigned numElts);
0143
0144
0145 std::pair<llvm::Type*, unsigned>
0146 splitLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,
0147 llvm::VectorType *vectorTy);
0148
0149
0150
0151
0152
0153 void legalizeVectorType(CodeGenModule &CGM, CharUnits vectorSize,
0154 llvm::VectorType *vectorTy,
0155 llvm::SmallVectorImpl<llvm::Type*> &types);
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 bool mustPassRecordIndirectly(CodeGenModule &CGM, const RecordDecl *record);
0166
0167
0168 ABIArgInfo classifyReturnType(CodeGenModule &CGM, CanQualType type);
0169
0170
0171 ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type);
0172
0173
0174
0175 void computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI);
0176
0177
0178 bool isSwiftErrorLoweredInRegister(CodeGenModule &CGM);
0179
0180 }
0181 }
0182 }
0183
0184 #endif