aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-04-20 18:26:01 +0200
committerTristan Gingold <tgingold@free.fr>2023-04-20 18:26:01 +0200
commitb72b92ad29ec7b60a3abd8b344c6bddca0c68ee8 (patch)
tree92c80b2ecc598226b2bcee6605e1c420b2e6f9e2
parentaff11ca0c49a8c0c6917bace81976a92ff7dc6b9 (diff)
downloadghdl-b72b92ad29ec7b60a3abd8b344c6bddca0c68ee8.tar.gz
ghdl-b72b92ad29ec7b60a3abd8b344c6bddca0c68ee8.tar.bz2
ghdl-b72b92ad29ec7b60a3abd8b344c6bddca0c68ee8.zip
trans-chap7: optimize is_a_derived_type for #2417
Avoid useless subtype conversions
-rw-r--r--src/vhdl/translate/trans-chap7.adb25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/vhdl/translate/trans-chap7.adb b/src/vhdl/translate/trans-chap7.adb
index 3192fe305..1fe302fe4 100644
--- a/src/vhdl/translate/trans-chap7.adb
+++ b/src/vhdl/translate/trans-chap7.adb
@@ -853,17 +853,32 @@ package body Trans.Chap7 is
function Is_A_Derived_Type (Atype : Iir; Parent_Type : Iir) return Boolean
is
Ptype : Iir;
+ T : Iir;
begin
- -- If ATYPE is a parent type of EXPR_TYPE, then all the constrained
+ -- Optimize: if PARENT_TYPE is an alias of its parent (or if it
+ -- just add a resolution function), use its parent type instead.
+ -- This mainly optimize conversions between std_ulogic_vector and
+ -- std_logic_vector.
+ Ptype := Parent_Type;
+ while Get_Kind (Ptype) = Iir_Kind_Array_Subtype_Definition
+ and then Get_Index_Constraint_List (Ptype) = Null_Iir_Flist
+ and then Get_Array_Element_Constraint (Ptype) = Null_Iir
+ loop
+ T := Get_Parent_Type (Ptype);
+ exit when T = Null_Iir;
+ Ptype := T;
+ end loop;
+
+ -- If ATYPE is a parent type of PARENT_TYPE, then all the constrained
-- are inherited and there is nothing to check.
- Ptype := Atype;
+ T := Atype;
loop
- if Ptype = Parent_Type then
+ if T = Ptype then
return True;
end if;
- exit when (Get_Kind (Ptype)
+ exit when (Get_Kind (T)
not in Iir_Kinds_Composite_Subtype_Definition);
- Ptype := Get_Parent_Type (Ptype);
+ T := Get_Parent_Type (T);
end loop;
return False;
end Is_A_Derived_Type;