instructionssoa.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 #ifndef INSTRUCTIONSSOA_H
00029 #define INSTRUCTIONSSOA_H
00030 
00031 #include <pipe/p_shader_tokens.h>
00032 #include <llvm/Support/IRBuilder.h>
00033 
00034 #include <map>
00035 #include <vector>
00036 
00037 namespace llvm {
00038    class Module;
00039    class Function;
00040    class BasicBlock;
00041    class Value;
00042 }
00043 class StorageSoa;
00044 
00045 class InstructionsSoa
00046 {
00047 public:
00048    InstructionsSoa(llvm::Module *mod, llvm::Function *func,
00049                    llvm::BasicBlock *block, StorageSoa *storage);
00050 
00051    std::vector<llvm::Value*> abs(const std::vector<llvm::Value*> in1);
00052    std::vector<llvm::Value*> arl(const std::vector<llvm::Value*> in);
00053    std::vector<llvm::Value*> add(const std::vector<llvm::Value*> in1,
00054                                  const std::vector<llvm::Value*> in2);
00055    std::vector<llvm::Value*> dp3(const std::vector<llvm::Value*> in1,
00056                                  const std::vector<llvm::Value*> in2);
00057    std::vector<llvm::Value*> dp4(const std::vector<llvm::Value*> in1,
00058                                  const std::vector<llvm::Value*> in2);
00059    std::vector<llvm::Value*> lit(const std::vector<llvm::Value*> in);
00060    std::vector<llvm::Value*> madd(const std::vector<llvm::Value*> in1,
00061                                   const std::vector<llvm::Value*> in2,
00062                                   const std::vector<llvm::Value*> in3);
00063    std::vector<llvm::Value*> max(const std::vector<llvm::Value*> in1,
00064                                  const std::vector<llvm::Value*> in2);
00065    std::vector<llvm::Value*> min(const std::vector<llvm::Value*> in1,
00066                                  const std::vector<llvm::Value*> in2);
00067    std::vector<llvm::Value*> mul(const std::vector<llvm::Value*> in1,
00068                                  const std::vector<llvm::Value*> in2);
00069    std::vector<llvm::Value*> pow(const std::vector<llvm::Value*> in1,
00070                                  const std::vector<llvm::Value*> in2);
00071    std::vector<llvm::Value*> rsq(const std::vector<llvm::Value*> in1);
00072    std::vector<llvm::Value*> slt(const std::vector<llvm::Value*> in1,
00073                                  const std::vector<llvm::Value*> in2);
00074    std::vector<llvm::Value*> sub(const std::vector<llvm::Value*> in1,
00075                                  const std::vector<llvm::Value*> in2);
00076    void         end();
00077 
00078    std::vector<llvm::Value*> extractVector(llvm::Value *vector);
00079 private:
00080    const char * name(const char *prefix) const;
00081    llvm::Value *vectorFromVals(llvm::Value *x, llvm::Value *y,
00082                                llvm::Value *z, llvm::Value *w);
00083    void createFunctionMap();
00084    void createBuiltins();
00085    void createDependencies();
00086    llvm::Function *function(int);
00087    llvm::Module *currentModule() const;
00088    llvm::Value *allocaTemp();
00089    std::vector<llvm::Value*> allocaToResult(llvm::Value *allocaPtr);
00090    std::vector<llvm::Value*> callBuiltin(llvm::Function *func,
00091                                          const std::vector<llvm::Value*> in1);
00092    std::vector<llvm::Value*> callBuiltin(llvm::Function *func,
00093                                          const std::vector<llvm::Value*> in1,
00094                                          const std::vector<llvm::Value*> in2);
00095    std::vector<llvm::Value*> callBuiltin(llvm::Function *func,
00096                                          const std::vector<llvm::Value*> in1,
00097                                          const std::vector<llvm::Value*> in2,
00098                                          const std::vector<llvm::Value*> in3);
00099    void injectFunction(llvm::Function *originalFunc, int op = TGSI_OPCODE_LAST);
00100 private:
00101    llvm::IRBuilder<>  m_builder;
00102    StorageSoa *m_storage;
00103 
00104    std::map<int, std::string> m_functionsMap;
00105    std::map<int, llvm::Function*> m_functions;
00106    llvm::Module *m_builtins;
00107    std::map<std::string, std::vector<std::string> > m_builtinDependencies;
00108 
00109 private:
00110    mutable int  m_idx;
00111    mutable char m_name[32];
00112 };
00113 
00114 
00115 #endif

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