From a460a637ddd4e35acc468c01528ead973c50751b Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 27 Sep 2016 07:59:47 -0700 Subject: [PATCH] Add legalization patterns. --- meta/cretonne/legalize.py | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 meta/cretonne/legalize.py diff --git a/meta/cretonne/legalize.py b/meta/cretonne/legalize.py new file mode 100644 index 0000000000..14eb879abd --- /dev/null +++ b/meta/cretonne/legalize.py @@ -0,0 +1,48 @@ +""" +Patterns for legalizing the `base` instruction set. + +The base Cretonne instruction set is 'fat', and many instructions don't have +legal representations in a given target ISA. This module defines legalization +patterns that describe how base instructions can be transformed to other base +instructions that are legal. +""" +from __future__ import absolute_import +from .base import iadd, iadd_cout, iadd_cin, isplit_lohi, iconcat_lohi +from .base import isub, isub_bin, isub_bout +from .ast import Var +from .xform import Rtl, XFormGroup + + +narrow = XFormGroup() + +x = Var('x') +y = Var('y') +a = Var('a') +b = Var('b') +c = Var('c') +xl = Var('xl') +xh = Var('xh') +yl = Var('yl') +yh = Var('yh') +al = Var('al') +ah = Var('ah') + +narrow.legalize( + a << iadd(x, y), + Rtl( + (xl, xh) << isplit_lohi(x), + (yl, yh) << isplit_lohi(y), + (al, c) << iadd_cout(xl, yl), + ah << iadd_cin(xh, yh, c), + a << iconcat_lohi(al, ah) + )) + +narrow.legalize( + a << isub(x, y), + Rtl( + (xl, xh) << isplit_lohi(x), + (yl, yh) << isplit_lohi(y), + (al, b) << isub_bout(xl, yl), + ah << isub_bin(xh, yh, b), + a << iconcat_lohi(al, ah) + ))