Skip to content

Commit d03d7ea

Browse files
committed
Address code review comments
1 parent 84daae6 commit d03d7ea

File tree

2 files changed

+35
-94
lines changed

2 files changed

+35
-94
lines changed

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

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,45 +2856,59 @@ def CIR_CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
28562856
}
28572857

28582858
def CIR_TryCallOp : CIR_CallOpBase<"try_call",[
2859-
DeclareOpInterfaceMethods<BranchOpInterface>,
2860-
Terminator, AttrSizedOperandSegments
2859+
Terminator
28612860
]> {
28622861
let summary = "try_call operation";
2863-
28642862
let description = [{
2865-
Mostly similar to cir.call but requires two destination
2866-
branches, one for handling exceptions in case its thrown and
2867-
the other one to follow on regular control-flow.
2863+
Mostly similar to `cir.call` but requires two destination
2864+
branches, one for follow on regular control-flow, and the other
2865+
one for handling exceptions in case it's thrown.
2866+
2867+
This operation is used only after the CFG flatterning pass.
28682868

28692869
Example:
28702870

28712871
```mlir
2872-
// Direct call
2873-
%result = cir.try_call @division(%a, %b) ^normalDest, ^unwindDest
2872+
// Before CFG flattening
2873+
cir.try {
2874+
%call = cir.call @division(%a, %b) : () -> !s32i
2875+
cir.yield
2876+
} catch all {
2877+
cir.yield
2878+
}
2879+
2880+
// After CFG flattening
2881+
%call = cir.try_call @division(%a, %b) ^normalDest, ^unwindDest
28742882
: (f32, f32) -> f32
2883+
^normalDest:
2884+
cir.br ^afterTryBlock
2885+
^unwindDest:
2886+
%exception_ptr, %type_id = cir.eh.inflight_exception
2887+
cir.br ^catchHandlerBlock(%exception_ptr : !cir.ptr<!void>)
2888+
^catchHandlerBlock:
2889+
...
28752890
```
28762891
}];
28772892

2878-
let arguments = !con((ins
2879-
Variadic<CIR_AnyType>:$normalDestOperands,
2880-
Variadic<CIR_AnyType>:$unwindDestOperands
2881-
), commonArgs);
2882-
2893+
let arguments = commonArgs;
28832894
let results = (outs Optional<CIR_AnyType>:$result);
2884-
let successors = (successor AnySuccessor:$normalDest, AnySuccessor:$unwindDest);
2895+
let successors = (successor
2896+
AnySuccessor:$normalDest,
2897+
AnySuccessor:$unwindDest
2898+
);
28852899

28862900
let skipDefaultBuilders = 1;
28872901
let hasLLVMLowering = false;
28882902

28892903
let builders = [
2890-
OpBuilder<(ins "mlir::SymbolRefAttr":$callee, "mlir::Type":$resType,
2904+
OpBuilder<(ins "mlir::SymbolRefAttr":$callee,
2905+
"mlir::Type":$resType,
28912906
"mlir::Block *":$normalDest,
28922907
"mlir::Block *":$unwindDest,
2893-
CArg<"mlir::ValueRange", "{}">:$operands,
2894-
CArg<"mlir::ValueRange", "{}">:$normalDestOperands,
2895-
CArg<"mlir::ValueRange", "{}">:$unwindDestOperands,
2908+
CArg<"mlir::ValueRange", "{}">:$callOperands,
28962909
CArg<"SideEffect", "SideEffect::All">:$sideEffect), [{
2897-
$_state.addOperands(operands);
2910+
$_state.addOperands(callOperands);
2911+
28982912
if (callee)
28992913
$_state.addAttribute("callee", callee);
29002914
if (resType && !isa<VoidType>(resType))
@@ -2904,28 +2918,17 @@ def CIR_TryCallOp : CIR_CallOpBase<"try_call",[
29042918
SideEffectAttr::get($_builder.getContext(), sideEffect));
29052919

29062920
// Handle branches
2907-
$_state.addOperands(normalDestOperands);
2908-
$_state.addOperands(unwindDestOperands);
2909-
// The TryCall ODS layout is: cont, landing_pad, operands.
2910-
llvm::copy(::llvm::ArrayRef<int32_t>({
2911-
static_cast<int32_t>(normalDestOperands.size()),
2912-
static_cast<int32_t>(unwindDestOperands.size()),
2913-
static_cast<int32_t>(operands.size())
2914-
}),
2915-
odsState.getOrAddProperties<Properties>().operandSegmentSizes.begin());
29162921
$_state.addSuccessors(normalDest);
29172922
$_state.addSuccessors(unwindDest);
29182923
}]>,
29192924
OpBuilder<(ins "mlir::Value":$ind_target,
29202925
"FuncType":$fn_type,
29212926
"mlir::Block *":$normalDest,
29222927
"mlir::Block *":$unwindDest,
2923-
CArg<"mlir::ValueRange", "{}">:$operands,
2924-
CArg<"mlir::ValueRange", "{}">:$normalDestOperands,
2925-
CArg<"mlir::ValueRange", "{}">:$unwindDestOperands,
2928+
CArg<"mlir::ValueRange", "{}">:$callOperands,
29262929
CArg<"SideEffect", "SideEffect::All">:$sideEffect), [{
29272930
::llvm::SmallVector<mlir::Value, 4> finalCallOperands({ind_target});
2928-
finalCallOperands.append(operands.begin(), operands.end());
2931+
finalCallOperands.append(callOperands.begin(), callOperands.end());
29292932
$_state.addOperands(finalCallOperands);
29302933

29312934
if (!fn_type.hasVoidReturn())
@@ -2935,15 +2938,6 @@ def CIR_TryCallOp : CIR_CallOpBase<"try_call",[
29352938
SideEffectAttr::get($_builder.getContext(), sideEffect));
29362939

29372940
// Handle branches
2938-
$_state.addOperands(normalDestOperands);
2939-
$_state.addOperands(unwindDestOperands);
2940-
// The TryCall ODS layout is: cont, landing_pad, operands.
2941-
llvm::copy(::llvm::ArrayRef<int32_t>({
2942-
static_cast<int32_t>(normalDestOperands.size()),
2943-
static_cast<int32_t>(unwindDestOperands.size()),
2944-
static_cast<int32_t>(finalCallOperands.size())
2945-
}),
2946-
odsState.getOrAddProperties<Properties>().operandSegmentSizes.begin());
29472941
$_state.addSuccessors(normalDest);
29482942
$_state.addSuccessors(unwindDest);
29492943
}]>

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -742,14 +742,6 @@ static mlir::ParseResult parseCallCommon(mlir::OpAsmParser &parser,
742742
mlir::FlatSymbolRefAttr calleeAttr;
743743
llvm::ArrayRef<mlir::Type> allResultTypes;
744744

745-
// TryCall control flow related
746-
llvm::SmallVector<mlir::OpAsmParser::UnresolvedOperand, 4> continueOperands;
747-
llvm::SMLoc continueOperandsLoc;
748-
llvm::SmallVector<mlir::Type, 1> continueTypes;
749-
llvm::SmallVector<mlir::OpAsmParser::UnresolvedOperand, 4> landingPadOperands;
750-
llvm::SMLoc landingPadOperandsLoc;
751-
llvm::SmallVector<mlir::Type, 1> landingPadTypes;
752-
753745
// If we cannot parse a string callee, it means this is an indirect call.
754746
if (!parser
755747
.parseOptionalAttribute(calleeAttr, CIRDialect::getCalleeAttrName(),
@@ -808,24 +800,6 @@ static mlir::ParseResult parseCallCommon(mlir::OpAsmParser &parser,
808800
if (parser.resolveOperands(ops, opsFnTy.getInputs(), opsLoc, result.operands))
809801
return mlir::failure();
810802

811-
if (hasDestinationBlocks) {
812-
// The TryCall ODS layout is: cont, landing_pad, operands.
813-
llvm::copy(::llvm::ArrayRef<int32_t>(
814-
{static_cast<int32_t>(continueOperands.size()),
815-
static_cast<int32_t>(landingPadOperands.size()),
816-
static_cast<int32_t>(ops.size())}),
817-
result.getOrAddProperties<cir::TryCallOp::Properties>()
818-
.operandSegmentSizes.begin());
819-
820-
if (parser.resolveOperands(continueOperands, continueTypes,
821-
continueOperandsLoc, result.operands))
822-
return ::mlir::failure();
823-
824-
if (parser.resolveOperands(landingPadOperands, landingPadTypes,
825-
landingPadOperandsLoc, result.operands))
826-
return ::mlir::failure();
827-
}
828-
829803
return mlir::success();
830804
}
831805

@@ -857,25 +831,9 @@ static void printCallCommon(mlir::Operation *op,
857831
auto tryCall = dyn_cast<cir::TryCallOp>(op);
858832
assert(tryCall && "regular calls do not branch");
859833
printer << ' ' << tryCall.getNormalDest();
860-
if (!tryCall.getNormalDestOperands().empty()) {
861-
printer << "(";
862-
printer << tryCall.getNormalDestOperands();
863-
printer << ' ' << ":";
864-
printer << ' ';
865-
printer << tryCall.getNormalDestOperands().getTypes();
866-
printer << ")";
867-
}
868834
printer << ",";
869835
printer << ' ';
870836
printer << tryCall.getUnwindDest();
871-
if (!tryCall.getUnwindDestOperands().empty()) {
872-
printer << "(";
873-
printer << tryCall.getUnwindDestOperands();
874-
printer << ' ' << ":";
875-
printer << ' ';
876-
printer << tryCall.getUnwindDestOperands().getTypes();
877-
printer << ")";
878-
}
879837
}
880838

881839
if (isNothrow)
@@ -1026,17 +984,6 @@ void cir::TryCallOp::print(::mlir::OpAsmPrinter &p) {
1026984
sideEffect, getNormalDest(), getUnwindDest());
1027985
}
1028986

1029-
mlir::SuccessorOperands cir::TryCallOp::getSuccessorOperands(unsigned index) {
1030-
assert(index < getNumSuccessors() && "invalid successor index");
1031-
if (index == 0)
1032-
return SuccessorOperands(getNormalDestOperandsMutable());
1033-
if (index == 1)
1034-
return SuccessorOperands(getUnwindDestOperandsMutable());
1035-
1036-
// index == 2
1037-
return SuccessorOperands(getArgOperandsMutable());
1038-
}
1039-
1040987
//===----------------------------------------------------------------------===//
1041988
// ReturnOp
1042989
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)