Skip to content

Commit

Permalink
Simplify mibc usage in the build (dotnet#50536)
Browse files Browse the repository at this point in the history
- Produce a merged mibc with all scenarios squished together
- Properly attach the mibc data to the incremental build for System.Private.CoreLib
  - This can't be done for the framework here. It will require mibc integration in the SDK
- Enable pgo optimization in checked builds
- Enable pgo optimization in framework compile for outerloop runs
  • Loading branch information
davidwrighton authored Apr 14, 2021
1 parent 9ca2a70 commit fccdca0
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- Upfront restore hooks -->
<Import Project="$(RepositoryEngineeringDir)restore\docs.targets" Condition="'$(DotNetBuildFromSource)' != 'true'" />
<Import Project="$(RepositoryEngineeringDir)restore\optimizationData.targets" Condition="'$(DotNetBuildFromSource)' != 'true' and '$(EnableNgenOptimization)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)restore\optimizationData.targets" Condition="'$(DotNetBuildFromSource)' != 'true'" />

<Target Name="BuildLocalTasks"
BeforeTargets="Build">
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@

<!--Feature switches -->
<PropertyGroup>
<EnableNgenOptimization Condition="'$(EnableNgenOptimization)' == '' and '$(Configuration)' == 'Release'">true</EnableNgenOptimization>
<EnableNgenOptimization Condition="'$(EnableNgenOptimization)' == '' and ('$(Configuration)' == 'Release' or '$(Configuration)' == 'Checked')">true</EnableNgenOptimization>
<!-- Enable NuGet static graph evaluation to optimize incremental restore -->
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation>
<!-- Turn off end of life target framework checks as we intentionally build older .NETCoreApp configurations. -->
Expand Down
31 changes: 23 additions & 8 deletions src/coreclr/crossgen-corelib.proj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<CrossGen2DllFiles Condition="'$(CrossDir)' != ''" Include="$(BinDir)/$(CrossDir)/crossgen2/*" />
</ItemGroup>

<ItemGroup>
<OptimizationMibcFiles Include="$(MibcOptimizationDataDir)/$(TargetOS)/$(TargetArchitecture)/**/*.mibc" />
</ItemGroup>

<PropertyGroup>
<CoreLibAssemblyName>System.Private.CoreLib</CoreLibAssemblyName>
<CoreLibInputPath>$([MSBuild]::NormalizePath('$(BinDir)', 'IL', '$(CoreLibAssemblyName).dll'))</CoreLibInputPath>
Expand All @@ -53,12 +57,28 @@
<CoreLibPerfMapPath></CoreLibPerfMapPath>
<CoreLibNiPdbPath Condition="$(BuildPdb)">$([MSBuild]::NormalizePath('$(BinDir)', 'PDB', '$(CoreLibAssemblyName).ni.pdb'))</CoreLibNiPdbPath>
<CoreLibPerfMapPath Condition="$(BuildPerfMap)">$([MSBuild]::NormalizePath('$(BinDir)', '$(CoreLibAssemblyName).perf.map'))</CoreLibPerfMapPath>
<MergedMibcPath>$([MSBuild]::NormalizePath('$(BinDir)', 'StandardOptimizationData.mibc'))</MergedMibcPath>
</PropertyGroup>
</Target>

<Target Name="InvokeCrossgen"
<Target Name="CreateMergedMibcFile"
DependsOnTargets="PrepareForCrossgen"
Inputs="$(CoreLibInputPath);@(CrossGen2DllFiles)"
Inputs="@(OptimizationMibcFiles)"
Outputs="$(MergedMibcPath)">

<PropertyGroup>
<DotNetPgoCmd>$(DotNetCli) $([MSBuild]::NormalizePath('$(BinDir)', 'dotnet-pgo', 'dotnet-pgo.dll')) merge</DotNetPgoCmd>
<DotNetPgoCmd>$(DotNetPgoCmd) -o:$(MergedMibcPath)</DotNetPgoCmd>
<DotNetPgoCmd>$(DotNetPgoCmd) @(OptimizationMibcFiles->'-i:%(Identity)', ' ')</DotNetPgoCmd>
</PropertyGroup>

<Message Condition="'$(DotNetBuildFromSource)' != 'true'" Importance="High" Text="$(DotNetPgoCmd)"/>
<Exec Condition="'$(DotNetBuildFromSource)' != 'true'" Command="$(DotNetPgoCmd)" />
</Target>

<Target Name="InvokeCrossgen"
DependsOnTargets="PrepareForCrossgen;CreateMergedMibcFile"
Inputs="$(CoreLibInputPath);@(CrossGen2DllFiles);$(MergedMibcPath)"
Outputs="$(CoreLibOutputPath);$(CoreLibNiPdbPath);$(CoreLibPerfMapPath)"
AfterTargets="Build">

Expand All @@ -75,17 +95,12 @@
<Message Importance="High"
Text="Generating native image of System.Private.CoreLib for $(OSPlatformConfig). Logging to $(CrossGenCoreLibLog)" />

<ItemGroup>
<OptimizationMibcFiles Include="$(MibcOptimizationDataDir)/$(TargetOS)/$(TargetArchitecture)/**/*.mibc" />
</ItemGroup>

<PropertyGroup>
<CrossGenDllCmd>$(DotNetCli) $([MSBuild]::NormalizePath('$(BinDir)', '$(CrossDir)', 'crossgen2', 'crossgen2.dll'))</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) -o:$(CoreLibOutputPath)</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) -r:$([MSBuild]::NormalizePath('$(BinDir)', 'IL', '*.dll'))</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) --targetarch:$(TargetArchitecture)</CrossGenDllCmd>
<MibcArgs>@(OptimizationMibcFiles->'-m:%(Identity)', ' ')</MibcArgs>
<CrossGenDllCmd Condition="'$(UsingToolIbcOptimization)' != 'true' and '$(Configuration)' == 'Release'">$(CrossGenDllCmd) $(MibcArgs) --embed-pgo-data</CrossGenDllCmd>
<CrossGenDllCmd Condition="'$(UsingToolIbcOptimization)' != 'true' and '$(EnableNgenOptimization)' == 'true'">$(CrossGenDllCmd) -m:$(MergedMibcPath) --embed-pgo-data</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) -O</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) $(CoreLibInputPath)</CrossGenDllCmd>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/r2rtest/BuildOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class BuildOptions
public string InputFileSearchString { get; set; }
public string ConfigurationSuffix => (Release ? "-ret.out" : "-chk.out");
public string GCStress { get; set; }
public FileInfo[] MibcPath { get; set; }
public string DotNetCli
{
get
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/tools/r2rtest/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Command CompileFolder() =>
R2RDumpPath(),
MeasurePerf(),
InputFileSearchString(),
MibcPath(),
},
CompileDirectoryCommand.CompileDirectory);

