Skip to content

Commit d848a4e

Browse files
krystian-andrzejewskipszymich
authored andcommitted
Tweaking types held in attribute lists of call instructions
This change is to attach correct attribute lists to new call instructions in `PromoteBools`. The attribute list must contain promoted types to be in sync with their called function. (cherry picked from commit 07a4be8)
1 parent 7f73de8 commit d848a4e

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

IGC/AdaptorOCL/preprocess_spvir/PromoteBools.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

IGC/AdaptorOCL/preprocess_spvir/PromoteBools.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ namespace IGC
7777
});
7878
}
7979

80-
void setPromotedAttributes(llvm::Function* newFunction, llvm::AttributeList& attributeList);
80+
template<typename T>
81+
void setPromotedAttributes(T* callOrFunc, const llvm::AttributeList& attributeList);
8182

8283
llvm::Value* getOrCreatePromotedValue(llvm::Value* value);
8384
llvm::Function* promoteFunction(llvm::Function* function);

IGC/Compiler/tests/PromoteBools/promote_attrs.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
%struct = type { [4 x <8 x i1*>], [4 x <8 x i1>*]* }
1616

17+
define spir_func void @entry() {
18+
%a = alloca %struct, align 8
19+
call void @prom_attr(%struct* byval(%struct) align 8 %a)
20+
ret void
21+
}
22+
1723
define spir_func void @prom_attr(%struct* byval(%struct) align 8 %0) {
1824
ret void
1925
}

0 commit comments

Comments
 (0)