Reland "[vm/compiler] Consistently use PointerBase.data values as FFiIntPtr."

This is a reland of commit 60d1a40462

Original change's description:
> Reland "[vm/compiler] Consistently use PointerBase.data values as FFiIntPtr."
>
> This is a reland of commit 5c4fd50667
>
> The range analysis change was replaced with a different change,
> on which this CL is based. In addition, another preceding CL
> unified a few methods on subclasses of UnboxIntegerOpInstr, because
> the inconsistencies between UnboxInt32OpInstr and UnboxUint32OpInstr
> and how unboxed int32 vs. uint32 constants were handled caused the
> issue seen after landing the original CL.
>
> Thus, this CL is purely changes of kUnboxedIntPtr to kUnboxedFfiIntPtr
> when appropriate plus test changes.
>
> TEST=vm/dart/regress_306327173_il_test
>      vm/dart/address_local_pointer_il_test
>
> Original change's description:
> > [vm/compiler] Consistently use PointerBase.data values as FFiIntPtr.
> >
> > Also if converting an unboxed int with only non-negative values
> > that fit in 32 bits to a uint32, then keep the range from the value.
> >
> > TEST=regress_306327173_il_test
> >
> > Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try
> > Change-Id: Id9e7c2d5f477e560822a02574739c57d77b5a6d1
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332202
> > Reviewed-by: Daco Harkes <dacoharkes@google.com>
> > Reviewed-by: Slava Egorov <vegorov@google.com>
> > Commit-Queue: Tess Strickland <sstrickl@google.com>
>
> Change-Id: I1f66bc9d1ca7569c913f02b611b4a27f189605ac
> Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-android-release-arm-try
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332340
> Reviewed-by: Daco Harkes <dacoharkes@google.com>
> Commit-Queue: Tess Strickland <sstrickl@google.com>

TEST=vm/dart/regress_306327173_il_test
     vm/dart/address_local_pointer_il_test

Change-Id: I8f789847670c66a823cbbc6dca5b74a8b7a2cd88
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-android-release-arm-try,vm-linux-release-simarm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333002
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
This commit is contained in:
Tess Strickland 2023-11-01 12:47:59 +00:00 committed by Commit Queue
parent 3a6daede9a
commit 0dc86856ca
3 changed files with 32 additions and 47 deletions

View file

@ -17,32 +17,21 @@ import 'package:vm/testing/il_matchers.dart';
int identity(int address) => Pointer<Void>.fromAddress(address).address;
void matchIL$identity(FlowGraph graph) {
graph.dump();
if (is32BitConfiguration) {
// The Dart int address is truncated before being returned.
graph.match([
match.block('Graph'),
match.block('Function', [
'address' << match.Parameter(index: 0),
'int32' <<
match.IntConverter('address',
from: 'int64', to: 'int32', is_truncating: true),
final retval = is32BitConfiguration ? 'retval' : 'address';
graph.match([
match.block('Graph'),
match.block('Function', [
'address' << match.Parameter(index: 0),
if (is32BitConfiguration) ...[
// The Dart int address is truncated before being returned.
'uint32' <<
match.IntConverter('int32',
from: 'int32', to: 'uint32', is_truncating: true),
match.IntConverter('address',
from: 'int64', to: 'uint32', is_truncating: true),
'retval' << match.IntConverter('uint32', from: 'uint32', to: 'int64'),
match.Return('retval'),
]),
]);
} else {
graph.match([
match.block('Graph'),
match.block('Function', [
'address' << match.Parameter(index: 0),
match.Return('address'),
]),
]);
}
],
match.Return(retval),
]),
]);
}
void main(List<String> args) {

View file

@ -30,12 +30,7 @@ void matchIL$deref(FlowGraph graph) {
// and int64 on 64-bit arches.
if (is32BitConfiguration) ...[
// 'unboxed' needs to be converted to int64 before returning.
//
// Note: The first two conversions here should be fixed once all
// kUnboxedIntPtr uses are appropriately converted to kUnboxedFfiIntPtr.
'extra1' << match.IntConverter('unboxed', from: 'uint32', to: 'int32'),
'extra2' << match.IntConverter('extra1', from: 'int32', to: 'uint32'),
'address' << match.IntConverter('extra2', from: 'uint32', to: 'int64'),
'address' << match.IntConverter('unboxed', from: 'uint32', to: 'int64'),
],
match.Return(retvalName),
]),

View file

