File: BiFManagerHandler.hpp

package info (click to toggle)
intel-graphics-compiler 1.0.17791.18-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 102,312 kB
  • sloc: cpp: 935,343; lisp: 286,143; ansic: 16,196; python: 3,279; yacc: 2,487; lex: 1,642; pascal: 300; sh: 174; makefile: 27
file content (113 lines) | stat: -rw-r--r-- 4,205 bytes parent folder | download
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
/*========================== 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(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);
        };
    }
}