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 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*========================== 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 "BiFManagerCommon.hpp"
namespace IGC
{
namespace BiFManager
{
typedef std::map<std::string, std::vector<BiFSectionID>> BiFDictionary;
class BiFManagerTool : public BiFManagerCommon
{
public:
BiFManagerTool(llvm::LLVMContext& Context);
~BiFManagerTool();
// Variables
private:
// How much we want to have built-in function in one section
const int MaxFuncInSection = 1000;
// Dictionary mapping which section is needed for
// the particular built-in function
// version for ptrsize32:
BiFDictionary Bif32;
// version for ptrsize64:
BiFDictionary Bif64;
// Counter for the max how much section needed will be by one built-in function
int Bif32MaxDep;
int Bif64MaxDep;
// The first ID number (in stream) of the section for
// the built-in function for ptr size 32
BiFSectionID Bif32Idx;
// The first ID number (in stream) of the section for
// the built-in function for ptr size 64
BiFSectionID Bif64Idx;
// Current counter of created sections
int sectionCounter;
// Collecion of the built-in function in module mapped by the ID
std::map<BiFSectionID, std::unique_ptr<llvm::Module>> BiFSections;
// Collecion of the pointers of built-in function mapped by the ID
std::map<BiFSectionID, TFunctionsVec> FuncPerSections;
// Private methods
private:
// Function looks for all calls of built-in function in the function
// pFunction : built-in function
// neededBuiltinInstr [OUT] : List of needed built-in functions
// BiFMap : Mapped built-in function by the name
void findAllBuiltins(
llvm::Function* pFunction,
TFunctionsVec& neededBuiltinInstr,
BiFDictionary* BiFMap
);
// Function is filling the built-in function dictionary dependency.
void prepareDependencies(BiFDictionary& BiFMapBitType,
int BiFMainMaxIdx,
int BiFSizeIdxStart,
int BiFSizeIdxEnd);
// Function looks for each of the built-in function, which sections will be needed
// to load to have fully working built-in function
int findDependency(BiFDictionary& BiFMapBitType);
// Function which splits logically the built-in functions
void splitBiFModules(llvm::Module* pMainModule);
// Function generating the splited sections of built-in functions
void generateSplitedBiFModules(llvm::Module* pMainModule);
static void writeHashMapSingle(
llvm::raw_fd_ostream& fileDataHeader,
BiFDictionary* ListOfFunctions,
std::vector<std::string>& listFunc,
int MaxDependencyList, int SizeType);
static void writeHashMap(llvm::raw_fd_ostream& fileDataHeader,
BiFDictionary* ListOfFunctions,
int MaxDependencyList, int SizeType);
static void markBuiltinFunc(llvm::Module* pM);
public:
// Function which is making the bif-stream package
void MakeBiFPackage(
llvm::Module* pBiFModuleMain,
llvm::Module* pBiFModuleSize32,
llvm::Module* pBiFModuleSize64);
// Function which writes the bif-stream package
void WriteBitcode(const llvm::StringRef BitCodePath);
// Function which writes the header with the mapping in bif-stream package
void WriteHeader(const llvm::StringRef HeaderPath);
};
}
}
|