Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,18 +564,21 @@ private void PublishCode()
_methodCodeNode.InitializeDebugLocInfos(_debugLocInfos);
_methodCodeNode.InitializeDebugVarInfos(_debugVarInfos);
#if READYTORUN
MethodDesc[] inlineeArray;
if (_inlinedMethods != null)
if (!_compilation.NodeFactory.OptimizationFlags.StripInliningInfo)
Comment thread
jkotas marked this conversation as resolved.
Resolved
{
inlineeArray = new MethodDesc[_inlinedMethods.Count];
_inlinedMethods.CopyTo(inlineeArray);
Array.Sort(inlineeArray, TypeSystemComparer.Instance.Compare);
}
else
{
inlineeArray = Array.Empty<MethodDesc>();
MethodDesc[] inlineeArray;
if (_inlinedMethods != null)
{
inlineeArray = new MethodDesc[_inlinedMethods.Count];
_inlinedMethods.CopyTo(inlineeArray);
Array.Sort(inlineeArray, TypeSystemComparer.Instance.Compare);
}
else
{
inlineeArray = Array.Empty<MethodDesc>();
}
_methodCodeNode.InitializeInliningInfo(inlineeArray, _compilation.NodeFactory);
}
_methodCodeNode.InitializeInliningInfo(inlineeArray, _compilation.NodeFactory);

if (RequiresInstructionSetSupportFixup())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,10 @@ static void Validate(ReadyToRunReader reader)
}
}

[ConditionalFact(typeof(TestPaths), nameof(TestPaths.IsNotWasmTarget))]
public void BasicCrossModuleInlining()
[ConditionalTheory(typeof(TestPaths), nameof(TestPaths.IsNotWasmTarget))]
[InlineData(false)]
[InlineData(true)]
public void BasicCrossModuleInlining(bool stripInliningInfo)
{
var inlineableLib = new CompiledAssembly
{
Expand All @@ -525,16 +527,26 @@ public void BasicCrossModuleInlining()

new R2RTestRunner(_output).Run(new R2RTestCase(
nameof(BasicCrossModuleInlining),
[new CrossgenCompilation(basicCrossModuleInlining.AssemblyName, [cgInlineableLib, cgBasicCrossModuleInlining]) { Validate = Validate }])
[new CrossgenCompilation(basicCrossModuleInlining.AssemblyName, [cgInlineableLib, cgBasicCrossModuleInlining])
{
AdditionalArgs = stripInliningInfo ? ["--strip-inlining-info"] : [],
Validate = Validate,
}])
);

static void Validate(ReadyToRunReader reader)
void Validate(ReadyToRunReader reader)
{
string diag;
Assert.True(R2RAssert.HasManifestRef(reader, "InlineableLib", out diag), diag);
Assert.True(R2RAssert.HasCrossModuleInlinedMethod(reader, "TestGetValue", "GetValue", out diag), diag);
Assert.True(R2RAssert.HasCrossModuleInlinedMethod(reader, "TestGetString", "GetString", out diag), diag);
Assert.True(R2RAssert.HasCrossModuleInliningInfo(reader, out diag), diag);
Assert.True(R2RAssert.HasFixupKindOnMethod(reader, ReadyToRunFixupKind.Check_IL_Body, "TestGetValue", out diag), diag);
Assert.True(R2RAssert.HasFixupKindOnMethod(reader, ReadyToRunFixupKind.Check_IL_Body, "TestGetString", out diag), diag);
Assert.Equal(!stripInliningInfo, reader.ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSectionType.CrossModuleInlineInfo));
if (!stripInliningInfo)
{
Assert.True(R2RAssert.HasCrossModuleInlinedMethod(reader, "TestGetValue", "GetValue", out diag), diag);
Assert.True(R2RAssert.HasCrossModuleInlinedMethod(reader, "TestGetString", "GetString", out diag), diag);
Assert.True(R2RAssert.HasCrossModuleInliningInfo(reader, out diag), diag);
}
}
}

Expand Down Expand Up @@ -1681,8 +1693,10 @@ static void Validate(ReadyToRunReader reader)
}
}

