@@ -154,26 +154,25 @@ def eq_value(left: Value | None, right: Value) -> bool:
154154 return left is right
155155
156156
157+ # Mapping from operation names to object types
158+ ALLOC_TYPE_MAP = {
159+ "alloc_array" : ObjectType .ARRAY ,
160+ "alloc_hash" : ObjectType .HASH ,
161+ "alloc_string" : ObjectType .STRING ,
162+ "alloc_integer" : ObjectType .INTEGER ,
163+ "alloc_float" : ObjectType .FLOAT ,
164+ "alloc_symbol" : ObjectType .SYMBOL ,
165+ "alloc_range" : ObjectType .RANGE ,
166+ "alloc_regexp" : ObjectType .REGEXP ,
167+ }
168+
169+
157170def get_object_type (obj : Value ) -> ObjectType :
158171 """Get the type of an object for TBAA."""
159172 if isinstance (obj , Operation ):
160173 # Check if the object was created with a typed allocation
161- if obj .name == "alloc_array" :
162- return ObjectType .ARRAY
163- elif obj .name == "alloc_hash" :
164- return ObjectType .HASH
165- elif obj .name == "alloc_string" :
166- return ObjectType .STRING
167- elif obj .name == "alloc_integer" :
168- return ObjectType .INTEGER
169- elif obj .name == "alloc_float" :
170- return ObjectType .FLOAT
171- elif obj .name == "alloc_symbol" :
172- return ObjectType .SYMBOL
173- elif obj .name == "alloc_range" :
174- return ObjectType .RANGE
175- elif obj .name == "alloc_regexp" :
176- return ObjectType .REGEXP
174+ if obj .name in ALLOC_TYPE_MAP :
175+ return ALLOC_TYPE_MAP [obj .name ]
177176 # Return the stored type information
178177 return obj .type
179178 return ObjectType .UNKNOWN
@@ -255,22 +254,8 @@ def optimize_load_store_tbaa(bb: Block):
255254
256255 elif op .name .startswith ("alloc_" ):
257256 # Typed allocation - set the type on the operation
258- if op .name == "alloc_array" :
259- op .type = ObjectType .ARRAY
260- elif op .name == "alloc_hash" :
261- op .type = ObjectType .HASH
262- elif op .name == "alloc_string" :
263- op .type = ObjectType .STRING
264- elif op .name == "alloc_integer" :
265- op .type = ObjectType .INTEGER
266- elif op .name == "alloc_float" :
267- op .type = ObjectType .FLOAT
268- elif op .name == "alloc_symbol" :
269- op .type = ObjectType .SYMBOL
270- elif op .name == "alloc_range" :
271- op .type = ObjectType .RANGE
272- elif op .name == "alloc_regexp" :
273- op .type = ObjectType .REGEXP
257+ if op .name in ALLOC_TYPE_MAP :
258+ op .type = ALLOC_TYPE_MAP [op .name ]
274259
275260 opt_bb .append (op )
276261 return opt_bb
0 commit comments