@@ -77,17 +77,40 @@ void CIRGenFunction::emitAggregateStore(mlir::Value value, Address dest) {
7777 builder.createStore (*currSrcLoc, value, dest);
7878}
7979
80+ static void addAttributesFromFunctionProtoType (CIRGenBuilderTy &builder,
81+ mlir::NamedAttrList &attrs,
82+ const FunctionProtoType *fpt) {
83+ if (!fpt)
84+ return ;
85+
86+ if (!isUnresolvedExceptionSpec (fpt->getExceptionSpecType ()) &&
87+ fpt->isNothrow ())
88+ attrs.set (cir::CIRDialect::getNoThrowAttrName (),
89+ mlir::UnitAttr::get (builder.getContext ()));
90+ }
91+
8092// / Construct the CIR attribute list of a function or call.
8193void CIRGenModule::constructAttributeList (CIRGenCalleeInfo calleeInfo,
82- cir::SideEffect &sideEffect ) {
94+ mlir::NamedAttrList &attrs ) {
8395 assert (!cir::MissingFeatures::opCallCallConv ());
84- sideEffect = cir::SideEffect::All;
96+ auto sideEffect = cir::SideEffect::All;
8597
86- assert (!cir::MissingFeatures::opCallAttrs ());
98+ addAttributesFromFunctionProtoType (getBuilder (), attrs,
99+ calleeInfo.getCalleeFunctionProtoType ());
87100
88101 const Decl *targetDecl = calleeInfo.getCalleeDecl ().getDecl ();
89102
90103 if (targetDecl) {
104+ if (targetDecl->hasAttr <NoThrowAttr>())
105+ attrs.set (cir::CIRDialect::getNoThrowAttrName (),
106+ mlir::UnitAttr::get (&getMLIRContext ()));
107+
108+ if (const FunctionDecl *func = dyn_cast<FunctionDecl>(targetDecl)) {
109+ addAttributesFromFunctionProtoType (
110+ getBuilder (), attrs, func->getType ()->getAs <FunctionProtoType>());
111+ assert (!cir::MissingFeatures::opCallAttrs ());
112+ }
113+
91114 assert (!cir::MissingFeatures::opCallAttrs ());
92115
93116 // 'const', 'pure' and 'noalias' attributed functions are also nounwind.
@@ -104,6 +127,9 @@ void CIRGenModule::constructAttributeList(CIRGenCalleeInfo calleeInfo,
104127 }
105128
106129 assert (!cir::MissingFeatures::opCallAttrs ());
130+
131+ attrs.set (cir::CIRDialect::getSideEffectAttrName (),
132+ cir::SideEffectAttr::get (&getMLIRContext (), sideEffect));
107133}
108134
109135// / Returns the canonical formal type of the given C++ method.
@@ -416,22 +442,25 @@ emitCallLikeOp(CIRGenFunction &cgf, mlir::Location callLoc,
416442 cir::FuncType indirectFuncTy, mlir::Value indirectFuncVal,
417443 cir::FuncOp directFuncOp,
418444 const SmallVectorImpl<mlir::Value> &cirCallArgs,
419- cir::SideEffect sideEffect ) {
445+ const mlir::NamedAttrList &attrs ) {
420446 CIRGenBuilderTy &builder = cgf.getBuilder ();
421447
422448 assert (!cir::MissingFeatures::opCallSurroundingTry ());
423449 assert (!cir::MissingFeatures::invokeOp ());
424450
425451 assert (builder.getInsertionBlock () && " expected valid basic block" );
426452
453+ cir::CallOp op;
427454 if (indirectFuncTy) {
428455 // TODO(cir): Set calling convention for indirect calls.
429456 assert (!cir::MissingFeatures::opCallCallConv ());
430- return builder.createIndirectCallOp (
431- callLoc, indirectFuncVal, indirectFuncTy, cirCallArgs, sideEffect);
457+ op = builder.createIndirectCallOp (callLoc, indirectFuncVal, indirectFuncTy,
458+ cirCallArgs, attrs);
459+ } else {
460+ op = builder.createCallOp (callLoc, directFuncOp, cirCallArgs, attrs);
432461 }
433462
434- return builder. createCallOp (callLoc, directFuncOp, cirCallArgs, sideEffect) ;
463+ return op ;
435464}
436465
437466const CIRGenFunctionInfo &
@@ -544,8 +573,7 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
544573
545574 assert (!cir::MissingFeatures::opCallCallConv ());
546575 assert (!cir::MissingFeatures::opCallAttrs ());
547- cir::SideEffect sideEffect;
548- cgm.constructAttributeList (callee.getAbstractInfo (), sideEffect);
576+ cgm.constructAttributeList (callee.getAbstractInfo (), attrs);
549577
550578 assert (!cir::MissingFeatures::invokeOp ());
551579
@@ -566,12 +594,10 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
566594 indirectFuncVal = calleePtr->getResult (0 );
567595 }
568596
569- assert (!cir::MissingFeatures::opCallAttrs ());
570-
571597 mlir::Location callLoc = loc;
572598 cir::CIRCallOpInterface theCall =
573599 emitCallLikeOp (*this , loc, indirectFuncTy, indirectFuncVal, directFuncOp,
574- cirCallArgs, sideEffect );
600+ cirCallArgs, attrs );
575601
576602 if (callOp)
577603 *callOp = theCall;
0 commit comments