Skip to content
Merged
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
17 changes: 7 additions & 10 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,10 @@ def SelectOp : CIR_Op<"select", [Pure,
// ConditionOp
//===----------------------------------------------------------------------===//

def ConditionOp : CIR_Op<"condition", [
Terminator,
DeclareOpInterfaceMethods<RegionBranchTerminatorOpInterface,
["getSuccessorRegions"]>
]> {
def ConditionOp : CIR_Op<"condition", [Terminator, CIR_ConditionOpInterface,
DeclareOpInterfaceMethods<
RegionBranchTerminatorOpInterface,
["getSuccessorRegions"]>]> {
let summary = "Loop continuation condition.";
let description = [{
The `cir.condition` terminates conditional regions. It takes a single
Expand Down Expand Up @@ -2195,10 +2194,8 @@ def BrCondOp : CIR_Op<"brcond",
// While & DoWhileOp
//===----------------------------------------------------------------------===//

class WhileOpBase<string mnemonic> : CIR_Op<mnemonic, [
LoopOpInterface,
NoRegionArguments,
]> {
class WhileOpBase<string mnemonic>
: CIR_Op<mnemonic, [CIR_LoopOpInterface, NoRegionArguments, ]> {
defvar isWhile = !eq(mnemonic, "while");
let summary = "C/C++ " # !if(isWhile, "while", "do-while") # " loop";
let builders = [
Expand Down Expand Up @@ -2273,7 +2270,7 @@ def DoWhileOp : WhileOpBase<"do"> {
// ForOp
//===----------------------------------------------------------------------===//

def ForOp : CIR_Op<"for", [LoopOpInterface, NoRegionArguments]> {
def ForOp : CIR_Op<"for", [CIR_LoopOpInterface, NoRegionArguments]> {
let summary = "C/C++ for loop counterpart";
let description = [{
Represents a C/C++ for loop. It consists of three regions:
Expand Down
16 changes: 12 additions & 4 deletions clang/include/clang/CIR/Interfaces/CIRLoopOpInterface.td
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ include "mlir/IR/OpBase.td"
include "mlir/Interfaces/ControlFlowInterfaces.td"
include "mlir/Interfaces/LoopLikeInterface.td"

def LoopOpInterface : OpInterface<"LoopOpInterface", [
DeclareOpInterfaceMethods<RegionBranchOpInterface>,
DeclareOpInterfaceMethods<LoopLikeOpInterface>
]> {
def CIR_LoopOpInterface
: OpInterface<"LoopOpInterface",
[DeclareOpInterfaceMethods<RegionBranchOpInterface>,
DeclareOpInterfaceMethods<LoopLikeOpInterface>]> {
let description = [{
Contains helper functions to query properties and perform transformations
on a loop.
Expand Down Expand Up @@ -96,4 +96,12 @@ def LoopOpInterface : OpInterface<"LoopOpInterface", [
}];
}

def CIR_ConditionOpInterface : OpInterface<"ConditionOpInterface", []> {
let description = [{
A singleton interface for ConditionOp only. This is used to break off a
a dependency from LoopOpInterface onto ConditionOp.
}];
let cppNamespace = "::cir";
}

#endif // CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE
9 changes: 4 additions & 5 deletions clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ void LoopOpInterface::getLoopOpSuccessorRegions(

/// Verify invariants of the LoopOpInterface.
llvm::LogicalResult detail::verifyLoopOpInterface(mlir::Operation *op) {
// FIXME: fix this so the conditionop isn't requiring MLIRCIR
// auto loopOp = mlir::cast<LoopOpInterface>(op);
// if (!mlir::isa<ConditionOp>(loopOp.getCond().back().getTerminator()))
// return op->emitOpError(
// "expected condition region to terminate with 'cir.condition'");
auto loopOp = mlir::cast<LoopOpInterface>(op);
if (!mlir::isa<ConditionOpInterface>(loopOp.getCond().back().getTerminator()))
return op->emitOpError(
"expected condition region to terminate with 'cir.condition'");
return llvm::success();
}

Expand Down
41 changes: 41 additions & 0 deletions clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -1533,3 +1533,44 @@ cir.global external dsolocal @vfp = #cir.ptr<null> : !cir.ptr<!cir.func<(!s32i)

// expected-error @below {{integer or floating point type}}
!complex = !cir.complex<!cir.ptr<!cir.void>>

// -----

#false = #cir.bool<false> : !cir.bool
#true = #cir.bool<true> : !cir.bool
cir.func @b0() {
cir.scope {
cir.while { // expected-error {{expected condition region to terminate with 'cir.condition'}}
cir.yield
} do {
cir.br ^bb1
^bb1:
cir.return
}
}
cir.return
}

// -----

cir.func @invalid_cond_region_terminator(%arg0 : !cir.bool) -> !cir.void {
cir.do { // expected-error {{op expected condition region to terminate with 'cir.condition'}}
cir.yield
} while {
cir.yield
}
cir.return
}

// -----

cir.func @invalidConditionTerminator (%arg0 : !cir.bool) -> !cir.void {
cir.for : cond { // expected-error {{op expected condition region to terminate with 'cir.condition'}}
cir.yield
} body {
cir.yield
} step {
cir.yield
}
cir.return
}
42 changes: 0 additions & 42 deletions clang/test/CIR/IR/invalid_xfail.cir

This file was deleted.

Loading