@@ -267,6 +267,42 @@ void parseVisibilityAttr(OpAsmParser &parser, cir::VisibilityAttr &visibility) {
267267 visibility = cir::VisibilityAttr::get (parser.getContext (), visibilityKind);
268268}
269269
270+ // ===----------------------------------------------------------------------===//
271+ // InlineKindAttr (FIXME: remove once FuncOp uses assembly format)
272+ // ===----------------------------------------------------------------------===//
273+
274+ ParseResult parseInlineKindAttr (OpAsmParser &parser,
275+ cir::InlineKindAttr &inlineKindAttr) {
276+ // Static list of possible inline kind keywords
277+ static constexpr llvm::StringRef keywords[] = {" no_inline" , " always_inline" ,
278+ " inline_hint" };
279+
280+ // Parse the inline kind keyword (optional)
281+ llvm::StringRef keyword;
282+ if (parser.parseOptionalKeyword (&keyword, keywords).failed ()) {
283+ // Not an inline kind keyword, leave inlineKindAttr empty
284+ return success ();
285+ }
286+
287+ // Parse the enum value from the keyword
288+ auto inlineKindResult = ::cir::symbolizeEnum<::cir::InlineKind>(keyword);
289+ if (!inlineKindResult) {
290+ return parser.emitError (parser.getCurrentLocation (), " expected one of [" )
291+ << llvm::join (llvm::ArrayRef (keywords), " , " )
292+ << " ] for inlineKind, got: " << keyword;
293+ }
294+
295+ inlineKindAttr =
296+ ::cir::InlineKindAttr::get (parser.getContext(), *inlineKindResult);
297+ return success ();
298+ }
299+
300+ void printInlineKindAttr (OpAsmPrinter &p, cir::InlineKindAttr inlineKindAttr) {
301+ if (inlineKindAttr) {
302+ p << " " << stringifyInlineKind (inlineKindAttr.getValue ());
303+ }
304+ }
305+
270306// ===----------------------------------------------------------------------===//
271307// CIR Custom Parsers/Printers
272308// ===----------------------------------------------------------------------===//
@@ -2646,6 +2682,7 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
26462682
26472683 auto builtinNameAttr = getBuiltinAttrName (state.name );
26482684 auto coroutineNameAttr = getCoroutineAttrName (state.name );
2685+ auto inlineKindNameAttr = getInlineKindAttrName (state.name );
26492686 auto lambdaNameAttr = getLambdaAttrName (state.name );
26502687 auto visNameAttr = getSymVisibilityAttrName (state.name );
26512688 auto noProtoNameAttr = getNoProtoAttrName (state.name );
@@ -2658,6 +2695,14 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
26582695 if (::mlir::succeeded (
26592696 parser.parseOptionalKeyword (coroutineNameAttr.strref ())))
26602697 state.addAttribute (coroutineNameAttr, parser.getBuilder ().getUnitAttr ());
2698+
2699+ // Parse optional inline kind attribute
2700+ cir::InlineKindAttr inlineKindAttr;
2701+ if (failed (parseInlineKindAttr (parser, inlineKindAttr)))
2702+ return failure ();
2703+ if (inlineKindAttr)
2704+ state.addAttribute (inlineKindNameAttr, inlineKindAttr);
2705+
26612706 if (::mlir::succeeded (parser.parseOptionalKeyword (lambdaNameAttr.strref ())))
26622707 state.addAttribute (lambdaNameAttr, parser.getBuilder ().getUnitAttr ());
26632708 if (parser.parseOptionalKeyword (noProtoNameAttr).succeeded ())
@@ -2892,6 +2937,8 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
28922937 if (getCoroutine ())
28932938 p << " coroutine" ;
28942939
2940+ printInlineKindAttr (p, getInlineKindAttr ());
2941+
28952942 if (getLambda ())
28962943 p << " lambda" ;
28972944
@@ -2941,14 +2988,26 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
29412988 function_interface_impl::printFunctionAttributes (
29422989 p, *this ,
29432990 // These are all omitted since they are custom printed already.
2944- {getAliaseeAttrName (), getBuiltinAttrName (), getCoroutineAttrName (),
2945- getDsoLocalAttrName (), getExtraAttrsAttrName (),
2946- getFunctionTypeAttrName (), getGlobalCtorPriorityAttrName (),
2947- getGlobalDtorPriorityAttrName (), getLambdaAttrName (),
2948- getLinkageAttrName (), getCallingConvAttrName (), getNoProtoAttrName (),
2949- getSymVisibilityAttrName (), getArgAttrsAttrName (), getResAttrsAttrName (),
2950- getComdatAttrName (), getGlobalVisibilityAttrName (),
2951- getAnnotationsAttrName (), getCxxSpecialMemberAttrName ()});
2991+ {getAliaseeAttrName (),
2992+ getBuiltinAttrName (),
2993+ getCoroutineAttrName (),
2994+ getDsoLocalAttrName (),
2995+ getExtraAttrsAttrName (),
2996+ getFunctionTypeAttrName (),
2997+ getGlobalCtorPriorityAttrName (),
2998+ getGlobalDtorPriorityAttrName (),
2999+ getInlineKindAttrName (),
3000+ getLambdaAttrName (),
3001+ getLinkageAttrName (),
3002+ getCallingConvAttrName (),
3003+ getNoProtoAttrName (),
3004+ getSymVisibilityAttrName (),
3005+ getArgAttrsAttrName (),
3006+ getResAttrsAttrName (),
3007+ getComdatAttrName (),
3008+ getGlobalVisibilityAttrName (),
3009+ getAnnotationsAttrName (),
3010+ getCxxSpecialMemberAttrName ()});
29523011
29533012 if (auto aliaseeName = getAliasee ()) {
29543013 p << " alias(" ;
0 commit comments