• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2 * Copyright (C) 2014-2015 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.h
24 *
25 * @brief Includes all the builder related functionality
26 *
27 * Notes:
28 *
29 ******************************************************************************/
30 
31 #include "jit_pch.hpp"
32 #include "builder.h"
33 
34 namespace SwrJit
35 {
36     using namespace llvm;
37 
38     //////////////////////////////////////////////////////////////////////////
39     /// @brief Contructor for Builder.
40     /// @param pJitMgr - JitManager which contains modules, function passes, etc.
Builder(JitManager * pJitMgr)41     Builder::Builder(JitManager *pJitMgr)
42         : mpJitMgr(pJitMgr)
43     {
44         SWR_ASSERT(pJitMgr->mVWidth == 8);
45 
46         mVWidth = pJitMgr->mVWidth;
47         mVWidth16 = pJitMgr->mVWidth * 2;
48 
49         mpIRBuilder = &pJitMgr->mBuilder;
50 
51         // Built in types: scalar
52 
53         mVoidTy     = Type::getVoidTy(pJitMgr->mContext);
54         mFP16Ty     = Type::getHalfTy(pJitMgr->mContext);
55         mFP32Ty     = Type::getFloatTy(pJitMgr->mContext);
56         mFP32PtrTy  = PointerType::get(mFP32Ty, 0);
57         mDoubleTy   = Type::getDoubleTy(pJitMgr->mContext);
58         mInt1Ty     = Type::getInt1Ty(pJitMgr->mContext);
59         mInt8Ty     = Type::getInt8Ty(pJitMgr->mContext);
60         mInt16Ty    = Type::getInt16Ty(pJitMgr->mContext);
61         mInt32Ty    = Type::getInt32Ty(pJitMgr->mContext);
62         mInt8PtrTy  = PointerType::get(mInt8Ty, 0);
63         mInt16PtrTy = PointerType::get(mInt16Ty, 0);
64         mInt32PtrTy = PointerType::get(mInt32Ty, 0);
65         mInt64Ty    = Type::getInt64Ty(pJitMgr->mContext);
66 
67         // Built in types: simd8
68 
69         mSimdInt1Ty     = VectorType::get(mInt1Ty,  mVWidth);
70         mSimdInt16Ty    = VectorType::get(mInt16Ty, mVWidth);
71         mSimdInt32Ty    = VectorType::get(mInt32Ty, mVWidth);
72         mSimdInt64Ty    = VectorType::get(mInt64Ty, mVWidth);
73         mSimdFP16Ty     = VectorType::get(mFP16Ty,  mVWidth);
74         mSimdFP32Ty     = VectorType::get(mFP32Ty,  mVWidth);
75         mSimdVectorTy   = ArrayType::get(mSimdFP32Ty, 4);
76         mSimdVectorTRTy = ArrayType::get(mSimdFP32Ty, 5);
77 
78         // Built in types: simd16
79 
80         mSimd16Int1Ty       = VectorType::get(mInt1Ty,  mVWidth16);
81         mSimd16Int16Ty      = VectorType::get(mInt16Ty, mVWidth16);
82         mSimd16Int32Ty      = VectorType::get(mInt32Ty, mVWidth16);
83         mSimd16Int64Ty      = VectorType::get(mInt64Ty, mVWidth16);
84         mSimd16FP16Ty       = VectorType::get(mFP16Ty,  mVWidth16);
85         mSimd16FP32Ty       = VectorType::get(mFP32Ty,  mVWidth16);
86         mSimd16VectorTy     = ArrayType::get(mSimd16FP32Ty, 4);
87         mSimd16VectorTRTy   = ArrayType::get(mSimd16FP32Ty, 5);
88 
89         if (sizeof(uint32_t*) == 4)
90         {
91             mIntPtrTy = mInt32Ty;
92             mSimdIntPtrTy = mSimdInt32Ty;
93             mSimd16IntPtrTy = mSimd16Int32Ty;
94         }
95         else
96         {
97             SWR_ASSERT(sizeof(uint32_t*) == 8);
98 
99             mIntPtrTy = mInt64Ty;
100             mSimdIntPtrTy = mSimdInt64Ty;
101             mSimd16IntPtrTy = mSimd16Int64Ty;
102         }
103     }
104 }
105