786511204a3ff2775d912582fad507995bdaf28d
1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "storagesoa.h"
31 #include "pipe/p_shader_tokens.h"
32 #include <llvm/BasicBlock.h>
33 #include <llvm/Module.h>
34 #include <llvm/Value.h>
36 #include <llvm/CallingConv.h>
37 #include <llvm/Constants.h>
38 #include <llvm/DerivedTypes.h>
39 #include <llvm/InstrTypes.h>
40 #include <llvm/Instructions.h>
44 StorageSoa::StorageSoa(llvm::BasicBlock
*block
,
56 void StorageSoa::addImmediate(float *vec
)
60 llvm::Value
*StorageSoa::addrElement(int idx
) const
65 std::vector
<llvm::Value
*> StorageSoa::inputElement(int idx
, int swizzle
,
68 std::vector
<llvm::Value
*> res(4);
70 res
[0] = element(m_input
, idx
, 0);
71 res
[1] = element(m_input
, idx
, 0);
72 res
[2] = element(m_input
, idx
, 0);
73 res
[3] = element(m_input
, idx
, 0);
78 std::vector
<llvm::Value
*> StorageSoa::constElement(int idx
, int swizzle
,
81 std::vector
<llvm::Value
*> res(4);
86 std::vector
<llvm::Value
*> StorageSoa::outputElement(int idx
, int swizzle
,
89 std::vector
<llvm::Value
*> res(4);
91 res
[0] = element(m_output
, idx
, 0);
92 res
[1] = element(m_output
, idx
, 0);
93 res
[2] = element(m_output
, idx
, 0);
94 res
[3] = element(m_output
, idx
, 0);
99 std::vector
<llvm::Value
*> StorageSoa::tempElement(int idx
, int swizzle
,
102 std::vector
<llvm::Value
*> res(4);
107 std::vector
<llvm::Value
*> StorageSoa::immediateElement(int idx
, int swizzle
)
109 std::vector
<llvm::Value
*> res(4);
114 llvm::Value
* StorageSoa::extractIndex(llvm::Value
*vec
)
119 void StorageSoa::storeOutput(int dstIdx
, const std::vector
<llvm::Value
*> &val
,
122 if (mask
!= TGSI_WRITEMASK_XYZW
) {
123 fprintf(stderr
, "requires swizzle!!\n");
126 llvm::Value
*xChannel
= elementPointer(m_output
, dstIdx
, 0);
127 llvm::Value
*yChannel
= elementPointer(m_output
, dstIdx
, 1);
128 llvm::Value
*zChannel
= elementPointer(m_output
, dstIdx
, 2);
129 llvm::Value
*wChannel
= elementPointer(m_output
, dstIdx
, 3);
131 StoreInst
*st
= new StoreInst(val
[0], xChannel
, false, m_block
);
132 st
= new StoreInst(val
[1], yChannel
, false, m_block
);
133 st
= new StoreInst(val
[2], zChannel
, false, m_block
);
134 st
= new StoreInst(val
[3], wChannel
, false, m_block
);
138 void StorageSoa::storeTemp(int idx
, const std::vector
<llvm::Value
*> &val
,
143 void StorageSoa::storeAddress(int idx
, const std::vector
<llvm::Value
*> &val
,
148 llvm::Value
* StorageSoa::elementPointer(llvm::Value
*ptr
, int index
,
151 std::vector
<Value
*> indices
;
152 indices
.push_back(constantInt(index
));
153 indices
.push_back(constantInt(channel
));
155 GetElementPtrInst
*getElem
= new GetElementPtrInst(ptr
,
163 llvm::Value
* StorageSoa::element(llvm::Value
*ptr
, int index
,
166 llvm::Value
*res
= elementPointer(ptr
, index
, channel
);
167 LoadInst
*load
= new LoadInst(res
, name("element"), false, m_block
);
168 //load->setAlignment(8);
172 const char * StorageSoa::name(const char *prefix
) const
175 snprintf(m_name
, 32, "%s%d", prefix
, m_idx
);
179 llvm::ConstantInt
* StorageSoa::constantInt(int idx
) const
181 if (m_constInts
.find(idx
) != m_constInts
.end()) {
182 return m_constInts
[idx
];
184 ConstantInt
*constInt
= ConstantInt::get(APInt(32, idx
));
185 m_constInts
[idx
] = constInt
;