Skip to content

Commit

Permalink
Add more context for unexpected errors in optimizer step (dotnet/link…
Browse files Browse the repository at this point in the history
…er#3113)

Co-authored-by: Vitek Karas <10670590+vitek-karas@users.noreply.github.com>

Commit migrated from dotnet/linker@13b8d6d
  • Loading branch information
marek-safar authored Nov 14, 2022
1 parent 255c5ea commit 0ca803f
Showing 1 changed file with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,32 @@ public void ProcessMethod (MethodDefinition method)

var reducer = new BodyReducer (method.Body, _context);

//
// If no external dependency can be extracted into constant there won't be
// anything to optimize in the method
//
if (!reducer.ApplyTemporaryInlining (this))
return;
try {
//
// If no external dependency can be extracted into constant there won't be
// anything to optimize in the method
//
if (!reducer.ApplyTemporaryInlining (this))
return;

//
// This is the main step which evaluates if any expression can
// produce folded branches. When it finds them the unreachable
// branch is removed.
//
if (reducer.RewriteBody ())
_context.LogMessage ($"Reduced '{reducer.InstructionsReplaced}' instructions in conditional branches for [{method.DeclaringType.Module.Assembly.Name}] method '{method.GetDisplayName ()}'.");
//
// This is the main step which evaluates if any expression can
// produce folded branches. When it finds them the unreachable
// branch is removed.
//
if (reducer.RewriteBody ())
_context.LogMessage ($"Reduced '{reducer.InstructionsReplaced}' instructions in conditional branches for [{method.DeclaringType.Module.Assembly.Name}] method '{method.GetDisplayName ()}'.");

//
// Note: The inliner cannot run before reducer rewrites body as it
// would require another recomputing offsets due to instructions replacement
// done by inliner
//
var inliner = new CallInliner (method.Body, this);
inliner.RewriteBody ();
//
// Note: The inliner cannot run before reducer rewrites body as it
// would require another recomputing offsets due to instructions replacement
// done by inliner
//
var inliner = new CallInliner (method.Body, this);
inliner.RewriteBody ();
} catch (Exception e) {
throw new InternalErrorException ($"Could not process the body of method '{method.GetDisplayName ()}'.", e);
}
}

static bool IsMethodSupported (MethodDefinition method)
Expand Down

0 comments on commit 0ca803f

Please sign in to comment.