1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.
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:
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
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
25 * @brief Includes all the builder related functionality
29 ******************************************************************************/
32 #include "JitManager.h"
33 #include "common/formats.h"
37 ///@todo Move this to better place
38 enum SHADER_STATS_COUNTER_TYPE
40 STATS_INST_EXECUTED
= 0,
41 STATS_SAMPLE_EXECUTED
= 1,
42 STATS_SAMPLE_L_EXECUTED
= 2,
43 STATS_SAMPLE_B_EXECUTED
= 3,
44 STATS_SAMPLE_C_EXECUTED
= 4,
45 STATS_SAMPLE_C_LZ_EXECUTED
= 5,
46 STATS_SAMPLE_C_D_EXECUTED
= 6,
47 STATS_LOD_EXECUTED
= 7,
48 STATS_GATHER4_EXECUTED
= 8,
49 STATS_GATHER4_C_EXECUTED
= 9,
50 STATS_GATHER4_C_PO_EXECUTED
= 10,
51 STATS_GATHER4_C_PO_C_EXECUTED
= 11,
52 STATS_LOAD_RAW_UAV
= 12,
53 STATS_LOAD_RAW_RESOURCE
= 13,
54 STATS_STORE_RAW_UAV
= 14,
55 STATS_STORE_TGSM
= 15,
66 Builder(JitManager
* pJitMgr
);
69 IRBuilder
<>* IRB() { return mpIRBuilder
; };
70 JitManager
* JM() { return mpJitMgr
; }
73 IRBuilder
<>* mpIRBuilder
;
75 uint32_t mVWidth
; // vector width target simd
76 uint32_t mVWidth16
; // vector width simd16
78 // Built in types: scalar
98 // Built in types: target SIMD
108 Type
* mSimdVectorTRTy
;
109 Type
* mSimdVectorIntTy
;
111 // Built in types: simd16
116 Type
* mSimd16Int16Ty
;
117 Type
* mSimd16Int32Ty
;
118 Type
* mSimd16Int64Ty
;
119 Type
* mSimd16IntPtrTy
;
120 Type
* mSimd16VectorTy
;
121 Type
* mSimd16VectorTRTy
;
125 void SetTargetWidth(uint32_t width
);
126 void SetTempAlloca(Value
* inst
);
127 bool IsTempAlloca(Value
* inst
);
128 bool SetNamedMetaDataOnCallInstr(Instruction
* inst
, StringRef mdName
);
129 bool HasNamedMetaDataOnCallInstr(Instruction
* inst
, StringRef mdName
);
130 Type
* GetVectorType(Type
* pType
);
131 void SetMetadata(StringRef s
, uint32_t val
)
133 llvm::NamedMDNode
* metaData
= mpJitMgr
->mpCurrentModule
->getOrInsertNamedMetadata(s
);
134 Constant
* cval
= mpIRBuilder
->getInt32(val
);
135 llvm::MDNode
* mdNode
= llvm::MDNode::get(mpJitMgr
->mpCurrentModule
->getContext(),
136 llvm::ConstantAsMetadata::get(cval
));
137 if (metaData
->getNumOperands())
139 metaData
->setOperand(0, mdNode
);
143 metaData
->addOperand(mdNode
);
146 uint32_t GetMetadata(StringRef s
)
148 NamedMDNode
* metaData
= mpJitMgr
->mpCurrentModule
->getNamedMetadata(s
);
151 MDNode
* mdNode
= metaData
->getOperand(0);
152 Metadata
* val
= mdNode
->getOperand(0);
153 return mdconst::dyn_extract
<ConstantInt
>(val
)->getZExtValue();
161 #include "gen_builder.hpp"
162 #include "gen_builder_meta.hpp"
163 #include "gen_builder_intrin.hpp"
164 #include "builder_misc.h"
165 #include "builder_math.h"
166 #include "builder_mem.h"
168 void SetPrivateContext(Value
* pPrivateContext
)
170 mpPrivateContext
= pPrivateContext
;
171 NotifyPrivateContextSet();
173 virtual void NotifyPrivateContextSet() {}
174 inline Value
* GetPrivateContext() { return mpPrivateContext
; }
177 Value
* mpPrivateContext
;
179 } // namespace SwrJit