instructions.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 INSTRUCTIONS_H
00034 #define INSTRUCTIONS_H
00035 
00036 #include <llvm/BasicBlock.h>
00037 #include <llvm/Module.h>
00038 #include <llvm/Value.h>
00039 #include <llvm/Support/IRBuilder.h>
00040 
00041 #include <map>
00042 #include <stack>
00043 
00044 namespace llvm {
00045    class VectorType;
00046    class Function;
00047 }
00048 
00049 class Storage;
00050 
00051 class Instructions
00052 {
00053 public:
00054    Instructions(llvm::Module *mod, llvm::Function *func, llvm::BasicBlock *block,
00055                 Storage *storage);
00056 
00057    llvm::BasicBlock *currentBlock() const;
00058 
00059    llvm::Value *abs(llvm::Value *in1);
00060    llvm::Value *add(llvm::Value *in1, llvm::Value *in2);
00061    llvm::Value *arl(llvm::Value *in1);
00062    void         beginLoop();
00063    void         bgnSub(unsigned);
00064    void         brk();
00065    void         cal(int label, llvm::Value *input);
00066    llvm::Value *ceil(llvm::Value *in);
00067    llvm::Value *clamp(llvm::Value *in);
00068    llvm::Value *cmp(llvm::Value *in1, llvm::Value *in2, llvm::Value *in3);
00069    llvm::Value *cnd(llvm::Value *in1, llvm::Value *in2, llvm::Value *in3);
00070    llvm::Value *cnd0(llvm::Value *in1, llvm::Value *in2, llvm::Value *in3);
00071    llvm::Value *cos(llvm::Value *in);
00072    llvm::Value *cross(llvm::Value *in1, llvm::Value *in2);
00073    llvm::Value *ddx(llvm::Value *in);
00074    llvm::Value *ddy(llvm::Value *in);
00075    llvm::Value *div(llvm::Value *in1, llvm::Value *in2);
00076    llvm::Value *dot2add(llvm::Value *in, llvm::Value *in2, llvm::Value *in3);
00077    llvm::Value *dp2(llvm::Value *in1, llvm::Value *in2);
00078    llvm::Value *dp3(llvm::Value *in1, llvm::Value *in2);
00079    llvm::Value *dp4(llvm::Value *in1, llvm::Value *in2);
00080    llvm::Value *dph(llvm::Value *in1, llvm::Value *in2);
00081    llvm::Value *dst(llvm::Value *in1, llvm::Value *in2);
00082    void         elseop();
00083    void         endif();
00084    void         endLoop();
00085    void         end();
00086    void         endSub();
00087    llvm::Value *exp(llvm::Value *in);
00088    llvm::Value *ex2(llvm::Value *in);
00089    llvm::Value *floor(llvm::Value *in);
00090    llvm::Value *frc(llvm::Value *in);
00091    void         ifop(llvm::Value *in);
00092    llvm::Value *kil(llvm::Value *in);
00093    llvm::Value *lerp(llvm::Value *in1, llvm::Value *in2,
00094                      llvm::Value *in3);
00095    llvm::Value *lg2(llvm::Value *in);
00096    llvm::Value *lit(llvm::Value *in);
00097    llvm::Value *log(llvm::Value *in);
00098    llvm::Value *madd(llvm::Value *in1, llvm::Value *in2,
00099                      llvm::Value *in3);
00100    llvm::Value *max(llvm::Value *in1, llvm::Value *in2);
00101    llvm::Value *min(llvm::Value *in1, llvm::Value *in2);
00102    llvm::Value *mul(llvm::Value *in1, llvm::Value *in2);
00103    llvm::Value *neg(llvm::Value *in);
00104    llvm::Value *nrm(llvm::Value *in);
00105    llvm::Value *pow(llvm::Value *in1, llvm::Value *in2);
00106    llvm::Value *rcp(llvm::Value *in);
00107    llvm::Value *rsq(llvm::Value *in);
00108    llvm::Value *scs(llvm::Value *in);
00109    llvm::Value *seq(llvm::Value *in1, llvm::Value *in2);
00110    llvm::Value *sfl(llvm::Value *in1, llvm::Value *in2);
00111    llvm::Value *sge(llvm::Value *in1, llvm::Value *in2);
00112    llvm::Value *sgt(llvm::Value *in1, llvm::Value *in2);
00113    llvm::Value *sin(llvm::Value *in);
00114    llvm::Value *sle(llvm::Value *in1, llvm::Value *in2);
00115    llvm::Value *slt(llvm::Value *in1, llvm::Value *in2);
00116    llvm::Value *sne(llvm::Value *in1, llvm::Value *in2);
00117    llvm::Value *str(llvm::Value *in1, llvm::Value *in2);
00118    llvm::Value *sub(llvm::Value *in1, llvm::Value *in2);
00119    llvm::Value *trunc(llvm::Value *in);
00120    llvm::Value *x2d(llvm::Value *in1, llvm::Value *in2, llvm::Value *in3);
00121 
00122    void printVector(llvm::Value *val);
00123 private:
00124    const char *name(const char *prefix);
00125 
00126    llvm::Value *callCeil(llvm::Value *val);
00127    llvm::Value *callFAbs(llvm::Value *val);
00128    llvm::Value *callFExp(llvm::Value *val);
00129    llvm::Value *callFLog(llvm::Value *val);
00130    llvm::Value *callFloor(llvm::Value *val);
00131    llvm::Value *callFSqrt(llvm::Value *val);
00132    llvm::Value *callPow(llvm::Value *val1, llvm::Value *val2);
00133 
00134    llvm::Value *vectorFromVals(llvm::Value *x, llvm::Value *y,
00135                                llvm::Value *z, llvm::Value *w=0);
00136 
00137    llvm::Value *constVector(float x, float y, float z, float w);
00138 
00139    llvm::Function *declarePrintf();
00140    llvm::Function *declareFunc(int label);
00141 
00142    llvm::Function *findFunction(int label);
00143 
00144    std::vector<llvm::Value*> extractVector(llvm::Value *vec);
00145 private:
00146    llvm::Module             *m_mod;
00147    llvm::Function           *m_func;
00148    char                      m_name[32];
00149    llvm::IRBuilder<>         m_builder;
00150    int                       m_idx;
00151 
00152    llvm::VectorType *m_floatVecType;
00153 
00154    llvm::Function   *m_llvmCeil;
00155    llvm::Function   *m_llvmFSqrt;
00156    llvm::Function   *m_llvmFAbs;
00157    llvm::Function   *m_llvmPow;
00158    llvm::Function   *m_llvmFloor;
00159    llvm::Function   *m_llvmFlog;
00160    llvm::Function   *m_llvmFexp;
00161    llvm::Function   *m_llvmLit;
00162 
00163    llvm::Constant   *m_fmtPtr;
00164 
00165    std::stack<llvm::BasicBlock*> m_ifStack;
00166    struct Loop {
00167       llvm::BasicBlock *begin;
00168       llvm::BasicBlock *end;
00169    };
00170    std::stack<Loop> m_loopStack;
00171    std::map<int, llvm::Function*> m_functions;
00172    Storage *m_storage;
00173 };
00174 
00175 #endif

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