Create value aliases when necessary.

If a secondary value in the source pattern becomes a primary value in
the destination pattern, it is not possible to overwrite the definition
of the source value.

Instead, change the original source value to an alias to the new promary
value.
This commit is contained in:
Jakob Stoklund Olesen
2016-11-04 14:49:31 -07:00
parent d34ec1bd06
commit 6f1a60366f
2 changed files with 13 additions and 0 deletions

View File

@@ -16,3 +16,6 @@ ebb0(v1: i32, v2: i32):
} }
; check: $v3 = iadd $v1, $v2 ; check: $v3 = iadd $v1, $v2
; check: $(cout=$V) = icmp ult, $v3, $v1 ; check: $(cout=$V) = icmp ult, $v3, $v1
; It's possible the legalizer will rewrite these value aliases in the future.
; check: $v4 -> $cout
; check: return $v3, $v4

View File

@@ -106,6 +106,7 @@ def emit_dst_inst(node, fmt):
# type: (Def, Formatter) -> None # type: (Def, Formatter) -> None
exact_replace = False exact_replace = False
replaced_inst = None # type: str replaced_inst = None # type: str
fixup_first_result = False
if len(node.defs) == 0: if len(node.defs) == 0:
# This node doesn't define any values, so just insert the new # This node doesn't define any values, so just insert the new
# instruction. # instruction.
@@ -125,6 +126,7 @@ def emit_dst_inst(node, fmt):
# Insert a new instruction since its primary def doesn't match the # Insert a new instruction since its primary def doesn't match the
# src. # src.
builder = 'let {} = dfg.ins(pos)'.format(wrap_tup(node.defs)) builder = 'let {} = dfg.ins(pos)'.format(wrap_tup(node.defs))
fixup_first_result = node.defs[0].is_output()
fmt.line('{}.{};'.format(builder, node.expr.rust_builder())) fmt.line('{}.{};'.format(builder, node.expr.rust_builder()))
@@ -139,6 +141,14 @@ def emit_dst_inst(node, fmt):
if exact_replace: if exact_replace:
fmt.comment('exactreplacement') fmt.comment('exactreplacement')
# Fix up any output vars.
if fixup_first_result:
# The first result of the instruction just inserted is an output var,
# but it was not a primary result in the source pattern.
# We need to change the original value to an alias of the primary one
# we just inserted.
fmt.line('dfg.change_to_alias(src_{0}, {0});'.format(node.defs[0]))
def gen_xform(xform, fmt): def gen_xform(xform, fmt):
# type: (XForm, Formatter) -> None # type: (XForm, Formatter) -> None