|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | #include "CIRGenBuilder.h"
|
| 10 | +#include "mlir/IR/BuiltinAttributes.h" |
| 11 | +#include "clang/CIR/MissingFeatures.h" |
| 12 | +#include "llvm/ADT/ArrayRef.h" |
10 | 13 | #include "llvm/ADT/TypeSwitch.h"
|
11 | 14 |
|
12 | 15 | using namespace clang::CIRGen;
|
@@ -130,6 +133,39 @@ void CIRGenBuilderTy::computeGlobalViewIndicesFromFlatOffset(
|
130 | 133 | computeGlobalViewIndicesFromFlatOffset(offset, subType, layout, indices);
|
131 | 134 | }
|
132 | 135 |
|
| 136 | +cir::RecordType clang::CIRGen::CIRGenBuilderTy::getCompleteRecordType( |
| 137 | + mlir::ArrayAttr fields, bool packed, bool padded, llvm::StringRef name) { |
| 138 | + assert(!cir::MissingFeatures::astRecordDeclAttr()); |
| 139 | + llvm::SmallVector<mlir::Type> members; |
| 140 | + members.reserve(fields.size()); |
| 141 | + llvm::transform(fields, std::back_inserter(members), |
| 142 | + [](mlir::Attribute attr) { |
| 143 | + return mlir::cast<mlir::TypedAttr>(attr).getType(); |
| 144 | + }); |
| 145 | + |
| 146 | + if (name.empty()) |
| 147 | + return getAnonRecordTy(members, packed, padded); |
| 148 | + |
| 149 | + return getCompleteNamedRecordType(members, packed, padded, name); |
| 150 | +} |
| 151 | + |
| 152 | +mlir::Attribute clang::CIRGen::CIRGenBuilderTy::getConstRecordOrZeroAttr( |
| 153 | + mlir::ArrayAttr arrayAttr, bool packed, bool padded, mlir::Type type) { |
| 154 | + auto recordTy = mlir::cast_or_null<cir::RecordType>(type); |
| 155 | + |
| 156 | + // Record type not specified: create anon record type from members. |
| 157 | + if (!recordTy) { |
| 158 | + recordTy = getCompleteRecordType(arrayAttr, packed, padded); |
| 159 | + } |
| 160 | + |
| 161 | + // Return zero or anonymous constant record. |
| 162 | + const bool isZero = llvm::all_of( |
| 163 | + arrayAttr, [&](mlir::Attribute a) { return isNullValue(a); }); |
| 164 | + if (isZero) |
| 165 | + return cir::ZeroAttr::get(recordTy); |
| 166 | + return cir::ConstRecordAttr::get(recordTy, arrayAttr); |
| 167 | +} |
| 168 | + |
133 | 169 | // This can't be defined in Address.h because that file is included by
|
134 | 170 | // CIRGenBuilder.h
|
135 | 171 | Address Address::withElementType(CIRGenBuilderTy &builder,
|
|
0 commit comments