@@ -162,8 +162,7 @@ static void AddAttributesFromFunctionProtoType(CIRGenBuilderTy &builder,
162162
163163 if (!isUnresolvedExceptionSpec (FPT->getExceptionSpecType ()) &&
164164 FPT->isNothrow ()) {
165- auto nu = cir::NoThrowAttr::get (builder.getContext ());
166- FuncAttrs.set (nu.getMnemonic (), nu);
165+ FuncAttrs.set (" nothrow" , builder.getUnitAttr ());
167166 }
168167}
169168
@@ -221,8 +220,8 @@ void CIRGenModule::constructAttributeList(
221220 if (TargetDecl) {
222221
223222 if (TargetDecl->hasAttr <NoThrowAttr>()) {
224- auto nu = cir::NoThrowAttr ::get (&getMLIRContext ());
225- funcAttrs.set (nu. getMnemonic () , nu);
223+ auto nu = mlir::UnitAttr ::get (&getMLIRContext ());
224+ funcAttrs.set (" nothrow " , nu);
226225 }
227226
228227 if (const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
@@ -324,7 +323,7 @@ emitCallLikeOp(CIRGenFunction &CGF, mlir::Location callLoc,
324323 cir::FuncOp directFuncOp,
325324 SmallVectorImpl<mlir::Value> &CIRCallArgs, bool isInvoke,
326325 cir::CallingConv callingConv, cir::SideEffect sideEffect,
327- cir::ExtraFuncAttributesAttr extraFnAttrs) {
326+ cir::ExtraFuncAttributesAttr extraFnAttrs, bool cannotThrow ) {
328327 auto &builder = CGF.getBuilder ();
329328 auto getOrCreateSurroundingTryOp = [&]() {
330329 // In OG, we build the landing pad for this scope. In CIR, we emit a
@@ -383,6 +382,8 @@ emitCallLikeOp(CIRGenFunction &CGF, mlir::Location callLoc,
383382 callLoc, directFuncOp, CIRCallArgs, callingConv, sideEffect);
384383 }
385384 callOpWithExceptions->setAttr (" extra_attrs" , extraFnAttrs);
385+ if (cannotThrow)
386+ callOpWithExceptions->setAttr (" nothrow" , builder.getUnitAttr ());
386387 CGF.mayThrow = true ;
387388
388389 CGF.callWithExceptionCtx = callOpWithExceptions;
@@ -398,15 +399,20 @@ emitCallLikeOp(CIRGenFunction &CGF, mlir::Location callLoc,
398399 }
399400
400401 assert (builder.getInsertionBlock () && " expected valid basic block" );
402+ cir::CIRCallOpInterface callOp;
401403 if (indirectFuncTy) {
402404 // TODO(cir): Set calling convention for indirect calls.
403405 assert (callingConv == cir::CallingConv::C && " NYI" );
404- return builder.createIndirectCallOp (
406+ callOp = builder.createIndirectCallOp (
405407 callLoc, indirectFuncVal, indirectFuncTy, CIRCallArgs,
406408 cir::CallingConv::C, sideEffect, extraFnAttrs);
409+ } else {
410+ callOp = builder.createCallOp (callLoc, directFuncOp, CIRCallArgs, callingConv,
411+ sideEffect, extraFnAttrs);
407412 }
408- return builder.createCallOp (callLoc, directFuncOp, CIRCallArgs, callingConv,
409- sideEffect, extraFnAttrs);
413+ if (cannotThrow)
414+ callOp->setAttr (" nothrow" , builder.getUnitAttr ());
415+ return callOp;
410416}
411417
412418static RValue getRValueThroughMemory (mlir::Location loc,
@@ -601,12 +607,10 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &CallInfo,
601607 CannotThrow = true ;
602608 } else {
603609 // Otherwise, nounwind call sites will never throw.
604- auto noThrowAttr = cir::NoThrowAttr::get (&getMLIRContext ());
605- CannotThrow = Attrs.getNamed (noThrowAttr.getMnemonic ()).has_value ();
610+ CannotThrow = Attrs.getNamed (" nothrow" ).has_value ();
606611
607612 if (auto fptr = dyn_cast<cir::FuncOp>(CalleePtr))
608- if (fptr.getExtraAttrs ().getElements ().contains (
609- noThrowAttr.getMnemonic ()))
613+ if (fptr.getNothrow ())
610614 CannotThrow = true ;
611615 }
612616 bool isInvoke = CannotThrow ? false : isInvokeDest ();
@@ -650,7 +654,7 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &CallInfo,
650654
651655 cir::CIRCallOpInterface callLikeOp = emitCallLikeOp (
652656 *this , callLoc, indirectFuncTy, indirectFuncVal, directFuncOp,
653- CIRCallArgs, isInvoke, callingConv, sideEffect, extraFnAttrs);
657+ CIRCallArgs, isInvoke, callingConv, sideEffect, extraFnAttrs, CannotThrow );
654658
655659 if (E)
656660 callLikeOp->setAttr (" ast" ,
@@ -1462,8 +1466,8 @@ static void getTrivialDefaultFunctionAttributes(
14621466 llvm_unreachable (" NYI" );
14631467 if (langOpts.OpenCL ||
14641468 ((langOpts.CUDA || langOpts.HIP ) && langOpts.CUDAIsDevice )) {
1465- auto noThrow = cir::NoThrowAttr ::get (CGM.getBuilder ().getContext ());
1466- funcAttrs.set (noThrow. getMnemonic () , noThrow);
1469+ auto noThrow = mlir::UnitAttr ::get (CGM.getBuilder ().getContext ());
1470+ funcAttrs.set (" nothrow " , noThrow);
14671471 }
14681472}
14691473
0 commit comments