Skip to content

Commit 9a9afcc

Browse files
committed
[SSCP] dynamic functions: Handle multiple undefined dynamic functions in the same TU
1 parent fc17fb2 commit 9a9afcc

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/compiler/sscp/DynamicFunctionSupport.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,14 @@ llvm::PreservedAnalyses HostSideDynamicFunctionHandlerPass::run(llvm::Module &M,
8282
if (F->isDeclaration()) {
8383
F->setLinkage(llvm::GlobalValue::LinkOnceODRLinkage);
8484
auto BB = llvm::BasicBlock::Create(M.getContext(), "entry", F);
85-
new llvm::UnreachableInst(M.getContext(), BB);
85+
// It seems that LLVM handles functions that only have unreachable inst differently
86+
// if there address is taken - we can no longer get unique function pointer
87+
// addresses for those, which breaks reflection. So try to generate a trivial function
88+
// instead.
89+
if(F->getReturnType()->isVoidTy())
90+
llvm::ReturnInst::Create(M.getContext(), BB);
91+
else
92+
llvm::ReturnInst::Create(M.getContext(), llvm::UndefValue::get(F->getReturnType()), BB);
8693
}
8794
}
8895
}

tests/compiler/sscp/dynamic_function.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ void execute_operations_with_definition(int* data, sycl::item<1> idx) {
2626

2727
void execute_operations_without_definition(int* data, sycl::item<1> idx);
2828

29+
// Checks that we can distinguish two undefined dynamic functions in the same
30+
// TU
31+
void execute_operations_without_definition2(int* data, sycl::item<1> idx);
32+
2933

3034
int main() {
3135
sycl::queue q = get_queue();
@@ -59,6 +63,20 @@ int main() {
5963
std::cout << *data << std::endl;
6064
}
6165

66+
{
67+
*data = 0;
68+
69+
sycl::AdaptiveCpp_jit::dynamic_function_config dyn_function_config;
70+
dyn_function_config.define(&execute_operations_without_definition2, &myfunction1);
71+
q.parallel_for(sycl::range{1}, dyn_function_config.apply([=](sycl::item<1> idx){
72+
execute_operations_without_definition2(data, idx);
73+
}));
74+
75+
q.wait();
76+
// CHECK: 1
77+
std::cout << *data << std::endl;
78+
}
79+
6280
{
6381
*data = 0;
6482

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy