Go to the source code of this file.
Functions | |
static void | AddStandardCompilePasses (PassManager &PM) |
void | gallivm_prog_delete (struct gallivm_prog *prog) |
static void | constant_interpolation (float(*inputs)[16][4], const struct tgsi_interp_coef *coefs, unsigned attrib, unsigned chan) |
static void | linear_interpolation (float(*inputs)[16][4], const struct tgsi_interp_coef *coefs, unsigned attrib, unsigned chan) |
static void | perspective_interpolation (float(*inputs)[16][4], const struct tgsi_interp_coef *coefs, unsigned attrib, unsigned chan) |
void | gallivm_ir_dump (struct gallivm_ir *ir, const char *file_prefix) |
void | gallivm_prog_inputs_interpolate (struct gallivm_prog *prog, float(*inputs)[16][4], const struct tgsi_interp_coef *coef) |
struct gallivm_ir * | gallivm_ir_new (enum gallivm_shader_type type) |
void | gallivm_ir_set_layout (struct gallivm_ir *ir, enum gallivm_vector_layout layout) |
void | gallivm_ir_set_components (struct gallivm_ir *ir, int num) |
void | gallivm_ir_fill_from_tgsi (struct gallivm_ir *ir, const struct tgsi_token *tokens) |
void | gallivm_ir_delete (struct gallivm_ir *ir) |
struct gallivm_prog * | gallivm_ir_compile (struct gallivm_ir *ir) |
Variables | |
static int | GLOBAL_ID = 0 |
static void AddStandardCompilePasses | ( | PassManager & | PM | ) | [static] |
Definition at line 78 of file gallivm.cpp.
00079 { 00080 PM.add(new LoweringPass()); 00081 PM.add(createVerifierPass()); // Verify that input is correct 00082 00083 PM.add(createLowerSetJmpPass()); // Lower llvm.setjmp/.longjmp 00084 00085 //PM.add(createStripSymbolsPass(true)); 00086 00087 PM.add(createRaiseAllocationsPass()); // call %malloc -> malloc inst 00088 PM.add(createCFGSimplificationPass()); // Clean up disgusting code 00089 PM.add(createPromoteMemoryToRegisterPass());// Kill useless allocas 00090 PM.add(createGlobalOptimizerPass()); // Optimize out global vars 00091 PM.add(createGlobalDCEPass()); // Remove unused fns and globs 00092 PM.add(createIPConstantPropagationPass());// IP Constant Propagation 00093 PM.add(createDeadArgEliminationPass()); // Dead argument elimination 00094 PM.add(createInstructionCombiningPass()); // Clean up after IPCP & DAE 00095 PM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE 00096 00097 PM.add(createPruneEHPass()); // Remove dead EH info 00098 00099 PM.add(createFunctionInliningPass()); // Inline small functions 00100 PM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args 00101 00102 PM.add(createTailDuplicationPass()); // Simplify cfg by copying code 00103 PM.add(createInstructionCombiningPass()); // Cleanup for scalarrepl. 00104 PM.add(createCFGSimplificationPass()); // Merge & remove BBs 00105 PM.add(createScalarReplAggregatesPass()); // Break up aggregate allocas 00106 PM.add(createInstructionCombiningPass()); // Combine silly seq's 00107 PM.add(createCondPropagationPass()); // Propagate conditionals 00108 00109 PM.add(createTailCallEliminationPass()); // Eliminate tail calls 00110 PM.add(createCFGSimplificationPass()); // Merge & remove BBs 00111 PM.add(createReassociatePass()); // Reassociate expressions 00112 PM.add(createLoopRotatePass()); 00113 PM.add(createLICMPass()); // Hoist loop invariants 00114 PM.add(createLoopUnswitchPass()); // Unswitch loops. 00115 PM.add(createLoopIndexSplitPass()); // Index split loops. 00116 PM.add(createInstructionCombiningPass()); // Clean up after LICM/reassoc 00117 PM.add(createIndVarSimplifyPass()); // Canonicalize indvars 00118 PM.add(createLoopUnrollPass()); // Unroll small loops 00119 PM.add(createInstructionCombiningPass()); // Clean up after the unroller 00120 PM.add(createGVNPass()); // Remove redundancies 00121 PM.add(createSCCPPass()); // Constant prop with SCCP 00122 00123 // Run instcombine after redundancy elimination to exploit opportunities 00124 // opened up by them. 00125 PM.add(createInstructionCombiningPass()); 00126 PM.add(createCondPropagationPass()); // Propagate conditionals 00127 00128 PM.add(createDeadStoreEliminationPass()); // Delete dead stores 00129 PM.add(createAggressiveDCEPass()); // SSA based 'Aggressive DCE' 00130 PM.add(createCFGSimplificationPass()); // Merge & remove BBs 00131 PM.add(createSimplifyLibCallsPass()); // Library Call Optimizations 00132 PM.add(createDeadTypeEliminationPass()); // Eliminate dead types 00133 PM.add(createConstantMergePass()); // Merge dup global constants 00134 }
static void constant_interpolation | ( | float * | inputs[16][4], | |
const struct tgsi_interp_coef * | coefs, | |||
unsigned | attrib, | |||
unsigned | chan | |||
) | [static] |
Definition at line 145 of file gallivm.cpp.
References tgsi_interp_coef::a0, and QUAD_SIZE.
00149 { 00150 unsigned i; 00151 00152 for (i = 0; i < QUAD_SIZE; ++i) { 00153 inputs[i][attrib][chan] = coefs[attrib].a0[chan]; 00154 } 00155 }
struct gallivm_prog* gallivm_ir_compile | ( | struct gallivm_ir * | ir | ) | [read] |
Definition at line 302 of file gallivm.cpp.
References AddStandardCompilePasses(), gallivm_ir::interpolators, gallivm_prog::interpolators, gallivm_prog::module, gallivm_ir::module, gallivm_ir::num_consts, gallivm_prog::num_consts, gallivm_ir::num_interp, and gallivm_prog::num_interp.
00303 { 00304 struct gallivm_prog *prog = 00305 (struct gallivm_prog *)calloc(1, sizeof(struct gallivm_prog)); 00306 00307 std::cout << "Before optimizations:"<<std::endl; 00308 ir->module->dump(); 00309 std::cout<<"-------------------------------"<<std::endl; 00310 00311 PassManager veri; 00312 veri.add(createVerifierPass()); 00313 veri.run(*ir->module); 00314 llvm::Module *mod = llvm::CloneModule(ir->module); 00315 prog->num_consts = ir->num_consts; 00316 memcpy(prog->interpolators, ir->interpolators, sizeof(prog->interpolators)); 00317 prog->num_interp = ir->num_interp; 00318 00319 /* Run optimization passes over it */ 00320 PassManager passes; 00321 passes.add(new TargetData(mod)); 00322 AddStandardCompilePasses(passes); 00323 passes.run(*mod); 00324 prog->module = mod; 00325 00326 std::cout << "After optimizations:"<<std::endl; 00327 mod->dump(); 00328 00329 return prog; 00330 }
void gallivm_ir_delete | ( | struct gallivm_ir * | ir | ) |
Definition at line 296 of file gallivm.cpp.
References gallivm_ir::module.
00297 { 00298 delete ir->module; 00299 free(ir); 00300 }
void gallivm_ir_dump | ( | struct gallivm_ir * | ir, | |
const char * | file_prefix | |||
) |
Definition at line 198 of file gallivm.cpp.
References gallivm_ir::id, gallivm_ir::module, and stream.
00199 { 00200 if (!ir || !ir->module) 00201 return; 00202 00203 if (file_prefix) { 00204 std::ostringstream stream; 00205 stream << file_prefix; 00206 stream << ir->id; 00207 stream << ".ll"; 00208 std::string name = stream.str(); 00209 std::ofstream out(name.c_str()); 00210 if (!out) { 00211 std::cerr<<"Can't open file : "<<stream.str()<<std::endl;; 00212 return; 00213 } 00214 out << (*ir->module); 00215 out.close(); 00216 } else { 00217 const llvm::Module::FunctionListType &funcs = ir->module->getFunctionList(); 00218 llvm::Module::FunctionListType::const_iterator itr; 00219 std::cout<<"; ---------- Start shader "<<ir->id<<std::endl; 00220 for (itr = funcs.begin(); itr != funcs.end(); ++itr) { 00221 const llvm::Function &func = (*itr); 00222 std::string name = func.getName(); 00223 const llvm::Function *found = 0; 00224 if (name.find("vs_shader") != std::string::npos || 00225 name.find("fs_shader") != std::string::npos || 00226 name.find("function") != std::string::npos) 00227 found = &func; 00228 if (found) { 00229 std::cout<<*found<<std::endl; 00230 } 00231 } 00232 std::cout<<"; ---------- End shader "<<ir->id<<std::endl; 00233 } 00234 }
void gallivm_ir_fill_from_tgsi | ( | struct gallivm_ir * | ir, | |
const struct tgsi_token * | tokens | |||
) |
Definition at line 285 of file gallivm.cpp.
References gallivm_ir_dump(), gallivm_ir::module, tgsi_dump(), and tgsi_to_llvmir().
00287 { 00288 std::cout << "Creating llvm from: " <<std::endl; 00289 tgsi_dump(tokens, 0); 00290 00291 llvm::Module *mod = tgsi_to_llvmir(ir, tokens); 00292 ir->module = mod; 00293 gallivm_ir_dump(ir, 0); 00294 }
struct gallivm_ir* gallivm_ir_new | ( | enum gallivm_shader_type | type | ) | [read] |
Definition at line 263 of file gallivm.cpp.
References GLOBAL_ID, gallivm_ir::id, and gallivm_ir::type.
00264 { 00265 struct gallivm_ir *ir = 00266 (struct gallivm_ir *)calloc(1, sizeof(struct gallivm_ir)); 00267 ++GLOBAL_ID; 00268 ir->id = GLOBAL_ID; 00269 ir->type = type; 00270 00271 return ir; 00272 }
void gallivm_ir_set_components | ( | struct gallivm_ir * | ir, | |
int | num | |||
) |
Definition at line 280 of file gallivm.cpp.
References gallivm_ir::num_components.
00281 { 00282 ir->num_components = num; 00283 }
void gallivm_ir_set_layout | ( | struct gallivm_ir * | ir, | |
enum gallivm_vector_layout | layout | |||
) |
void gallivm_prog_delete | ( | struct gallivm_prog * | prog | ) |
Definition at line 136 of file gallivm.cpp.
References gallivm_prog::function, and gallivm_prog::module.
00137 { 00138 delete prog->module; 00139 prog->module = 0; 00140 prog->function = 0; 00141 free(prog); 00142 }
void gallivm_prog_inputs_interpolate | ( | struct gallivm_prog * | prog, | |
float * | inputs[16][4], | |||
const struct tgsi_interp_coef * | coef | |||
) |
Definition at line 237 of file gallivm.cpp.
References assert, gallivm_interpolate::attrib, gallivm_interpolate::chan, constant_interpolation(), interp(), gallivm_prog::interpolators, linear_interpolation(), gallivm_prog::num_interp, perspective_interpolation(), TGSI_INTERPOLATE_CONSTANT, TGSI_INTERPOLATE_LINEAR, TGSI_INTERPOLATE_PERSPECTIVE, and gallivm_interpolate::type.
00240 { 00241 for (int i = 0; i < prog->num_interp; ++i) { 00242 const gallivm_interpolate &interp = prog->interpolators[i]; 00243 switch (interp.type) { 00244 case TGSI_INTERPOLATE_CONSTANT: 00245 constant_interpolation(inputs, coef, interp.attrib, interp.chan); 00246 break; 00247 00248 case TGSI_INTERPOLATE_LINEAR: 00249 linear_interpolation(inputs, coef, interp.attrib, interp.chan); 00250 break; 00251 00252 case TGSI_INTERPOLATE_PERSPECTIVE: 00253 perspective_interpolation(inputs, coef, interp.attrib, interp.chan); 00254 break; 00255 00256 default: 00257 assert( 0 ); 00258 } 00259 } 00260 }
static void linear_interpolation | ( | float * | inputs[16][4], | |
const struct tgsi_interp_coef * | coefs, | |||
unsigned | attrib, | |||
unsigned | chan | |||
) | [static] |
Definition at line 158 of file gallivm.cpp.
References tgsi_interp_coef::a0, tgsi_interp_coef::dadx, tgsi_interp_coef::dady, and QUAD_SIZE.
00162 { 00163 unsigned i; 00164 00165 for( i = 0; i < QUAD_SIZE; i++ ) { 00166 const float x = inputs[i][0][0]; 00167 const float y = inputs[i][0][1]; 00168 00169 inputs[i][attrib][chan] = 00170 coefs[attrib].a0[chan] + 00171 coefs[attrib].dadx[chan] * x + 00172 coefs[attrib].dady[chan] * y; 00173 } 00174 }
static void perspective_interpolation | ( | float * | inputs[16][4], | |
const struct tgsi_interp_coef * | coefs, | |||
unsigned | attrib, | |||
unsigned | chan | |||
) | [static] |
Definition at line 177 of file gallivm.cpp.
References tgsi_interp_coef::a0, assert, tgsi_interp_coef::dadx, tgsi_interp_coef::dady, and QUAD_SIZE.
00181 { 00182 unsigned i; 00183 00184 for( i = 0; i < QUAD_SIZE; i++ ) { 00185 const float x = inputs[i][0][0]; 00186 const float y = inputs[i][0][1]; 00187 /* WPOS.w here is really 1/w */ 00188 const float w = 1.0f / inputs[i][0][3]; 00189 assert(inputs[i][0][3] != 0.0); 00190 00191 inputs[i][attrib][chan] = 00192 (coefs[attrib].a0[chan] + 00193 coefs[attrib].dadx[chan] * x + 00194 coefs[attrib].dady[chan] * y) * w; 00195 } 00196 }
int GLOBAL_ID = 0 [static] |
Definition at line 73 of file gallivm.cpp.