9d5609f539898fc0b597f5e41a10e0a35d30cd3b
[mesa.git] / src / mesa / pipe / llvm / storagesoa.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #ifndef STORAGESOA_H
29 #define STORAGESOA_H
30
31 #include <vector>
32 #include <map>
33
34 namespace llvm {
35 class BasicBlock;
36 class Constant;
37 class ConstantInt;
38 class LoadInst;
39 class Value;
40 class VectorType;
41 }
42
43 class StorageSoa
44 {
45 public:
46 StorageSoa(llvm::BasicBlock *block,
47 llvm::Value *input,
48 llvm::Value *output,
49 llvm::Value *consts);
50
51 void addImmediate(float *vec);
52
53 llvm::Value * addrElement(int idx) const;
54
55 std::vector<llvm::Value*> inputElement(int idx, int swizzle, llvm::Value *indIdx =0);
56 std::vector<llvm::Value*> constElement(int idx, int swizzle, llvm::Value *indIdx =0);
57 std::vector<llvm::Value*> outputElement(int idx, int swizzle, llvm::Value *indIdx =0);
58 std::vector<llvm::Value*> tempElement(int idx, int swizzle, llvm::Value *indIdx =0);
59 std::vector<llvm::Value*> immediateElement(int idx, int swizzle);
60
61 llvm::Value *extractIndex(llvm::Value *vec);
62
63 void storeOutput(int dstIdx, const std::vector<llvm::Value*> &val,
64 int mask);
65 void storeTemp(int idx, const std::vector<llvm::Value*> &val,
66 int mask);
67 void storeAddress(int idx, const std::vector<llvm::Value*> &val,
68 int mask);
69 private:
70 llvm::Value *elementPointer(llvm::Value *ptr, int index,
71 int channel) const;
72 llvm::Value *element(llvm::Value *ptr, int index,
73 int channel) const;
74 const char *name(const char *prefix) const;
75 llvm::ConstantInt *constantInt(int) const;
76 private:
77 llvm::BasicBlock *m_block;
78
79 llvm::Value *m_input;
80 llvm::Value *m_output;
81 llvm::Value *m_consts;
82
83 mutable std::map<int, llvm::ConstantInt*> m_constInts;
84 mutable char m_name[32];
85 mutable int m_idx;
86 };
87
88 #endif