Tracing nodes in selectionDAG to final code...

Hello everyone.

I use this command

clang -emit-llvm hello.c -c -o hello.bc
llc hello.bc -march=mipsel -relocation-model=static -o hello.s

to produce this MIPS code:

.section .mdebug.abi32
.previous
.file "hello.bc"
.text
.globl main
.align 2
.type main,@function
.set nomips16 # @main
.ent main
main:
.cfi_startproc
.frame $sp,32,$ra
.mask 0x80000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
# BB#0: # %entry
addiu $sp, $sp, -32
$tmp2:
.cfi_def_cfa_offset 32
sw $ra, 28($sp) # 4-byte Folded Spill
$tmp3:
.cfi_offset 31, -4
lui $2, %hi(__gnu_local_gp)
addiu $2, $2, %lo(__gnu_local_gp)
sw $2, 16($sp)
sw $zero, 24($sp)
lui $2, %hi($.str)
addiu $4, $2, %lo($.str)
jal printf
nop
addiu $2, $zero, 0
lw $ra, 28($sp) # 4-byte Folded Reload
addiu $sp, $sp, 32
jr $ra
nop
.set macro
.set reorder
.end main
$tmp4:
.size main, ($tmp4)-main
.cfi_endproc

.type $.str,@object # @.str
.section .rodata.str1.1,"aMS",@progbits,1
$.str:
.asciz "hello world\n"
.size $.str, 13

from a simple hello world example that looks like:

#include <stdio.h>

int main() {
printf("hello world\n");
   return 0;
}

I use the method I talked about at
(http://markmail.org/message/3micyhqjpgx7fwvv) to itterate over the
nodes in the selectionDAG, the operations are effectively...

-Operation EntryToken has number 0
-Operation Constant has number 1
-Operation FrameIndex has number 2
-Operation undef has number 3
-Operation store has number 4
-Operation GlobalAddress has number 5
-Operation GlobalAddress has number 6
-Operation TargetConstant has number 7
-Operation callseq_start has number 8
-Operation TargetGlobalAddress has number 9
-Operation Register has number 10
-Operation CopyToReg has number 11
-Operation RegisterMask has number 12
-Operation MipsISD::JmpLink has number 13
-Operation TargetConstant has number 14
-Operation TargetConstant has number 15
-Operation callseq_end has number 16
-Operation Register has number 17
-Operation CopyFromReg has number 18
-Operation CopyToReg has number 19
-Operation Register has number 20
-Operation MipsISD::Ret has number 21

What I'd like to know now is how I might tell which parts of MIPS each
operation in the selectionDAG produced? I'm pressuming there is a
specification in the filesystem somewhere and it would be great to get
a pointer...

Thanks

Joe

Try -debug-only=isel. It would dump the DAG nodes from a given BB after each stage of instruction selection.

-Krzysztof

What Krzysztof said and you might want to look at
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp to see when the various
stages happen during ISel (SelectionDAGISel::CodeGenAndEmitDAG()).

There are also the various -view-<some>-dag flags that you can use
with llc if you have dotty or graphviz installed to watch instruction
lowering happening in a more graphical manner.

See also http://llvm.org/docs/CodeGenerator.html#instruction-selection-section.

For code and instruction lowering description specific to MIPS look in
lib/Target/Mips/Mips-ISelLowering.cpp, -InstrInfo.td, and
-ISelDAGToDAG.cpp.