@@ -530,13 +530,14 @@ Value* PromoteBools::getOrCreatePromotedValue(Value* value)
530530    return  newValue;
531531}
532532
533- void  PromoteBools::setPromotedAttributes (Function* newFunction, AttributeList& attributeList)
533+ template <typename  T>
534+ void  PromoteBools::setPromotedAttributes (T* newCallOrFunc, const  AttributeList& attributeList)
534535{
535-     auto  getPromoted = [this , &newFunction ](llvm::Attribute attr)
536+     auto  getPromoted = [this , &newCallOrFunc ](llvm::Attribute attr)
536537        {
537538            if  (attr.isTypeAttribute ())
538539            {
539-                 return  attr.getWithNewType (newFunction ->getContext (),
540+                 return  attr.getWithNewType (newCallOrFunc ->getContext (),
540541                    getOrCreatePromotedType (attr.getValueAsType ()));
541542            }
542543            else 
@@ -546,35 +547,28 @@ void PromoteBools::setPromotedAttributes(Function* newFunction, AttributeList& a
546547        };
547548
548549    //  set function attributes
549-     AttrBuilder attrBuilder (newFunction->getContext ());
550550    for  (const  auto & attr : attributeList.getFnAttrs ())
551551    {
552-         attrBuilder. addAttribute (getPromoted (attr));
552+         newCallOrFunc-> addFnAttr (getPromoted (attr));
553553    }
554-     newFunction->addFnAttrs (attrBuilder);
555554
556-     //  set return attributes
557-     attrBuilder.clear ();
558-     for  (const  auto  &attr : attributeList.getRetAttrs ())
555+     for  (const  auto & attr : attributeList.getRetAttrs ())
559556    {
560-         attrBuilder. addAttribute (getPromoted (attr));
557+         newCallOrFunc-> addRetAttr (getPromoted (attr));
561558    }
562-     newFunction->addRetAttrs (attrBuilder);
563559
564560    //  set params' attributes
565-     for  (size_t  i = 0 ; i < newFunction ->arg_size (); i++)
561+     for  (size_t  i = 0 ; i < newCallOrFunc ->arg_size (); i++)
566562    {
567563        if  (!attributeList.hasParamAttrs (i))
568564        {
569565            continue ;
570566        }
571567
572-         attrBuilder.clear ();
573568        for  (const  auto & attr : attributeList.getParamAttrs (i))
574569        {
575-             attrBuilder. addAttribute ( getPromoted (attr));
570+             newCallOrFunc-> addParamAttr (i,  getPromoted (attr));
576571        }
577-         newFunction->addParamAttrs (i, attrBuilder);
578572    }
579573}
580574
@@ -895,7 +889,7 @@ CallInst* PromoteBools::promoteIndirectCallOrInlineAsm(CallInst* call)
895889        call
896890    );
897891    newCall->setCallingConv (call->getCallingConv ());
898-     newCall-> setAttributes ( call->getAttributes ());
892+     setPromotedAttributes (newCall,  call->getAttributes ());
899893    newCall->setDebugLoc (call->getDebugLoc ());
900894    return  newCall;
901895}
@@ -968,7 +962,7 @@ CallInst* PromoteBools::promoteCall(CallInst* call)
968962        call
969963    );
970964    newCall->setCallingConv (call->getCallingConv ());
971-     newCall-> setAttributes ( call->getAttributes ());
965+     setPromotedAttributes (newCall,  call->getAttributes ());
972966    newCall->setDebugLoc (call->getDebugLoc ());
973967    return  newCall;
974968}
0 commit comments