Add custom legalization for floating point constants.
Use the simplest expansion which materializes the bits of the floating point constant as an integer and then bit-casts to the floating point type. In the future, we may want to use constant pools instead. Either way, we need custom legalization. Also add a legalize_monomorphic() function to the Python targetISA class which permits the configuration of a default legalization action for monomorphic instructions, just like legalize_type() does for polymorphic instructions.
This commit is contained in:
@@ -54,6 +54,11 @@ expand.custom_legalize(insts.heap_addr, 'expand_heap_addr')
|
||||
expand.custom_legalize(insts.trapz, 'expand_cond_trap')
|
||||
expand.custom_legalize(insts.trapnz, 'expand_cond_trap')
|
||||
|
||||
# Custom expansions for floating point constants.
|
||||
# These expansions require bit-casting or creating constant pool entries.
|
||||
expand.custom_legalize(insts.f32const, 'expand_fconst')
|
||||
expand.custom_legalize(insts.f64const, 'expand_fconst')
|
||||
|
||||
x = Var('x')
|
||||
y = Var('y')
|
||||
a = Var('a')
|
||||
|
||||
@@ -263,6 +263,16 @@ class CPUMode(object):
|
||||
ty = ValueType.by_name(name)
|
||||
self.type_legalize[ty] = xgrp
|
||||
|
||||
def legalize_monomorphic(self, xgrp):
|
||||
# type: (XFormGroup) -> None
|
||||
"""
|
||||
Configure the legalization action to take for monomorphic instructions
|
||||
which don't have a controlling type variable.
|
||||
|
||||
See also `legalize_type()` for polymorphic instructions.
|
||||
"""
|
||||
self.type_legalize[None] = xgrp
|
||||
|
||||
def get_legalize_action(self, ty):
|
||||
# type: (ValueType) -> XFormGroup
|
||||
"""
|
||||
|
||||
@@ -20,6 +20,7 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
I32.legalize_monomorphic(expand)
|
||||
I32.legalize_type(
|
||||
default=narrow,
|
||||
b1=expand,
|
||||
@@ -27,6 +28,7 @@ I32.legalize_type(
|
||||
f32=expand,
|
||||
f64=expand)
|
||||
|
||||
I64.legalize_monomorphic(expand)
|
||||
I64.legalize_type(
|
||||
default=narrow,
|
||||
b1=expand,
|
||||
|
||||
@@ -13,12 +13,14 @@ from .settings import use_m
|
||||
from cdsl.ast import Var
|
||||
from base.legalize import narrow, expand
|
||||
|
||||
RV32.legalize_monomorphic(expand)
|
||||
RV32.legalize_type(
|
||||
default=narrow,
|
||||
i32=expand,
|
||||
f32=expand,
|
||||
f64=expand)
|
||||
|
||||
RV64.legalize_monomorphic(expand)
|
||||
RV64.legalize_type(
|
||||
default=narrow,
|
||||
i32=expand,
|
||||
|
||||
Reference in New Issue
Block a user