[ConditionalFact(typeof(TestPaths), nameof(TestPaths.IsNotWasmTarget))]
public void TransitiveReferences()
[ConditionalTheory(typeof(TestPaths), nameof(TestPaths.IsNotWasmTarget))]
[InlineData(false)]
[InlineData(true)]
public void TransitiveReferences(bool stripInliningInfo)
{
var externalLib = new CompiledAssembly()
{
Expand Down Expand Up @@ -1713,12 +1727,18 @@ public void TransitiveReferences()
},
])
{
AdditionalArgs = stripInliningInfo ? ["--strip-inlining-info"] : [],
Validate = reader =>
{
string diag;
Assert.True(R2RAssert.HasManifestRef(reader, "InlineableLibTransitive", out diag), diag);
Assert.True(R2RAssert.HasManifestRef(reader, "ExternalLib", out diag), diag);
Assert.True(R2RAssert.HasCrossModuleInlinedMethod(reader, "TestTransitiveValue", "GetExternalValue", out diag), diag);
Assert.True(R2RAssert.HasFixupKindOnMethod(reader, ReadyToRunFixupKind.Check_IL_Body, "TestTransitiveValue", out diag), diag);
Assert.Equal(!stripInliningInfo, reader.ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSectionType.CrossModuleInlineInfo));
if (!stripInliningInfo)
{
Assert.True(R2RAssert.HasCrossModuleInlinedMethod(reader, "TestTransitiveValue", "GetExternalValue", out diag), diag);
}
},
},
]));
Expand Down Expand Up @@ -2391,8 +2411,10 @@ static void Validate(ReadyToRunReader reader)
/// Validates that inlining info (CrossModuleInlineInfo or InliningInfo2) is
/// properly populated (CompositeBasic only validates ManifestRef).
/// </summary>
[ConditionalFact(typeof(TestPaths), nameof(TestPaths.IsNotWasmTarget))]
public void CompositeCrossModuleInlining()
[ConditionalTheory(typeof(TestPaths), nameof(TestPaths.IsNotWasmTarget))]
[InlineData(false)]
[InlineData(true)]
public void CompositeCrossModuleInlining(bool stripInliningInfo)
{
var inlineableLib = new CompiledAssembly
{
Expand All @@ -2416,15 +2438,22 @@ public void CompositeCrossModuleInlining()
])
{
Options = [Crossgen2Option.Composite, Crossgen2Option.Optimize],
AdditionalArgs = stripInliningInfo ? ["--strip-inlining-info"] : [],
Validate = Validate,
},
]));

static void Validate(ReadyToRunReader reader)
void Validate(ReadyToRunReader reader)
{
string diag;
Assert.True(R2RAssert.HasManifestRef(reader, "InlineableLib", out diag), diag);
Assert.True(R2RAssert.HasInlinedMethod(reader, "TestGetValue", "GetValue", out diag), diag);
Assert.NotEmpty(reader.ReadyToRunAssemblyHeaders);
Assert.All(reader.ReadyToRunAssemblyHeaders, header =>
Assert.Equal(!stripInliningInfo, header.Sections.ContainsKey(ReadyToRunSectionType.InliningInfo2)));
if (!stripInliningInfo)
{
Assert.True(R2RAssert.HasInlinedMethod(reader, "TestGetValue", "GetValue", out diag), diag);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3751,8 +3751,11 @@ private void beginInlining(CORINFO_METHOD_STRUCT_* inlinerHnd, CORINFO_METHOD_ST
{
_stashedPrecodeFixups.Push(_precodeFixups);
_precodeFixups = null;
_stashedInlinedMethods.Push(_inlinedMethods);
_inlinedMethods = null;
if (!_compilation.NodeFactory.OptimizationFlags.StripInliningInfo)
{
_stashedInlinedMethods.Push(_inlinedMethods);
_inlinedMethods = null;
}
}

private void reportInliningDecision(CORINFO_METHOD_STRUCT_* inlinerHnd, CORINFO_METHOD_STRUCT_* inlineeHnd, CorInfoInline inlineResult, byte* reason)
Expand Down Expand Up @@ -3787,20 +3790,21 @@ inlineeModule is not null &&
classMustBeLoadedBeforeCodeIsRun(inlineeModule.GetGlobalModuleType());
}

// If during inlining we found new inlinees, then if the inline was successful, add them to the set of fixups
// for the entire method.
HashSet<MethodDesc> previouslyStashedInlinees = _stashedInlinedMethods.Pop();
if (_inlinedMethods != null)
if (!_compilation.NodeFactory.OptimizationFlags.StripInliningInfo)
{
previouslyStashedInlinees = previouslyStashedInlinees ?? new HashSet<MethodDesc>();
foreach (var inlineeInHashSet in _inlinedMethods)
previouslyStashedInlinees.Add(inlineeInHashSet);
}
_inlinedMethods = previouslyStashedInlinees;
// Propagate nested inlinees only when the enclosing inline succeeds.
HashSet<MethodDesc> previouslyStashedInlinees = _stashedInlinedMethods.Pop();
if (_inlinedMethods != null)
{
previouslyStashedInlinees = previouslyStashedInlinees ?? new HashSet<MethodDesc>();
foreach (var inlineeInHashSet in _inlinedMethods)
previouslyStashedInlinees.Add(inlineeInHashSet);
}
_inlinedMethods = previouslyStashedInlinees;

// Then add the fact we inlined this method.
_inlinedMethods = _inlinedMethods ?? new HashSet<MethodDesc>();
_inlinedMethods.Add(inlinee);
_inlinedMethods = _inlinedMethods ?? new HashSet<MethodDesc>();
_inlinedMethods.Add(inlinee);
}

var typicalMethod = inlinee.GetTypicalMethodDefinition();

Expand Down Expand Up @@ -3852,7 +3856,10 @@ inlineeModule is not null &&
{
// If we didn't succeed on the inline, just pop back to the state before inlining
_precodeFixups = _stashedPrecodeFixups.Pop();
_inlinedMethods = _stashedInlinedMethods.Pop();
if (!_compilation.NodeFactory.OptimizationFlags.StripInliningInfo)
{
_inlinedMethods = _stashedInlinedMethods.Pop();
}
}
}

Expand Down
Loading