Skip to content

Commit bbe9010

Browse files
xlaukolanza
authored andcommitted
[CIR] Refactor constraints for integers, floats, and complex pointees (llvm#1605)
- Rename `PrimitiveIntOrFPPtr` to `CIR_PtrToIntOrFloatType` and broaden it to accept any floating-point type. - Fix incorrect constraint name from `PrimitiveInt` to any `Int`; prior constraint already allowed arbitrary bitwidths, so the name was misleading. - Rename `ComplexPtr` to `CIR_PtrToComplexType` for clarity.
1 parent cd9bd41 commit bbe9010

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,8 @@ def ComplexRealPtrOp : CIR_Op<"complex.real_ptr", [Pure]> {
14551455
```
14561456
}];
14571457

1458-
let results = (outs PrimitiveIntOrFPPtr:$result);
1459-
let arguments = (ins ComplexPtr:$operand);
1458+
let results = (outs CIR_PtrToIntOrFloatType:$result);
1459+
let arguments = (ins CIR_PtrToComplexType:$operand);
14601460

14611461
let assemblyFormat = [{
14621462
$operand `:`
@@ -1480,8 +1480,8 @@ def ComplexImagPtrOp : CIR_Op<"complex.imag_ptr", [Pure]> {
14801480
```
14811481
}];
14821482

1483-
let results = (outs PrimitiveIntOrFPPtr:$result);
1484-
let arguments = (ins ComplexPtr:$operand);
1483+
let results = (outs CIR_PtrToIntOrFloatType:$result);
1484+
let arguments = (ins CIR_PtrToComplexType:$operand);
14851485

14861486
let assemblyFormat = [{
14871487
$operand `:`
@@ -5515,17 +5515,19 @@ def AtomicFetch : CIR_Op<"atomic.fetch",
55155515
%val : !s32i, seq_cst) : !s32i
55165516
}];
55175517
let results = (outs CIR_AnyIntOrFloatType:$result);
5518-
let arguments = (ins Arg<PrimitiveIntOrFPPtr, "", [MemRead, MemWrite]>:$ptr,
5519-
CIR_AnyIntOrFloatType:$val,
5520-
AtomicFetchKind:$binop,
5521-
Arg<MemOrder, "memory order">:$mem_order,
5522-
UnitAttr:$is_volatile,
5523-
UnitAttr:$fetch_first);
5518+
let arguments = (ins
5519+
Arg<CIR_PtrToIntOrFloatType, "", [MemRead, MemWrite]>:$ptr,
5520+
CIR_AnyIntOrFloatType:$val,
5521+
AtomicFetchKind:$binop,
5522+
Arg<MemOrder, "memory order">:$mem_order,
5523+
UnitAttr:$is_volatile,
5524+
UnitAttr:$fetch_first
5525+
);
55245526

55255527
let assemblyFormat = [{
55265528
`(`
55275529
$binop `,`
5528-
$ptr `:` type($ptr) `,`
5530+
$ptr `:` qualified(type($ptr)) `,`
55295531
$val `:` type($val) `,`
55305532
$mem_order `)`
55315533
(`volatile` $is_volatile^)?

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ def CIR_AnyFloatType : AnyTypeOf<[
135135
let cppFunctionName = "isAnyFloatingPointType";
136136
}
137137

138+
//===----------------------------------------------------------------------===//
139+
// Integer or Float Type predicates
140+
//===----------------------------------------------------------------------===//
141+
138142
def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType],
139143
"integer or floating point type"
140144
> {
@@ -168,6 +172,14 @@ class CIR_PtrToPtrTo<code type, string summary>
168172
: CIR_ConfinedType<CIR_AnyPtrType, [CIR_IsPtrToPtrToPred<type>],
169173
"pointer to pointer to " # summary>;
170174

175+
// Pointee type constraint bases
176+
class CIR_PointeePred<Pred pred> : SubstLeaves<"$_self",
177+
"::mlir::cast<::cir::PointerType>($_self).getPointee()", pred>;
178+
179+
class CIR_PtrToType<Type type>
180+
: CIR_ConfinedType<CIR_AnyPtrType, [CIR_PointeePred<type.predicate>],
181+
"pointer to " # type.summary>;
182+
171183
// Void pointer type constraints
172184
def CIR_VoidPtrType
173185
: CIR_PtrTo<"::cir::VoidType", "void type">,
@@ -180,4 +192,9 @@ def CIR_PtrToVoidPtrType
180192
"$_builder.getType<" # cppType # ">("
181193
"cir::VoidType::get($_builder.getContext())))">;
182194

195+
// Pointer to type constraints
196+
def CIR_PtrToIntOrFloatType : CIR_PtrToType<CIR_AnyIntOrFloatType>;
197+
198+
def CIR_PtrToComplexType : CIR_PtrToType<CIR_AnyComplexType>;
199+
183200
#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -505,24 +505,6 @@ def CIR_VoidType : CIR_Type<"Void", "void"> {
505505

506506
// Constraints
507507

508-
// Pointer to a primitive int, float or double
509-
def PrimitiveIntOrFPPtr : Type<
510-
And<[
511-
CPred<"::mlir::isa<::cir::PointerType>($_self)">,
512-
CPred<"::mlir::isa<::cir::IntType, ::cir::SingleType,"
513-
"::cir::DoubleType>("
514-
"::mlir::cast<::cir::PointerType>($_self).getPointee())">,
515-
]>, "{int,void}*"> {
516-
}
517-
518-
def ComplexPtr : Type<
519-
And<[
520-
CPred<"::mlir::isa<::cir::PointerType>($_self)">,
521-
CPred<"::mlir::isa<::cir::ComplexType>("
522-
"::mlir::cast<::cir::PointerType>($_self).getPointee())">,
523-
]>, "!cir.complex*"> {
524-
}
525-
526508
// Pointer to record
527509
def RecordPtr : Type<
528510
And<[

0 commit comments

Comments
 (0)