@ -1384,8 +1384,8 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfRecognizedMethod(
LocalVariable* pointer = MakeTemporary();
body += LoadLocal(pointer);
body += LoadLocal(address);
body += UnboxTruncate(kUnboxedIntPtr);
body += ConvertUnboxedToUntagged(kUnboxedIntPtr);
body += UnboxTruncate(kUnboxedFfiIntPtr);
body += ConvertUnboxedToUntagged(kUnboxedFfiIntPtr);
body += StoreNativeField(Slot::PointerBase_data(),
InnerPointerAccess::kCannotBeInnerPointer,
StoreFieldInstr::Kind::kInitializing);
@ -1467,8 +1467,8 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfRecognizedMethod(
body += LoadLocal(MakeTemporary()); // Duplicate Pointer.
body += LoadLocal(parsed_function_->RawParameterVariable(0)); // Address.
body += CheckNullOptimized(String::ZoneHandle(Z, function.name()));
body += UnboxTruncate(kUnboxedIntPtr);
body += ConvertUnboxedToUntagged(kUnboxedIntPtr);
body += UnboxTruncate(kUnboxedFfiIntPtr);
body += ConvertUnboxedToUntagged(kUnboxedFfiIntPtr);
body += StoreNativeField(Slot::PointerBase_data(),
InnerPointerAccess::kCannotBeInnerPointer,
StoreFieldInstr::Kind::kInitializing);
@ -1800,11 +1800,12 @@ Fragment FlowGraphBuilder::BuildTypedDataViewFactoryConstructor(
body += LoadLocal(typed_data);
body += LoadNativeField(Slot::PointerBase_data(),
InnerPointerAccess::kMayBeInnerPointer);
body += ConvertUntaggedToUnboxed(kUnboxedIntPtr);
body += ConvertUntaggedToUnboxed(kUnboxedFfiIntPtr);
body += LoadLocal(offset_in_bytes);
body += UnboxTruncate(kUnboxedIntPtr);
body += BinaryIntegerOp(Token::kADD, kUnboxedIntPtr, /*is_truncating=*/true);
body += ConvertUnboxedToUntagged(kUnboxedIntPtr);
body += UnboxTruncate(kUnboxedFfiIntPtr);
body +=
BinaryIntegerOp(Token::kADD, kUnboxedFfiIntPtr, /*is_truncating=*/true);
body += ConvertUnboxedToUntagged(kUnboxedFfiIntPtr);
body += StoreNativeField(Slot::PointerBase_data(),
InnerPointerAccess::kMayBeInnerPointer,
StoreFieldInstr::Kind::kInitializing);
@ -1865,27 +1866,27 @@ Fragment FlowGraphBuilder::BuildTypedDataMemMove(const Function& function,
call_memmove += LoadLocal(arg_to);
call_memmove += LoadNativeField(Slot::PointerBase_data(),
InnerPointerAccess::kMayBeInnerPointer);
call_memmove += ConvertUntaggedToUnboxed(kUnboxedIntPtr);
call_memmove += ConvertUntaggedToUnboxed(kUnboxedFfiIntPtr);
call_memmove += LoadLocal(arg_to_start);
call_memmove += IntConstant(element_size);
call_memmove += SmiBinaryOp(Token::kMUL, /*is_truncating=*/true);
call_memmove += UnboxTruncate(kUnboxedIntPtr);
call_memmove += UnboxTruncate(kUnboxedFfiIntPtr);
call_memmove +=
BinaryIntegerOp(Token::kADD, kUnboxedIntPtr, /*is_truncating=*/true);
BinaryIntegerOp(Token::kADD, kUnboxedFfiIntPtr, /*is_truncating=*/true);
call_memmove += LoadLocal(arg_from);
call_memmove += LoadNativeField(Slot::PointerBase_data(),
InnerPointerAccess::kMayBeInnerPointer);
call_memmove += ConvertUntaggedToUnboxed(kUnboxedIntPtr);
call_memmove += ConvertUntaggedToUnboxed(kUnboxedFfiIntPtr);
call_memmove += LoadLocal(arg_from_start);
call_memmove += IntConstant(element_size);
call_memmove += SmiBinaryOp(Token::kMUL, /*is_truncating=*/true);
call_memmove += UnboxTruncate(kUnboxedIntPtr);
call_memmove += UnboxTruncate(kUnboxedFfiIntPtr);
call_memmove +=
BinaryIntegerOp(Token::kADD, kUnboxedIntPtr, /*is_truncating=*/true);
BinaryIntegerOp(Token::kADD, kUnboxedFfiIntPtr, /*is_truncating=*/true);
call_memmove += LoadLocal(arg_count);
call_memmove += IntConstant(element_size);
call_memmove += SmiBinaryOp(Token::kMUL, /*is_truncating=*/true);
call_memmove += UnboxTruncate(kUnboxedIntPtr);
call_memmove += UnboxTruncate(kUnboxedFfiIntPtr);
call_memmove += LoadThread();
call_memmove += LoadUntagged(
compiler::target::Thread::OffsetFromThread(&kMemoryMoveRuntimeEntry));
@ -4529,8 +4530,8 @@ Fragment FlowGraphBuilder::FfiPointerFromAddress() {
LocalVariable* pointer = MakeTemporary();
code += LoadLocal(pointer);
code += LoadLocal(address);
code += UnboxTruncate(kUnboxedIntPtr);
code += ConvertUnboxedToUntagged(kUnboxedIntPtr);
code += UnboxTruncate(kUnboxedFfiIntPtr);
code += ConvertUnboxedToUntagged(kUnboxedFfiIntPtr);
code += StoreNativeField(Slot::PointerBase_data(),
InnerPointerAccess::kCannotBeInnerPointer,
StoreFieldInstr::Kind::kInitializing);