@@ -36,9 +36,11 @@ SPDX-License-Identifier: MIT
36
36
#include < llvm/IR/Instruction.h>
37
37
#include < llvm/IR/Intrinsics.h>
38
38
#include < llvm/IR/Module.h>
39
+ #include < llvm/IR/ValueSymbolTable.h>
39
40
#include < llvm/Linker/Linker.h>
40
41
#include < llvm/Support/Error.h>
41
42
#include < llvm/Support/ErrorHandling.h>
43
+ #include < llvm/Transforms/IPO/Internalize.h>
42
44
#include < llvm/Transforms/Utils/Cloning.h>
43
45
#include < llvm/Transforms/Utils/ValueMapper.h>
44
46
#include < llvmWrapper/IR/Instructions.h>
@@ -492,23 +494,37 @@ static bool OCLBuiltinsRequired(const Module &M) {
492
494
[](const Function &F) { return isOCLBuiltinDecl (F); });
493
495
}
494
496
497
+ static void forceInlining (Module &M, const StringSet<> &GVS) {
498
+ for (auto &Entry : GVS) {
499
+ StringRef Name = Entry.getKey ();
500
+ Value *GV = M.getValueSymbolTable ().lookup (Name);
501
+ if (!isa<Function>(GV))
502
+ continue ;
503
+ cast<Function>(GV)->addFnAttr (Attribute::AlwaysInline);
504
+ }
505
+ }
506
+
495
507
bool GenXImportOCLBiF::runOnModule (Module &M) {
496
- auto OCLBuiltins = vc::collectFunctionNamesIf (
497
- M, [](const Function &F) { return isOCLBuiltinDecl (F); });
498
- if (OCLBuiltins.empty ())
508
+ if (llvm::none_of (M, [](const Function &F) { return isOCLBuiltinDecl (F); }))
499
509
return false ;
500
510
std::unique_ptr<Module> GenericBiFModule =
501
511
getBiFModule (BiFKind::OCLGeneric, M.getContext ());
502
512
GenericBiFModule->setDataLayout (M.getDataLayout ());
503
513
GenericBiFModule->setTargetTriple (M.getTargetTriple ());
514
+ auto LinkerCallback = [](Module &M, const StringSet<> &GVS) {
515
+ internalizeModule (M, [&GVS](const GlobalValue &GV) {
516
+ return !GV.hasName () || (GVS.count (GV.getName ()) == 0 );
517
+ });
518
+ // FIXME: workaround to solve several issues in the backend, remove it
519
+ forceInlining (M, GVS);
520
+ };
504
521
if (Linker::linkModules (M, std::move (GenericBiFModule),
505
- Linker::Flags::LinkOnlyNeeded)) {
522
+ Linker::Flags::LinkOnlyNeeded, LinkerCallback )) {
506
523
IGC_ASSERT_MESSAGE (0 , " Error OCL builtin implementation module" );
507
524
}
508
525
removeFunctionBitcasts (M);
509
526
InitializeBIFlags (M);
510
527
BIConvert{}.runOnModule (M);
511
- vc::internalizeImportedFunctions (M, OCLBuiltins, /* SetAlwaysInline=*/ true );
512
528
return true ;
513
529
}
514
530
0 commit comments