Skip to content

Commit dacbb29

Browse files
committed
[interp] Inline more AggressiveInlining methods
By default, the interpreter stops inlining when encountering a call that it cannot inline or a throw. Inline the method anyway if the aggressive inlining attribute is present.
1 parent a66b4e3 commit dacbb29

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/mono/mono/mini/interp/transform.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,7 @@ interp_inline_method (TransformData *td, MonoMethod *target_method, MonoMethodHe
26502650
int prev_n_data_items;
26512651
int i;
26522652
int prev_sp_offset;
2653+
int prev_aggressive_inlining;
26532654
MonoGenericContext *generic_context = NULL;
26542655
StackInfo *prev_param_area;
26552656
InterpBasicBlock **prev_offset_to_bb;
@@ -2676,6 +2677,7 @@ interp_inline_method (TransformData *td, MonoMethod *target_method, MonoMethodHe
26762677
prev_offset_to_bb = td->offset_to_bb;
26772678
prev_cbb = td->cbb;
26782679
prev_entry_bb = td->entry_bb;
2680+
prev_aggressive_inlining = td->aggressive_inlining;
26792681
td->inlined_method = target_method;
26802682

26812683
prev_max_stack_height = td->max_stack_height;
@@ -2691,7 +2693,7 @@ interp_inline_method (TransformData *td, MonoMethod *target_method, MonoMethodHe
26912693

26922694
int const prev_code_size = td->code_size;
26932695
td->code_size = header->code_size;
2694-
2696+
td->aggressive_inlining = !!(target_method->iflags & METHOD_IMPL_ATTRIBUTE_AGGRESSIVE_INLINING);
26952697
if (td->verbose_level)
26962698
g_print ("Inline start method %s.%s\n", m_class_get_name (target_method->klass), target_method->name);
26972699

@@ -2736,6 +2738,7 @@ interp_inline_method (TransformData *td, MonoMethod *target_method, MonoMethodHe
27362738
td->offset_to_bb = prev_offset_to_bb;
27372739
td->code_size = prev_code_size;
27382740
td->entry_bb = prev_entry_bb;
2741+
td->aggressive_inlining = prev_aggressive_inlining;
27392742

27402743
g_free (td->in_offsets);
27412744
td->in_offsets = prev_in_offsets;
@@ -2973,7 +2976,7 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target
29732976
}
29742977

29752978
/* Don't inline methods that do calls */
2976-
if (op == -1 && td->inlined_method)
2979+
if (op == -1 && td->inlined_method && !td->aggressive_inlining)
29772980
return FALSE;
29782981

29792982
/* We need to convert delegate invoke to a indirect call on the interp_invoke_impl field */
@@ -5453,7 +5456,8 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
54535456
// Inlining failed. Set the method to be executed as part of newobj instruction
54545457
newobj_fast->data [0] = get_data_item_index (td, mono_interp_get_imethod (domain, m, error));
54555458
/* The constructor was not inlined, abort inlining of current method */
5456-
INLINE_FAILURE;
5459+
if (!td->aggressive_inlining)
5460+
INLINE_FAILURE;
54575461
} else {
54585462
interp_add_ins (td, MINT_NEWOBJ);
54595463
g_assert (!m_class_is_valuetype (klass));
@@ -5589,7 +5593,8 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
55895593

55905594
break;
55915595
case CEE_THROW:
5592-
INLINE_FAILURE;
5596+
if (!td->aggressive_inlining)
5597+
INLINE_FAILURE;
55935598
CHECK_STACK (td, 1);
55945599
interp_add_ins (td, MINT_THROW);
55955600
interp_ins_set_sreg (td->last_ins, td->sp [-1].local);

src/mono/mono/mini/interp/transform.h

+3
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ typedef struct
192192
GList *dont_inline;
193193
int inline_depth;
194194
int has_localloc : 1;
195+
// If the current method (inlined_method) has the aggressive inlining attribute, we no longer
196+
// bail out of inlining when having to generate certain opcodes (like call, throw).
197+
int aggressive_inlining : 1;
195198
} TransformData;
196199

197200
#define STACK_TYPE_I4 0

0 commit comments

Comments
 (0)