handle temporaries in llvm code generated paths
[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 llvm::Value *temps);
51
52 void addImmediate(float *vec);
53
54 llvm::Value * addrElement(int idx) const;
55
56 std::vector<llvm::Value*> inputElement(int idx, int swizzle, llvm::Value *indIdx =0);
57 std::vector<llvm::Value*> constElement(int idx, int swizzle, llvm::Value *indIdx =0);
58 std::vector<llvm::Value*> outputElement(int idx, int swizzle, llvm::Value *indIdx =0);
59 std::vector<llvm::Value*> tempElement(int idx, int swizzle, llvm::Value *indIdx =0);
60 std::vector<llvm::Value*> immediateElement(int idx, int swizzle);
61
62 llvm::Value *extractIndex(llvm::Value *vec);
63
64 void storeOutput(int dstIdx, const std::vector<llvm::Value*> &val,
65 int mask);
66 void storeTemp(int idx, const std::vector<llvm::Value*> &val,
67 int mask);
68 void storeAddress(int idx, const std::vector<llvm::Value*> &val,
69 int mask);
70 private:
71 llvm::Value *elementPointer(llvm::Value *ptr, int index,
72 int channel) const;
73 llvm::Value *element(llvm::Value *ptr, int index,
74 int channel) const;
75 const char *name(const char *prefix) const;
76 llvm::ConstantInt *constantInt(int) const;
77 private:
78 llvm::BasicBlock *m_block;
79
80 llvm::Value *m_input;
81 llvm::Value *m_output;
82 llvm::Value *m_consts;
83 llvm::Value *m_temps;
84
85 mutable std::map<int, llvm::ConstantInt*> m_constInts;
86 mutable char m_name[32];
87 mutable int m_idx;
88 };
89
90 #endif