Skip to content

Commit ab4febc

Browse files
committed
[CIR] Add BuildableType traits to relevant constraints (NFC)
This also eliminates some explicit uses of buildable types.
1 parent f3c1645 commit ab4febc

File tree

7 files changed

+50
-42
lines changed

7 files changed

+50
-42
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
588588

589589
cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind,
590590
mlir::Value lhs, mlir::Value rhs) {
591-
return cir::CmpOp::create(*this, loc, getBoolTy(), kind, lhs, rhs);
591+
return cir::CmpOp::create(*this, loc, kind, lhs, rhs);
592592
}
593593

594594
cir::VecCmpOp createVecCompare(mlir::Location loc, cir::CmpOpKind kind,

clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class CIR_TypeSummaries<list<Type> types> {
4747
// Bool Type predicates
4848
//===----------------------------------------------------------------------===//
4949

50-
def CIR_AnyBoolType : CIR_TypeBase<"::cir::BoolType", "boolean type">;
50+
def CIR_AnyBoolType : CIR_TypeBase<"::cir::BoolType", "boolean type">,
51+
BuildableType<"$_builder.getType<" # cppType # ">()">;
5152

5253
//===----------------------------------------------------------------------===//
5354
// IntType predicates
@@ -132,18 +133,25 @@ def CIR_AnyFundamentalSIntType
132133
// Float Type predicates
133134
//===----------------------------------------------------------------------===//
134135

135-
def CIR_AnySingleType : CIR_TypeBase<"::cir::SingleType", "single float type">;
136+
def CIR_AnySingleType : CIR_TypeBase<"::cir::SingleType", "single float type">,
137+
BuildableType<"$_builder.getType<" # cppType # ">()">;
136138
def CIR_AnyFP32Type : TypeAlias<CIR_AnySingleType>;
137139

138-
def CIR_AnyDoubleType : CIR_TypeBase<"::cir::DoubleType", "double float type">;
140+
def CIR_AnyDoubleType : CIR_TypeBase<"::cir::DoubleType", "double float type">,
141+
BuildableType<"$_builder.getType<" # cppType # ">()">;
139142
def CIR_AnyFP64Type : TypeAlias<CIR_AnyDoubleType>;
140143

141-
def CIR_AnyFP16Type : CIR_TypeBase<"::cir::FP16Type", "f16 type">;
142-
def CIR_AnyBFloat16Type : CIR_TypeBase<"::cir::BF16Type", "bf16 type">;
143-
def CIR_AnyFP80Type : CIR_TypeBase<"::cir::FP80Type", "f80 type">;
144-
def CIR_AnyFP128Type : CIR_TypeBase<"::cir::FP128Type", "f128 type">;
144+
def CIR_AnyFP16Type : CIR_TypeBase<"::cir::FP16Type", "f16 type">,
145+
BuildableType<"$_builder.getType<" # cppType # ">()">;
146+
def CIR_AnyBFloat16Type : CIR_TypeBase<"::cir::BF16Type", "bf16 type">,
147+
BuildableType<"$_builder.getType<" # cppType # ">()">;
148+
def CIR_AnyFP80Type : CIR_TypeBase<"::cir::FP80Type", "f80 type">,
149+
BuildableType<"$_builder.getType<" # cppType # ">()">;
150+
def CIR_AnyFP128Type : CIR_TypeBase<"::cir::FP128Type", "f128 type">,
151+
BuildableType<"$_builder.getType<" # cppType # ">()">;
145152
def CIR_AnyLongDoubleType : CIR_TypeBase<"::cir::LongDoubleType",
146-
"long double type">;
153+
"long double type">,
154+
BuildableType<"$_builder.getType<" # cppType # ">()">;
147155

148156
def CIR_AnyFloatType : AnyTypeOf<[
149157
CIR_AnySingleType, CIR_AnyDoubleType, CIR_AnyFP16Type,
@@ -196,19 +204,25 @@ def CIR_AnyArrayType : CIR_TypeBase<"::cir::ArrayType", "array type">;
196204
def CIR_AnyPtrType : CIR_TypeBase<"::cir::PointerType", "pointer type">;
197205

198206
// Pointer to type constraint bases
199-
class CIR_IsPtrToPred<code type> : CPred<"$_self.isPtrTo<" # type # ">()">;
207+
class CIR_IsPtrToPred<Type type>
208+
: CPred<"$_self.isPtrTo<" # type.cppType # ">()">;
200209

201-
class CIR_PtrTo<code type, string summary>
210+
class CIR_PtrTo<Type type, string summary>
202211
: CIR_ConfinedType<CIR_AnyPtrType, [CIR_IsPtrToPred<type>],
203-
"pointer to " # summary>;
212+
"pointer to " # summary>,
213+
SameBuildabilityAs<type,
214+
"$_builder.getType<" # cppType # ">(" # type.builderCall # ")">;
204215

205216
// Pointer to pointer constraint bases
206-
class CIR_IsPtrToPtrToPred<code type>
207-
: CPred<"$_self.isPtrToPtrTo<" # type # ">()">;
217+
class CIR_IsPtrToPtrToPred<Type type>
218+
: CPred<"$_self.isPtrToPtrTo<" # type.cppType # ">()">;
208219

209-
class CIR_PtrToPtrTo<code type, string summary>
220+
class CIR_PtrToPtrTo<Type type, string summary>
210221
: CIR_ConfinedType<CIR_AnyPtrType, [CIR_IsPtrToPtrToPred<type>],
211-
"pointer to pointer to " # summary>;
222+
"pointer to pointer to " # summary>,
223+
SameBuildabilityAs<type,
224+
"$_builder.getType<" # cppType # ">($_builder.getType<" # cppType #
225+
">(" # type.builderCall # "))">;
212226

213227
// Pointee type constraint bases
214228
class CIR_PointeePred<Pred pred> : SubstLeaves<"$_self",
@@ -221,17 +235,14 @@ class CIR_PtrToAnyOf<list<Type> types, string summary = "">
221235
"pointer to " # CIR_TypeSummaries<types>.value,
222236
summary)>;
223237

238+
// Void type constraints
239+
def CIR_AnyVoidType : CIR_TypeBase<"::cir::VoidType", "void type">,
240+
BuildableType<"$_builder.getType<" # cppType # ">()">;
241+
224242
// Void pointer type constraints
225-
def CIR_VoidPtrType
226-
: CIR_PtrTo<"::cir::VoidType", "void type">,
227-
BuildableType<"$_builder.getType<" # cppType # ">("
228-
"cir::VoidType::get($_builder.getContext()))">;
243+
def CIR_VoidPtrType : CIR_PtrTo<CIR_AnyVoidType, "void type">;
229244

230-
def CIR_PtrToVoidPtrType
231-
: CIR_PtrToPtrTo<"::cir::VoidType", "void type">,
232-
BuildableType<"$_builder.getType<" # cppType # ">("
233-
"$_builder.getType<" # cppType # ">("
234-
"cir::VoidType::get($_builder.getContext())))">;
245+
def CIR_PtrToVoidPtrType : CIR_PtrToPtrTo<CIR_AnyVoidType, "void type">;
235246

236247
class CIR_PtrToType<Type type> : CIR_PtrToAnyOf<[type]>;
237248

@@ -323,9 +334,12 @@ def CIR_AnyDataMemberType : CIR_TypeBase<"::cir::DataMemberType",
323334
// VPtr type predicates
324335
//===----------------------------------------------------------------------===//
325336

326-
def CIR_AnyVPtrType : CIR_TypeBase<"::cir::VPtrType", "vptr type">;
337+
def CIR_AnyVPtrType : CIR_TypeBase<"::cir::VPtrType", "vptr type">,
338+
BuildableType<"$_builder.getType<" # cppType # ">()">;
327339

328-
def CIR_PtrToVPtr : CIR_PtrToType<CIR_AnyVPtrType>;
340+
def CIR_PtrToVPtr : CIR_PtrToType<CIR_AnyVPtrType>,
341+
BuildableType<"$_builder.getType<" # cppType # ">("
342+
"$_builder.getType<::cir::VPtrType>())">;
329343

330344
//===----------------------------------------------------------------------===//
331345
// Scalar Type predicates

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ void CIRGenFunction::initializeVTablePointer(mlir::Location loc,
440440
// vtable field is derived from `this` pointer, therefore they should be in
441441
// the same addr space.
442442
assert(!cir::MissingFeatures::addressSpace());
443-
auto vtablePtr = cir::VTableGetVPtrOp::create(
444-
builder, loc, builder.getPtrToVPtrType(), classAddr.getPointer());
443+
auto vtablePtr =
444+
cir::VTableGetVPtrOp::create(builder, loc, classAddr.getPointer());
445445
Address vtableField = Address(vtablePtr, classAddr.getAlignment());
446446
builder.createStore(loc, vtableAddressPoint, vtableField);
447447
assert(!cir::MissingFeatures::opTBAA());
@@ -1244,8 +1244,8 @@ bool CIRGenFunction::shouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *rd) {
12441244

12451245
mlir::Value CIRGenFunction::getVTablePtr(mlir::Location loc, Address thisAddr,
12461246
const CXXRecordDecl *rd) {
1247-
auto vtablePtr = cir::VTableGetVPtrOp::create(
1248-
builder, loc, builder.getPtrToVPtrType(), thisAddr.getPointer());
1247+
auto vtablePtr =
1248+
cir::VTableGetVPtrOp::create(builder, loc, thisAddr.getPointer());
12491249
Address vtablePtrAddr = Address(vtablePtr, thisAddr.getAlignment());
12501250

12511251
auto vtable = builder.createLoad(loc, vtablePtrAddr);

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,8 @@ void AggExprEmitter::emitArrayInit(Address destPtr, cir::ArrayType arrayTy,
535535
/*condBuilder=*/
536536
[&](mlir::OpBuilder &b, mlir::Location loc) {
537537
cir::LoadOp currentElement = builder.createLoad(loc, tmpAddr);
538-
mlir::Type boolTy = cgf.convertType(cgf.getContext().BoolTy);
539-
cir::CmpOp cmp = cir::CmpOp::create(
540-
builder, loc, boolTy, cir::CmpOpKind::ne, currentElement, end);
538+
cir::CmpOp cmp = cir::CmpOp::create(builder, loc, cir::CmpOpKind::ne,
539+
currentElement, end);
541540
builder.createCondition(cmp);
542541
},
543542
/*bodyBuilder=*/

clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ class CIRSwitchOpFlattening : public mlir::OpRewritePattern<cir::SwitchOp> {
217217
rewriter, op.getLoc(), uIntType, CastKind::integral, rangeLength);
218218

219219
cir::CmpOp cmpResult = cir::CmpOp::create(
220-
rewriter, op.getLoc(), cir::BoolType::get(op.getContext()),
221-
cir::CmpOpKind::le, uDiffValue, uRangeLength);
220+
rewriter, op.getLoc(), cir::CmpOpKind::le, uDiffValue, uRangeLength);
222221
cir::BrCondOp::create(rewriter, op.getLoc(), cmpResult, rangeDestination,
223222
defaultDestination);
224223
return resBlock;

clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,7 @@ static void lowerArrayDtorCtorIntoLoop(cir::CIRBaseBuilderTy &builder,
10291029
/*condBuilder=*/
10301030
[&](mlir::OpBuilder &b, mlir::Location loc) {
10311031
auto currentElement = cir::LoadOp::create(b, loc, eltTy, tmpAddr);
1032-
mlir::Type boolTy = cir::BoolType::get(b.getContext());
1033-
auto cmp = cir::CmpOp::create(builder, loc, boolTy, cir::CmpOpKind::ne,
1032+
auto cmp = cir::CmpOp::create(builder, loc, cir::CmpOpKind::ne,
10341033
currentElement, stop);
10351034
builder.createCondition(cmp);
10361035
},

clang/lib/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ buildDynamicCastToVoidAfterNullCheck(cir::CIRBaseBuilderTy &builder,
119119
// Access vtable to get the offset from the given object to its containing
120120
// complete object.
121121
// TODO: Add a specialized operation to get the object offset?
122-
auto vptrTy = cir::VPtrType::get(builder.getContext());
123-
cir::PointerType vptrPtrTy = builder.getPointerTo(vptrTy);
124-
auto vptrPtr =
125-
cir::VTableGetVPtrOp::create(builder, loc, vptrPtrTy, op.getSrc());
122+
auto vptrPtr = cir::VTableGetVPtrOp::create(builder, loc, op.getSrc());
126123
mlir::Value vptr = builder.createLoad(loc, vptrPtr);
127124
mlir::Value elementPtr =
128125
builder.createBitcast(vptr, builder.getPointerTo(vtableElemTy));

0 commit comments

Comments
 (0)