Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / auxiliary / gallivm / 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 <pipe/p_shader_tokens.h>
32 #include <llvm/Support/IRBuilder.h>
33
34 #include <vector>
35 #include <list>
36 #include <map>
37
38 namespace llvm {
39 class BasicBlock;
40 class Constant;
41 class ConstantInt;
42 class GlobalVariable;
43 class LoadInst;
44 class Value;
45 class VectorType;
46 class Module;
47 }
48
49 class StorageSoa
50 {
51 public:
52 StorageSoa(llvm::BasicBlock *block,
53 llvm::Value *input,
54 llvm::Value *output,
55 llvm::Value *consts);
56
57
58 std::vector<llvm::Value*> load(enum tgsi_file_type type, int idx, int swizzle,
59 llvm::IRBuilder<>* m_builder, llvm::Value *indIdx =0);
60 void store(enum tgsi_file_type type, int idx, const std::vector<llvm::Value*> &val,
61 int mask, llvm::IRBuilder<>* m_builder);
62
63 void addImmediate(float *vec);
64 void declareImmediates();
65
66 void addAddress(int idx);
67
68 llvm::Value * addrElement(int idx) const;
69
70 llvm::ConstantInt *constantInt(int) const;
71 private:
72 llvm::Value *elementPointer(llvm::Value *ptr, llvm::Value *indIdx,
73 int channel) const;
74 llvm::Value *element(llvm::Value *ptr, llvm::Value *idx,
75 int channel) const;
76 const char *name(const char *prefix) const;
77 llvm::Value *alignedArrayLoad(llvm::Value *val);
78 llvm::Module *currentModule() const;
79 llvm::Constant *createConstGlobalFloat(const float val);
80 llvm::Constant *createConstGlobalVector(const std::vector<float> &vec);
81
82 std::vector<llvm::Value*> inputElement(llvm::Value *indIdx);
83 llvm::Value* unpackConstElement(llvm::IRBuilder<>* m_builder, llvm::Value *indIdx, int cc);
84 std::vector<llvm::Value*> constElement(llvm::IRBuilder<>* m_builder, llvm::Value *indIdx);
85 std::vector<llvm::Value*> outputElement(llvm::Value *indIdx);
86 std::vector<llvm::Value*> tempElement(llvm::IRBuilder<>* m_builder, int idx);
87 std::vector<llvm::Value*> immediateElement(llvm::Value *indIdx);
88 private:
89 llvm::BasicBlock *m_block;
90
91 llvm::Value *m_input;
92 llvm::Value *m_output;
93 llvm::Value *m_consts;
94 std::map<int, llvm::Value*> m_temps;
95 llvm::GlobalVariable *m_immediates;
96
97 std::map<int, llvm::Value*> m_addresses;
98
99 std::vector<std::vector<float> > m_immediatesToFlush;
100 llvm::Value * allocaTemp(llvm::IRBuilder<>* m_builder);
101
102 mutable std::map<int, llvm::ConstantInt*> m_constInts;
103 mutable char m_name[32];
104 mutable int m_idx;
105 };
106
107 #endif