diff options
author | Quentin Carbonneaux <quentin@c9x.me> | 2017-04-08 21:06:33 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin@c9x.me> | 2017-04-08 21:56:20 -0400 |
commit | 49a4593c335126ba279f47328824abfef379725e (patch) | |
tree | 2f4cb5e9884ec958ea32a494da302a9aae8ca420 /fold.c | |
parent | 9d1c38d69547d835f7228651e71e8a7d744c456d (diff) | |
download | roux-49a4593c335126ba279f47328824abfef379725e.tar.gz |
prepare for multi-target
This big diff does multiple changes to allow the addition of new targets to qbe. The changes are listed below in decreasing order of impact. 1. Add a new Target structure. To add support for a given target, one has to implement all the members of the Target structure. All the source files where changed to use this interface where needed. 2. Single out amd64-specific code. In this commit, the amd64 target T_amd64_sysv is the only target available, it is implemented in the amd64/ directory. All the non-static items in this directory are prefixed with either amd64_ or amd64_sysv (for items that are specific to the System V ABI). 3. Centralize Ops information. There is now a file 'ops.h' that must be used to store all the available operations together with their metadata. The various targets will only select what they need; but it is beneficial that there is only *one* place to change to add a new instruction. One good side effect of this change is that any operation 'xyz' in the IL now as a corresponding 'Oxyz' in the code. 4. Misc fixes. One notable change is that instruction selection now generates generic comparison operations and the lowering to the target's comparisons is done in the emitter. GAS directives for data are the same for many targets, so data emission was extracted in a file 'gas.c'. 5. Modularize the Makefile. The Makefile now has a list of C files that are target-independent (SRC), and one list of C files per target. Each target can also use its own 'all.h' header (for example to define registers).
Diffstat (limited to 'fold.c')
-rw-r--r-- | fold.c | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/fold.c b/fold.c index 6129421..55672dd 100644 --- a/fold.c +++ b/fold.c @@ -100,7 +100,7 @@ visitins(Ins *i, Fn *fn) if (rtype(i->to) != RTmp) return; - if (opdesc[i->op].cfold) { + if (optab[i->op].canfold) { l = latval(i->arg[0]); if (!req(i->arg[1], R)) r = latval(i->arg[1]); @@ -114,7 +114,7 @@ visitins(Ins *i, Fn *fn) v = opfold(i->op, i->cls, &fn->con[l], &fn->con[r], fn); } else v = Bot; - /* fprintf(stderr, "\nvisiting %s (%p)", opdesc[i->op].name, (void *)i); */ + /* fprintf(stderr, "\nvisiting %s (%p)", optab[i->op].name, (void *)i); */ update(i->to.val, v, fn); } @@ -360,7 +360,7 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr) else if (cl->type == CAddr || cr->type == CAddr) { if (Ocmpl <= op && op <= Ocmpl1) return 1; - err("invalid address operand for '%s'", opdesc[op].name); + err("invalid address operand for '%s'", optab[op].name); } switch (op) { case Oadd: x = l.u + r.u; break; @@ -397,42 +397,42 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr) } else op -= Ocmpl - Ocmpw; switch (op - Ocmpw) { - case ICule: x = l.u <= r.u; break; - case ICult: x = l.u < r.u; break; - case ICsle: x = l.s <= r.s; break; - case ICslt: x = l.s < r.s; break; - case ICsgt: x = l.s > r.s; break; - case ICsge: x = l.s >= r.s; break; - case ICugt: x = l.u > r.u; break; - case ICuge: x = l.u >= r.u; break; - case ICeq: x = l.u == r.u; break; - case ICne: x = l.u != r.u; break; + case Ciule: x = l.u <= r.u; break; + case Ciult: x = l.u < r.u; break; + case Cisle: x = l.s <= r.s; break; + case Cislt: x = l.s < r.s; break; + case Cisgt: x = l.s > r.s; break; + case Cisge: x = l.s >= r.s; break; + case Ciugt: x = l.u > r.u; break; + case Ciuge: x = l.u >= r.u; break; + case Cieq: x = l.u == r.u; break; + case Cine: x = l.u != r.u; break; default: die("unreachable"); } } else if (Ocmps <= op && op <= Ocmps1) { switch (op - Ocmps) { - case FCle: x = l.fs <= r.fs; break; - case FClt: x = l.fs < r.fs; break; - case FCgt: x = l.fs > r.fs; break; - case FCge: x = l.fs >= r.fs; break; - case FCne: x = l.fs != r.fs; break; - case FCeq: x = l.fs == r.fs; break; - case FCo: x = l.fs < r.fs || l.fs >= r.fs; break; - case FCuo: x = !(l.fs < r.fs || l.fs >= r.fs); break; + case Cfle: x = l.fs <= r.fs; break; + case Cflt: x = l.fs < r.fs; break; + case Cfgt: x = l.fs > r.fs; break; + case Cfge: x = l.fs >= r.fs; break; + case Cfne: x = l.fs != r.fs; break; + case Cfeq: x = l.fs == r.fs; break; + case Cfo: x = l.fs < r.fs || l.fs >= r.fs; break; + case Cfuo: x = !(l.fs < r.fs || l.fs >= r.fs); break; default: die("unreachable"); } } else if (Ocmpd <= op && op <= Ocmpd1) { switch (op - Ocmpd) { - case FCle: x = l.fd <= r.fd; break; - case FClt: x = l.fd < r.fd; break; - case FCgt: x = l.fd > r.fd; break; - case FCge: x = l.fd >= r.fd; break; - case FCne: x = l.fd != r.fd; break; - case FCeq: x = l.fd == r.fd; break; - case FCo: x = l.fd < r.fd || l.fd >= r.fd; break; - case FCuo: x = !(l.fd < r.fd || l.fd >= r.fd); break; + case Cfle: x = l.fd <= r.fd; break; + case Cflt: x = l.fd < r.fd; break; + case Cfgt: x = l.fd > r.fd; break; + case Cfge: x = l.fd >= r.fd; break; + case Cfne: x = l.fd != r.fd; break; + case Cfeq: x = l.fd == r.fd; break; + case Cfo: x = l.fd < r.fd || l.fd >= r.fd; break; + case Cfuo: x = !(l.fd < r.fd || l.fd >= r.fd); break; default: die("unreachable"); } } @@ -453,7 +453,7 @@ foldflt(Con *res, int op, int w, Con *cl, Con *cr) double xd, ld, rd; if (cl->type != CBits || cr->type != CBits) - err("invalid address operand for '%s'", opdesc[op].name); + err("invalid address operand for '%s'", optab[op].name); if (w) { ld = cl->bits.d; rd = cr->bits.d; @@ -495,7 +495,7 @@ opfold(int op, int cls, Con *cl, Con *cr, Fn *fn) if ((op == Odiv || op == Oudiv || op == Orem || op == Ourem) && czero(cr, KWIDE(cls))) - err("null divisor in '%s'", opdesc[op].name); + err("null divisor in '%s'", optab[op].name); if (cls == Kw || cls == Kl) { if (foldint(&c, op, cls == Kl, cl, cr)) return Bot; |