@@ -2856,45 +2856,59 @@ def CIR_CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
28562856}
28572857
28582858def 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 }]>
0 commit comments