Zack Rusin | e761161 | 2008-02-11 09:43:59 -0500 | [diff] [blame] | 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 | |
Zack Rusin | e884c7e | 2008-03-01 08:04:21 -0500 | [diff] [blame] | 31 | #include <pipe/p_shader_tokens.h> |
Stephane Marchesin | 94ba48b | 2008-10-07 21:11:01 +0200 | [diff] [blame] | 32 | #include <llvm/Support/IRBuilder.h> |
Zack Rusin | e884c7e | 2008-03-01 08:04:21 -0500 | [diff] [blame] | 33 | |
Zack Rusin | e761161 | 2008-02-11 09:43:59 -0500 | [diff] [blame] | 34 | #include <vector> |
Zack Rusin | f70cc89 | 2008-02-14 22:42:57 -0500 | [diff] [blame] | 35 | #include <list> |
Zack Rusin | cad7bc7 | 2008-02-12 05:35:51 -0500 | [diff] [blame] | 36 | #include <map> |
Zack Rusin | e761161 | 2008-02-11 09:43:59 -0500 | [diff] [blame] | 37 | |
| 38 | namespace llvm { |
| 39 | class BasicBlock; |
| 40 | class Constant; |
| 41 | class ConstantInt; |
Zack Rusin | f70cc89 | 2008-02-14 22:42:57 -0500 | [diff] [blame] | 42 | class GlobalVariable; |
Zack Rusin | e761161 | 2008-02-11 09:43:59 -0500 | [diff] [blame] | 43 | class LoadInst; |
| 44 | class Value; |
| 45 | class VectorType; |
Zack Rusin | 7e51d2a | 2008-02-13 08:31:13 -0500 | [diff] [blame] | 46 | class Module; |
Zack Rusin | e761161 | 2008-02-11 09:43:59 -0500 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | class StorageSoa |
| 50 | { |
| 51 | public: |
| 52 | StorageSoa(llvm::BasicBlock *block, |
| 53 | llvm::Value *input, |
| 54 | llvm::Value *output, |
Stephane Marchesin | b81a7dc | 2008-10-30 23:52:59 +0100 | [diff] [blame] | 55 | llvm::Value *consts); |
Zack Rusin | e761161 | 2008-02-11 09:43:59 -0500 | [diff] [blame] | 56 | |
Zack Rusin | d036458 | 2008-02-13 22:53:00 -0500 | [diff] [blame] | 57 | |
Zack Rusin | e884c7e | 2008-03-01 08:04:21 -0500 | [diff] [blame] | 58 | std::vector<llvm::Value*> load(enum tgsi_file_type type, int idx, int swizzle, |
Stephane Marchesin | 94ba48b | 2008-10-07 21:11:01 +0200 | [diff] [blame] | 59 | llvm::IRBuilder<>* m_builder, llvm::Value *indIdx =0); |
Zack Rusin | e884c7e | 2008-03-01 08:04:21 -0500 | [diff] [blame] | 60 | void store(enum tgsi_file_type type, int idx, const std::vector<llvm::Value*> &val, |
Stephane Marchesin | b81a7dc | 2008-10-30 23:52:59 +0100 | [diff] [blame] | 61 | int mask, llvm::IRBuilder<>* m_builder); |
Zack Rusin | d036458 | 2008-02-13 22:53:00 -0500 | [diff] [blame] | 62 | |
Zack Rusin | e761161 | 2008-02-11 09:43:59 -0500 | [diff] [blame] | 63 | void addImmediate(float *vec); |
Zack Rusin | f70cc89 | 2008-02-14 22:42:57 -0500 | [diff] [blame] | 64 | void declareImmediates(); |
| 65 | |
| 66 | void addAddress(int idx); |
Zack Rusin | e761161 | 2008-02-11 09:43:59 -0500 | [diff] [blame] | 67 | |
| 68 | llvm::Value * addrElement(int idx) const; |
| 69 | |
Zack Rusin | f70cc89 | 2008-02-14 22:42:57 -0500 | [diff] [blame] | 70 | llvm::ConstantInt *constantInt(int) const; |
Zack Rusin | cad7bc7 | 2008-02-12 05:35:51 -0500 | [diff] [blame] | 71 | private: |
Zack Rusin | 4593be3 | 2008-02-15 00:36:18 -0500 | [diff] [blame] | 72 | llvm::Value *elementPointer(llvm::Value *ptr, llvm::Value *indIdx, |
Zack Rusin | cad7bc7 | 2008-02-12 05:35:51 -0500 | [diff] [blame] | 73 | int channel) const; |
Zack Rusin | 4593be3 | 2008-02-15 00:36:18 -0500 | [diff] [blame] | 74 | llvm::Value *element(llvm::Value *ptr, llvm::Value *idx, |
Zack Rusin | cad7bc7 | 2008-02-12 05:35:51 -0500 | [diff] [blame] | 75 | int channel) const; |
| 76 | const char *name(const char *prefix) const; |
Zack Rusin | 7e51d2a | 2008-02-13 08:31:13 -0500 | [diff] [blame] | 77 | llvm::Value *alignedArrayLoad(llvm::Value *val); |
| 78 | llvm::Module *currentModule() const; |
Stephane Marchesin | 94ba48b | 2008-10-07 21:11:01 +0200 | [diff] [blame] | 79 | llvm::Constant *createConstGlobalFloat(const float val); |
Zack Rusin | f70cc89 | 2008-02-14 22:42:57 -0500 | [diff] [blame] | 80 | llvm::Constant *createConstGlobalVector(const std::vector<float> &vec); |
Zack Rusin | c107d57 | 2008-02-13 07:28:26 -0500 | [diff] [blame] | 81 | |
Zack Rusin | 4593be3 | 2008-02-15 00:36:18 -0500 | [diff] [blame] | 82 | std::vector<llvm::Value*> inputElement(llvm::Value *indIdx); |
Stephane Marchesin | 94ba48b | 2008-10-07 21:11:01 +0200 | [diff] [blame] | 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); |
Zack Rusin | 4593be3 | 2008-02-15 00:36:18 -0500 | [diff] [blame] | 85 | std::vector<llvm::Value*> outputElement(llvm::Value *indIdx); |
Stephane Marchesin | b81a7dc | 2008-10-30 23:52:59 +0100 | [diff] [blame] | 86 | std::vector<llvm::Value*> tempElement(llvm::IRBuilder<>* m_builder, int idx); |
Zack Rusin | 4593be3 | 2008-02-15 00:36:18 -0500 | [diff] [blame] | 87 | std::vector<llvm::Value*> immediateElement(llvm::Value *indIdx); |
Zack Rusin | cad7bc7 | 2008-02-12 05:35:51 -0500 | [diff] [blame] | 88 | private: |
| 89 | llvm::BasicBlock *m_block; |
Zack Rusin | e761161 | 2008-02-11 09:43:59 -0500 | [diff] [blame] | 90 | |
Zack Rusin | cad7bc7 | 2008-02-12 05:35:51 -0500 | [diff] [blame] | 91 | llvm::Value *m_input; |
| 92 | llvm::Value *m_output; |
| 93 | llvm::Value *m_consts; |
Stephane Marchesin | b81a7dc | 2008-10-30 23:52:59 +0100 | [diff] [blame] | 94 | std::map<int, llvm::Value*> m_temps; |
Zack Rusin | f70cc89 | 2008-02-14 22:42:57 -0500 | [diff] [blame] | 95 | llvm::GlobalVariable *m_immediates; |
Zack Rusin | cad7bc7 | 2008-02-12 05:35:51 -0500 | [diff] [blame] | 96 | |
Zack Rusin | f70cc89 | 2008-02-14 22:42:57 -0500 | [diff] [blame] | 97 | std::map<int, llvm::Value*> m_addresses; |
| 98 | |
| 99 | std::vector<std::vector<float> > m_immediatesToFlush; |
Stephane Marchesin | b81a7dc | 2008-10-30 23:52:59 +0100 | [diff] [blame] | 100 | llvm::Value * allocaTemp(llvm::IRBuilder<>* m_builder); |
Zack Rusin | 7e51d2a | 2008-02-13 08:31:13 -0500 | [diff] [blame] | 101 | |
Zack Rusin | cad7bc7 | 2008-02-12 05:35:51 -0500 | [diff] [blame] | 102 | mutable std::map<int, llvm::ConstantInt*> m_constInts; |
| 103 | mutable char m_name[32]; |
| 104 | mutable int m_idx; |
Zack Rusin | e761161 | 2008-02-11 09:43:59 -0500 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | #endif |