Expand Down Expand Up @@ -107,6 +108,7 @@ Command CompileSubtree() =>
ExecutionTimeoutMinutes(),
R2RDumpPath(),
GCStress(),
MibcPath(),
},
CompileSubtreeCommand.CompileSubtree);

Expand Down Expand Up @@ -137,6 +139,7 @@ Command CompileFramework() =>
MeasurePerf(),
InputFileSearchString(),
OutputDirectory(),
MibcPath(),
},
CompileFrameworkCommand.CompileFramework);

Expand All @@ -155,6 +158,7 @@ Command CompileNugetPackages() =>
DegreeOfParallelism(),
CompilationTimeoutMinutes(),
ExecutionTimeoutMinutes(),
MibcPath(),
},
CompileNugetCommand.CompileNuget);

Expand All @@ -170,6 +174,7 @@ Command CompileSerp() =>
Pdb(),
CompilationTimeoutMinutes(),
Crossgen2Path(),
MibcPath(),
},
options =>
{
Expand All @@ -195,6 +200,10 @@ Option ReferencePath() =>
new Option<DirectoryInfo[]>(new[] { "--reference-path", "-r" }, "Folder containing assemblies to reference during compilation")
{ Argument = new Argument<DirectoryInfo[]>() { Arity = ArgumentArity.ZeroOrMore }.ExistingOnly() };

Option MibcPath() =>
new Option<FileInfo[]>(new[] { "--mibc-path", "-m" }, "Mibc files to use in compilation")
{ Argument = new Argument<FileInfo[]>() { Arity = ArgumentArity.ZeroOrMore }.ExistingOnly() };

Option Crossgen() =>
new Option<bool>(new[] { "--crossgen" }, "Compile the apps using Crossgen in the CORE_ROOT folder");

Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/tools/r2rtest/Crossgen2Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ protected override IEnumerable<string> BuildCommandLineArguments(IEnumerable<str
yield return "--composite";
}

if (_options.MibcPath != null && _options.MibcPath.Length > 0)
{
yield return "--embed-pgo-data";
foreach (FileInfo mibc in _options.MibcPath)
{
yield return $"-m:{mibc.FullName}";
}
}

if (!string.IsNullOrEmpty(Crossgen2RunnerOptions.CompositeRoot))
{
yield return $"--compositerootpath={Crossgen2RunnerOptions.CompositeRoot}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project>
<Target Name="ResolveReadyToRunCompilers" DependsOnTargets="ResolveRuntimeFilesFromLocalBuild">
<ItemGroup>
<OptimizationMibcFiles Include="$(MibcOptimizationDataDir)/$(TargetOS)/$(TargetArchitecture)/**/*.mibc" />
<OptimizationMibcFiles Include="$(CoreCLRArtifactsPath)StandardOptimizationData.mibc" Condition="'$(DotNetBuildFromSource)' != 'true'" />
</ItemGroup>

<ItemGroup>
<PublishReadyToRunCrossgen2ExtraArgsList Include="--targetarch:$(TargetArchitecture)"/>

<!-- Only use mibc files if UsingToolIbcOptimization is false. Allows enabling/disabling using ibc instead of mibc data -->
<PublishReadyToRunCrossgen2ExtraArgsList Condition="'$(UsingToolIbcOptimization)' != 'true' and '$(Configuration)' == 'Release'" Include="@(OptimizationMibcFiles->'-m:%(Identity)')"/>
<PublishReadyToRunCrossgen2ExtraArgsList Condition="'$(UsingToolIbcOptimization)' != 'true' and '$(Configuration)' == 'Release'" Include="--embed-pgo-data"/>
<PublishReadyToRunCrossgen2ExtraArgsList Condition="'$(UsingToolIbcOptimization)' != 'true' and '$(EnableNgenOptimization)' == 'true'" Include="@(OptimizationMibcFiles->'-m:%(Identity)')"/>
<PublishReadyToRunCrossgen2ExtraArgsList Condition="'$(UsingToolIbcOptimization)' != 'true' and '$(EnableNgenOptimization)' == 'true'" Include="--embed-pgo-data"/>
</ItemGroup>

<!-- The following property group can be simplified once runtime repo switches over to SDK 6.0 drop -->
Expand Down
2 changes: 1 addition & 1 deletion src/tests/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ exit /b 1

set "__CrossgenOutputDir=%__TestIntermediatesDir%\crossgen.out"

set __CrossgenCmd="%__RepoRootDir%\dotnet.cmd" "%CORE_ROOT%\R2RTest\R2RTest.dll" compile-framework -cr "%CORE_ROOT%" --output-directory "%__CrossgenOutputDir%" --release --nocleanup --target-arch %__BuildArch% -dop %NUMBER_OF_PROCESSORS%
set __CrossgenCmd="%__RepoRootDir%\dotnet.cmd" "%CORE_ROOT%\R2RTest\R2RTest.dll" compile-framework -cr "%CORE_ROOT%" --output-directory "%__CrossgenOutputDir%" --release --nocleanup --target-arch %__BuildArch% -dop %NUMBER_OF_PROCESSORS% -m "%CORE_ROOT%\StandardOptimizationData.mibc"

if defined __CreatePdb (
set __CrossgenCmd=!__CrossgenCmd! --pdb
Expand Down
2 changes: 1 addition & 1 deletion src/tests/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ precompile_coreroot_fx()
fi

local outputDir="$__TestIntermediatesDir/crossgen.out"
local crossgenCmd="\"$__DotNetCli\" \"$CORE_ROOT/R2RTest/R2RTest.dll\" compile-framework -cr \"$CORE_ROOT\" --output-directory \"$outputDir\" --release --nocleanup --target-arch $__BuildArch -dop $__NumProc"
local crossgenCmd="\"$__DotNetCli\" \"$CORE_ROOT/R2RTest/R2RTest.dll\" compile-framework -cr \"$CORE_ROOT\" --output-directory \"$outputDir\" --release --nocleanup --target-arch $__BuildArch -dop $__NumProc -m \"$CORE_ROOT/StandardOptimizationData.mibc\""

if [[ "$__CompositeBuildMode" != 0 ]]; then
crossgenCmd="$crossgenCmd --composite"
Expand Down

0 comments on commit fccdca0

Please sign in to comment.