Skip to content
Open
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
78 changes: 53 additions & 25 deletions src/coreclr/tools/Common/InstructionSetHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace System.CommandLine
internal static partial class Helpers
{
public static InstructionSetSupport ConfigureInstructionSetSupport(string instructionSet, int maxVectorTBitWidth, bool isVectorTOptimistic, TargetArchitecture targetArchitecture, TargetOS targetOS,
string mustNotBeMessage, string invalidImplicationMessage, Logger logger, bool allowOptimistic, bool isReadyToRun)
string mustNotBeMessage, string invalidImplicationMessage, Logger logger, bool allowOptimistic, bool isReadyToRun, string optimisticInstructionSetOverrides = null)
{
InstructionSetSupportBuilder instructionSetSupportBuilder = new(targetArchitecture);

Expand Down Expand Up @@ -174,17 +174,7 @@ public static InstructionSetSupport ConfigureInstructionSetSupport(string instru
// Normalize instruction set format to include implied +.
for (int i = 0; i < instructionSetParamsInput.Length; i++)
{
instructionSet = instructionSetParamsInput[i].Trim();

if (string.IsNullOrEmpty(instructionSet))
throw new CommandLineException(string.Format(mustNotBeMessage, ""));

char firstChar = instructionSet[0];

if ((firstChar != '+') && (firstChar != '-'))
{
instructionSet = "+" + instructionSet;
}
instructionSet = NormalizeInstructionSetSpecifier(instructionSetParamsInput[i], mustNotBeMessage);

if (instructionSet == "+optimistic")
{
Expand All @@ -202,19 +192,7 @@ public static InstructionSetSupport ConfigureInstructionSetSupport(string instru

foreach (string instructionSetSpecifier in instructionSetParams)
{
instructionSet = instructionSetSpecifier.Substring(1);

bool enabled = instructionSetSpecifier[0] == '+' ? true : false;
if (enabled)
{
if (!instructionSetSupportBuilder.AddSupportedInstructionSet(instructionSet))
throw new CommandLineException(string.Format(mustNotBeMessage, instructionSet));
}
else
{
if (!instructionSetSupportBuilder.RemoveInstructionSetSupport(instructionSet))
throw new CommandLineException(string.Format(mustNotBeMessage, instructionSet));
}
ApplyInstructionSetSpecifier(instructionSetSupportBuilder, instructionSetSpecifier, mustNotBeMessage);
}
}

Expand All @@ -241,6 +219,7 @@ public static InstructionSetSupport ConfigureInstructionSetSupport(string instru
// the optimistic set would be missing the explicitly unsupported sets. So we effectively clone the list and
// tack on the additional optimistic bits after. This ensures the optimistic set remains an accurate superset
InstructionSetSupportBuilder optimisticInstructionSetSupportBuilder = new InstructionSetSupportBuilder(instructionSetSupportBuilder);
InstructionSetSupportBuilder optimisticInstructionSetOverrideBuilder = new(targetArchitecture);

// Optimistically assume some instruction sets are present.
if (allowOptimistic && targetArchitecture is TargetArchitecture.X86 or TargetArchitecture.X64)
Expand Down Expand Up @@ -305,9 +284,24 @@ public static InstructionSetSupport ConfigureInstructionSetSupport(string instru
optimisticInstructionSetSupportBuilder.AddSupportedInstructionSet("sha2");
}

if (optimisticInstructionSetOverrides != null)
{
string[] optimisticInstructionSetOverrideParams = optimisticInstructionSetOverrides.Split(',');
for (int i = 0; i < optimisticInstructionSetOverrideParams.Length; i++)
{
string instructionSetSpecifier = NormalizeInstructionSetSpecifier(optimisticInstructionSetOverrideParams[i], mustNotBeMessage);
ApplyInstructionSetSpecifier(optimisticInstructionSetOverrideBuilder, instructionSetSpecifier, mustNotBeMessage);
}
}

// Vector<T> can always be part of the optimistic set, we only want to optionally exclude it from the supported set
optimisticInstructionSetSupportBuilder.ComputeInstructionSetFlags(maxVectorTBitWidth, skipAddingVectorT: false, out var optimisticInstructionSet, out _,
(string specifiedInstructionSet, string impliedInstructionSet) => throw new NotSupportedException());
optimisticInstructionSetOverrideBuilder.ComputeInstructionSetFlags(maxVectorTBitWidth, skipAddingVectorT: true, out var supportedOptimisticInstructionSetOverride, out var unsupportedOptimisticInstructionSetOverride,
(string specifiedInstructionSet, string impliedInstructionSet) =>
throw new CommandLineException(string.Format(invalidImplicationMessage, specifiedInstructionSet, impliedInstructionSet)));
optimisticInstructionSet.Add(supportedOptimisticInstructionSetOverride);
optimisticInstructionSet.Remove(unsupportedOptimisticInstructionSetOverride);
optimisticInstructionSet.Remove(unsupportedInstructionSet);
optimisticInstructionSet.Add(supportedInstructionSet);

Expand Down Expand Up @@ -349,6 +343,40 @@ public static InstructionSetSupport ConfigureInstructionSetSupport(string instru
targetArchitecture);
}

private static string NormalizeInstructionSetSpecifier(string instructionSet, string mustNotBeMessage)
{
instructionSet = instructionSet.Trim();

if (string.IsNullOrEmpty(instructionSet))
throw new CommandLineException(string.Format(mustNotBeMessage, ""));

char firstChar = instructionSet[0];

if ((firstChar != '+') && (firstChar != '-'))
{
instructionSet = "+" + instructionSet;
}

return instructionSet;
}

private static void ApplyInstructionSetSpecifier(InstructionSetSupportBuilder instructionSetSupportBuilder, string instructionSetSpecifier, string mustNotBeMessage)
{
string instructionSet = instructionSetSpecifier.Substring(1);

bool enabled = instructionSetSpecifier[0] == '+' ? true : false;
if (enabled)
{
if (!instructionSetSupportBuilder.AddSupportedInstructionSet(instructionSet))
throw new CommandLineException(string.Format(mustNotBeMessage, instructionSet));
}
else
{
if (!instructionSetSupportBuilder.RemoveInstructionSetSupport(instructionSet))
throw new CommandLineException(string.Format(mustNotBeMessage, instructionSet));
}
}

// Produces an InstructionSetSupport where the instruction sets are fixed at compile time: every
// specifiable instruction set that is not already supported is marked explicitly unsupported, and the
// supported sets are also treated as optimistic. This is used for targets without runtime code generation
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ internal class Crossgen2RootCommand : RootCommand
new("--reference", "-r") { CustomParser = result => Helpers.BuildPathDictionary(result.Tokens, false), DefaultValueFactory = result => Helpers.BuildPathDictionary(result.Tokens, false), Description = SR.ReferenceFiles };
public Option<string> InstructionSet { get; } =
new("--instruction-set") { Description = SR.InstructionSets };
public Option<string> OptimisticInstructionSetOverrides { get; } =
new("--optimistic-instruction-set") { Description = SR.OptimisticInstructionSets };
Comment on lines 25 to +28
public Option<int> MaxVectorTBitWidth { get; } =
new("--max-vectort-bitwidth") { Description = SR.MaxVectorTBitWidths };
public Option<string[]> MibcFilePaths { get; } =
Expand Down Expand Up @@ -168,6 +170,7 @@ public Crossgen2RootCommand(string[] args) : base(SR.Crossgen2BannerText)
Options.Add(UnrootedInputFilePaths);
Options.Add(ReferenceFilePaths);
Options.Add(InstructionSet);
Options.Add(OptimisticInstructionSetOverrides);
Options.Add(MaxVectorTBitWidth);
Options.Add(MibcFilePaths);
Options.Add(OutputFilePath);
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public int Run()
InstructionSetSupport instructionSetSupport = Helpers.ConfigureInstructionSetSupport(Get(_command.InstructionSet), Get(_command.MaxVectorTBitWidth), isVectorTOptimistic, targetArchitecture, targetOS,
SR.InstructionSetMustNotBe, SR.InstructionSetInvalidImplication, logger,
allowOptimistic: allowOptimistic,
isReadyToRun: true);
isReadyToRun: true,
optimisticInstructionSetOverrides: Get(_command.OptimisticInstructionSetOverrides));
if (!targetAllowsRuntimeCodeGeneration)
{
instructionSetSupport = Helpers.GetFixedInstructionSetSupport(instructionSetSupport);
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/tools/aot/crossgen2/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@
<data name="InstructionSetInvalidImplication" xml:space="preserve">
<value>Instruction set '{0}' implies support for instruction set '{1}'</value>
</data>
<data name="OptimisticInstructionSets" xml:space="preserve">
<value>Instruction set(s) to add to or remove from optimistic compilation without changing baseline requirements</value>
</data>
<data name="MaxVectorTBitWidths" xml:space="preserve">
<value>The maximum width, in bits, for System.Numerics.Vector&lt;T&gt;. For example '128', '256', or '512'.</value>
</data>
Expand Down
Loading