@@ -750,8 +750,10 @@ def IfOp : CIR_Op<"if",
750
750
}
751
751
```
752
752
753
- `cir.if` defines no values and the 'else' can be omitted. `cir.yield` must
754
- explicitly terminate the region if it has more than one block.
753
+ `cir.if` defines no values and the 'else' can be omitted. The if/else
754
+ regions must be terminated. If the region has only one block, the terminator
755
+ can be left out, and `cir.yield` terminator will be inserted implictly.
756
+ Otherwise, the region must be explicitly terminated.
755
757
}];
756
758
let arguments = (ins CIR_BoolType:$condition);
757
759
let regions = (region AnyRegion:$thenRegion, AnyRegion:$elseRegion);
@@ -1070,6 +1072,16 @@ def ScopeOp : CIR_Op<"scope", [
1070
1072
custom<OmittedTerminatorRegion>($scopeRegion) (`:` type($results)^)? attr-dict
1071
1073
}];
1072
1074
1075
+ let extraClassDeclaration = [{
1076
+ /// Determine whether the scope is empty, meaning it contains a single block
1077
+ /// terminated by a cir.yield.
1078
+ bool isEmpty() {
1079
+ auto &entry = getRegion().front();
1080
+ return getRegion().hasOneBlock() &&
1081
+ llvm::isa<cir::YieldOp>(entry.front());
1082
+ }
1083
+ }];
1084
+
1073
1085
let builders = [
1074
1086
// Scopes for yielding values.
1075
1087
OpBuilder<(ins
@@ -1200,7 +1212,7 @@ def ShiftOp : CIR_Op<"shift", [Pure]> {
1200
1212
be either integer type or vector of integer type. However, they must be
1201
1213
either all vector of integer type, or all integer type. If they are vectors,
1202
1214
each vector element of the shift target is shifted by the corresponding
1203
- shift amount in the shift amount vector.
1215
+ shift amount in the shift amount vector.
1204
1216
1205
1217
```mlir
1206
1218
%7 = cir.shift(left, %1 : !u64i, %4 : !s32i) -> !u64i
@@ -1879,17 +1891,17 @@ def SwitchOp : CIR_Op<"switch",
1879
1891
is an integral condition value.
1880
1892
1881
1893
The set of `cir.case` operations and their enclosing `cir.switch`
1882
- represents the semantics of a C/C++ switch statement. Users can use
1894
+ represents the semantics of a C/C++ switch statement. Users can use
1883
1895
`collectCases(llvm::SmallVector<CaseOp> &cases)` to collect the `cir.case`
1884
1896
operation in the `cir.switch` operation easily.
1885
1897
1886
1898
The `cir.case` operations doesn't have to be in the region of `cir.switch`
1887
1899
directly. However, when all the `cir.case` operations lives in the region
1888
1900
of `cir.switch` directly and there is no other operations except the ending
1889
- `cir.yield` operation in the region of `cir.switch` directly, we call the
1890
- `cir.switch` operation is in a simple form. Users can use
1901
+ `cir.yield` operation in the region of `cir.switch` directly, we call the
1902
+ `cir.switch` operation is in a simple form. Users can use
1891
1903
`bool isSimpleForm(llvm::SmallVector<CaseOp> &cases)` member function to
1892
- detect if the `cir.switch` operation is in a simple form. The simple form
1904
+ detect if the `cir.switch` operation is in a simple form. The simple form
1893
1905
makes analysis easier to handle the `cir.switch` operation
1894
1906
and makes the boundary to give up pretty clear.
1895
1907
@@ -1976,7 +1988,7 @@ def SwitchOp : CIR_Op<"switch",
1976
1988
switch(int cond) {
1977
1989
l:
1978
1990
b++;
1979
-
1991
+
1980
1992
case 4:
1981
1993
a++;
1982
1994
break;
@@ -4136,13 +4148,13 @@ def ReturnAddrOp : CIR_Op<"return_address"> {
4136
4148
let results = (outs Res<VoidPtr, "">:$result);
4137
4149
4138
4150
let description = [{
4139
- Represents call to builtin function ` __builtin_return_address` in CIR.
4140
- This builtin function returns the return address of the current function,
4141
- or of one of its callers.
4151
+ Represents call to builtin function ` __builtin_return_address` in CIR.
4152
+ This builtin function returns the return address of the current function,
4153
+ or of one of its callers.
4142
4154
The `level` argument is number of frames to scan up the call stack.
4143
- For instance, value of 0 yields the return address of the current function,
4144
- value of 1 yields the return address of the caller of the current function,
4145
- and so forth.
4155
+ For instance, value of 0 yields the return address of the current function,
4156
+ value of 1 yields the return address of the caller of the current function,
4157
+ and so forth.
4146
4158
4147
4159
Examples:
4148
4160
@@ -4282,8 +4294,8 @@ def AbsOp : CIR_Op<"abs", [Pure, SameOperandsAndResultType]> {
4282
4294
let summary = [{
4283
4295
libc builtin equivalent abs, labs, llabs
4284
4296
4285
- The `poison` argument indicate whether the result value
4286
- is a poison value if the first argument is statically or
4297
+ The `poison` argument indicate whether the result value
4298
+ is a poison value if the first argument is statically or
4287
4299
dynamically an INT_MIN value.
4288
4300
4289
4301
Example:
0 commit comments