File: ImageFuncResolution.hpp

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 (145 lines) | stat: -rw-r--r-- 6,546 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
138
139
140
141
142
143
144
145
/*========================== begin_copyright_notice ============================

Copyright (C) 2017-2021 Intel Corporation

SPDX-License-Identifier: MIT

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

#pragma once

#include "AdaptorCommon/ImplicitArgs.hpp"
#include "Compiler/MetaDataUtilsWrapper.h"

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

namespace IGC
{
    /// @brief  ImageFuncResolution pass used for resolving OpenCL image dimension functions.
    ///         This pass depends on the ImageFuncAnalysis and AddImplicitArgs passes runing before it

    class ImageFuncResolution : public llvm::FunctionPass, public llvm::InstVisitor<ImageFuncResolution>
    {
    public:
        // Pass identification, replacement for typeid
        static char ID;

        /// @brief  Constructor
        ImageFuncResolution();

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

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

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

        /// @brief  Main entry point.
        ///         Finds all OpenCL image dimension function calls and resolve them into an llvm sequence
        /// @param  F The destination function.
        virtual bool runOnFunction(llvm::Function& F) override;

        /// @brief  Call instructions visitor.
        ///         Checks for OpenCL image dimension functions and resolves them into appropriate sequence of code
        /// @param  CI The call instruction.
        void visitCallInst(llvm::CallInst& CI);

    private:

        /// @brief  Resolves get_image_height(image).
        ///         Adds the appropriate sequence of code before the given call instruction
        /// @param  CI The call instruction.
        /// @return A value representing the image height
        llvm::Value* getImageHeight(llvm::CallInst& CI);

        /// @brief  Resolves get_image_width(image).
        ///         Adds the appropriate sequence of code before the given call instruction
        /// @param  CI The call instruction.
        /// @return A value representing the image width
        llvm::Value* getImageWidth(llvm::CallInst& CI);

        /// @brief  Resolves get_image_depth(image).
        ///         Adds the appropriate sequence of code before the given call instruction
        /// @param  CI The call instruction.
        /// @return A value representing the image depth
        llvm::Value* getImageDepth(llvm::CallInst& CI);

        /// @brief  Resolves get_image_num_mip_levels(image).
        ///         Adds the appropriate sequence of code before the given call instruction
        /// @param  CI The call instruction.
        /// @return A value representing the image num mip levels
        llvm::Value* getImageNumMipLevels(llvm::CallInst& CI);

        /// @brief  Resolves get_image_channel_data_type(image).
        ///         Adds the approtiate sequence of code before the given call isntruction
        /// @param  CI The call instruction.
        /// @return A value representing the image channel data type
        llvm::Value* getImageChannelDataType(llvm::CallInst& CI);

        /// @brief  Resolves get_image_channel_order(image).
        ///         Adds the approtiate sequence of code before the given call isntruction
        /// @param  CI The call instruction.
        /// @return A value representing the image order
        llvm::Value* getImageChannelOrder(llvm::CallInst& CI);

        /// @brief  Resolves get_image_array_size(image_array).
        ///         Adds the approtiate sequence of code before the given call isntruction
        /// @param  CI The call instruction.
        /// @return A value representing the image array size
        llvm::Value* getImageArraySize(llvm::CallInst& CI);

        /// @brief  Resolves get_image_num_samples(image).
        ///         Adds the approtiate sequence of code before the given call instruction
        /// @param  CI The call instruction.
        /// @return A value representing the image number of samples.
        llvm::Value* getImageNumSamples(llvm::CallInst& CI);

        /// @brief  Resolves the pseudo-builtin get_sampler_address_mode(sampler_t).
        ///         Adds the approtiate sequence of code before the given call isntruction
        /// @param  CI The call instruction.
        /// @return A value representing the sampler address mode, which may either be
        ///         a ConstantInt or an Argument
        llvm::Value* getSamplerAddressMode(llvm::CallInst& CI);

        /// @brief  Resolves the pseudo-builtin get_sampler_normalized_coords(sampler_t).
        ///         Adds the approtiate sequence of code before the given call isntruction
        /// @param  CI The call instruction.
        /// @return A value representing the sampler normalized coords mode, which may either be
        ///         a ConstantInt or an Argument
        llvm::Value* getSamplerNormalizedCoords(llvm::CallInst& CI);

        /// @brief  Resolves the pseudo-builtin get_sampler_snap_wa_reqd(sampler_t).
        ///         Adds the approtiate sequence of code before the given call isntruction
        /// @param  CI The call instruction.
        /// @return A value representing whether the snap workaround is required for the sample
        ///         which may either be a ConstantInt or an Argument
        llvm::Value* getSamplerSnapWARequired(llvm::CallInst& CI);

        /// @brief  Returns the appropriate implicit argument of the function
        ///         containing the given call instruction, based on the given implicit image
        ///         argument type
        /// @param  CI       The call instruction.
        /// @param  argType  The implicit image argument type.
        /// @return The function argument associated with the given implicit image arg type
        llvm::Argument* getImplicitImageArg(llvm::CallInst& CI, ImplicitArg::ArgType argType);

        /// @brief  The implicit arguments of the current function
        ImplicitArgs m_implicitArgs;

        /// @brief  Indicates if the pass changed the processed function
        bool m_changed;
    };

} // namespace IGC