[M3commit] [modula3/cm3] 022c32: Yet another rework of M3CG_LLVM to handle non-LOOP...

GitHub noreply at github.com
Sat Jan 23 21:43:56 CET 2016


  Branch: refs/heads/master
  Home:   https://github.com/modula3/cm3
  Commit: 022c327c7d3628a4981af9744c0320ce237300ec
      https://github.com/modula3/cm3/commit/022c327c7d3628a4981af9744c0320ce237300ec
  Author: Rodney Bates <rodney.m.bates at acm.org>
  Date:   2016-01-23 (Sat, 23 Jan 2016)

  Changed paths:
    M m3-sys/llvm3.6.1/src/M3CG_LLVM.m3

  Log Message:
  -----------
  Yet another rework of M3CG_LLVM to handle non-LOOPHOLE cases of loophole operator.

The cm3 loophole IR operator was misdocumented as equivalent to Modula-3
LOOPHOLE, but this is not so.

LOOPHOLE always requires equal sizes, but the front end emits loophole
operators that call for various conversions involving different integer,
address and real sizes and different signednesses.

Inferring the complete specification of the loophole operator is difficult
and probably ambiguous, and involves extensive vetting of the front end and
all back ends.  This implementation supports a very liberal set of conversions.
Hopefully, they do what is right, at least for all the cases that can happen.

Any ZType can be converted to any other.  Shortening is always done by
truncation of high bits.  Extending is by sign extension when the final
type is signed, or zero extension otherwise.  One exception is converting
32-bit integer type to a 64-bit real.  Here, the final type gives no clue
whether to sign extend, so the decision is taken from the signedness of the
initial type.  This probably can't happen, would be irrelevant if it could,
or just doesn't make much sense, but it's there for hopeful completeness.

Meanwhile, llvm has several different operators for different cases.
bitcast requires identical sizes and either both types are pointers or
neither is a pointer.  PtrToInt and IntToPtr must be used for any conversion
to/from a pointer, but will handle size changes with zero extend or truncate.
trunc, zext, and sext work only on nonequal sized integer types.  trunc
requires converting to a properly smaller size, and zext and sext require
converting to a properly larger size.

The right thing to do would be to change CG so it emits loophole
operators only when they satisfy the contraints of the Modula-3
LOOPHOLE builtin function.  But this would entail using the IR
operators widen and chop.  These are currently not ever emitted
by CG and not implemented in some backends, making for an involved
fix.  This change makes m3llvm's handling of loophole quite
forgiving, hopefully forgiving enough.

With this change, the llvm backend mode compiles, without crashes
or unexpected errors, m3core, libm3, all of the packages in the
front group, llvmbindings, and llvm3.6.1.




More information about the M3commit mailing list