Commit 33c717fb authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Introduce dedicated BitcastWordToTagged machine operator.

This operator doesn't generate any actual code, but teaches the register
allocator that a certain computed pointer value is tagged. This is
required to safely implement InnerAllocate (and we also use this for
Allocate to be sure that we don't suddenly leak a dangling pointer into
the heap somewhere).

R=epertoso@chromium.org
BUG=v8:4939
LOG=n

Review URL: https://codereview.chromium.org/1905813003

Cr-Commit-Position: refs/heads/master@{#35700}
parent 7dfb5bee
......@@ -343,8 +343,8 @@ Node* CodeStubAssembler::AllocateRawUnaligned(Node* size_in_bytes,
Node* no_runtime_result = top;
StoreNoWriteBarrier(MachineType::PointerRepresentation(), top_address,
IntPtrAdd(top, size_in_bytes));
no_runtime_result =
IntPtrAdd(no_runtime_result, IntPtrConstant(kHeapObjectTag));
no_runtime_result = BitcastWordToTagged(
IntPtrAdd(no_runtime_result, IntPtrConstant(kHeapObjectTag)));
result.Bind(no_runtime_result);
Goto(&merge_runtime);
......@@ -392,7 +392,8 @@ Node* CodeStubAssembler::AllocateRawAligned(Node* size_in_bytes,
// it when Simd128 alignment is supported.
StoreNoWriteBarrier(MachineType::PointerRepresentation(), top,
LoadRoot(Heap::kOnePointerFillerMapRootIndex));
address.Bind(IntPtrAdd(address.value(), IntPtrConstant(kPointerSize)));
address.Bind(BitcastWordToTagged(
IntPtrAdd(address.value(), IntPtrConstant(kPointerSize))));
Goto(&merge_address);
Bind(&doesnt_need_filler);
......@@ -428,7 +429,7 @@ Node* CodeStubAssembler::Allocate(int size_in_bytes, AllocationFlags flags) {
}
Node* CodeStubAssembler::InnerAllocate(Node* previous, int offset) {
return IntPtrAdd(previous, IntPtrConstant(offset));
return BitcastWordToTagged(IntPtrAdd(previous, IntPtrConstant(offset)));
}
Node* CodeStubAssembler::LoadBufferObject(Node* buffer, int offset,
......
......@@ -107,6 +107,7 @@ class Schedule;
V(Float64Sqrt) \
V(Float64ExtractLowWord32) \
V(Float64ExtractHighWord32) \
V(BitcastWordToTagged) \
V(TruncateInt64ToInt32) \
V(ChangeFloat64ToUint32) \
V(ChangeInt32ToFloat64) \
......
......@@ -1014,6 +1014,8 @@ void InstructionSelector::VisitNode(Node* node) {
return VisitUint64LessThanOrEqual(node);
case IrOpcode::kUint64Mod:
return MarkAsWord64(node), VisitUint64Mod(node);
case IrOpcode::kBitcastWordToTagged:
return MarkAsReference(node), VisitBitcastWordToTagged(node);
case IrOpcode::kChangeFloat32ToFloat64:
return MarkAsFloat64(node), VisitChangeFloat32ToFloat64(node);
case IrOpcode::kChangeInt32ToFloat64:
......@@ -1253,6 +1255,12 @@ void InstructionSelector::VisitStackSlot(Node* node) {
sequence()->AddImmediate(Constant(slot)), 0, nullptr);
}
void InstructionSelector::VisitBitcastWordToTagged(Node* node) {
OperandGenerator g(this);
Node* value = node->InputAt(0);
Emit(kArchNop, g.DefineSameAsFirst(node), g.Use(value));
}
// 32 bit targets do not implement the following instructions.
#if V8_TARGET_ARCH_32_BIT
......
......@@ -146,6 +146,7 @@ MachineRepresentation StackSlotRepresentationOf(Operator const* op) {
V(Uint64Mod, Operator::kNoProperties, 2, 1, 1) \
V(Uint64LessThan, Operator::kNoProperties, 2, 0, 1) \
V(Uint64LessThanOrEqual, Operator::kNoProperties, 2, 0, 1) \
V(BitcastWordToTagged, Operator::kNoProperties, 1, 0, 1) \
V(ChangeFloat32ToFloat64, Operator::kNoProperties, 1, 0, 1) \
V(ChangeFloat64ToInt32, Operator::kNoProperties, 1, 0, 1) \
V(ChangeFloat64ToUint32, Operator::kNoProperties, 1, 0, 1) \
......
......@@ -220,6 +220,9 @@ class MachineOperatorBuilder final : public ZoneObject {
const Operator* Uint64LessThanOrEqual();
const Operator* Uint64Mod();
// This operator reinterprets the bits of a word as tagged pointer.
const Operator* BitcastWordToTagged();
// These operators change the representation of numbers while preserving the
// value of the number. Narrowing operators assume the input is representable
// in the target type and are *not* defined for other inputs.
......
......@@ -285,6 +285,7 @@
V(Int64Mod) \
V(Uint64Div) \
V(Uint64Mod) \
V(BitcastWordToTagged) \
V(ChangeFloat32ToFloat64) \
V(ChangeFloat64ToInt32) \
V(ChangeFloat64ToUint32) \
......
......@@ -469,6 +469,9 @@ class RawMachineAssembler {
}
// Conversions.
Node* BitcastWordToTagged(Node* a) {
return AddNode(machine()->BitcastWordToTagged(), a);
}
Node* ChangeFloat32ToFloat64(Node* a) {
return AddNode(machine()->ChangeFloat32ToFloat64(), a);
}
......
......@@ -2217,6 +2217,9 @@ Type* Typer::Visitor::TypeUint64LessThanOrEqual(Node* node) {
Type* Typer::Visitor::TypeUint64Mod(Node* node) { return Type::Internal(); }
Type* Typer::Visitor::TypeBitcastWordToTagged(Node* node) {
return Type::TaggedPointer();
}
Type* Typer::Visitor::TypeChangeFloat32ToFloat64(Node* node) {
return Type::Intersect(Type::Number(), Type::UntaggedFloat64(), zone());
......
......@@ -975,6 +975,7 @@ void Verifier::Visitor::Check(Node* node) {
case IrOpcode::kBitcastFloat64ToInt64:
case IrOpcode::kBitcastInt32ToFloat32:
case IrOpcode::kBitcastInt64ToFloat64:
case IrOpcode::kBitcastWordToTagged:
case IrOpcode::kChangeInt32ToInt64:
case IrOpcode::kChangeUint32ToUint64:
case IrOpcode::kChangeInt32ToFloat64:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment