ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

slang_ir.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  *
00004  * Copyright (C) 2005-2008  Brian Paul   All Rights Reserved.
00005  * Copyright (C) 2009  VMware, Inc.   All Rights Reserved.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this software and associated documentation files (the "Software"),
00009  * to deal in the Software without restriction, including without limitation
00010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011  * and/or sell copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included
00015  * in all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 
00025 
00026 #include "main/imports.h"
00027 #include "main/context.h"
00028 #include "slang_ir.h"
00029 #include "slang_mem.h"
00030 #include "shader/prog_instruction.h"
00031 #include "shader/prog_print.h"
00032 
00033 
00034 static const slang_ir_info IrInfo[] = {
00035    /* binary ops */
00036    { IR_ADD, "IR_ADD", OPCODE_ADD, 4, 2 },
00037    { IR_SUB, "IR_SUB", OPCODE_SUB, 4, 2 },
00038    { IR_MUL, "IR_MUL", OPCODE_MUL, 4, 2 },
00039    { IR_DIV, "IR_DIV", OPCODE_NOP, 0, 2 }, /* XXX broke */
00040    { IR_DOT4, "IR_DOT4", OPCODE_DP4, 1, 2 },
00041    { IR_DOT3, "IR_DOT3", OPCODE_DP3, 1, 2 },
00042    { IR_DOT2, "IR_DOT2", OPCODE_DP2, 1, 2 },
00043    { IR_NRM4, "IR_NRM4", OPCODE_NRM4, 1, 1 },
00044    { IR_NRM3, "IR_NRM3", OPCODE_NRM3, 1, 1 },
00045    { IR_CROSS, "IR_CROSS", OPCODE_XPD, 3, 2 },
00046    { IR_LRP, "IR_LRP", OPCODE_LRP, 4, 3 },
00047    { IR_MIN, "IR_MIN", OPCODE_MIN, 4, 2 },
00048    { IR_MAX, "IR_MAX", OPCODE_MAX, 4, 2 },
00049    { IR_CLAMP, "IR_CLAMP", OPCODE_NOP, 4, 3 }, /* special case: emit_clamp() */
00050    { IR_SEQUAL, "IR_SEQUAL", OPCODE_SEQ, 4, 2 },
00051    { IR_SNEQUAL, "IR_SNEQUAL", OPCODE_SNE, 4, 2 },
00052    { IR_SGE, "IR_SGE", OPCODE_SGE, 4, 2 },
00053    { IR_SGT, "IR_SGT", OPCODE_SGT, 4, 2 },
00054    { IR_SLE, "IR_SLE", OPCODE_SLE, 4, 2 },
00055    { IR_SLT, "IR_SLT", OPCODE_SLT, 4, 2 },
00056    { IR_POW, "IR_POW", OPCODE_POW, 1, 2 },
00057    { IR_EQUAL, "IR_EQUAL", OPCODE_NOP, 1, 2 },
00058    { IR_NOTEQUAL, "IR_NOTEQUAL", OPCODE_NOP, 1, 2 },
00059 
00060    /* unary ops */
00061    { IR_MOVE, "IR_MOVE", OPCODE_MOV, 4, 1 },
00062    { IR_I_TO_F, "IR_I_TO_F", OPCODE_MOV, 4, 1 },  /* int[4] to float[4] */
00063    { IR_F_TO_I, "IR_F_TO_I", OPCODE_TRUNC, 4, 1 },
00064    { IR_EXP, "IR_EXP", OPCODE_EXP, 1, 1 },
00065    { IR_EXP2, "IR_EXP2", OPCODE_EX2, 1, 1 },
00066    { IR_LOG2, "IR_LOG2", OPCODE_LG2, 1, 1 },
00067    { IR_RSQ, "IR_RSQ", OPCODE_RSQ, 1, 1 },
00068    { IR_RCP, "IR_RCP", OPCODE_RCP, 1, 1 },
00069    { IR_FLOOR, "IR_FLOOR", OPCODE_FLR, 4, 1 },
00070    { IR_FRAC, "IR_FRAC", OPCODE_FRC, 4, 1 },
00071    { IR_ABS, "IR_ABS", OPCODE_ABS, 4, 1 },
00072    { IR_NEG, "IR_NEG", OPCODE_NOP, 4, 1 }, /* special case: emit_negation() */
00073    { IR_DDX, "IR_DDX", OPCODE_DDX, 4, 1 },
00074    { IR_DDY, "IR_DDY", OPCODE_DDY, 4, 1 },
00075    { IR_SIN, "IR_SIN", OPCODE_SIN, 1, 1 },
00076    { IR_COS, "IR_COS", OPCODE_COS, 1, 1 },
00077    { IR_NOISE1, "IR_NOISE1", OPCODE_NOISE1, 1, 1 },
00078    { IR_NOISE2, "IR_NOISE2", OPCODE_NOISE2, 1, 1 },
00079    { IR_NOISE3, "IR_NOISE3", OPCODE_NOISE3, 1, 1 },
00080    { IR_NOISE4, "IR_NOISE4", OPCODE_NOISE4, 1, 1 },
00081 
00082    /* other */
00083    { IR_SEQ, "IR_SEQ", OPCODE_NOP, 0, 0 },
00084    { IR_SCOPE, "IR_SCOPE", OPCODE_NOP, 0, 0 },
00085    { IR_LABEL, "IR_LABEL", OPCODE_NOP, 0, 0 },
00086    { IR_IF, "IR_IF", OPCODE_NOP, 0, 0 },
00087    { IR_KILL, "IR_KILL", OPCODE_NOP, 0, 0 },
00088    { IR_COND, "IR_COND", OPCODE_NOP, 0, 0 },
00089    { IR_CALL, "IR_CALL", OPCODE_NOP, 0, 0 },
00090    { IR_COPY, "IR_COPY", OPCODE_NOP, 0, 1 },
00091    { IR_NOT, "IR_NOT", OPCODE_NOP, 1, 1 },
00092    { IR_VAR, "IR_VAR", OPCODE_NOP, 0, 0 },
00093    { IR_VAR_DECL, "IR_VAR_DECL", OPCODE_NOP, 0, 0 },
00094    { IR_TEX, "IR_TEX", OPCODE_TEX, 4, 1 },
00095    { IR_TEXB, "IR_TEXB", OPCODE_TXB, 4, 1 },
00096    { IR_TEXP, "IR_TEXP", OPCODE_TXP, 4, 1 },
00097    { IR_FLOAT, "IR_FLOAT", OPCODE_NOP, 0, 0 }, /* float literal */
00098    { IR_FIELD, "IR_FIELD", OPCODE_NOP, 0, 0 },
00099    { IR_ELEMENT, "IR_ELEMENT", OPCODE_NOP, 0, 0 },
00100    { IR_SWIZZLE, "IR_SWIZZLE", OPCODE_NOP, 0, 0 },
00101    { IR_NOP, "IR_NOP", OPCODE_NOP, 0, 0 },
00102    { 0, NULL, 0, 0, 0 }
00103 };
00104 
00105 
00106 const slang_ir_info *
00107 _slang_ir_info(slang_ir_opcode opcode)
00108 {
00109    GLuint i;
00110    for (i = 0; IrInfo[i].IrName; i++) {
00111       if (IrInfo[i].IrOpcode == opcode) {
00112      return IrInfo + i;
00113       }
00114    }
00115    return NULL;
00116 }
00117 
00118 
00119 void
00120 _slang_init_ir_storage(slang_ir_storage *st,
00121                        enum register_file file, GLint index, GLint size,
00122                        GLuint swizzle)
00123 {
00124    st->File = file;
00125    st->Index = index;
00126    st->Size = size;
00127    st->Swizzle = swizzle;
00128    st->Parent = NULL;
00129    st->IsIndirect = GL_FALSE;
00130 }
00131 
00132 
00136 slang_ir_storage *
00137 _slang_new_ir_storage(enum register_file file, GLint index, GLint size)
00138 {
00139    slang_ir_storage *st;
00140    st = (slang_ir_storage *) _slang_alloc(sizeof(slang_ir_storage));
00141    if (st) {
00142       st->File = file;
00143       st->Index = index;
00144       st->Size = size;
00145       st->Swizzle = SWIZZLE_NOOP;
00146       st->Parent = NULL;
00147       st->IsIndirect = GL_FALSE;
00148    }
00149    return st;
00150 }
00151 
00152 
00156 slang_ir_storage *
00157 _slang_new_ir_storage_swz(enum register_file file, GLint index, GLint size,
00158                           GLuint swizzle)
00159 {
00160    slang_ir_storage *st;
00161    st = (slang_ir_storage *) _slang_alloc(sizeof(slang_ir_storage));
00162    if (st) {
00163       st->File = file;
00164       st->Index = index;
00165       st->Size = size;
00166       st->Swizzle = swizzle;
00167       st->Parent = NULL;
00168       st->IsIndirect = GL_FALSE;
00169    }
00170    return st;
00171 }
00172 
00173 
00177 slang_ir_storage *
00178 _slang_new_ir_storage_relative(GLint index, GLint size,
00179                                slang_ir_storage *parent)
00180 {
00181    slang_ir_storage *st;
00182    st = (slang_ir_storage *) _slang_alloc(sizeof(slang_ir_storage));
00183    if (st) {
00184       st->File = PROGRAM_UNDEFINED;
00185       st->Index = index;
00186       st->Size = size;
00187       st->Swizzle = SWIZZLE_NOOP;
00188       st->Parent = parent;
00189       st->IsIndirect = GL_FALSE;
00190    }
00191    return st;
00192 }
00193 
00194 
00195 slang_ir_storage *
00196 _slang_new_ir_storage_indirect(enum register_file file,
00197                                GLint index,
00198                                GLint size,
00199                                enum register_file indirectFile,
00200                                GLint indirectIndex,
00201                                GLuint indirectSwizzle)
00202 {
00203    slang_ir_storage *st;
00204    st = (slang_ir_storage *) _slang_alloc(sizeof(slang_ir_storage));
00205    if (st) {
00206       st->File = file;
00207       st->Index = index;
00208       st->Size = size;
00209       st->Swizzle = SWIZZLE_NOOP;
00210       st->IsIndirect = GL_TRUE;
00211       st->IndirectFile = indirectFile;
00212       st->IndirectIndex = indirectIndex;
00213       st->IndirectSwizzle = indirectSwizzle;
00214    }
00215    return st;
00216 }
00217 
00218 
00225 slang_ir_storage *
00226 _slang_new_ir_storage_sampler(GLint sampNum, GLuint texTarget, GLint size)
00227 {
00228    slang_ir_storage *st;
00229    assert(texTarget < NUM_TEXTURE_TARGETS);
00230    st = _slang_new_ir_storage(PROGRAM_SAMPLER, sampNum, size);
00231    if (st) {
00232       st->TexTarget = texTarget;
00233    }
00234    return st;
00235 }
00236 
00237 
00238 
00239 /* XXX temporary function */
00240 void
00241 _slang_copy_ir_storage(slang_ir_storage *dst, const slang_ir_storage *src)
00242 {
00243    *dst = *src;
00244    dst->Parent = NULL;
00245 }
00246 
00247 
00248 
00249 static const char *
00250 _slang_ir_name(slang_ir_opcode opcode)
00251 {
00252    return _slang_ir_info(opcode)->IrName;
00253 }
00254 
00255 
00256 
00257 #if 0 /* no longer needed with mempool */
00258 
00265 static void
00266 _slang_refcount_storage(slang_ir_node *n)
00267 {
00268    GLuint i;
00269    if (!n)
00270       return;
00271    if (n->Store)
00272       n->Store->RefCount++;
00273    for (i = 0; i < 3; i++)
00274       _slang_refcount_storage(n->Children[i]);
00275 }
00276 #endif
00277 
00278 
00279 static void
00280 _slang_free_ir(slang_ir_node *n)
00281 {
00282    GLuint i;
00283    if (!n)
00284       return;
00285 
00286 #if 0
00287    if (n->Store) {
00288       n->Store->RefCount--;
00289       if (n->Store->RefCount == 0) {
00290          _slang_free(n->Store);
00291          n->Store = NULL;
00292       }
00293    }
00294 #endif
00295 
00296    for (i = 0; i < 3; i++)
00297       _slang_free_ir(n->Children[i]);
00298    /* Do not free n->List since it's a child elsewhere */
00299    _slang_free(n);
00300 }
00301 
00302 
00306 void
00307 _slang_free_ir_tree(slang_ir_node *n)
00308 {
00309 #if 0
00310    _slang_refcount_storage(n);
00311 #endif
00312    _slang_free_ir(n);
00313 }
00314 
00315 
00316 static const char *
00317 storage_string(const slang_ir_storage *st)
00318 {
00319    static const char *files[] = {
00320       "TEMP",
00321       "LOCAL_PARAM",
00322       "ENV_PARAM",
00323       "STATE",
00324       "INPUT",
00325       "OUTPUT",
00326       "NAMED_PARAM",
00327       "CONSTANT",
00328       "UNIFORM",
00329       "VARYING",
00330       "WRITE_ONLY",
00331       "ADDRESS",
00332       "SAMPLER",
00333       "UNDEFINED"
00334    };
00335    static char s[100];
00336    assert(Elements(files) == PROGRAM_FILE_MAX);
00337 #if 0
00338    if (st->Size == 1)
00339       sprintf(s, "%s[%d]", files[st->File], st->Index);
00340    else
00341       sprintf(s, "%s[%d..%d]", files[st->File], st->Index,
00342               st->Index + st->Size - 1);
00343 #endif
00344    assert(st->File < (GLint) (sizeof(files) / sizeof(files[0])));
00345    sprintf(s, "%s[%d]", files[st->File], st->Index);
00346    return s;
00347 }
00348 
00349 
00350 static void
00351 spaces(int n)
00352 {
00353    while (n-- > 0) {
00354       printf(" ");
00355    }
00356 }
00357 
00358 
00359 void
00360 _slang_print_ir_tree(const slang_ir_node *n, int indent)
00361 {
00362 #define IND 0
00363 
00364    if (!n)
00365       return;
00366 #if !IND
00367    if (n->Opcode != IR_SEQ)
00368 #else
00369       printf("%3d:", indent);
00370 #endif
00371       spaces(indent);
00372 
00373    switch (n->Opcode) {
00374    case IR_SEQ:
00375 #if IND
00376       printf("SEQ  at %p\n", (void*) n);
00377 #endif
00378       assert(n->Children[0]);
00379       assert(n->Children[1]);
00380       _slang_print_ir_tree(n->Children[0], indent + IND);
00381       _slang_print_ir_tree(n->Children[1], indent + IND);
00382       break;
00383    case IR_SCOPE:
00384       printf("NEW SCOPE\n");
00385       assert(!n->Children[1]);
00386       _slang_print_ir_tree(n->Children[0], indent + 3);
00387       break;
00388    case IR_COPY:
00389       printf("COPY\n");
00390       _slang_print_ir_tree(n->Children[0], indent+3);
00391       _slang_print_ir_tree(n->Children[1], indent+3);
00392       break;
00393    case IR_LABEL:
00394       printf("LABEL: %s\n", n->Label->Name);
00395       break;
00396    case IR_COND:
00397       printf("COND\n");
00398       _slang_print_ir_tree(n->Children[0], indent + 3);
00399       break;
00400 
00401    case IR_IF:
00402       printf("IF \n");
00403       _slang_print_ir_tree(n->Children[0], indent+3);
00404       spaces(indent);
00405       printf("THEN\n");
00406       _slang_print_ir_tree(n->Children[1], indent+3);
00407       if (n->Children[2]) {
00408          spaces(indent);
00409          printf("ELSE\n");
00410          _slang_print_ir_tree(n->Children[2], indent+3);
00411       }
00412       spaces(indent);
00413       printf("ENDIF\n");
00414       break;
00415 
00416    case IR_BEGIN_SUB:
00417       printf("BEGIN_SUB\n");
00418       break;
00419    case IR_END_SUB:
00420       printf("END_SUB\n");
00421       break;
00422    case IR_RETURN:
00423       printf("RETURN\n");
00424       break;
00425    case IR_CALL:
00426       printf("CALL %s\n", n->Label->Name);
00427       break;
00428 
00429    case IR_LOOP:
00430       printf("LOOP\n");
00431       _slang_print_ir_tree(n->Children[0], indent+3);
00432       if (n->Children[1]) {
00433          spaces(indent);
00434          printf("TAIL:\n");
00435          _slang_print_ir_tree(n->Children[1], indent+3);
00436       }
00437       spaces(indent);
00438       printf("ENDLOOP\n");
00439       break;
00440    case IR_CONT:
00441       printf("CONT\n");
00442       break;
00443    case IR_BREAK:
00444       printf("BREAK\n");
00445       break;
00446    case IR_BREAK_IF_TRUE:
00447       printf("BREAK_IF_TRUE\n");
00448       _slang_print_ir_tree(n->Children[0], indent+3);
00449       break;
00450    case IR_CONT_IF_TRUE:
00451       printf("CONT_IF_TRUE\n");
00452       _slang_print_ir_tree(n->Children[0], indent+3);
00453       break;
00454 
00455    case IR_VAR:
00456       printf("VAR %s%s at %s  store %p\n",
00457              (n->Var ? (char *) n->Var->a_name : "TEMP"),
00458              _mesa_swizzle_string(n->Store->Swizzle, 0, 0),
00459              storage_string(n->Store), (void*) n->Store);
00460       break;
00461    case IR_VAR_DECL:
00462       printf("VAR_DECL %s (%p) at %s  store %p\n",
00463              (n->Var ? (char *) n->Var->a_name : "TEMP"),
00464              (void*) n->Var, storage_string(n->Store),
00465              (void*) n->Store);
00466       break;
00467    case IR_FIELD:
00468       printf("FIELD %s of\n", n->Field);
00469       _slang_print_ir_tree(n->Children[0], indent+3);
00470       break;
00471    case IR_FLOAT:
00472       printf("FLOAT %g %g %g %g\n",
00473              n->Value[0], n->Value[1], n->Value[2], n->Value[3]);
00474       break;
00475    case IR_I_TO_F:
00476       printf("INT_TO_FLOAT\n");
00477       _slang_print_ir_tree(n->Children[0], indent+3);
00478       break;
00479    case IR_F_TO_I:
00480       printf("FLOAT_TO_INT\n");
00481       _slang_print_ir_tree(n->Children[0], indent+3);
00482       break;
00483    case IR_SWIZZLE:
00484       printf("SWIZZLE %s of  (store %p) \n",
00485              _mesa_swizzle_string(n->Store->Swizzle, 0, 0), (void*) n->Store);
00486       _slang_print_ir_tree(n->Children[0], indent + 3);
00487       break;
00488    default:
00489       printf("%s (%p, %p)  (store %p)\n", _slang_ir_name(n->Opcode),
00490              (void*) n->Children[0], (void*) n->Children[1], (void*) n->Store);
00491       _slang_print_ir_tree(n->Children[0], indent+3);
00492       _slang_print_ir_tree(n->Children[1], indent+3);
00493    }
00494 }

Generated on Fri May 25 2012 04:18:49 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.