storage.h

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00028  /*
00029   * Authors:
00030   *   Zack Rusin zack@tungstengraphics.com
00031   */
00032 
00033 #ifndef STORAGE_H
00034 #define STORAGE_H
00035 
00036 #include <map>
00037 #include <set>
00038 #include <stack>
00039 #include <vector>
00040 
00041 namespace llvm {
00042    class BasicBlock;
00043    class Constant;
00044    class ConstantInt;
00045    class LoadInst;
00046    class Value;
00047    class VectorType;
00048 }
00049 
00050 class Storage
00051 {
00052 public:
00053    Storage(llvm::BasicBlock *block,
00054            llvm::Value *input);
00055 
00056    llvm::Value *inputPtr() const;
00057 
00058    void setCurrentBlock(llvm::BasicBlock *block);
00059 
00060    llvm::ConstantInt *constantInt(int);
00061    llvm::Constant *shuffleMask(int vec);
00062    llvm::Value *inputElement(int idx, llvm::Value *indIdx =0);
00063    llvm::Value *constElement(int idx, llvm::Value *indIdx =0);
00064    llvm::Value *outputElement(int idx, llvm::Value *indIdx =0);
00065    llvm::Value *tempElement(int idx, llvm::Value *indIdx =0);
00066    llvm::Value *immediateElement(int idx);
00067 
00068    void setOutputElement(int dstIdx, llvm::Value *val, int mask);
00069    void setTempElement(int idx, llvm::Value *val, int mask);
00070 
00071    llvm::Value *addrElement(int idx) const;
00072    void setAddrElement(int idx, llvm::Value *val, int mask);
00073 
00074    void setKilElement(llvm::Value *val);
00075 
00076    llvm::Value *shuffleVector(llvm::Value *vec, int shuffle);
00077 
00078    llvm::Value *extractIndex(llvm::Value *vec);
00079 
00080    int numConsts() const;
00081 
00082    void pushArguments(llvm::Value *input);
00083    void popArguments();
00084    void pushTemps();
00085    void popTemps();
00086 
00087    void addImmediate(float *val);
00088 
00089 private:
00090    llvm::Value *maskWrite(llvm::Value *src, int mask, llvm::Value *templ);
00091    const char *name(const char *prefix);
00092 
00093    enum Args {
00094       DestsArg   = 0,
00095       InputsArg  = 1,
00096       TempsArg   = 2,
00097       ConstsArg  = 3,
00098       KilArg     = 4
00099    };
00100    llvm::Value *elemPtr(Args arg);
00101    llvm::Value *elemIdx(llvm::Value *ptr, int idx,
00102                         llvm::Value *indIdx = 0);
00103    llvm::Value *element(Args arg, int idx, llvm::Value *indIdx = 0);
00104 
00105 private:
00106    llvm::BasicBlock *m_block;
00107    llvm::Value *m_INPUT;
00108 
00109    std::map<int, llvm::ConstantInt*> m_constInts;
00110    std::map<int, llvm::Constant*>    m_intVecs;
00111    std::vector<llvm::Value*>         m_addrs;
00112    std::vector<llvm::Constant*>      m_immediates;
00113 
00114    llvm::VectorType *m_floatVecType;
00115    llvm::VectorType *m_intVecType;
00116 
00117    char        m_name[32];
00118    int         m_idx;
00119 
00120    int         m_numConsts;
00121 
00122    std::map<int, bool > m_destWriteMap;
00123    std::map<int, bool > m_tempWriteMap;
00124 
00125    llvm::Value      *m_undefFloatVec;
00126    llvm::Value      *m_undefIntVec;
00127    llvm::Value      *m_extSwizzleVec;
00128 
00129    std::stack<llvm::Value*> m_argStack;
00130    std::stack<std::vector<llvm::Value*> > m_tempStack;
00131 };
00132 
00133 #endif

Generated on Tue Sep 29 06:25:14 2009 for Gallium3D by  doxygen 1.5.4