Commit graph

169 commits

Author SHA1 Message Date
David Given ed91ea4371 When parsing constants which don't fit into an arith, handle overflow properly
(and don't turn them all into INT_MAX...).
2018-09-22 12:45:59 +02:00
David Given 79e7636537 Teach the code generator about the zero register and how to efficiently access
the stack.
2018-09-22 11:49:13 +02:00
David Given 99fcde69dc Take hreg aliases into account when finding evicted registers and performing
the register shuffle dance.
2018-09-22 11:19:50 +02:00
David Given bbb708717a Add the OPTIONS clause to the mcgg grammar; add an optional pass which converts
sequences of PUSHes to a single STACKADJUST followed by STOREs. This should
dramatically improve code on stack-unfriendly architectures like MIPS.
2018-09-22 11:19:00 +02:00
David Given 65a20ce2d6 Fix subtle register corruption bug where aliases weren't taken into account
when assigning input registers to phis, which could cause the same hreg to be
assigned to two vregs of different types. Also improve tracing.
2018-09-20 23:24:46 +02:00
David Given ac856f3b09 The approach I was taking to csa and csb turns out not to work --- critical
edge splitting can cause new basic blocks to be added to the graph, but while
the graph itself gets properly rewritten the descriptor tables can't be updated
to take these into account, so they end up pointing at the wrong blocks. This
causes really hard-to-debug problems.

The new approach is to parse the descriptor blocks and then generate a
comparison chain. Brute force, but much easier for the compiler to reason
about.
2018-09-20 00:12:03 +02:00
David Given 52ee317878 Fixed some bad mcg ir code generation: only nodes which have been appendir'd
may be used multiple times.
2018-09-18 23:32:53 +02:00
David Given f362d12dee Add extern declaration which I forget to check in. 2018-09-17 23:59:49 +02:00
David Given fe177bd688 Add specialist rules for signed integer comparisons; much better code. 2018-09-17 23:53:18 +02:00
David Given c2dc1e184e rotate() now generates valid code. 2018-09-17 13:13:39 +01:00
David Given 642956fa2f mcg now uses dataf4 and dataf8 to emit floating point constants, and so doesn't
need flt_arith any more. (And also generates them correctly on little-endian
systems.) as now parses numbers properly, doesn't trash memory all over the
place, and can handle negative numbers.
2018-09-12 23:19:32 +02:00
David Given d2c14ca44f Precisely one stack hreg gets allocated for each vreg/congruence group for
eviction; this prevents us from having to worry about moving values from stack
slot to stack slot, which is hard.
2018-09-08 18:59:55 +02:00
David Given fc0b0ae178 (Slightly) better errors on phi congruence group mismatches. 2018-09-05 23:53:08 +02:00
George Koehler a60738a50d Don't use '-' in option string to getopt().
Using '-' might fail on platforms like FreeBSD.  Commit 50a7031
stopped using '-' in the B compiler and ego.  I now stop using '-' in
mcg, because I can now check that mcg still works.
2018-02-05 14:55:10 -05:00
George Koehler 9077b3a5ab Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.

Add or correct some EM instructions in treebuilder.c:
 - "lof", "stf": handle negative offsets in load() and store().
 - "cuu": add using IR_FROMUI.
 - "lim", "sim": keep an entire word in ".ignmask", to be compatible
   with mach/powerpc/libem/trp.s and ncg.  We also keep a word in
   ".ignmask" in ncg for both i386 and m68020.
 - "trp": pass trap number in register.  See comment in
   helper_function_with_arg().
 - "sig": push the old value of .trppc on the stack.
 - "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
   connect to helper functions in libem.
 - "blm", "bls": drop call to memmove() and use new helper ".bls4",
   because tests/plat/structcopy_e.c can't call memmove().
 - "xor s", "cms s": if s is large, fall back on helper function.
 - "rol", "ror": add by decomposing each rotate into 4 IR ops.
 - "rck s", "bls s": make fatal unless s is word size.
 - "loi": push multiple loads in the correct order.
 - "dup s", "exg s": if s is large, fall back on helper.
 - "dus": add using new helper ".dus4".
 - "lxl", "lxa": follow the static chain, not the dynamic chain.
 - "lor 1": materialise the stack before pushing the stack pointer.
 - "lor 2", "str 2": make fatal.
 - "los", "sts": drop calls to memcpy() and use helpers ".los4" and
   and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
 - "gto": correctly read descriptor.

Change mach/powerpc/mcg/table:
 - ANY.L: add for "asp -8".
 - LOAD.L: work around register corruption.
 - COMPAREUL.I: add for "cms 8".
2018-01-31 21:05:40 -05:00
David Given 81c677d218 Add a bunch more set operations to the PowerPC backends, and the Pascal test
for the same.
2017-01-17 22:31:38 +01:00
David Given e7e29d34ff Add a test (currently failing) to check that Pascal char sets can store all 256
possible values. Add the PowerPC ncg and mcg backend support to let the test
actually run, including modifying a bunch of PowrePC libem functions so that
they can be called from both ncg and mcg.
2017-01-15 22:28:14 +01:00
David Given efab08178b Fix a bunch of issues with pushing and popping mismatched sizes, which the B
compiler does a lot; dup 8 for pairs of words is now optimised.
2017-01-07 18:47:00 +01:00
David Given 7710c76d56 Introduce sequence points before store instructions to prevent loads from the
same address being delayed until after the store (at which point they'll return
the wrong value).
2017-01-07 13:17:39 +01:00
David Given fbd6e8f63d Add support for consecutive labels; needed by the B compiler. 2016-11-27 21:18:00 +01:00
David Given 953c08839f inn works now; add a helper for it. 2016-11-20 12:53:44 +01:00
David Given 196fa914b3 lxa now works, I hope; traps are better (and stubbed out on qemuppc). 2016-11-20 11:57:21 +01:00
David Given d5328492d7 Better handling of float conversions; more tests; converting to unsigned ints
works now.
2016-11-20 11:27:40 +01:00
David Given cc660b230f Floats and doubles are now written out correctly. 2016-11-19 11:39:13 +01:00
David Given d31bc6a3f9 Made csa and csb work with mcg; adjust the libem functions and the
corresponding invocation in the ncg table so the same helpers can be used for
both mcg and ncg. Add a new IR opcode, FARJUMP, which jumps to a helper
function but saves volatile registers.
2016-11-19 10:55:41 +01:00
David Given 43439c6d0c Remember to push the result of lor onto the stack. 2016-11-17 22:04:32 +01:00
David Given 81bc2c74c5 A bb's regsin are no longer the same as those of its first instruction;
occasionally the first hop of a block would try to rearrange its registers (due
to evicted throughs), resulting in the phi moves copying values into the wrong
registers.
2016-11-16 20:52:15 +01:00
David Given 581fa4a457 Reenable eviction of corrupted registers, which had been broken by a previous
change. Change the register move code to get swaps right, or at least righter.
2016-11-15 21:55:10 +01:00
David Given 0289b1004e Allow values left on the stack at the end of the procedure (it's legal!). 2016-11-14 21:47:49 +01:00
David Given 852d3a691d Update the table to return call output values in the right registers. Fix the
register allocator so the corrupted registers only apply to throughs
(otherwise, you can't put output registers in corrupted registers).
2016-11-11 21:48:36 +01:00
David Given b5c1d622f5 Rework the way stack frames are laid out to be simpler and, hopefully, more
correct. Saved registers are now placed in what may be the right place.
2016-11-11 21:17:45 +01:00
David Given 4fa2c94a4a Correctly mangle labels used in initialisers. 2016-10-31 23:21:33 +01:00
David Given e19850b114 Fix a few c11isms. 2016-10-30 16:51:06 +01:00
David Given ca5b6e07bb Properly export symbols. 2016-10-29 23:52:17 +02:00
David Given 8c3670483f Get top working with the PowerPC; use it to eliminate useless branches and
moves.
2016-10-29 23:37:11 +02:00
David Given a311e61360 Add support for preserved registers. 2016-10-29 20:22:44 +02:00
David Given e3ebf986e9 More opcodes. 2016-10-29 13:32:09 +02:00
David Given acaae765af Emit negative constants correctly. 2016-10-29 12:55:21 +02:00
David Given 61349389fb More opcodes. sti can now cope with non-standard sizes (really need a better
fix for this). Hack in crude support for mismatched stack pushes and pops (ints
vs longs).
2016-10-29 12:48:05 +02:00
David Given 2cc2c0ae98 Lots more opcodes. Rearrange the stack layout so that fp->ab is a fixed value
(needed for CHAINFP and FPTOAB). Wire up lfrs to calls via a phi when
necessary, to allow call-bra-lfr chains.
2016-10-29 11:57:56 +02:00
David Given bfa65168e2 Don't generate phis if unnecessary (because this breaks the
critical-edge-splitting guarantee and causes insertion of phi copies to fail).
2016-10-29 10:55:48 +02:00
David Given 658db4ba71 Mangle label names (turns out that the ACK assembler can't really cope with
labels that are the same name as instructions...).
2016-10-27 23:17:16 +02:00
David Given 81525c0f2c Swaps work (at least for registers). More opcodes. Rearrange the stack layout
so we can always trivially find fp, which lets CHAINFP work.
2016-10-27 21:50:58 +02:00
David Given be3dece5af Allow emission of strings containing ". 2016-10-27 21:48:46 +02:00
David Given 51bd3ee4dd Fix bug where some phis weren't being inserted when a given variable definition
needed more than one phi (due to the dominance frontier containing more than
one basic block).
2016-10-27 21:40:25 +02:00
David Given 9977ce841a Remove the bytes1, bytes2, bytes4, bytes8 attributes; remove the concept of a
register 'type'; now use int/float/long/double throughout to identify
registers. Lots of register allocator tweaks and table bugfixes --- we now get
through the dreading Mathlib.mod!
2016-10-25 23:04:20 +02:00
David Given 45a7f2e993 Phi copies are now inserted as part of type inference. More opcodes. 2016-10-24 22:14:08 +02:00
David Given 111c13e253 More opcodes. 2016-10-24 20:15:22 +02:00
David Given a4644dee4d More opcodes. 2016-10-24 12:08:40 +02:00
David Given b22780c075 More opcodes, including the difficult and fairly stupid los/sts. 2016-10-23 22:24:08 +02:00