• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  * Copyright (C) 2014-2018 Intel Corporation.   All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * @file builder_gfx_mem.h
24  *
25  * @brief Definition of the builder to support different translation types for gfx memory access
26  *
27  * Notes:
28  *
29  ******************************************************************************/
30 #pragma once
31 
32 #include "builder.h"
33 
34 namespace SwrJit
35 {
36     using namespace llvm;
37 
38     class BuilderGfxMem : public Builder
39     {
40     public:
41         BuilderGfxMem(JitManager* pJitMgr);
~BuilderGfxMem()42         virtual ~BuilderGfxMem() {}
43 
44         virtual Value* GEP(Value* Ptr, Value* Idx, Type* Ty = nullptr, bool isReadOnly = true, const Twine& Name = "");
45         virtual Value* GEP(Type* Ty, Value* Ptr, Value* Idx, const Twine& Name = "");
46         virtual Value*
47         GEP(Value* Ptr, const std::initializer_list<Value*>& indexList, Type* Ty = nullptr);
48         virtual Value*
49         GEP(Value* Ptr, const std::initializer_list<uint32_t>& indexList, Type* Ty = nullptr);
50 
51         virtual LoadInst* LOAD(Value*         Ptr,
52                                const char*    Name,
53                                Type*          Ty    = nullptr,
54                                MEM_CLIENT usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
55         virtual LoadInst* LOAD(Value*         Ptr,
56                                const Twine&   Name  = "",
57                                Type*          Ty    = nullptr,
58                                MEM_CLIENT     usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
59         virtual LoadInst* LOAD(Value*         Ptr,
60                                bool           isVolatile,
61                                const Twine&   Name  = "",
62                                Type*          Ty    = nullptr,
63                                MEM_CLIENT     usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
64         virtual LoadInst* LOAD(Value*                                 BasePtr,
65                                const std::initializer_list<uint32_t>& offset,
66                                const llvm::Twine&                     Name  = "",
67                                Type*                                  Ty    = nullptr,
68                                MEM_CLIENT                         usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
69 
70         virtual CallInst* MASKED_LOAD(Value*         Ptr,
71                                       unsigned       Align,
72                                       Value*         Mask,
73                                       Value*         PassThru = nullptr,
74                                       const Twine&   Name     = "",
75                                       Type*          Ty       = nullptr,
76                                       MEM_CLIENT     usage    = MEM_CLIENT::MEM_CLIENT_INTERNAL);
77 
78         virtual StoreInst* STORE(Value *Val, Value *Ptr, bool isVolatile = false, Type* Ty = nullptr, MEM_CLIENT usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
79 
80         virtual StoreInst* STORE(Value* Val, Value* BasePtr, const std::initializer_list<uint32_t>& offset, Type* Ty = nullptr, MEM_CLIENT usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
81 
82         virtual CallInst* MASKED_STORE(Value *Val, Value *Ptr, unsigned Align, Value *Mask, Type* Ty = nullptr, MEM_CLIENT usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
83 
84         virtual Value* GATHERPS(Value*         src,
85                                 Value*         pBase,
86                                 Value*         indices,
87                                 Value*         mask,
88                                 uint8_t        scale = 1,
89                                 MEM_CLIENT     usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
90         virtual Value* GATHERDD(Value*         src,
91                                 Value*         pBase,
92                                 Value*         indices,
93                                 Value*         mask,
94                                 uint8_t        scale = 1,
95                                 MEM_CLIENT     usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
96 
97         virtual void SCATTERPS(Value*         pDst,
98                                Value*         vSrc,
99                                Value*         vOffsets,
100                                Value*         vMask,
101                                MEM_CLIENT     usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
102 
103         Value* TranslateGfxAddressForRead(Value*         xpGfxAddress,
104                                           Type*          PtrTy = nullptr,
105                                           const Twine&   Name  = "",
106                                           MEM_CLIENT     usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
107         Value* TranslateGfxAddressForWrite(Value*         xpGfxAddress,
108                                            Type*          PtrTy = nullptr,
109                                            const Twine&   Name  = "",
110                                            MEM_CLIENT     usage = MEM_CLIENT::MEM_CLIENT_INTERNAL);
111 
112     protected:
113         void AssertGFXMemoryParams(Value* ptr, MEM_CLIENT usage);
114 
115         virtual void NotifyPrivateContextSet();
116 
117         virtual Value* OFFSET_TO_NEXT_COMPONENT(Value* base, Constant* offset);
118 
119         Value* TranslationHelper(Value* Ptr, Type* Ty, Value* pfnTranslateGfxAddress);
120         void   TrackerHelper(Value* Ptr, Type* Ty, MEM_CLIENT usage, bool isRead);
121 
GetTranslationFunctionType()122         FunctionType* GetTranslationFunctionType() { return mpTranslationFuncTy; }
GetTranslationFunctionForRead()123         Value*        GetTranslationFunctionForRead() { return mpfnTranslateGfxAddressForRead; }
GetTranslationFunctionForWrite()124         Value*        GetTranslationFunctionForWrite() { return mpfnTranslateGfxAddressForWrite; }
GetParamSimDC()125         Value*        GetParamSimDC() { return mpParamSimDC; }
126 
127         Value*        mpWorkerData;
128 
129     private:
130         FunctionType* mpTranslationFuncTy;
131         Value*        mpfnTranslateGfxAddressForRead;
132         Value*        mpfnTranslateGfxAddressForWrite;
133         Value*        mpParamSimDC;
134         Value*        mpfnTrackMemAccess;
135     };
136 } // namespace SwrJit
137