Code reorganization: placeholder for state-trackers.
[mesa.git] / src / gallium / aux / llvm / storage.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 /*
29 * Authors:
30 * Zack Rusin zack@tungstengraphics.com
31 */
32
33 #ifndef STORAGE_H
34 #define STORAGE_H
35
36 #include <map>
37 #include <set>
38 #include <stack>
39 #include <vector>
40
41 namespace llvm {
42 class BasicBlock;
43 class Constant;
44 class ConstantInt;
45 class LoadInst;
46 class Value;
47 class VectorType;
48 }
49
50 class Storage
51 {
52 public:
53 Storage(llvm::BasicBlock *block,
54 llvm::Value *input);
55
56 llvm::Value *inputPtr() const;
57
58 void setCurrentBlock(llvm::BasicBlock *block);
59
60 llvm::ConstantInt *constantInt(int);
61 llvm::Constant *shuffleMask(int vec);
62 llvm::Value *inputElement(int idx, llvm::Value *indIdx =0);
63 llvm::Value *constElement(int idx, llvm::Value *indIdx =0);
64 llvm::Value *outputElement(int idx, llvm::Value *indIdx =0);
65 llvm::Value *tempElement(int idx, llvm::Value *indIdx =0);
66 llvm::Value *immediateElement(int idx);
67
68 void setOutputElement(int dstIdx, llvm::Value *val, int mask);
69 void setTempElement(int idx, llvm::Value *val, int mask);
70
71 llvm::Value *addrElement(int idx) const;
72 void setAddrElement(int idx, llvm::Value *val, int mask);
73
74 void setKilElement(llvm::Value *val);
75
76 llvm::Value *shuffleVector(llvm::Value *vec, int shuffle);
77
78 llvm::Value *extractIndex(llvm::Value *vec);
79
80 int numConsts() const;
81
82 void pushArguments(llvm::Value *input);
83 void popArguments();
84 void pushTemps();
85 void popTemps();
86
87 void addImmediate(float *val);
88
89 private:
90 llvm::Value *maskWrite(llvm::Value *src, int mask, llvm::Value *templ);
91 const char *name(const char *prefix);
92
93 enum Args {
94 DestsArg = 0,
95 InputsArg = 1,
96 TempsArg = 2,
97 ConstsArg = 3,
98 KilArg = 4
99 };
100 llvm::Value *elemPtr(Args arg);
101 llvm::Value *elemIdx(llvm::Value *ptr, int idx,
102 llvm::Value *indIdx = 0);
103 llvm::Value *element(Args arg, int idx, llvm::Value *indIdx = 0);
104
105 private:
106 llvm::BasicBlock *m_block;
107 llvm::Value *m_INPUT;
108
109 std::map<int, llvm::ConstantInt*> m_constInts;
110 std::map<int, llvm::Constant*> m_intVecs;
111 std::vector<llvm::Value*> m_addrs;
112 std::vector<llvm::Constant*> m_immediates;
113
114 llvm::VectorType *m_floatVecType;
115 llvm::VectorType *m_intVecType;
116
117 char m_name[32];
118 int m_idx;
119
120 int m_numConsts;
121
122 std::map<int, bool > m_destWriteMap;
123 std::map<int, bool > m_tempWriteMap;
124
125 llvm::Value *m_undefFloatVec;
126 llvm::Value *m_undefIntVec;
127 llvm::Value *m_extSwizzleVec;
128
129 std::stack<llvm::Value*> m_argStack;
130 std::stack<std::vector<llvm::Value*> > m_tempStack;
131 };
132
133 #endif