redo indirection
[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 <list>
33 #include <map>
34
35 namespace llvm {
36 class BasicBlock;
37 class Constant;
38 class ConstantInt;
39 class GlobalVariable;
40 class LoadInst;
41 class Value;
42 class VectorType;
43 class Module;
44 }
45
46 class StorageSoa
47 {
48 public:
49 enum Argument {
50 Input,
51 Output,
52 Temp,
53 Const,
54 Immediate,
55 Address
56 };
57 public:
58 StorageSoa(llvm::BasicBlock *block,
59 llvm::Value *input,
60 llvm::Value *output,
61 llvm::Value *consts,
62 llvm::Value *temps);
63
64
65 std::vector<llvm::Value*> load(Argument type, int idx, int swizzle,
66 llvm::Value *indIdx =0);
67 void store(Argument type, int idx, const std::vector<llvm::Value*> &val,
68 int mask);
69
70 void addImmediate(float *vec);
71 void declareImmediates();
72
73 void addAddress(int idx);
74
75 llvm::Value * addrElement(int idx) const;
76
77 llvm::ConstantInt *constantInt(int) const;
78 private:
79 llvm::Value *elementPointer(llvm::Value *ptr, int index,
80 int channel) const;
81 llvm::Value *element(llvm::Value *ptr, int index,
82 int channel) const;
83 llvm::Value *indirectElementPointer(llvm::Value *ptr, llvm::Value *indIdx,
84 int channel) const;
85 llvm::Value *indirectElement(llvm::Value *ptr, llvm::Value *indIdx,
86 int channel) const;
87 const char *name(const char *prefix) const;
88 llvm::Value *alignedArrayLoad(llvm::Value *val);
89 llvm::Module *currentModule() const;
90 llvm::Constant *createConstGlobalVector(const std::vector<float> &vec);
91
92 std::vector<llvm::Value*> inputElement(int idx, llvm::Value *indIdx =0);
93 std::vector<llvm::Value*> constElement(int idx, llvm::Value *indIdx =0);
94 std::vector<llvm::Value*> outputElement(int idx, llvm::Value *indIdx =0);
95 std::vector<llvm::Value*> tempElement(int idx, llvm::Value *indIdx =0);
96 std::vector<llvm::Value*> immediateElement(int idx, llvm::Value *indIdx =0);
97 private:
98 llvm::BasicBlock *m_block;
99
100 llvm::Value *m_input;
101 llvm::Value *m_output;
102 llvm::Value *m_consts;
103 llvm::Value *m_temps;
104 llvm::GlobalVariable *m_immediates;
105
106 std::map<int, llvm::Value*> m_addresses;
107
108 std::vector<std::vector<float> > m_immediatesToFlush;
109
110 mutable std::map<int, llvm::ConstantInt*> m_constInts;
111 mutable char m_name[32];
112 mutable int m_idx;
113 };
114
115 #endif