Commit 1f5f74c9 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Add sparc_emitf() to make the SPARC emitter more readable.

parent 99585f06
This diff is collapsed.
......@@ -35,26 +35,28 @@
#include "bearch_sparc_t.h"
/**
* indent before instruction. (Adds additional indentation when emitting
* delay slots)
* fmt parameter output
* ---- ---------------------- -------------------------------
* %% %
* %Dx <node> destination register x
* %E <node> entity+offset
* %F <node> floating point mode
* %H <node> high immediate
* %L <node> control flow target of the node
* %ML <node> load mode
* %MS <node> store mode
* %R arch_register_t const* register
* %Sx <node> source register x
* %SIx <node> immediate or source register x
* %d signed int signed int
* %s const char* string
* %u unsigned int unsigned int
*
* x starts at 0
* %#M prints load modeu
* + may be used with %d and %u
*/
void sparc_emit_indent(void);
void sparc_emit_immediate(const ir_node *node);
void sparc_emit_high_immediate(const ir_node *node);
void sparc_emit_mode(const ir_node *node);
void sparc_emit_source_register(const ir_node *node, int pos);
void sparc_emit_reg_or_imm(const ir_node *node, int pos);
void sparc_emit_dest_register(const ir_node *node, int pos);
void sparc_emit_offset(const ir_node *node, int offset_node_pos);
void sparc_emit_load_mode(const ir_node *node);
void sparc_emit_store_mode(const ir_node *node);
void sparc_emit_float_load_store_mode(const ir_node *node);
void sparc_emit_source_reg_and_offset(const ir_node *node, int regpos,
int offpos);
void sparc_emit_fp_mode_suffix(const ir_node *node);
void sparc_emit_fp_conv_source(const ir_node *node);
void sparc_emit_fp_conv_destination(const ir_node *node);
void sparc_emitf(ir_node const *node, char const *fmt, ...);
void sparc_emit_routine(ir_graph *irg);
......
......@@ -99,29 +99,6 @@ $mode_fp4 = "mode_Q";
]
); # %reg_classes
%emit_templates = (
# emit source reg or imm dep. on node's arity
RI => "${arch}_emit_reg_or_imm(node, -1);",
R1I => "${arch}_emit_reg_or_imm(node, 1);",
R2I => "${arch}_emit_reg_or_imm(node, 2);",
S0 => "${arch}_emit_source_register(node, 0);",
S1 => "${arch}_emit_source_register(node, 1);",
D0 => "${arch}_emit_dest_register(node, 0);",
D1 => "${arch}_emit_dest_register(node, 1);",
HIM => "${arch}_emit_high_immediate(node);",
LM => "${arch}_emit_load_mode(node);",
SM => "${arch}_emit_store_mode(node);",
FLSM => "${arch}_emit_float_load_store_mode(node);",
FPM => "${arch}_emit_fp_mode_suffix(node);",
FCONVS => "${arch}_emit_fp_conv_source(node);",
FCONVD => "${arch}_emit_fp_conv_destination(node);",
O1 => "${arch}_emit_offset(node, 1);",
O2 => "${arch}_emit_offset(node, 2);",
S0O1 => "${arch}_emit_source_reg_and_offset(node, 0, 1);",
S1O2 => "${arch}_emit_source_reg_and_offset(node, 1, 2);",
);
$indent_line_func = "sparc_emit_indent()";
$default_attr_type = "sparc_attr_t";
$default_copy_attr = "sparc_copy_attr";
......@@ -264,20 +241,20 @@ my %float_unop_constructors = (
Add => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. add %S0, %R1I, %D0',
emit => 'add %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
AddCC => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. addcc %S0, %R1I, %D0',
emit => 'addcc %S0, %SI1, %D0',
outs => [ "res", "flags" ],
constructors => \%binopcc_operand_constructors,
},
AddCCZero => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. addcc %S0, %R1I, %%g0',
emit => 'addcc %S0, %SI1, %%g0',
mode => $mode_flags,
constructors => \%binopcczero_operand_constructors,
},
......@@ -286,7 +263,7 @@ AddX => {
# At the moment not rematerializable because of assert in beflags.c/
# (it claims that spiller can't rematerialize flag stuff correctly)
#irn_flags => [ "rematerializable" ],
emit => '. addx %S0, %R1I, %D0',
emit => 'addx %S0, %SI1, %D0',
constructors => \%binopx_operand_constructors,
mode => $mode_gp,
},
......@@ -307,27 +284,27 @@ AddX_t => {
Sub => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. sub %S0, %R1I, %D0',
emit => 'sub %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
SubCC => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. subcc %S0, %R1I, %D0',
emit => 'subcc %S0, %SI1, %D0',
outs => [ "res", "flags" ],
constructors => \%binopcc_operand_constructors,
},
SubCCZero => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. subcc %S0, %R1I, %%g0',
emit => 'subcc %S0, %SI1, %%g0',
mode => $mode_flags,
constructors => \%binopcczero_operand_constructors,
},
SubX => {
# Not rematerializable (see AddX)
emit => '. subx %S0, %R1I, %D0',
emit => 'subx %S0, %SI1, %D0',
constructors => \%binopx_operand_constructors,
mode => $mode_gp,
},
......@@ -366,7 +343,7 @@ Ld => {
ins => [ "ptr", "mem" ],
outs => [ "res", "M" ],
attr_type => "sparc_load_store_attr_t",
emit => '. ld%LM [%S0O1], %D0'
emit => 'ld%ML [%S0%O1], %D0'
},
SetHi => {
......@@ -376,7 +353,7 @@ SetHi => {
reg_req => { in => [], out => [ "gp" ] },
attr => "ir_entity *entity, int32_t immediate_value",
custominit => "sparc_set_attr_imm(res, entity, immediate_value);",
emit => '. sethi %HIM, %D0'
emit => 'sethi %H, %D0'
},
St => {
......@@ -400,11 +377,11 @@ St => {
ins => [ "val", "ptr", "mem" ],
outs => [ "M" ],
attr_type => "sparc_load_store_attr_t",
emit => '. st%SM %S0, [%S1O2]'
emit => 'st%MS %S0, [%S1%O2]'
},
Save => {
emit => '. save %S0, %R1I, %D0',
emit => 'save %S0, %SI1, %D0',
outs => [ "stack" ],
ins => [ "stack" ],
constructors => {
......@@ -442,7 +419,7 @@ RestoreZero => {
reg_req => { in => [ "sp", "frame_pointer" ], out => [ "sp:I|S" ] },
ins => [ "stack", "frame_pointer" ],
outs => [ "stack" ],
emit => '. restore',
emit => 'restore',
mode => $mode_gp,
},
......@@ -466,7 +443,7 @@ AddSP => {
reg_req => { in => [ "sp", "gp" ], out => [ "sp:I|S" ] },
ins => [ "stack", "size" ],
outs => [ "stack" ],
emit => ". add %S0, %S1, %D0\n",
emit => "add %S0, %S1, %D0\n",
mode => $mode_gp,
},
......@@ -571,7 +548,7 @@ Call => {
Cmp => { # aka SubccZero
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. cmp %S0, %R1I',
emit => 'cmp %S0, %SI1',
mode => $mode_flags,
constructors => \%binopcczero_operand_constructors,
},
......@@ -590,34 +567,34 @@ SwitchJmp => {
Sll => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. sll %S0, %R1I, %D0',
emit => 'sll %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
Srl => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. srl %S0, %R1I, %D0',
emit => 'srl %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
Sra => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. sra %S0, %R1I, %D0',
emit => 'sra %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
And => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. and %S0, %R1I, %D0',
emit => 'and %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
AndCCZero => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. andcc %S0, %R1I, %%g0',
emit => 'andcc %S0, %SI1, %%g0',
mode => $mode_flags,
constructors => \%binopcczero_operand_constructors,
},
......@@ -625,13 +602,13 @@ AndCCZero => {
AndN => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. andn %S0, %R1I, %D0',
emit => 'andn %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
AndNCCZero => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. andncc %S0, %R1I, %%g0',
emit => 'andncc %S0, %SI1, %%g0',
mode => $mode_flags,
constructors => \%binopcczero_operand_constructors,
},
......@@ -639,13 +616,13 @@ AndNCCZero => {
Or => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. or %S0, %R1I, %D0',
emit => 'or %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
OrCCZero => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. orcc %S0, %R1I, %%g0',
emit => 'orcc %S0, %SI1, %%g0',
mode => $mode_flags,
constructors => \%binopcczero_operand_constructors,
},
......@@ -653,13 +630,13 @@ OrCCZero => {
OrN => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. orn %S0, %R1I, %D0',
emit => 'orn %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
OrNCCZero => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. orncc %S0, %R1I, %%g0',
emit => 'orncc %S0, %SI1, %%g0',
mode => $mode_flags,
constructors => \%binopcczero_operand_constructors,
},
......@@ -667,13 +644,13 @@ OrNCCZero => {
Xor => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. xor %S0, %R1I, %D0',
emit => 'xor %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
XorCCZero => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. xorcc %S0, %R1I, %%g0',
emit => 'xorcc %S0, %SI1, %%g0',
mode => $mode_flags,
constructors => \%binopcczero_operand_constructors,
},
......@@ -681,13 +658,13 @@ XorCCZero => {
XNor => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. xnor %S0, %R1I, %D0',
emit => 'xnor %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
XNorCCZero => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. xnorcc %S0, %R1I, %%g0',
emit => 'xnorcc %S0, %SI1, %%g0',
mode => $mode_flags,
constructors => \%binopcczero_operand_constructors,
},
......@@ -695,13 +672,13 @@ XNorCCZero => {
Mul => {
irn_flags => [ "rematerializable" ],
mode => $mode_gp,
emit => '. smul %S0, %R1I, %D0',
emit => 'smul %S0, %SI1, %D0',
constructors => \%binop_operand_constructors,
},
MulCCZero => {
irn_flags => [ "rematerializable", "modifies_flags" ],
emit => '. smulcc %S0, %R1I, %%g0',
emit => 'smulcc %S0, %SI1, %%g0',
mode => $mode_flags,
constructors => \%binopcczero_operand_constructors,
},
......@@ -709,12 +686,16 @@ MulCCZero => {
SMulh => {
irn_flags => [ "rematerializable" ],
outs => [ "low", "high" ],
emit => 'smul %S0, %SI1, %D0\n'.
'mov %%y, %D0',
constructors => \%binop_operand_constructors,
},
UMulh => {
irn_flags => [ "rematerializable" ],
outs => [ "low", "high" ],
emit => 'umul %S0, %SI1, %D0\n'.
'mov %%y, %D0',
constructors => \%binop_operand_constructors,
},
......@@ -736,7 +717,7 @@ UDiv => {
fcmp => {
irn_flags => [ "rematerializable", "modifies_fp_flags" ],
emit => '. fcmp%FPM %S0, %S1',
emit => 'fcmp%FM %S0, %S1',
attr_type => "sparc_fp_attr_t",
attr => "ir_mode *fp_mode",
mode => $mode_fpflags,
......@@ -756,7 +737,7 @@ fcmp => {
fadd => {
op_flags => [ "commutative" ],
irn_flags => [ "rematerializable" ],
emit => '. fadd%FPM %S0, %S1, %D0',
emit => 'fadd%FM %S0, %S1, %D0',
attr_type => "sparc_fp_attr_t",
attr => "ir_mode *fp_mode",
ins => [ "left", "right" ],
......@@ -765,7 +746,7 @@ fadd => {
fsub => {
irn_flags => [ "rematerializable" ],
emit => '. fsub%FPM %S0, %S1, %D0',
emit => 'fsub%FM %S0, %S1, %D0',
attr_type => "sparc_fp_attr_t",
attr => "ir_mode *fp_mode",
ins => [ "left", "right" ],
......@@ -775,7 +756,7 @@ fsub => {
fmul => {
irn_flags => [ "rematerializable" ],
op_flags => [ "commutative" ],
emit =>'. fmul%FPM %S0, %S1, %D0',
emit =>'fmul%FM %S0, %S1, %D0',
attr_type => "sparc_fp_attr_t",
attr => "ir_mode *fp_mode",
ins => [ "left", "right" ],
......@@ -784,7 +765,7 @@ fmul => {
fdiv => {
irn_flags => [ "rematerializable" ],
emit => '. fdiv%FPM %S0, %S1, %D0',
emit => 'fdiv%FM %S0, %S1, %D0',
attr_type => "sparc_fp_attr_t",
attr => "ir_mode *fp_mode",
ins => [ "left", "right" ],
......@@ -806,7 +787,7 @@ fneg => {
irn_flags => [ "rematerializable" ],
reg_req => { in => [ "fp" ], out => [ "fp" ] },
# note that we only need the first register even for wide-values
emit => '. fnegs %S0, %D0',
emit => 'fnegs %S0, %D0',
attr_type => "sparc_fp_attr_t",
attr => "ir_mode *fp_mode",
ins => [ "val" ],
......@@ -816,7 +797,7 @@ fneg => {
"fabs" => {
irn_flags => [ "rematerializable" ],
# note that we only need the first register even for wide-values
emit => '. fabs %S0, %D0',
emit => 'fabs %S0, %D0',
attr_type => "sparc_fp_attr_t",
attr => "ir_mode *fp_mode",
ins => [ "val" ],
......@@ -825,7 +806,7 @@ fneg => {
fftof => {
irn_flags => [ "rematerializable" ],
emit => '. f%FCONVS%.to%FCONVD %S0, %D0',
emit => 'f%FSto%FD %S0, %D0',
attr_type => "sparc_fp_conv_attr_t",
attr => "ir_mode *src_mode, ir_mode *dest_mode",
constructors => {
......@@ -858,7 +839,7 @@ fftof => {
fitof => {
irn_flags => [ "rematerializable" ],
emit => '. fito%FPM %S0, %D0',
emit => 'fito%FM %S0, %D0',
attr_type => "sparc_fp_attr_t",
attr => "ir_mode *fp_mode",
constructors => {
......@@ -879,7 +860,7 @@ fitof => {
fftoi => {
irn_flags => [ "rematerializable" ],
emit => '. f%FPM%.toi %S0, %D0',
emit => 'f%FMtoi %S0, %D0',
attr_type => "sparc_fp_attr_t",
attr => "ir_mode *fp_mode",
mode => $mode_gp,
......@@ -915,7 +896,7 @@ Ldf => {
attr_type => "sparc_load_store_attr_t",
attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
emit => '. ld%FLSM [%S0%O1], %D0'
emit => 'ld%ML [%S0%O1], %D0'
},
Stf => {
......@@ -937,7 +918,7 @@ Stf => {
attr_type => "sparc_load_store_attr_t",
attr => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
emit => '. st%FLSM %S0, [%S1%O2]',
emit => 'st%MS %S0, [%S1%O2]',
mode => 'mode_M',
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment