mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
2a2781edff
This pragma forces compiler to align loop headers within the function by architecture specific boundary: 32 bytes on X64 and ARM64 (with the exception of Apple Silicon, which explicitly discourages aligning branch targets in the optimization manual). Current implementation is rather naive and does not do any attempt to decide whether aligning is actually profitable based on loop body itself. I have found this pragma to be helpful both to stabilize benchmark results and achieve better performance for tight loops on Intel hardware. Issue https://github.com/dart-lang/sdk/issues/55522 TEST=vm/dart/align_loops_test Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-arm64-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-product-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-aot-win-product-x64-try,vm-aot-win-release-arm64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-simriscv64-try,vm-aot-dwarf-linux-product-x64-try,vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try Change-Id: Ic22fb90d85e7fdebeeaa3908a43328c59436ab58 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364121 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Slava Egorov <vegorov@google.com>
98 lines
3 KiB
Dart
Executable file
98 lines
3 KiB
Dart
Executable file
#!tools/sdks/dart-sdk/bin/dart
|
|
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:pool/pool.dart';
|
|
|
|
final pool = Pool(Platform.numberOfProcessors);
|
|
|
|
main(List<String> args) async {
|
|
final sdkRoot = Platform.script.resolve('../').toFilePath();
|
|
Directory.current = Directory(sdkRoot);
|
|
|
|
final extractedOffsetsFile =
|
|
'runtime/vm/compiler/runtime_offsets_extracted.h';
|
|
|
|
final old = File(extractedOffsetsFile).readAsStringSync();
|
|
final header = old.substring(0, old.indexOf('\n#if '));
|
|
final footer = old.substring(old.lastIndexOf('\n#endif '));
|
|
|
|
// Build all configurations
|
|
await forAllConfigurationsMode(
|
|
(String buildDir, String mode, String arch) async {
|
|
print('Building $buildDir');
|
|
await run([
|
|
'tools/build.py',
|
|
...args,
|
|
'-a$arch',
|
|
'-m$mode',
|
|
'--no-rbe',
|
|
'offsets_extractor',
|
|
'offsets_extractor_precompiled_runtime'
|
|
]);
|
|
print('Building $buildDir - done');
|
|
});
|
|
|
|
final (jit, aot) = await (
|
|
forAllConfigurationsMode((String buildDir, _, __) async {
|
|
return await run(['$buildDir/offsets_extractor']);
|
|
}).then<String>((lines) => lines.join('\n')),
|
|
forAllConfigurationsMode((String buildDir, _, __) async {
|
|
return await run(['$buildDir/offsets_extractor_precompiled_runtime']);
|
|
}).then<String>((lines) => lines.join('\n')),
|
|
).wait;
|
|
|
|
if (exitCode == 0) {
|
|
final output = StringBuffer();
|
|
output.writeln(header);
|
|
output.writeln(jit);
|
|
output.writeln(aot);
|
|
output.writeln(footer);
|
|
File(extractedOffsetsFile).writeAsStringSync(output.toString());
|
|
print('Written $extractedOffsetsFile');
|
|
print('Running `git cl format $extractedOffsetsFile');
|
|
await run(['git', 'cl', 'format', extractedOffsetsFile]);
|
|
}
|
|
}
|
|
|
|
Future<List<T>> forAllConfigurationsMode<T>(
|
|
Future<T> Function(String buildDir, String mode, String arch) fun) async {
|
|
final archs = [
|
|
'simarm',
|
|
'x64',
|
|
'ia32',
|
|
'simarm64',
|
|
'x64c',
|
|
'simarm64c',
|
|
'simriscv32',
|
|
'simriscv64',
|
|
];
|
|
final futures = <Future<T>>[];
|
|
for (final mode in ['release', 'product']) {
|
|
for (final arch in archs) {
|
|
final buildDir = 'out/${mode.capitalized}${arch.upper}/';
|
|
futures.add(pool.withResource(() => fun(buildDir, mode, arch)));
|
|
}
|
|
}
|
|
return await Future.wait(futures);
|
|
}
|
|
|
|
Future<String> run(List<String> args) async {
|
|
final result =
|
|
await Process.run(args.first, args.skip(1).toList(), runInShell: true);
|
|
if (result.exitCode != 0) {
|
|
exitCode = result.exitCode;
|
|
print('Running ${args.join(' ')} has failed with exit code $exitCode:');
|
|
print('${result.stdout}');
|
|
print('${result.stderr}');
|
|
}
|
|
return result.stdout;
|
|
}
|
|
|
|
extension on String {
|
|
String get capitalized => substring(0, 1).toUpperCase() + substring(1);
|
|
String get upper => toUpperCase();
|
|
}
|