File: BuiltInFuncImport.h

package info (click to toggle)
intel-graphics-compiler 1.0.12504.6-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 83,912 kB
  • sloc: cpp: 910,147; lisp: 202,655; ansic: 15,197; python: 4,025; yacc: 2,241; lex: 1,570; pascal: 244; sh: 104; makefile: 25
file content (137 lines) | stat: -rw-r--r-- 5,078 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*========================== begin_copyright_notice ============================

Copyright (C) 2017-2021 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#pragma once

#include "Compiler/MetaDataUtilsWrapper.h"
#include "Compiler/CodeGenContextWrapper.hpp"

#include "common/LLVMWarningsPush.hpp"
#include <llvm/Pass.h>
#include "common/LLVMWarningsPop.hpp"

#include "AdaptorOCL/CLElfLib/ElfReader.h"

#include <vector>
#include <set>
#include <queue>

namespace IGC
{
    /// This pass imports built-in functions from source module to destination module.
    class BIImport : public llvm::ModulePass
    {
    protected:
        // Type used to hold a vector of Functions and augment it during traversal.
        typedef std::vector<llvm::Function*>       TFunctionsVec;

    public:
        // Pass identification, replacement for typeid.
        static char ID;

        /// @brief Constructor
        BIImport(std::unique_ptr<llvm::Module> pGenericModule = nullptr,
            std::unique_ptr<llvm::Module> pSizeModule = nullptr);

        /// @brief analyses used
        virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const override
        {
            AU.addRequired<MetaDataUtilsWrapper>();
            AU.addRequired<CodeGenContextWrapper>();
        }

        /// @brief Provides name of pass
        virtual llvm::StringRef getPassName() const override
        {
            return "BIImport";
        }

        /// @brief Main entry point.
        ///        Find all builtins to import, and import them along with callees and globals.
        /// @param M The destination module.
        bool runOnModule(llvm::Module& M) override;

        static void supportOldManglingSchemes(llvm::Module& M);
        static std::unique_ptr<llvm::Module> Construct(llvm::Module& M, CLElfLib::CElfReader* pElfReader, bool hasSizet);
    protected:
        /// @brief Get all the functions called by given function.
        /// @param [IN] pFunc The given function.
        /// @param [OUT] calledFuncs The list of all functions called by pFunc.
        static void GetCalledFunctions(const llvm::Function* pFunc, TFunctionsVec& calledFuncs);

        /// @brief  Remove function bitcasts that sometimes may appear due to the changed in the way
        ///         the BiFs are linked. We can remove this code once llvm implements typeless pointers.
        void removeFunctionBitcasts(llvm::Module& M);

        /// @brief  Initialize values for global flags needed for the built-ins (FlushDenormal).
        ///         Only initializes flags that the built-ins need.
        void InitializeBIFlags(llvm::Module& M);

        /// @brief  Search through all builtin modules for the specified function.
        /// @param  funcName - name of func to search for.
        static llvm::Function* GetBuiltinFunction(llvm::StringRef funcName, llvm::Module* GenericModule);
        llvm::Function* GetBuiltinFunction2(llvm::StringRef funcName) const;

        /// @brief  Read elf Header file that is constructed by Build Packager and write to a DenseMap.
        static void WriteElfHeaderToMap(llvm::DenseMap<llvm::StringRef, int>& Map, char* pData, size_t dataSize);

        /// @brief Fix SPIR builtins return type
        void fixSPIRFunctionsReturnType(llvm::Module& M);

    protected:
        /// Builtin module - contains the source function definition to import
        std::unique_ptr<llvm::Module> m_GenericModule;
        std::unique_ptr<llvm::Module> m_SizeModule;
    };

} // namespace IGC

extern "C" llvm::ModulePass* createBuiltInImportPass(
    std::unique_ptr<llvm::Module> pGenericModule, std::unique_ptr<llvm::Module> pSizeModule);

namespace IGC
{
    class PreBIImportAnalysis : public llvm::ModulePass
    {
    public:
        // Pass identification, replacement for typeid
        static char ID;

        /// @brief  Constructor
        PreBIImportAnalysis();

        /// @brief  Destructor
        ~PreBIImportAnalysis() {}

        /// @brief  Provides name of pass
        virtual llvm::StringRef getPassName() const override
        {
            return "PreBIImportAnalysis";
        }

        void getAnalysisUsage(llvm::AnalysisUsage& AU) const override
        {
            AU.addRequired<MetaDataUtilsWrapper>();
            AU.addRequired<CodeGenContextWrapper>();
        }

        /// @brief  Main entry point.
        /// @param  M The destination module.
        virtual bool runOnModule(llvm::Module& M) override;

        static const llvm::StringRef OCL_GET_GLOBAL_OFFSET;
        static const llvm::StringRef OCL_GET_LOCAL_ID;
        static const llvm::StringRef OCL_GET_GROUP_ID;
        static const llvm::StringRef OCL_GET_SUBGROUP_ID_IGC_SPVIR;
        static const llvm::StringRef OCL_GET_SUBGROUP_ID_KHR_SPVIR;
        static const llvm::StringRef OCL_GET_SUBGROUP_ID;
        static const llvm::StringRef OCL_SUBGROUP_BLOCK_PREFIX;
        static const llvm::StringRef OCL_SUBGROUP_IMAGE_BLOCK_PREFIX;
    };

} // namespace IGC