Instruction predicates work now.
This commit is contained in:
parent
9ebf731335
commit
2198db69b1
4 changed files with 251 additions and 104 deletions
|
@ -8,5 +8,8 @@
|
||||||
|
|
||||||
extern void burm_panic_cannot_match(NODEPTR_TYPE node);
|
extern void burm_panic_cannot_match(NODEPTR_TYPE node);
|
||||||
|
|
||||||
|
extern bool burm_predicate_constant_signed_16_bit(struct burm_node* node);
|
||||||
|
extern bool burm_predicate_constant_is_zero(struct burm_node* node);
|
||||||
|
|
||||||
/* vim: set sw=4 ts=4 expandtab : */
|
/* vim: set sw=4 ts=4 expandtab : */
|
||||||
|
|
||||||
|
|
19
mach/proto/mcg/powerpc_predicates.c
Normal file
19
mach/proto/mcg/powerpc_predicates.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#include "mcg.h"
|
||||||
|
|
||||||
|
bool burm_predicate_constant_signed_16_bit(struct burm_node* node)
|
||||||
|
{
|
||||||
|
struct ir* ir = node->ir;
|
||||||
|
assert(ir->opcode == IR_CONST);
|
||||||
|
return (ir->u.ivalue >= -0x8000) && (ir->u.ivalue <= 0x7fff);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool burm_predicate_constant_is_zero(struct burm_node* node)
|
||||||
|
{
|
||||||
|
struct ir* ir = node->ir;
|
||||||
|
assert(ir->opcode == IR_CONST);
|
||||||
|
return (ir->u.ivalue == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim: set sw=4 ts=4 expandtab : */
|
||||||
|
|
||||||
|
|
|
@ -1,38 +1,78 @@
|
||||||
REGISTERS
|
REGISTERS
|
||||||
|
|
||||||
r0 bytes4 int ret;
|
/* Reverse order because registers are assigned from top down. */
|
||||||
r1 bytes4 int;
|
|
||||||
r2 bytes4 int;
|
r31 bytes4 int;
|
||||||
r3 bytes4 int;
|
r30 bytes4 int;
|
||||||
r4 bytes4 int;
|
r29 bytes4 int;
|
||||||
r5 bytes4 int;
|
r28 bytes4 int;
|
||||||
r6 bytes4 int;
|
r27 bytes4 int;
|
||||||
r7 bytes4 int;
|
r26 bytes4 int;
|
||||||
r8 bytes4 int;
|
r25 bytes4 int;
|
||||||
r9 bytes4 int;
|
r24 bytes4 int;
|
||||||
r10 bytes4 int;
|
r23 bytes4 int;
|
||||||
|
r22 bytes4 int;
|
||||||
|
r21 bytes4 int;
|
||||||
|
r20 bytes4 int;
|
||||||
|
r19 bytes4 int;
|
||||||
|
r18 bytes4 int;
|
||||||
|
r17 bytes4 int;
|
||||||
|
r16 bytes4 int;
|
||||||
|
r15 bytes4 int;
|
||||||
|
r14 bytes4 int;
|
||||||
|
r13 bytes4 int;
|
||||||
|
r12 bytes4 int;
|
||||||
r11 bytes4 int;
|
r11 bytes4 int;
|
||||||
|
r10 bytes4 int;
|
||||||
|
r9 bytes4 int;
|
||||||
|
r8 bytes4 int;
|
||||||
|
r7 bytes4 int;
|
||||||
|
r6 bytes4 int;
|
||||||
|
r5 bytes4 int;
|
||||||
|
r4 bytes4 int;
|
||||||
|
r3 bytes4 int ret;
|
||||||
|
|
||||||
s0 bytes4 float;
|
f31 bytes4 bytes8 float;
|
||||||
s1 bytes4 float;
|
f30 bytes4 bytes8 float;
|
||||||
s2 bytes4 float;
|
f29 bytes4 bytes8 float;
|
||||||
s3 bytes4 float;
|
f28 bytes4 bytes8 float;
|
||||||
s4 bytes4 float;
|
f27 bytes4 bytes8 float;
|
||||||
s5 bytes4 float;
|
f26 bytes4 bytes8 float;
|
||||||
s6 bytes4 float;
|
f25 bytes4 bytes8 float;
|
||||||
s7 bytes4 float;
|
f24 bytes4 bytes8 float;
|
||||||
s8 bytes4 float;
|
f23 bytes4 bytes8 float;
|
||||||
s9 bytes4 float;
|
f22 bytes4 bytes8 float;
|
||||||
|
f21 bytes4 bytes8 float;
|
||||||
|
f20 bytes4 bytes8 float;
|
||||||
|
f19 bytes4 bytes8 float;
|
||||||
|
f18 bytes4 bytes8 float;
|
||||||
|
f17 bytes4 bytes8 float;
|
||||||
|
f16 bytes4 bytes8 float;
|
||||||
|
f15 bytes4 bytes8 float;
|
||||||
|
f14 bytes4 bytes8 float;
|
||||||
|
f13 bytes4 bytes8 float;
|
||||||
|
f12 bytes4 bytes8 float;
|
||||||
|
f11 bytes4 bytes8 float;
|
||||||
|
f10 bytes4 bytes8 float;
|
||||||
|
f9 bytes4 bytes8 float;
|
||||||
|
f8 bytes4 bytes8 float;
|
||||||
|
f7 bytes4 bytes8 float;
|
||||||
|
f6 bytes4 bytes8 float;
|
||||||
|
f5 bytes4 bytes8 float;
|
||||||
|
f4 bytes4 bytes8 float;
|
||||||
|
f3 bytes4 bytes8 float;
|
||||||
|
f2 bytes4 bytes8 float;
|
||||||
|
f1 bytes4 bytes8 float;
|
||||||
|
f0 bytes4 bytes8 float;
|
||||||
|
|
||||||
cc cc;
|
cr0 cr;
|
||||||
|
|
||||||
|
|
||||||
DECLARATIONS
|
DECLARATIONS
|
||||||
|
|
||||||
cc;
|
cr;
|
||||||
|
|
||||||
address fragment;
|
address fragment;
|
||||||
aluparam fragment;
|
|
||||||
|
|
||||||
|
|
||||||
PATTERNS
|
PATTERNS
|
||||||
|
@ -42,15 +82,22 @@ PATTERNS
|
||||||
PAIR(BLOCK4, BLOCK4);
|
PAIR(BLOCK4, BLOCK4);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Miscellaneous special things */
|
/* Miscellaneous special things */
|
||||||
|
|
||||||
PUSH4(in:(int)reg)
|
PUSH4(in:(int)reg)
|
||||||
emit "push %in"
|
emit "stwu %in, -4(sp)"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = POP4
|
out:(int)reg = POP4
|
||||||
emit "pop %out"
|
emit "lwz %out, 0(sp)"
|
||||||
cost 4;
|
emit "addi sp, sp, 4"
|
||||||
|
cost 8;
|
||||||
|
|
||||||
|
out:(float)reg = POPF4
|
||||||
|
emit "lfs %out, 0(sp)"
|
||||||
|
emit "addi sp, sp, 4"
|
||||||
|
cost 8;
|
||||||
|
|
||||||
RET
|
RET
|
||||||
emit "ret"
|
emit "ret"
|
||||||
|
@ -60,58 +107,71 @@ PATTERNS
|
||||||
emit "mov r0, %in"
|
emit "mov r0, %in"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
STACKADJUST4(delta:aluparam)
|
(ret)reg = GETRET4
|
||||||
emit "add sp, sp, %delta"
|
cost 1;
|
||||||
|
|
||||||
|
STACKADJUST4(delta:CONST4)
|
||||||
|
when constant_signed_16_bit(delta)
|
||||||
|
emit "addi sp, sp, $delta"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Memory operations */
|
/* Memory operations */
|
||||||
|
|
||||||
STORE4(addr:address, value:(int)reg)
|
STORE4(addr:address, value:(int)reg)
|
||||||
emit "str %value, %addr"
|
emit "stw %value, %addr"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
STORE2(addr:address, value:(int)reg)
|
||||||
|
emit "sth %value, %addr"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
STORE1(addr:address, value:(int)reg)
|
STORE1(addr:address, value:(int)reg)
|
||||||
emit "strb %value, %addr"
|
emit "stb %value, %addr"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = LOAD4(addr:address)
|
out:(int)reg = LOAD4(addr:address)
|
||||||
emit "ldr %out, %addr"
|
emit "lwz %out, %addr"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
out:(int)reg = LOAD2(addr:address)
|
||||||
|
emit "lhz %out, %addr"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = LOAD1(addr:address)
|
out:(int)reg = LOAD1(addr:address)
|
||||||
emit "ldrb %out, %addr"
|
emit "lbz %out, %addr"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = CIU14(LOAD1(addr:address))
|
out:(int)reg = CIU14(LOAD1(addr:address))
|
||||||
emit "ldrb %out, %addr"
|
emit "lbz %out, %addr"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = CII14(CIU41(CIU14(LOAD1(addr:address))))
|
out:(int)reg = CIU24(LOAD2(addr:address))
|
||||||
emit "ldrsb %out, %addr"
|
emit "lhz %out, %addr"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Locals */
|
/* Locals */
|
||||||
|
|
||||||
out:(int)reg = in:LOCAL4
|
out:(int)reg = in:LOCAL4
|
||||||
emit "add %out, fp, #$in"
|
emit "addi %out, fp, #$in"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
address = in:LOCAL4
|
address = in:LOCAL4
|
||||||
emit "[fp, #$in]";
|
emit "$in(fp)";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Memory addressing modes */
|
/* Memory addressing modes */
|
||||||
|
|
||||||
address = ADD4(addr:(int)reg, offset:CONST4)
|
address = ADD4(addr:(int)reg, offset:CONST4)
|
||||||
emit "[%addr, #$offset]";
|
when constant_signed_16_bit(offset)
|
||||||
|
emit "$offset(%addr)";
|
||||||
address = ADD4(addr1:(int)reg, addr2:(int)reg)
|
|
||||||
emit "[%addr1, %addr2]";
|
|
||||||
|
|
||||||
address = addr:(int)reg
|
address = addr:(int)reg
|
||||||
emit "[%addr]";
|
emit "0(%addr)";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,18 +181,18 @@ PATTERNS
|
||||||
emit "b $addr"
|
emit "b $addr"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
CJUMPEQ(value:(cc)cc, PAIR(true:BLOCK4, false:BLOCK4))
|
CJUMPEQ(value:(cr)cr, PAIR(true:BLOCK4, false:BLOCK4))
|
||||||
emit "beq $true"
|
emit "bc IFTRUE, EQ, $true"
|
||||||
emit "b $false"
|
emit "b $false"
|
||||||
cost 8;
|
cost 8;
|
||||||
|
|
||||||
CJUMPLE(value:(cc)cc, PAIR(true:BLOCK4, false:BLOCK4))
|
CJUMPLE(value:(cr)cr, PAIR(true:BLOCK4, false:BLOCK4))
|
||||||
emit "ble $true"
|
emit "bc IFTRUE, LE, $true"
|
||||||
emit "b $false"
|
emit "b $false"
|
||||||
cost 8;
|
cost 8;
|
||||||
|
|
||||||
CJUMPLT(value:(cc)cc, PAIR(true:BLOCK4, false:BLOCK4))
|
CJUMPLT(value:(cr)cr, PAIR(true:BLOCK4, false:BLOCK4))
|
||||||
emit "blt $true"
|
emit "bc IFTRUE, LT, $true"
|
||||||
emit "b $false"
|
emit "b $false"
|
||||||
cost 8;
|
cost 8;
|
||||||
|
|
||||||
|
@ -140,80 +200,134 @@ PATTERNS
|
||||||
emit "bl $dest"
|
emit "bl $dest"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
|
CALL(dest:(int)reg)
|
||||||
|
emit "mtspr ctr, %dest"
|
||||||
|
emit "bcctrl ALWAYS, 0, 0"
|
||||||
|
cost 8;
|
||||||
|
|
||||||
|
JUMP(dest:LABEL4)
|
||||||
|
emit "b $dest"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Comparisons */
|
/* Comparisons */
|
||||||
|
|
||||||
(cc)cc = COMPARES4(left:(int)reg, right:aluparam)
|
cr:(cr)cr = COMPARES4(left:(int)reg, right:(int)reg)
|
||||||
emit "cmp %left, %right"
|
emit "cmp %cr, 0, %left, %right"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
(cc)cc = COMPARES4(COMPARES4(left:(int)reg, right:aluparam), CONST4)
|
cr:(cr)cr = COMPARES4(left:(int)reg, right:CONST4)
|
||||||
emit "cmp %left, %right"
|
when constant_signed_16_bit(right)
|
||||||
|
emit "cmpi %cr, 0, %left, $right"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
cr:(cr)cr = COMPAREU4(left:(int)reg, right:(int)reg)
|
||||||
|
emit "cmpl %cr, 0, %left, %right"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
cr:(cr)cr = COMPAREU4(left:(int)reg, right:CONST4)
|
||||||
|
when constant_signed_16_bit(right)
|
||||||
|
emit "cmpli %cr, 0, %left, $right"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
cr:(cr)cr = COMPARES4(COMPARES4(left:(int)reg, right:(int)reg), result:CONST4)
|
||||||
|
when constant_is_zero(result)
|
||||||
|
emit "cmp %cr, 0, %left, %right"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
cr:(cr)cr = COMPARES4(COMPARES4(left:(int)reg, right:CONST4), result:CONST4)
|
||||||
|
when constant_is_zero(result)
|
||||||
|
when constant_signed_16_bit(right)
|
||||||
|
emit "cmpi %cr, 0, %left, $right"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
cr:(cr)cr = COMPARES4(COMPAREU4(left:(int)reg, right:(int)reg), result:CONST4)
|
||||||
|
when constant_is_zero(result)
|
||||||
|
emit "cmpl %cr, 0, %left, %right"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = (cc)cc
|
|
||||||
emit "mov %out, #0"
|
|
||||||
emit "movlt %out, #-1"
|
|
||||||
emit "movgt %out, #1"
|
|
||||||
cost 12;
|
|
||||||
|
|
||||||
|
|
||||||
/* Conversions */
|
/* Conversions */
|
||||||
|
|
||||||
out:(int)reg = CII14(CIU41(value:(int)reg))
|
out:(int)reg = CII14(CIU41(value:(int)reg))
|
||||||
emit "sxtb %out, %value"
|
emit "extsb %out, %value"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
out:(int)reg = CII24(CIU42(value:(int)reg))
|
||||||
|
emit "extsh %out, %value"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = CIU41(in:(int)reg)
|
out:(int)reg = CIU41(in:(int)reg)
|
||||||
emit "and %out, %in, #0xff"
|
emit "andi %out, %in, 0xff"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
|
out:(int)reg = CIU42(in:(int)reg)
|
||||||
|
emit "andi %out, %in, 0xffff"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
out:(int)reg = CIU44(in:(int)reg)
|
||||||
|
emit "mr %out, %in"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ALU operations */
|
/* ALU operations */
|
||||||
|
|
||||||
out:(int)reg = ADD4(left:(int)reg, right:aluparam)
|
out:(int)reg = ADD4(left:(int)reg, right:(int)reg)
|
||||||
emit "add %out, %left, %right"
|
emit "add %out, %left, %right"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = ADD4(left:aluparam, right:(int)reg)
|
out:(int)reg = ADD4(left:(int)reg, right:CONST4)
|
||||||
emit "add %out, %right, %left"
|
when constant_signed_16_bit(right)
|
||||||
|
emit "addi %out, %left, $right"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
out:(int)reg = SUB4(left:(int)reg, right:(int)reg)
|
||||||
|
emit "sub %out, %right, %left"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
|
out:(int)reg = MUL4(left:(int)reg, right:(int)reg)
|
||||||
|
emit "mullw %out, %right, %left"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = MOD4(left:(int)reg, right:(int)reg)
|
out:(int)reg = MOD4(left:(int)reg, right:(int)reg)
|
||||||
emit "udiv %out, %left, %right"
|
emit "divw %out, %left, %right"
|
||||||
emit "mls %out, %out, %right, %left"
|
emit "mullw %out, %out, %right"
|
||||||
cost 8;
|
emit "subf %out, %out, %left"
|
||||||
|
cost 12;
|
||||||
|
|
||||||
out:(int)reg = DIV4(left:(int)reg, right:aluparam)
|
out:(int)reg = DIV4(left:(int)reg, right:(int)reg)
|
||||||
emit "div %out, %left, %right"
|
emit "divw %out, %left, %right"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
aluparam = value:CONST4
|
out:(int)reg = NEG4(left:(int)reg)
|
||||||
emit "#$value";
|
emit "neg %out, %left"
|
||||||
|
cost 4;
|
||||||
|
|
||||||
aluparam = value:(int)reg
|
out:(int)reg = EOR4(left:(int)reg, right:(int)reg)
|
||||||
emit "%value";
|
emit "xor %out, %right, %left"
|
||||||
|
|
||||||
out:(int)reg = value:aluparam
|
|
||||||
emit "mov %out, %value"
|
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = value:LABEL4
|
out:(int)reg = value:LABEL4
|
||||||
emit "adr %out, $value"
|
emit "la %out, $value"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = value:BLOCK4
|
out:(int)reg = value:BLOCK4
|
||||||
emit "adr %out, $value"
|
emit "la %out, $value"
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
out:(int)reg = value:CONST4
|
out:(int)reg = value:CONST4
|
||||||
emit "ldr %out, address-containing-$value"
|
emit "la %out, $value"
|
||||||
cost 8;
|
cost 8;
|
||||||
|
|
||||||
out:(int)reg = value:CONSTF4
|
out:(int)reg = value:CONSTF4
|
||||||
emit "vldr %out, address-containing-$value"
|
emit "lfs %out, address-containing-$value"
|
||||||
cost 8;
|
cost 8;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* FPU operations */
|
/* FPU operations */
|
||||||
|
|
||||||
out:(float)reg = ADDF4(left:(float)reg, right:(float)reg)
|
out:(float)reg = ADDF4(left:(float)reg, right:(float)reg)
|
||||||
|
|
|
@ -1000,19 +1000,8 @@ static bool find_child_index(Tree node, const char* name, int* index, Tree* foun
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* emitpredicates - emit predicates for rules */
|
static void emit_predicate_expr(Rule r, struct expr* p)
|
||||||
static void emitpredicatedefinitions(Rule r)
|
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
while (r)
|
|
||||||
{
|
|
||||||
print("/* %R */\n", r);
|
|
||||||
print("static int %Padjust_cost_%d(NODEPTR_TYPE node, int cost) {\n", r->ern);
|
|
||||||
|
|
||||||
for (i=0; i<r->prefers.count; i++)
|
|
||||||
{
|
|
||||||
struct expr* p = r->prefers.item[i];
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
||||||
print("%1if (%Ppredicate_%s(", p->name);
|
print("%1if (%Ppredicate_%s(", p->name);
|
||||||
|
@ -1033,7 +1022,29 @@ static void emitpredicatedefinitions(Rule r)
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(")) cost -= 1;\n");
|
print("))");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* emitpredicates - emit predicates for rules */
|
||||||
|
static void emitpredicatedefinitions(Rule r)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
while (r)
|
||||||
|
{
|
||||||
|
print("/* %R */\n", r);
|
||||||
|
print("static int %Padjust_cost_%d(NODEPTR_TYPE node, int cost) {\n", r->ern);
|
||||||
|
|
||||||
|
for (i=0; i<r->prefers.count; i++)
|
||||||
|
{
|
||||||
|
emit_predicate_expr(r, r->prefers.item[i]);
|
||||||
|
print(" cost -= 1;\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i<r->requires.count; i++)
|
||||||
|
{
|
||||||
|
emit_predicate_expr(r, r->requires.item[i]);
|
||||||
|
print(" {} else return %d;\n", maxcost);
|
||||||
}
|
}
|
||||||
|
|
||||||
print("%1if (cost > %d) return %d;\n", maxcost, maxcost);
|
print("%1if (cost > %d) return %d;\n", maxcost, maxcost);
|
||||||
|
|
Loading…
Reference in a new issue