1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2024 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
#pragma once
#include "common/LLVMWarningsPush.hpp"
#include <llvm/IR/Module.h>
#include <llvm/ADT/StringSet.h>
#include "common/LLVMWarningsPop.hpp"
#include <map>
#include <vector>
#include <AdaptorOCL/OCL/BuiltinResource.h>
#include <Compiler/Optimizer/BuiltInFuncImport.h>
#include "common/Stats.hpp"
#include "BiFManagerCommon.hpp"
namespace IGC {
namespace BiFManager {
typedef std::function<void(COMPILE_TIME_INTERVALS)> FuncTimer;
typedef std::function<void(llvm::Module &, const llvm::StringSet<> &)> LinkerCallback;
class BiFManagerHandler : public BiFManagerCommon {
public:
BiFManagerHandler(llvm::LLVMContext &Context);
~BiFManagerHandler();
// Indicator if we have pointer size 32 in user module
bool isPtrSizeInBits32;
// Ptr for functions to collect timestamps
FuncTimer *startTimer;
FuncTimer *endTimer;
// Ptr to the stream with all sections of built-in functions
std::unique_ptr<llvm::MemoryBuffer> BufferData;
// Collection of the loaded sections of built-in functions mapped by ID
std::map<BiFSectionID, std::unique_ptr<llvm::Module>> LoadedBiFSections;
// Extra setup for the linked sections to the user module
llvm::DataLayout *DL;
std::string T;
LinkerCallback CallbackLinker;
llvm::StringSet<> InternalizeLinkList;
// Private methods
private:
// Function which gets the stream with all sections of built-in functions
static std::unique_ptr<llvm::MemoryBuffer> getBiFModuleBuffer();
llvm::Module *builtinSizeModule();
static bool isModulePtrSize32(llvm::Module *pMain);
// Function looks for all calls of built-in function in user module
// pModule : User module
// neededBuiltinInstr [OUT] : List of needed built-in functions
void findAllBuiltins(llvm::Module *pModule, TFunctionsVec &neededBuiltinInstr);
// Function loads and preapre built-in function modules for linking
// pMainModule : User module
// BuiltInNeeded : List of needed built-in functions
void preapareBiFSections(llvm::Module &pMainModule, TFunctionsVec &BuiltInNeeded);
// Function which clean-up the user module with included and not needed
// function built-ins.
// Base : User module
void cleanModule(llvm::Module &Base);
// Get all the functions called by given function.
// pFunc : the given function.
// calledFuncs [OUT] : The list of all functions called by pFunc.
static void getCalledFunctions(const llvm::Function *pFunc, TFunctionsVec &calledFuncs);
public:
void SetDataLayout(const llvm::DataLayout &DL);
void SetTargetTriple(llvm::StringRef T);
void SetCallbackLinker(const std::function<void(llvm::Module &, const llvm::StringSet<> &)> &CallbackLinker);
void SetFuncTimers(FuncTimer *startTimer, FuncTimer *endTimer) {
this->startTimer = startTimer;
this->endTimer = endTimer;
}
// Function links all needed built-in function to the user module
// Module : User module
void LinkBiF(llvm::Module &Module);
// Function which checks if the pFunc is a built-in function from BiFModule
// pFunc : Function to be check
static bool IsBiF(llvm::Function *pFunc);
// Function which checks if the pVar is a global variable from built-in function from BiFModule
// pVar : Global variable to be check
static bool IsBiF(llvm::GlobalVariable *pVar);
};
} // namespace BiFManager
} // namespace IGC
|