Skip to content

Commit

Permalink
Tweaking types held in attribute lists of call instructions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
krystian-andrzejewski authored and igcbot committed Jan 31, 2025
1 parent c5a9f76 commit 07a4be8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
28 changes: 11 additions & 17 deletions IGC/AdaptorOCL/preprocess_spvir/PromoteBools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,14 @@ Value* PromoteBools::getOrCreatePromotedValue(Value* value)
return newValue;
}

void PromoteBools::setPromotedAttributes(Function* newFunction, AttributeList& attributeList)
template<typename T>
void PromoteBools::setPromotedAttributes(T* newCallOrFunc, const AttributeList& attributeList)
{
auto getPromoted = [this, &newFunction](llvm::Attribute attr)
auto getPromoted = [this, &newCallOrFunc](llvm::Attribute attr)
{
if (attr.isTypeAttribute())
{
return attr.getWithNewType(newFunction->getContext(),
return attr.getWithNewType(newCallOrFunc->getContext(),
getOrCreatePromotedType(attr.getValueAsType()));
}
else
Expand All @@ -546,35 +547,28 @@ void PromoteBools::setPromotedAttributes(Function* newFunction, AttributeList& a
};

// set function attributes
AttrBuilder attrBuilder(newFunction->getContext());
for (const auto& attr : attributeList.getFnAttrs())
{
attrBuilder.addAttribute(getPromoted(attr));
newCallOrFunc->addFnAttr(getPromoted(attr));
}
newFunction->addFnAttrs(attrBuilder);

// set return attributes
attrBuilder.clear();
for (const auto &attr : attributeList.getRetAttrs())
for (const auto& attr : attributeList.getRetAttrs())
{
attrBuilder.addAttribute(getPromoted(attr));
newCallOrFunc->addRetAttr(getPromoted(attr));
}
newFunction->addRetAttrs(attrBuilder);

// set params' attributes
for (size_t i = 0; i < newFunction->arg_size(); i++)
for (size_t i = 0; i < newCallOrFunc->arg_size(); i++)
{
if (!attributeList.hasParamAttrs(i))
{
continue;
}

attrBuilder.clear();
for (const auto& attr : attributeList.getParamAttrs(i))
{
attrBuilder.addAttribute(getPromoted(attr));
newCallOrFunc->addParamAttr(i, getPromoted(attr));
}
newFunction->addParamAttrs(i, attrBuilder);
}
}

Expand Down Expand Up @@ -895,7 +889,7 @@ CallInst* PromoteBools::promoteIndirectCallOrInlineAsm(CallInst* call)
call
);
newCall->setCallingConv(call->getCallingConv());
newCall->setAttributes(call->getAttributes());
setPromotedAttributes(newCall, call->getAttributes());
newCall->setDebugLoc(call->getDebugLoc());
return newCall;
}
Expand Down Expand Up @@ -968,7 +962,7 @@ CallInst* PromoteBools::promoteCall(CallInst* call)
call
);
newCall->setCallingConv(call->getCallingConv());
newCall->setAttributes(call->getAttributes());
setPromotedAttributes(newCall, call->getAttributes());
newCall->setDebugLoc(call->getDebugLoc());
return newCall;
}
Expand Down
3 changes: 2 additions & 1 deletion IGC/AdaptorOCL/preprocess_spvir/PromoteBools.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ namespace IGC
});
}

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

llvm::Value* getOrCreatePromotedValue(llvm::Value* value);
llvm::Function* promoteFunction(llvm::Function* function);
Expand Down
6 changes: 6 additions & 0 deletions IGC/Compiler/tests/PromoteBools/promote_attrs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

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

define spir_func void @entry() {
%a = alloca %struct, align 8
call void @prom_attr(%struct* byval(%struct) align 8 %a)
ret void
}

define spir_func void @prom_attr(%struct* byval(%struct) align 8 %0) {
ret void
}

0 comments on commit 07a4be8

Please sign in to comment.