Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,20 @@ def DynamicCastOp : CIR_Op<"dyn_cast"> {
cast-to-complete operation.
}];

let arguments = (ins DynamicCastKind:$kind,
RecordPtr:$src,
OptionalAttr<DynamicCastInfoAttr>:$info,
UnitAttr:$relative_layout);
let results = (outs CIR_PointerType:$result);
let arguments = (ins
DynamicCastKind:$kind,
CIR_PtrToRecordType:$src,
OptionalAttr<DynamicCastInfoAttr>:$info,
UnitAttr:$relative_layout
);

let results = (outs
CIR_PtrToAnyOf<[CIR_VoidType, CIR_RecordType]>:$result
);

let assemblyFormat = [{
`(`
$kind `,` $src `:` type($src)
$kind `,` $src `:` qualified(type($src))
(`,` qualified($info)^)?
(`relative_layout` $relative_layout^)?
`)`
Expand All @@ -273,8 +278,6 @@ def DynamicCastOp : CIR_Op<"dyn_cast"> {
return getType().isVoidPtr();
}
}];

let hasVerifier = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -3037,7 +3040,7 @@ def GetRuntimeMemberOp : CIR_Op<"get_runtime_member"> {
}];

let arguments = (ins
Arg<RecordPtr, "address of the record object", [MemRead]>:$addr,
Arg<CIR_PtrToRecordType, "address of the record object", [MemRead]>:$addr,
Arg<CIR_DataMemberType, "pointer to the target member">:$member);

let results = (outs Res<CIR_PointerType, "">:$result);
Expand Down Expand Up @@ -3091,7 +3094,7 @@ def GetMethodOp : CIR_Op<"get_method"> {
method.
}];

let arguments = (ins CIR_MethodType:$method, RecordPtr:$object);
let arguments = (ins CIR_MethodType:$method, CIR_PtrToRecordType:$object);
let results = (outs FuncPtr:$callee, CIR_VoidPtrType:$adjusted_this);

let assemblyFormat = [{
Expand Down
31 changes: 28 additions & 3 deletions clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ class CIR_ConfinedType<Type type, list<Pred> preds, string summary = "">
: Type<And<[type.predicate, CIR_CastedSelfsToType<type.cppType, preds>]>,
summary, type.cppType>;

// Generates a type summary.
// - For a single type: returns its summary.
// - For multiple types: returns `any of <comma-separated summaries>`.
class CIR_TypeSummaries<list<Type> types> {
assert !not(!empty(types)), "expects non-empty list of types";

list<string> summaries = !foreach(type, types, type.summary);
string joined = !interleave(summaries, ", ");

string value = !if(!eq(!size(types), 1), joined, "any of " # joined);
}

//===----------------------------------------------------------------------===//
// IntType predicates
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -151,6 +163,12 @@ def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType],

def CIR_AnyComplexType : CIR_TypeBase<"::cir::ComplexType", "complex type">;

//===----------------------------------------------------------------------===//
// Record Type predicates
//===----------------------------------------------------------------------===//

def CIR_AnyRecordType : CIR_TypeBase<"::cir::RecordType", "record type">;

//===----------------------------------------------------------------------===//
// Pointer Type predicates
//===----------------------------------------------------------------------===//
Expand All @@ -176,9 +194,14 @@ class CIR_PtrToPtrTo<code type, string summary>
class CIR_PointeePred<Pred pred> : SubstLeaves<"$_self",
"::mlir::cast<::cir::PointerType>($_self).getPointee()", pred>;

class CIR_PtrToType<Type type>
: CIR_ConfinedType<CIR_AnyPtrType, [CIR_PointeePred<type.predicate>],
"pointer to " # type.summary>;
class CIR_PtrToAnyOf<list<Type> types, string summary = "">
: CIR_ConfinedType<CIR_AnyPtrType,
[Or<!foreach(type, types, CIR_PointeePred<type.predicate>)>],
!if(!empty(summary),
"pointer to " # CIR_TypeSummaries<types>.value,
summary)>;

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

// Void pointer type constraints
def CIR_VoidPtrType
Expand All @@ -197,4 +220,6 @@ def CIR_PtrToIntOrFloatType : CIR_PtrToType<CIR_AnyIntOrFloatType>;

def CIR_PtrToComplexType : CIR_PtrToType<CIR_AnyComplexType>;

def CIR_PtrToRecordType : CIR_PtrToType<CIR_AnyRecordType>;

#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD
9 changes: 0 additions & 9 deletions clang/include/clang/CIR/Dialect/IR/CIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,6 @@ def CIR_VoidType : CIR_Type<"Void", "void"> {

// Constraints

// Pointer to record
def RecordPtr : Type<
And<[
CPred<"::mlir::isa<::cir::PointerType>($_self)">,
CPred<"::mlir::isa<::cir::RecordType>("
"::mlir::cast<::cir::PointerType>($_self).getPointee())">
]>, "!cir.record*"> {
}

// Pointer to exception info
def ExceptionPtr : Type<
And<[
Expand Down
16 changes: 1 addition & 15 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,19 +843,6 @@ OpFoldResult cir::UnaryOp::fold(FoldAdaptor adaptor) {
return {};
}

//===----------------------------------------------------------------------===//
// DynamicCastOp
//===----------------------------------------------------------------------===//

LogicalResult cir::DynamicCastOp::verify() {
auto resultPointeeTy = mlir::cast<cir::PointerType>(getType()).getPointee();
if (!mlir::isa<cir::VoidType, cir::RecordType>(resultPointeeTy))
return emitOpError()
<< "cir.dyn_cast must produce a void ptr or record ptr";

return mlir::success();
}

//===----------------------------------------------------------------------===//
// BaseDataMemberOp & DerivedDataMemberOp
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -3650,8 +3637,7 @@ LogicalResult cir::InsertMemberOp::verify() {
//===----------------------------------------------------------------------===//

LogicalResult cir::GetRuntimeMemberOp::verify() {
auto recordTy =
cast<RecordType>(cast<PointerType>(getAddr().getType()).getPointee());
auto recordTy = cast<RecordType>(getAddr().getType().getPointee());
auto memberPtrTy = getMember().getType();

if (recordTy != memberPtrTy.getClsTy()) {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ module {
module {
cir.func @invalid_base_type(%arg0 : !cir.data_member<!u32i in !struct1>) {
%0 = cir.alloca !u32i, !cir.ptr<!u32i>, ["tmp"] {alignment = 4 : i64}
// expected-error@+1 {{'cir.get_runtime_member' op operand #0 must be !cir.record*}}
// expected-error@+1 {{'cir.get_runtime_member' op operand #0 must be pointer to record type}}
%1 = cir.get_runtime_member %0[%arg0 : !cir.data_member<!u32i in !struct1>] : !cir.ptr<!u32i> -> !cir.ptr<!u32i>
cir.return
}
Expand Down
Loading