@@ -530,13 +530,14 @@ Value* PromoteBools::getOrCreatePromotedValue(Value* value)
530
530
return newValue;
531
531
}
532
532
533
- void PromoteBools::setPromotedAttributes (Function* newFunction, AttributeList& attributeList)
533
+ template <typename T>
534
+ void PromoteBools::setPromotedAttributes (T* newCallOrFunc, const AttributeList& attributeList)
534
535
{
535
- auto getPromoted = [this , &newFunction ](llvm::Attribute attr)
536
+ auto getPromoted = [this , &newCallOrFunc ](llvm::Attribute attr)
536
537
{
537
538
if (attr.isTypeAttribute ())
538
539
{
539
- return attr.getWithNewType (newFunction ->getContext (),
540
+ return attr.getWithNewType (newCallOrFunc ->getContext (),
540
541
getOrCreatePromotedType (attr.getValueAsType ()));
541
542
}
542
543
else
@@ -546,35 +547,28 @@ void PromoteBools::setPromotedAttributes(Function* newFunction, AttributeList& a
546
547
};
547
548
548
549
// set function attributes
549
- AttrBuilder attrBuilder (newFunction->getContext ());
550
550
for (const auto & attr : attributeList.getFnAttrs ())
551
551
{
552
- attrBuilder. addAttribute (getPromoted (attr));
552
+ newCallOrFunc-> addFnAttr (getPromoted (attr));
553
553
}
554
- newFunction->addFnAttrs (attrBuilder);
555
554
556
- // set return attributes
557
- attrBuilder.clear ();
558
- for (const auto &attr : attributeList.getRetAttrs ())
555
+ for (const auto & attr : attributeList.getRetAttrs ())
559
556
{
560
- attrBuilder. addAttribute (getPromoted (attr));
557
+ newCallOrFunc-> addRetAttr (getPromoted (attr));
561
558
}
562
- newFunction->addRetAttrs (attrBuilder);
563
559
564
560
// 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++)
566
562
{
567
563
if (!attributeList.hasParamAttrs (i))
568
564
{
569
565
continue ;
570
566
}
571
567
572
- attrBuilder.clear ();
573
568
for (const auto & attr : attributeList.getParamAttrs (i))
574
569
{
575
- attrBuilder. addAttribute ( getPromoted (attr));
570
+ newCallOrFunc-> addParamAttr (i, getPromoted (attr));
576
571
}
577
- newFunction->addParamAttrs (i, attrBuilder);
578
572
}
579
573
}
580
574
@@ -895,7 +889,7 @@ CallInst* PromoteBools::promoteIndirectCallOrInlineAsm(CallInst* call)
895
889
call
896
890
);
897
891
newCall->setCallingConv (call->getCallingConv ());
898
- newCall-> setAttributes ( call->getAttributes ());
892
+ setPromotedAttributes (newCall, call->getAttributes ());
899
893
newCall->setDebugLoc (call->getDebugLoc ());
900
894
return newCall;
901
895
}
@@ -968,7 +962,7 @@ CallInst* PromoteBools::promoteCall(CallInst* call)
968
962
call
969
963
);
970
964
newCall->setCallingConv (call->getCallingConv ());
971
- newCall-> setAttributes ( call->getAttributes ());
965
+ setPromotedAttributes (newCall, call->getAttributes ());
972
966
newCall->setDebugLoc (call->getDebugLoc ());
973
967
return newCall;
974
968
}
0 commit comments