3 #include "pipe/p_context.h"
4 #include "pipe/tgsi/exec/tgsi_exec.h"
5 #include "pipe/tgsi/exec/tgsi_token.h"
6 #include "pipe/tgsi/exec/tgsi_build.h"
7 #include "pipe/tgsi/exec/tgsi_util.h"
8 #include "pipe/tgsi/exec/tgsi_parse.h"
9 #include "pipe/tgsi/exec/tgsi_dump.h"
10 //#include "pipe/tgsi/tgsi_platform.h"
12 #include <llvm/Module.h>
13 #include <llvm/CallingConv.h>
14 #include <llvm/Constants.h>
15 #include <llvm/DerivedTypes.h>
16 #include <llvm/Instructions.h>
17 #include <llvm/ModuleProvider.h>
18 #include <llvm/Pass.h>
19 #include <llvm/PassManager.h>
20 #include <llvm/ParameterAttributes.h>
21 #include <llvm/Support/PatternMatch.h>
22 #include <llvm/ExecutionEngine/JIT.h>
23 #include <llvm/ExecutionEngine/Interpreter.h>
24 #include <llvm/ExecutionEngine/GenericValue.h>
25 #include <llvm/Support/MemoryBuffer.h>
26 #include <llvm/LinkAllPasses.h>
27 #include <llvm/Analysis/Verifier.h>
28 #include <llvm/Analysis/LoopPass.h>
29 #include <llvm/Target/TargetData.h>
30 #include <llvm/Bitcode/ReaderWriter.h>
34 #include "llvm_base_shader.cpp"
37 static inline void addPass(PassManager
&PM
, Pass
*P
) {
38 // Add the pass to the pass manager...
42 static inline void AddStandardCompilePasses(PassManager
&PM
) {
43 PM
.add(createVerifierPass()); // Verify that input is correct
45 addPass(PM
, createLowerSetJmpPass()); // Lower llvm.setjmp/.longjmp
47 // If the -strip-debug command line option was specified, do it.
49 // addPass(PM, createStripSymbolsPass(true));
51 addPass(PM
, createRaiseAllocationsPass()); // call %malloc -> malloc inst
52 addPass(PM
, createCFGSimplificationPass()); // Clean up disgusting code
53 addPass(PM
, createPromoteMemoryToRegisterPass());// Kill useless allocas
54 addPass(PM
, createGlobalOptimizerPass()); // Optimize out global vars
55 addPass(PM
, createGlobalDCEPass()); // Remove unused fns and globs
56 addPass(PM
, createIPConstantPropagationPass());// IP Constant Propagation
57 addPass(PM
, createDeadArgEliminationPass()); // Dead argument elimination
58 addPass(PM
, createInstructionCombiningPass()); // Clean up after IPCP & DAE
59 addPass(PM
, createCFGSimplificationPass()); // Clean up after IPCP & DAE
61 addPass(PM
, createPruneEHPass()); // Remove dead EH info
64 addPass(PM
, createFunctionInliningPass()); // Inline small functions
65 addPass(PM
, createArgumentPromotionPass()); // Scalarize uninlined fn args
67 addPass(PM
, createTailDuplicationPass()); // Simplify cfg by copying code
68 addPass(PM
, createInstructionCombiningPass()); // Cleanup for scalarrepl.
69 addPass(PM
, createCFGSimplificationPass()); // Merge & remove BBs
70 addPass(PM
, createScalarReplAggregatesPass()); // Break up aggregate allocas
71 addPass(PM
, createInstructionCombiningPass()); // Combine silly seq's
72 addPass(PM
, createCondPropagationPass()); // Propagate conditionals
74 addPass(PM
, createTailCallEliminationPass()); // Eliminate tail calls
75 addPass(PM
, createCFGSimplificationPass()); // Merge & remove BBs
76 addPass(PM
, createReassociatePass()); // Reassociate expressions
77 addPass(PM
, createLoopRotatePass());
78 addPass(PM
, createLICMPass()); // Hoist loop invariants
79 addPass(PM
, createLoopUnswitchPass()); // Unswitch loops.
80 addPass(PM
, createLoopIndexSplitPass()); // Index split loops.
81 addPass(PM
, createInstructionCombiningPass()); // Clean up after LICM/reassoc
82 addPass(PM
, createIndVarSimplifyPass()); // Canonicalize indvars
83 addPass(PM
, createLoopUnrollPass()); // Unroll small loops
84 addPass(PM
, createInstructionCombiningPass()); // Clean up after the unroller
85 addPass(PM
, createGVNPass()); // Remove redundancies
86 addPass(PM
, createSCCPPass()); // Constant prop with SCCP
88 // Run instcombine after redundancy elimination to exploit opportunities
90 addPass(PM
, createInstructionCombiningPass());
91 addPass(PM
, createCondPropagationPass()); // Propagate conditionals
93 addPass(PM
, createDeadStoreEliminationPass()); // Delete dead stores
94 addPass(PM
, createAggressiveDCEPass()); // SSA based 'Aggressive DCE'
95 addPass(PM
, createCFGSimplificationPass()); // Merge & remove BBs
96 addPass(PM
, createSimplifyLibCallsPass()); // Library Call Optimizations
97 addPass(PM
, createDeadTypeEliminationPass()); // Eliminate dead types
98 addPass(PM
, createConstantMergePass()); // Merge dup global constants
102 translate_declaration(llvm::Module
*module
,
103 struct tgsi_full_declaration
*decl
,
104 struct tgsi_full_declaration
*fd
)
106 /* i think this is going to be a noop */
111 translate_immediate(llvm::Module
*module
,
112 struct tgsi_full_immediate
*imm
)
118 translate_instruction(llvm::Module
*module
,
119 struct tgsi_full_instruction
*inst
,
120 struct tgsi_full_instruction
*fi
)
122 switch (inst
->Instruction
.Opcode
) {
123 case TGSI_OPCODE_ARL
:
125 case TGSI_OPCODE_MOV
:
127 case TGSI_OPCODE_LIT
:
129 case TGSI_OPCODE_RCP
:
131 case TGSI_OPCODE_RSQ
:
133 case TGSI_OPCODE_EXP
:
135 case TGSI_OPCODE_LOG
:
137 case TGSI_OPCODE_MUL
:
139 case TGSI_OPCODE_ADD
:
141 case TGSI_OPCODE_DP3
:
143 case TGSI_OPCODE_DP4
:
145 case TGSI_OPCODE_DST
:
147 case TGSI_OPCODE_MIN
:
149 case TGSI_OPCODE_MAX
:
151 case TGSI_OPCODE_SLT
:
153 case TGSI_OPCODE_SGE
:
155 case TGSI_OPCODE_MAD
:
157 case TGSI_OPCODE_SUB
:
159 case TGSI_OPCODE_LERP
:
161 case TGSI_OPCODE_CND
:
163 case TGSI_OPCODE_CND0
:
165 case TGSI_OPCODE_DOT2ADD
:
167 case TGSI_OPCODE_INDEX
:
169 case TGSI_OPCODE_NEGATE
:
171 case TGSI_OPCODE_FRAC
:
173 case TGSI_OPCODE_CLAMP
:
175 case TGSI_OPCODE_FLOOR
:
177 case TGSI_OPCODE_ROUND
:
179 case TGSI_OPCODE_EXPBASE2
:
181 case TGSI_OPCODE_LOGBASE2
:
183 case TGSI_OPCODE_POWER
:
185 case TGSI_OPCODE_CROSSPRODUCT
:
187 case TGSI_OPCODE_MULTIPLYMATRIX
:
189 case TGSI_OPCODE_ABS
:
191 case TGSI_OPCODE_RCC
:
193 case TGSI_OPCODE_DPH
:
195 case TGSI_OPCODE_COS
:
197 case TGSI_OPCODE_DDX
:
199 case TGSI_OPCODE_DDY
:
201 case TGSI_OPCODE_KILP
:
203 case TGSI_OPCODE_PK2H
:
205 case TGSI_OPCODE_PK2US
:
207 case TGSI_OPCODE_PK4B
:
209 case TGSI_OPCODE_PK4UB
:
211 case TGSI_OPCODE_RFL
:
213 case TGSI_OPCODE_SEQ
:
215 case TGSI_OPCODE_SFL
:
217 case TGSI_OPCODE_SGT
:
219 case TGSI_OPCODE_SIN
:
221 case TGSI_OPCODE_SLE
:
223 case TGSI_OPCODE_SNE
:
225 case TGSI_OPCODE_STR
:
227 case TGSI_OPCODE_TEX
:
229 case TGSI_OPCODE_TXD
:
231 case TGSI_OPCODE_TXP
:
233 case TGSI_OPCODE_UP2H
:
235 case TGSI_OPCODE_UP2US
:
237 case TGSI_OPCODE_UP4B
:
239 case TGSI_OPCODE_UP4UB
:
241 case TGSI_OPCODE_X2D
:
243 case TGSI_OPCODE_ARA
:
245 case TGSI_OPCODE_ARR
:
247 case TGSI_OPCODE_BRA
:
249 case TGSI_OPCODE_CAL
:
251 case TGSI_OPCODE_RET
:
253 case TGSI_OPCODE_SSG
:
255 case TGSI_OPCODE_CMP
:
257 case TGSI_OPCODE_SCS
:
259 case TGSI_OPCODE_TXB
:
261 case TGSI_OPCODE_NRM
:
263 case TGSI_OPCODE_DIV
:
265 case TGSI_OPCODE_DP2
:
267 case TGSI_OPCODE_TXL
:
269 case TGSI_OPCODE_BRK
:
273 case TGSI_OPCODE_LOOP
:
275 case TGSI_OPCODE_REP
:
277 case TGSI_OPCODE_ELSE
:
279 case TGSI_OPCODE_ENDIF
:
281 case TGSI_OPCODE_ENDLOOP
:
283 case TGSI_OPCODE_ENDREP
:
285 case TGSI_OPCODE_PUSHA
:
287 case TGSI_OPCODE_POPA
:
289 case TGSI_OPCODE_CEIL
:
291 case TGSI_OPCODE_I2F
:
293 case TGSI_OPCODE_NOT
:
295 case TGSI_OPCODE_TRUNC
:
297 case TGSI_OPCODE_SHL
:
299 case TGSI_OPCODE_SHR
:
301 case TGSI_OPCODE_AND
:
305 case TGSI_OPCODE_MOD
:
307 case TGSI_OPCODE_XOR
:
309 case TGSI_OPCODE_SAD
:
311 case TGSI_OPCODE_TXF
:
313 case TGSI_OPCODE_TXQ
:
315 case TGSI_OPCODE_CONT
:
317 case TGSI_OPCODE_EMIT
:
319 case TGSI_OPCODE_ENDPRIM
:
321 case TGSI_OPCODE_BGNLOOP2
:
323 case TGSI_OPCODE_BGNSUB
:
325 case TGSI_OPCODE_ENDLOOP2
:
327 case TGSI_OPCODE_ENDSUB
:
329 case TGSI_OPCODE_NOISE1
:
331 case TGSI_OPCODE_NOISE2
:
333 case TGSI_OPCODE_NOISE3
:
335 case TGSI_OPCODE_NOISE4
:
337 case TGSI_OPCODE_NOP
:
339 case TGSI_OPCODE_TEXBEM
:
341 case TGSI_OPCODE_TEXBEML
:
343 case TGSI_OPCODE_TEXREG2AR
:
345 case TGSI_OPCODE_TEXM3X2PAD
:
347 case TGSI_OPCODE_TEXM3X2TEX
:
349 case TGSI_OPCODE_TEXM3X3PAD
:
351 case TGSI_OPCODE_TEXM3X3TEX
:
353 case TGSI_OPCODE_TEXM3X3SPEC
:
355 case TGSI_OPCODE_TEXM3X3VSPEC
:
357 case TGSI_OPCODE_TEXREG2GB
:
359 case TGSI_OPCODE_TEXREG2RGB
:
361 case TGSI_OPCODE_TEXDP3TEX
:
363 case TGSI_OPCODE_TEXDP3
:
365 case TGSI_OPCODE_TEXM3X3
:
367 case TGSI_OPCODE_TEXM3X2DEPTH
:
369 case TGSI_OPCODE_TEXDEPTH
:
371 case TGSI_OPCODE_BEM
:
373 case TGSI_OPCODE_M4X3
:
375 case TGSI_OPCODE_M3X4
:
377 case TGSI_OPCODE_M3X3
:
379 case TGSI_OPCODE_M3X2
:
381 case TGSI_OPCODE_NRM4
:
383 case TGSI_OPCODE_CALLNZ
:
385 case TGSI_OPCODE_IFC
:
387 case TGSI_OPCODE_BREAKC
:
389 case TGSI_OPCODE_KIL
:
391 case TGSI_OPCODE_END
:
394 fprintf(stderr
, "ERROR: Unknown opcode %d\n",
395 inst
->Instruction
.Opcode
);
400 switch( inst
->Instruction
.Saturate
) {
403 case TGSI_SAT_ZERO_ONE
:
406 case TGSI_SAT_MINUS_PLUS_ONE
:
407 /*TXT( "_SAT[-1,1]" );*/
415 static llvm::Module
*
416 tgsi_to_llvm(const struct tgsi_token
*tokens
)
418 llvm::Module
*mod
= createBaseShader();
419 struct tgsi_parse_context parse
;
420 struct tgsi_full_instruction fi
;
421 struct tgsi_full_declaration fd
;
423 Function
* shader
= mod
->getFunction("execute_shader");
424 shader
->setName("execute_shader_2");
426 Function::arg_iterator args
= shader
->arg_begin();
427 Value
*ptr_OUT
= args
++;
428 ptr_OUT
->setName("OUT");
429 Value
*ptr_IN
= args
++;
430 ptr_IN
->setName("IN");
431 Value
*ptr_CONST
= args
++;
432 ptr_CONST
->setName("CONST");
434 BasicBlock
*label_entry
= new BasicBlock("entry", shader
, 0);
436 tgsi_parse_init(&parse
, tokens
);
438 //parse.FullHeader.Processor.Processor
440 //parse.FullVersion.Version.MajorVersion
441 //parse.FullVersion.Version.MinorVersion
443 //parse.FullHeader.Header.HeaderSize
444 //parse.FullHeader.Header.BodySize
445 //parse.FullHeader.Processor.Processor
447 fi
= tgsi_default_full_instruction();
448 fd
= tgsi_default_full_declaration();
450 while(!tgsi_parse_end_of_tokens(&parse
)) {
451 tgsi_parse_token(&parse
);
453 fprintf(stderr
, "Translating %d\n", parse
.FullToken
.Token
.Type
);
455 switch (parse
.FullToken
.Token
.Type
) {
456 case TGSI_TOKEN_TYPE_DECLARATION
:
457 translate_declaration(mod
,
458 &parse
.FullToken
.FullDeclaration
,
462 case TGSI_TOKEN_TYPE_IMMEDIATE
:
463 translate_immediate(mod
,
464 &parse
.FullToken
.FullImmediate
);
467 case TGSI_TOKEN_TYPE_INSTRUCTION
:
468 translate_instruction(mod
,
469 &parse
.FullToken
.FullInstruction
,
479 Function
* func_printf
= mod
->getFunction("printf");
483 ArrayType
* ArrayTy_0
= ArrayType::get(IntegerType::get(8), 19);
485 PointerType
* PointerTy_1
= PointerType::get(ArrayTy_0
);
487 VectorType
* VectorTy_4
= VectorType::get(Type::FloatTy
, 4);
489 PointerType
* PointerTy_3
= PointerType::get(VectorTy_4
);
492 VectorType
* VectorTy_5
= VectorType::get(IntegerType::get(32), 4);
495 PointerType
* PointerTy_8
= PointerType::get(IntegerType::get(8));
498 // Global Variable Declarations
501 GlobalVariable
* gvar_array__str
= new GlobalVariable(
504 /*Linkage=*/GlobalValue::InternalLinkage
,
505 /*Initializer=*/0, // has initializer, specified below
509 GlobalVariable
* gvar_array__str1
= new GlobalVariable(
512 /*Linkage=*/GlobalValue::InternalLinkage
,
513 /*Initializer=*/0, // has initializer, specified below
517 GlobalVariable
* gvar_array__str2
= new GlobalVariable(
520 /*Linkage=*/GlobalValue::InternalLinkage
,
521 /*Initializer=*/0, // has initializer, specified below
525 // Constant Definitions
526 Constant
* const_array_9
= ConstantArray::get("const %f %f %f %f\x0A", true);
527 Constant
* const_array_10
= ConstantArray::get("resul %f %f %f %f\x0A", true);
528 Constant
* const_array_11
= ConstantArray::get("outpu %f %f %f %f\x0A", true);
529 UndefValue
* const_packed_12
= UndefValue::get(VectorTy_4
);
530 Constant
* const_packed_13
= Constant::getNullValue(VectorTy_5
);
531 std::vector
<Constant
*> const_packed_14_elems
;
532 ConstantInt
* const_int32_15
= ConstantInt::get(APInt(32, "1", 10));
533 const_packed_14_elems
.push_back(const_int32_15
);
534 const_packed_14_elems
.push_back(const_int32_15
);
535 const_packed_14_elems
.push_back(const_int32_15
);
536 const_packed_14_elems
.push_back(const_int32_15
);
537 Constant
* const_packed_14
= ConstantVector::get(VectorTy_5
, const_packed_14_elems
);
538 std::vector
<Constant
*> const_packed_16_elems
;
539 ConstantInt
* const_int32_17
= ConstantInt::get(APInt(32, "2", 10));
540 const_packed_16_elems
.push_back(const_int32_17
);
541 const_packed_16_elems
.push_back(const_int32_17
);
542 const_packed_16_elems
.push_back(const_int32_17
);
543 const_packed_16_elems
.push_back(const_int32_17
);
544 Constant
* const_packed_16
= ConstantVector::get(VectorTy_5
, const_packed_16_elems
);
545 std::vector
<Constant
*> const_packed_18_elems
;
546 ConstantInt
* const_int32_19
= ConstantInt::get(APInt(32, "3", 10));
547 const_packed_18_elems
.push_back(const_int32_19
);
548 const_packed_18_elems
.push_back(const_int32_19
);
549 const_packed_18_elems
.push_back(const_int32_19
);
550 const_packed_18_elems
.push_back(const_int32_19
);
551 Constant
* const_packed_18
= ConstantVector::get(VectorTy_5
, const_packed_18_elems
);
552 std::vector
<Constant
*> const_ptr_20_indices
;
553 Constant
* const_int32_21
= Constant::getNullValue(IntegerType::get(32));
554 const_ptr_20_indices
.push_back(const_int32_21
);
555 const_ptr_20_indices
.push_back(const_int32_21
);
556 Constant
* const_ptr_20
= ConstantExpr::getGetElementPtr(gvar_array__str
, &const_ptr_20_indices
[0], const_ptr_20_indices
.size() );
557 UndefValue
* const_double_22
= UndefValue::get(Type::DoubleTy
);
558 std::vector
<Constant
*> const_ptr_23_indices
;
559 const_ptr_23_indices
.push_back(const_int32_21
);
560 const_ptr_23_indices
.push_back(const_int32_21
);
561 Constant
* const_ptr_23
= ConstantExpr::getGetElementPtr(gvar_array__str1
, &const_ptr_23_indices
[0], const_ptr_23_indices
.size() );
562 std::vector
<Constant
*> const_ptr_24_indices
;
563 const_ptr_24_indices
.push_back(const_int32_21
);
564 const_ptr_24_indices
.push_back(const_int32_21
);
565 Constant
* const_ptr_24
= ConstantExpr::getGetElementPtr(gvar_array__str2
, &const_ptr_24_indices
[0], const_ptr_24_indices
.size() );
567 // Global Variable Definitions
568 gvar_array__str
->setInitializer(const_array_9
);
569 gvar_array__str1
->setInitializer(const_array_10
);
570 gvar_array__str2
->setInitializer(const_array_11
);
572 // Function Definitions
574 // Function: execute_shader (func_execute_shader)
576 // Block entry (label_entry)
577 LoadInst
* packed_tmp1
= new LoadInst(ptr_IN
, "tmp1", false, label_entry
);
578 ShuffleVectorInst
* packed_tmp3
= new ShuffleVectorInst(packed_tmp1
, const_packed_12
, const_packed_13
, "tmp3", label_entry
);
579 LoadInst
* packed_tmp6
= new LoadInst(ptr_CONST
, "tmp6", false, label_entry
);
580 BinaryOperator
* packed_mul
= BinaryOperator::create(Instruction::Mul
, packed_tmp3
, packed_tmp6
, "mul", label_entry
);
581 ShuffleVectorInst
* packed_tmp8
= new ShuffleVectorInst(packed_tmp1
, const_packed_12
, const_packed_14
, "tmp8", label_entry
);
582 GetElementPtrInst
* ptr_arrayidx10
= new GetElementPtrInst(ptr_CONST
, const_int32_15
, "arrayidx10", label_entry
);
583 LoadInst
* packed_tmp11
= new LoadInst(ptr_arrayidx10
, "tmp11", false, label_entry
);
584 BinaryOperator
* packed_mul12
= BinaryOperator::create(Instruction::Mul
, packed_tmp8
, packed_tmp11
, "mul12", label_entry
);
585 BinaryOperator
* packed_add
= BinaryOperator::create(Instruction::Add
, packed_mul12
, packed_mul
, "add", label_entry
);
586 ShuffleVectorInst
* packed_tmp15
= new ShuffleVectorInst(packed_tmp1
, const_packed_12
, const_packed_16
, "tmp15", label_entry
);
587 GetElementPtrInst
* ptr_arrayidx17
= new GetElementPtrInst(ptr_CONST
, const_int32_17
, "arrayidx17", label_entry
);
588 LoadInst
* packed_tmp18
= new LoadInst(ptr_arrayidx17
, "tmp18", false, label_entry
);
589 BinaryOperator
* packed_mul19
= BinaryOperator::create(Instruction::Mul
, packed_tmp15
, packed_tmp18
, "mul19", label_entry
);
590 BinaryOperator
* packed_add21
= BinaryOperator::create(Instruction::Add
, packed_mul19
, packed_add
, "add21", label_entry
);
591 ShuffleVectorInst
* packed_tmp25
= new ShuffleVectorInst(packed_tmp1
, const_packed_12
, const_packed_18
, "tmp25", label_entry
);
592 GetElementPtrInst
* ptr_arrayidx27
= new GetElementPtrInst(ptr_CONST
, const_int32_19
, "arrayidx27", label_entry
);
593 LoadInst
* packed_tmp28
= new LoadInst(ptr_arrayidx27
, "tmp28", false, label_entry
);
594 BinaryOperator
* packed_mul29
= BinaryOperator::create(Instruction::Mul
, packed_tmp25
, packed_tmp28
, "mul29", label_entry
);
595 BinaryOperator
* packed_add31
= BinaryOperator::create(Instruction::Add
, packed_mul29
, packed_add21
, "add31", label_entry
);
596 StoreInst
* void_25
= new StoreInst(packed_add31
, ptr_OUT
, false, label_entry
);
597 GetElementPtrInst
* ptr_arrayidx33
= new GetElementPtrInst(ptr_OUT
, const_int32_15
, "arrayidx33", label_entry
);
598 GetElementPtrInst
* ptr_arrayidx35
= new GetElementPtrInst(ptr_IN
, const_int32_15
, "arrayidx35", label_entry
);
599 LoadInst
* packed_tmp36
= new LoadInst(ptr_arrayidx35
, "tmp36", false, label_entry
);
600 StoreInst
* void_26
= new StoreInst(packed_tmp36
, ptr_arrayidx33
, false, label_entry
);
601 std::vector
<Value
*> int32_call_params
;
602 int32_call_params
.push_back(const_ptr_20
);
603 int32_call_params
.push_back(const_double_22
);
604 int32_call_params
.push_back(const_double_22
);
605 int32_call_params
.push_back(const_double_22
);
606 int32_call_params
.push_back(const_double_22
);
607 //CallInst* int32_call = new CallInst(func_printf, int32_call_params.begin(), int32_call_params.end(), "call", label_entry);
608 //int32_call->setCallingConv(CallingConv::C);
609 //int32_call->setTailCall(true);
610 ExtractElementInst
* float_tmp52
= new ExtractElementInst(packed_tmp1
, const_int32_21
, "tmp52", label_entry
);
611 CastInst
* double_conv53
= new FPExtInst(float_tmp52
, Type::DoubleTy
, "conv53", label_entry
);
612 ExtractElementInst
* float_tmp55
= new ExtractElementInst(packed_tmp1
, const_int32_15
, "tmp55", label_entry
);
613 CastInst
* double_conv56
= new FPExtInst(float_tmp55
, Type::DoubleTy
, "conv56", label_entry
);
614 ExtractElementInst
* float_tmp58
= new ExtractElementInst(packed_tmp1
, const_int32_17
, "tmp58", label_entry
);
615 CastInst
* double_conv59
= new FPExtInst(float_tmp58
, Type::DoubleTy
, "conv59", label_entry
);
616 ExtractElementInst
* float_tmp61
= new ExtractElementInst(packed_tmp1
, const_int32_19
, "tmp61", label_entry
);
617 CastInst
* double_conv62
= new FPExtInst(float_tmp61
, Type::DoubleTy
, "conv62", label_entry
);
618 std::vector
<Value
*> int32_call63_params
;
619 int32_call63_params
.push_back(const_ptr_23
);
620 int32_call63_params
.push_back(double_conv53
);
621 int32_call63_params
.push_back(double_conv56
);
622 int32_call63_params
.push_back(double_conv59
);
623 int32_call63_params
.push_back(double_conv62
);
624 //CallInst* int32_call63 = new CallInst(func_printf, int32_call63_params.begin(), int32_call63_params.end(), "call63", label_entry);
625 //int32_call63->setCallingConv(CallingConv::C);
626 //int32_call63->setTailCall(true);
627 ExtractElementInst
* float_tmp65
= new ExtractElementInst(packed_add31
, const_int32_21
, "tmp65", label_entry
);
628 CastInst
* double_conv66
= new FPExtInst(float_tmp65
, Type::DoubleTy
, "conv66", label_entry
);
629 ExtractElementInst
* float_tmp68
= new ExtractElementInst(packed_add31
, const_int32_15
, "tmp68", label_entry
);
630 CastInst
* double_conv69
= new FPExtInst(float_tmp68
, Type::DoubleTy
, "conv69", label_entry
);
631 ExtractElementInst
* float_tmp71
= new ExtractElementInst(packed_add31
, const_int32_17
, "tmp71", label_entry
);
632 CastInst
* double_conv72
= new FPExtInst(float_tmp71
, Type::DoubleTy
, "conv72", label_entry
);
633 ExtractElementInst
* float_tmp74
= new ExtractElementInst(packed_add31
, const_int32_19
, "tmp74", label_entry
);
634 CastInst
* double_conv75
= new FPExtInst(float_tmp74
, Type::DoubleTy
, "conv75", label_entry
);
635 std::vector
<Value
*> int32_call76_params
;
636 int32_call76_params
.push_back(const_ptr_24
);
637 int32_call76_params
.push_back(double_conv66
);
638 int32_call76_params
.push_back(double_conv69
);
639 int32_call76_params
.push_back(double_conv72
);
640 int32_call76_params
.push_back(double_conv75
);
641 //CallInst* int32_call76 = new CallInst(func_printf, int32_call76_params.begin(), int32_call76_params.end(), "call76", label_entry);
642 //int32_call76->setCallingConv(CallingConv::C);
643 //int32_call76->setTailCall(true);
647 new ReturnInst(label_entry
);
649 //TXT("\ntgsi-dump end -------------------\n");
651 tgsi_parse_free(&parse
);
653 std::cout
<<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"<<std::endl
;
654 std::cout
<<*mod
<<std::endl
;
655 std::cout
<<"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"<<std::endl
;
659 struct ga_llvm_prog
*
660 ga_llvm_from_tgsi(struct pipe_context
*pipe
, const struct tgsi_token
*tokens
)
662 std::cout
<< "Creating llvm " <<std::endl
;
663 struct ga_llvm_prog
*ga_llvm
=
664 (struct ga_llvm_prog
*)malloc(sizeof(struct ga_llvm_prog
));
665 llvm::Module
*mod
= tgsi_to_llvm(tokens
);
667 /* Run optimization passes over it */
669 // Add an appropriate TargetData instance for this module...
670 passes
.add(new TargetData(mod
));
671 AddStandardCompilePasses(passes
);
672 std::cout
<<"Running optimization passes..."<<std::endl
;
673 bool b
= passes
.run(*mod
);
674 std::cout
<<"\tModified mod = "<<b
<<std::endl
;
676 llvm::ExistingModuleProvider
*mp
=
677 new llvm::ExistingModuleProvider(mod
);
678 llvm::ExecutionEngine
*ee
= 0;
679 if (!pipe
->llvm_execution_engine
) {
680 ee
= llvm::ExecutionEngine::create(mp
, false);
681 pipe
->llvm_execution_engine
= ee
;
683 ee
= (llvm::ExecutionEngine
*)pipe
->llvm_execution_engine
;
684 ee
->addModuleProvider(mp
);
686 ga_llvm
->module
= mod
;
687 fprintf(stderr
, "DUMPX \n");
688 //tgsi_dump(tokens, TGSI_DUMP_VERBOSE);
689 tgsi_dump(tokens
, 0);
690 fprintf(stderr
, "DUMPEND \n");
692 Function
*func
= mod
->getFunction("run_vertex_shader");
693 std::cout
<< "run_vertex_shader = "<<func
<<std::endl
;
694 ga_llvm
->function
= ee
->getPointerToFunctionOrStub(func
);
695 std::cout
<< " -- FUNC is " <<ga_llvm
->function
<<std::endl
;
700 void ga_llvm_prog_delete(struct ga_llvm_prog
*prog
)
702 llvm::Module
*mod
= static_cast<llvm::Module
*>(prog
->module
);
710 typedef void (*vertex_shader_runner
)(float (*ainputs
)[PIPE_MAX_SHADER_INPUTS
][4],
711 float (*dests
)[PIPE_MAX_SHADER_INPUTS
][4],
716 int ga_llvm_prog_exec(struct ga_llvm_prog
*prog
,
717 float (*inputs
)[PIPE_MAX_SHADER_INPUTS
][4],
718 float (*dests
)[PIPE_MAX_SHADER_INPUTS
][4],
723 std::cout
<< "---- START LLVM Execution "<<std::endl
;
724 vertex_shader_runner runner
= reinterpret_cast<vertex_shader_runner
>(prog
->function
);
725 runner(inputs
, dests
, consts
, count
, num_attribs
);
727 std::cout
<< "---- END LLVM Execution "<<std::endl
;