blob: 56886f85e7a75334c5e7855685e12839f04ed8fc [file] [log] [blame]
Zack Rusine7611612008-02-11 09:43:59 -05001/**************************************************************************
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
Zack Rusine884c7e2008-03-01 08:04:21 -050031#include <pipe/p_shader_tokens.h>
Stephane Marchesin94ba48b2008-10-07 21:11:01 +020032#include <llvm/Support/IRBuilder.h>
Zack Rusine884c7e2008-03-01 08:04:21 -050033
Zack Rusine7611612008-02-11 09:43:59 -050034#include <vector>
Zack Rusinf70cc892008-02-14 22:42:57 -050035#include <list>
Zack Rusincad7bc72008-02-12 05:35:51 -050036#include <map>
Zack Rusine7611612008-02-11 09:43:59 -050037
38namespace llvm {
39 class BasicBlock;
40 class Constant;
41 class ConstantInt;
Zack Rusinf70cc892008-02-14 22:42:57 -050042 class GlobalVariable;
Zack Rusine7611612008-02-11 09:43:59 -050043 class LoadInst;
44 class Value;
45 class VectorType;
Zack Rusin7e51d2a2008-02-13 08:31:13 -050046 class Module;
Zack Rusine7611612008-02-11 09:43:59 -050047}
48
49class StorageSoa
50{
51public:
52 StorageSoa(llvm::BasicBlock *block,
53 llvm::Value *input,
54 llvm::Value *output,
Stephane Marchesinb81a7dc2008-10-30 23:52:59 +010055 llvm::Value *consts);
Zack Rusine7611612008-02-11 09:43:59 -050056
Zack Rusind0364582008-02-13 22:53:00 -050057
Zack Rusine884c7e2008-03-01 08:04:21 -050058 std::vector<llvm::Value*> load(enum tgsi_file_type type, int idx, int swizzle,
Stephane Marchesin94ba48b2008-10-07 21:11:01 +020059 llvm::IRBuilder<>* m_builder, llvm::Value *indIdx =0);
Zack Rusine884c7e2008-03-01 08:04:21 -050060 void store(enum tgsi_file_type type, int idx, const std::vector<llvm::Value*> &val,
Stephane Marchesinb81a7dc2008-10-30 23:52:59 +010061 int mask, llvm::IRBuilder<>* m_builder);
Zack Rusind0364582008-02-13 22:53:00 -050062
Zack Rusine7611612008-02-11 09:43:59 -050063 void addImmediate(float *vec);
Zack Rusinf70cc892008-02-14 22:42:57 -050064 void declareImmediates();
65
66 void addAddress(int idx);
Zack Rusine7611612008-02-11 09:43:59 -050067
68 llvm::Value * addrElement(int idx) const;
69
Zack Rusinf70cc892008-02-14 22:42:57 -050070 llvm::ConstantInt *constantInt(int) const;
Zack Rusincad7bc72008-02-12 05:35:51 -050071private:
Zack Rusin4593be32008-02-15 00:36:18 -050072 llvm::Value *elementPointer(llvm::Value *ptr, llvm::Value *indIdx,
Zack Rusincad7bc72008-02-12 05:35:51 -050073 int channel) const;
Zack Rusin4593be32008-02-15 00:36:18 -050074 llvm::Value *element(llvm::Value *ptr, llvm::Value *idx,
Zack Rusincad7bc72008-02-12 05:35:51 -050075 int channel) const;
76 const char *name(const char *prefix) const;
Zack Rusin7e51d2a2008-02-13 08:31:13 -050077 llvm::Value *alignedArrayLoad(llvm::Value *val);
78 llvm::Module *currentModule() const;
Stephane Marchesin94ba48b2008-10-07 21:11:01 +020079 llvm::Constant *createConstGlobalFloat(const float val);
Zack Rusinf70cc892008-02-14 22:42:57 -050080 llvm::Constant *createConstGlobalVector(const std::vector<float> &vec);
Zack Rusinc107d572008-02-13 07:28:26 -050081
Zack Rusin4593be32008-02-15 00:36:18 -050082 std::vector<llvm::Value*> inputElement(llvm::Value *indIdx);
Stephane Marchesin94ba48b2008-10-07 21:11:01 +020083 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);
Zack Rusin4593be32008-02-15 00:36:18 -050085 std::vector<llvm::Value*> outputElement(llvm::Value *indIdx);
Stephane Marchesinb81a7dc2008-10-30 23:52:59 +010086 std::vector<llvm::Value*> tempElement(llvm::IRBuilder<>* m_builder, int idx);
Zack Rusin4593be32008-02-15 00:36:18 -050087 std::vector<llvm::Value*> immediateElement(llvm::Value *indIdx);
Zack Rusincad7bc72008-02-12 05:35:51 -050088private:
89 llvm::BasicBlock *m_block;
Zack Rusine7611612008-02-11 09:43:59 -050090
Zack Rusincad7bc72008-02-12 05:35:51 -050091 llvm::Value *m_input;
92 llvm::Value *m_output;
93 llvm::Value *m_consts;
Stephane Marchesinb81a7dc2008-10-30 23:52:59 +010094 std::map<int, llvm::Value*> m_temps;
Zack Rusinf70cc892008-02-14 22:42:57 -050095 llvm::GlobalVariable *m_immediates;
Zack Rusincad7bc72008-02-12 05:35:51 -050096
Zack Rusinf70cc892008-02-14 22:42:57 -050097 std::map<int, llvm::Value*> m_addresses;
98
99 std::vector<std::vector<float> > m_immediatesToFlush;
Stephane Marchesinb81a7dc2008-10-30 23:52:59 +0100100 llvm::Value * allocaTemp(llvm::IRBuilder<>* m_builder);
Zack Rusin7e51d2a2008-02-13 08:31:13 -0500101
Zack Rusincad7bc72008-02-12 05:35:51 -0500102 mutable std::map<int, llvm::ConstantInt*> m_constInts;
103 mutable char m_name[32];
104 mutable int m_idx;
Zack Rusine7611612008-02-11 09:43:59 -0500105};
106
107#endif