Skip to content

Commit 9c1c27b

Browse files
author
Nathan Ricci
authored
[Mono] Actually AOT things in AOT mode; prevent JIT fall back (#1966)
1 parent 41a1517 commit 9c1c27b

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private static Job CreateAotJob(Job baseJob, CommandLineOptions options, Runtime
410410

411411
private static Job MakeMonoAOTLLVMJob(Job baseJob, CommandLineOptions options, string msBuildMoniker)
412412
{
413-
var monoAotLLVMRuntime = new MonoAotLLVMRuntime(aotCompilerPath: options.AOTCompilerPath, msBuildMoniker: msBuildMoniker);
413+
var monoAotLLVMRuntime = new MonoAotLLVMRuntime(aotCompilerPath: options.AOTCompilerPath, aotCompilerMode: options.AOTCompilerMode, msBuildMoniker: msBuildMoniker);
414414

415415
var toolChain = MonoAotLLVMToolChain.From(
416416
new NetCoreAppSettings(

src/BenchmarkDotNet/Environments/Runtimes/MonoAotLLVMRuntime.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using BenchmarkDotNet.Extensions;
55
using BenchmarkDotNet.Jobs;
6+
using BenchmarkDotNet.Toolchains.MonoAotLLVM;
67

78
namespace BenchmarkDotNet.Environments
89
{
@@ -12,20 +13,22 @@ public class MonoAotLLVMRuntime : Runtime, IEquatable<MonoAotLLVMRuntime>
1213
internal static readonly MonoAotLLVMRuntime Default = new MonoAotLLVMRuntime();
1314

1415
public FileInfo AOTCompilerPath { get; }
16+
public MonoAotCompilerMode AOTCompilerMode { get; }
1517

1618
public override bool IsAOT => true;
1719

1820
/// <summary>
1921
/// creates new instance of MonoAotLLVMRuntime
2022
/// </summary>
21-
public MonoAotLLVMRuntime(FileInfo aotCompilerPath, string msBuildMoniker = "net6.0", string displayName = "MonoAOTLLVM") : base(RuntimeMoniker.MonoAOTLLVM, msBuildMoniker, displayName)
23+
public MonoAotLLVMRuntime(FileInfo aotCompilerPath, MonoAotCompilerMode aotCompilerMode, string msBuildMoniker = "net6.0", string displayName = "MonoAOTLLVM") : base(RuntimeMoniker.MonoAOTLLVM, msBuildMoniker, displayName)
2224
{
2325
if (aotCompilerPath == null)
2426
throw new ArgumentNullException(paramName: nameof(aotCompilerPath));
2527
if (aotCompilerPath.IsNotNullButDoesNotExist())
2628
throw new FileNotFoundException($"Provided {nameof(aotCompilerPath)} file: \"{aotCompilerPath.FullName}\" doest NOT exist");
2729

2830
AOTCompilerPath = aotCompilerPath;
31+
AOTCompilerMode = aotCompilerMode;
2932
}
3033

3134
// this ctor exists only for the purpose of having .Default property that returns something consumable by RuntimeInformation.GetCurrentRuntime()

src/BenchmarkDotNet/Extensions/ProcessExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
using BenchmarkDotNet.Portability;
1111
using BenchmarkDotNet.Running;
1212
using BenchmarkDotNet.Toolchains.CoreRun;
13+
using BenchmarkDotNet.Toolchains.MonoAotLLVM;
1314
using JetBrains.Annotations;
1415

16+
1517
namespace BenchmarkDotNet.Extensions
1618
{
1719
// we need it public to reuse it in the auto-generated dll
@@ -129,6 +131,16 @@ internal static void SetEnvironmentVariables(this ProcessStartInfo start, Benchm
129131
// disable ReSharper's Dynamic Program Analysis (see https://github.com/dotnet/BenchmarkDotNet/issues/1871 for details)
130132
start.EnvironmentVariables["JETBRAINS_DPA_AGENT_ENABLE"] = "0";
131133

134+
if (benchmarkCase.Job.Infrastructure.Toolchain is MonoAotLLVMToolChain)
135+
{
136+
MonoAotLLVMRuntime aotruntime = (MonoAotLLVMRuntime)benchmarkCase.GetRuntime();
137+
138+
if (aotruntime.AOTCompilerMode == MonoAotCompilerMode.llvm)
139+
{
140+
start.EnvironmentVariables["MONO_ENV_OPTIONS"] = "--full-aot";
141+
}
142+
}
143+
132144
if (!benchmarkCase.Job.HasValue(EnvironmentMode.EnvironmentVariablesCharacteristic))
133145
return;
134146

src/BenchmarkDotNet/Templates/MonoAOTLLVMCsProj.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,29 @@
4040

4141
<PropertyGroup>
4242
<PublishDirFullPath>$([System.IO.Path]::GetFullPath($(PublishDir)))</PublishDirFullPath>
43+
<SharedLibraryType Condition="$([MSBuild]::IsOSPlatform('OSX'))">Dylib</SharedLibraryType>
44+
<SharedLibraryType Condition="$([MSBuild]::IsOSPlatform('Windows'))">Dll</SharedLibraryType>
45+
<SharedLibraryType Condition="$([MSBuild]::IsOSPlatform('Linux'))">So</SharedLibraryType>
46+
<SharedLibraryType Condition="$([MSBuild]::IsOSPlatform('FreeBSD'))">Dll</SharedLibraryType>
4347
</PropertyGroup>
4448

4549
<ItemGroup>
4650
<AotInputAssemblies Include="$(PublishDirFullPath)\*.dll">
47-
<AotArguments>@(MonoAOTCompilerDefaultAotArguments, ';')</AotArguments>
51+
<AotArguments>@(MonoAOTCompilerDefaultAotArguments, ';');mcpu=native</AotArguments>
4852
<ProcessArguments>@(MonoAOTCompilerDefaultProcessArguments, ';')</ProcessArguments>
4953
</AotInputAssemblies>
5054
</ItemGroup>
5155

56+
5257
<MonoAOTCompiler
5358
CompilerBinaryPath="$COMPILERBINARYPATH$"
54-
Mode="Normal"
55-
OutputType="Normal"
59+
Mode="Full"
60+
OutputType="Library"
61+
LibraryFormat="$(SharedLibraryType)"
5662
Assemblies="@(AotInputAssemblies)"
5763
UseLLVM="$USELLVM$"
5864
LLVMPath="$(MicrosoftNetCoreAppRuntimePackDir)\runtimes\$(RuntimeIdentifier)\native"
59-
OutputDir="$(PublishDir)"
65+
OutputDir="$(PublishDir)"
6066
UseAotDataFile="false"
6167
IntermediateOutputPath="$(IntermediateOutputPath)">
6268
<Output TaskParameter="CompiledAssemblies" ItemName="BundleAssemblies" />

0 commit comments

Comments
 (0)