Commit 4a505517 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

[turbofan] Embed the actual backing store address for typed loads/stores.

TEST=unittests
R=dcarney@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24548 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 363ac55a
......@@ -21,6 +21,10 @@ class CommonNodeCache FINAL : public ZoneObject {
return int32_constants_.Find(zone_, value);
}
Node** FindInt64Constant(int64_t value) {
return int64_constants_.Find(zone_, value);
}
Node** FindFloat64Constant(double value) {
// We canonicalize double constants at the bit representation level.
return float64_constants_.Find(zone_, bit_cast<int64_t>(value));
......@@ -39,13 +43,15 @@ class CommonNodeCache FINAL : public ZoneObject {
private:
Int32NodeCache int32_constants_;
Int64NodeCache int64_constants_;
Int64NodeCache float64_constants_;
PtrNodeCache external_constants_;
Int64NodeCache number_constants_;
Zone* zone_;
};
}
}
} // namespace v8::internal::compiler
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_COMMON_NODE_CACHE_H_
......@@ -157,6 +157,15 @@ Node* JSGraph::Int32Constant(int32_t value) {
}
Node* JSGraph::Int64Constant(int64_t value) {
Node** loc = cache_.FindInt64Constant(value);
if (*loc == NULL) {
*loc = NewNode(common()->Int64Constant(value));
}
return *loc;
}
Node* JSGraph::NumberConstant(double value) {
Node** loc = cache_.FindNumberConstant(value);
if (*loc == NULL) {
......@@ -188,6 +197,7 @@ Node* JSGraph::ExternalConstant(ExternalReference reference) {
}
return *loc;
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -69,6 +69,21 @@ class JSGraph : public ZoneObject {
return Int32Constant(bit_cast<int32_t>(value));
}
// Creates a Int64Constant node, usually canonicalized.
Node* Int64Constant(int64_t value);
Node* Uint64Constant(uint64_t value) {
return Int64Constant(bit_cast<int64_t>(value));
}
// Creates a Int32Constant/Int64Constant node, depending on the word size of
// the target machine.
// TODO(turbofan): Code using Int32Constant/Int64Constant to store pointer
// constants is probably not serializable.
Node* IntPtrConstant(intptr_t value) {
return machine()->Is32() ? Int32Constant(static_cast<int32_t>(value))
: Int64Constant(static_cast<int64_t>(value));
}
// Creates a Float32Constant node, usually canonicalized.
Node* Float32Constant(float value);
......
......@@ -543,12 +543,10 @@ Reduction JSTypedLowering::ReduceJSLoadProperty(Node* node) {
ExternalArrayType type = array->type();
uint32_t byte_length;
if (array->byte_length()->ToUint32(&byte_length)) {
Node* elements = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base,
graph()->start());
Node* pointer = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()),
elements, elements);
Handle<ExternalArray> elements =
Handle<ExternalArray>::cast(handle(array->elements()));
Node* pointer = jsgraph()->IntPtrConstant(
bit_cast<intptr_t>(elements->external_pointer()));
Node* length = jsgraph()->Uint32Constant(
static_cast<uint32_t>(byte_length / array->element_size()));
Node* effect = NodeProperties::GetEffectInput(node);
......@@ -582,12 +580,10 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) {
ExternalArrayType type = array->type();
uint32_t byte_length;
if (array->byte_length()->ToUint32(&byte_length)) {
Node* elements = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base,
graph()->start());
Node* pointer = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()),
elements, elements);
Handle<ExternalArray> elements =
Handle<ExternalArray>::cast(handle(array->elements()));
Node* pointer = jsgraph()->IntPtrConstant(
bit_cast<intptr_t>(elements->external_pointer()));
Node* length = jsgraph()->Uint32Constant(
static_cast<uint32_t>(byte_length / array->element_size()));
Node* effect = NodeProperties::GetEffectInput(node);
......
......@@ -11,12 +11,7 @@
#include "src/compiler/typer.h"
#include "test/unittests/compiler/compiler-test-utils.h"
#include "test/unittests/compiler/graph-unittest.h"
#include "testing/gmock-support.h"
using testing::_;
using testing::AllOf;
using testing::Capture;
using testing::CaptureEq;
#include "testing/gtest-support.h"
namespace v8 {
namespace internal {
......@@ -62,6 +57,11 @@ class JSTypedLoweringTest : public GraphTest {
return buffer;
}
Matcher<Node*> IsIntPtrConstant(intptr_t value) {
return sizeof(value) == 4 ? IsInt32Constant(static_cast<int32_t>(value))
: IsInt64Constant(static_cast<int64_t>(value));
}
JSOperatorBuilder* javascript() { return &javascript_; }
private:
......@@ -98,18 +98,13 @@ TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) {
node->AppendInput(zone(), control);
Reduction r = Reduce(node);
Capture<Node*> elements;
ASSERT_TRUE(r.Changed());
EXPECT_THAT(
r.replacement(),
IsLoadElement(
AccessBuilder::ForTypedArrayElement(type, true),
IsLoadField(AccessBuilder::ForExternalArrayPointer(),
AllOf(CaptureEq(&elements),
IsLoadField(AccessBuilder::ForJSObjectElements(),
base, _)),
CaptureEq(&elements)),
key, IsInt32Constant(static_cast<int>(kLength)), effect, control));
IsLoadElement(AccessBuilder::ForTypedArrayElement(type, true),
IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])),
key, IsInt32Constant(static_cast<int>(kLength)), effect,
control));
}
}
......@@ -143,20 +138,13 @@ TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) {
node->AppendInput(zone(), control);
Reduction r = Reduce(node);
Capture<Node*> elements;
ASSERT_TRUE(r.Changed());
EXPECT_THAT(
r.replacement(),
IsStoreElement(
AccessBuilder::ForTypedArrayElement(type, true),
IsLoadField(
AccessBuilder::ForExternalArrayPointer(),
AllOf(CaptureEq(&elements),
IsLoadField(AccessBuilder::ForJSObjectElements(), base,
_)),
CaptureEq(&elements)),
key, IsInt32Constant(static_cast<int>(kLength)), value, effect,
control));
EXPECT_THAT(r.replacement(),
IsStoreElement(
AccessBuilder::ForTypedArrayElement(type, true),
IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])),
key, IsInt32Constant(static_cast<int>(kLength)), value,
effect, control));
}
}
}
......
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