Skip to content

Commit

Permalink
Do not mix alwaysinline and stackcall attributes for VC
Browse files Browse the repository at this point in the history
.
  • Loading branch information
vmustya authored and igcbot committed Sep 20, 2023
1 parent 0cb29b6 commit 34f1575
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ static void cloneIndirectFunction(Function &F,
auto *Direct = CloneFunction(&F, VMap);
Direct->setName(F.getName() + "_direct");
Direct->setLinkage(GlobalValue::InternalLinkage);
Direct->removeFnAttr(genx::FunctionMD::CMStackCall);

// Replace all uses of the original function that are direct calls.
IGCLLVM::replaceUsesWithIf(&F, Direct, [&F](Use &U) {
Expand All @@ -146,10 +147,13 @@ bool GenXCloneIndirectFunctions::runOnModule(Module &M) {

auto &&BECfg = getAnalysis<GenXBackendConfig>();
IGC_ASSERT_MESSAGE(
llvm::none_of(M.functions(),
[&](const Function& F) { return F.hasAddressTaken() && BECfg.directCallsOnly(F.getName()); }),
"A function has address taken inside the module that contradicts "
"DirectCallsOnly option");
llvm::none_of(M.functions(),
[&](const Function &F) {
return F.hasAddressTaken() &&
BECfg.directCallsOnly(F.getName());
}),
"A function has address taken inside the module that contradicts "
"DirectCallsOnly option");

// If direct calls are forced for all functions.
if (BECfg.directCallsOnly()) {
Expand All @@ -161,7 +165,8 @@ bool GenXCloneIndirectFunctions::runOnModule(Module &M) {
bool Modified = false;

for (auto [F, IsExternal] : IndirectFuncs) {
if (BECfg.directCallsOnly(F->getName())) continue;
if (BECfg.directCallsOnly(F->getName()))
continue;

auto CheckDirectCall = [Func = F](User *U) {
auto *CI = dyn_cast<CallInst>(U);
Expand Down
13 changes: 9 additions & 4 deletions IGC/VectorCompiler/lib/GenXOpts/CMTrans/GenXLinkageCorruptor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*========================== begin_copyright_notice ============================
Copyright (C) 2021 Intel Corporation
Copyright (C) 2021-2023 Intel Corporation
SPDX-License-Identifier: MIT
Expand Down Expand Up @@ -68,6 +68,8 @@ bool GenXLinkageCorruptor::runOnModule(Module &M) {

// Indirect functions are always stack calls.
if (F.hasAddressTaken()) {
LLVM_DEBUG(dbgs() << "Adding stack call to indirect function: "
<< F.getName() << "\n");
F.addFnAttr(genx::FunctionMD::CMStackCall);
Changed = true;
IGC_ASSERT(vc::isIndirect(F));
Expand All @@ -80,10 +82,13 @@ bool GenXLinkageCorruptor::runOnModule(Module &M) {
Changed = true;
}

// Do not change stack calls linkage as we may have both types of stack
// calls.
if (vc::requiresStackCall(&F) && SaveStackCallLinkage)
// Remove alwaysinline attribute and keep unchanged stack calls linkage as
// we may have both types of stack calls.
if (vc::requiresStackCall(&F) && SaveStackCallLinkage) {
F.removeFnAttr(Attribute::AlwaysInline);
Changed = true;
continue;
}

F.setLinkage(GlobalValue::InternalLinkage);
Changed = true;
Expand Down
3 changes: 2 additions & 1 deletion IGC/VectorCompiler/test/CloneIndirectFunctions/basic.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;=========================== begin_copyright_notice ============================
;
; Copyright (C) 2022 Intel Corporation
; Copyright (C) 2022-2023 Intel Corporation
;
; SPDX-License-Identifier: MIT
;
Expand Down Expand Up @@ -31,6 +31,7 @@ define dllexport void @kernel() {

; COM: direct with internal linkage type
; CHECK: define internal spir_func void @foo_direct
; CHECK-SAME: ) {
; CHECK-NEXT: %vec.ref.ld = load <8 x i32>, <8 x i32>* %vec.ref
; CHECK-NEXT: ret void

Expand Down

0 comments on commit 34f1575

Please sign in to comment.