summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/ftl/FTLAbstractHeap.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/ftl/FTLAbstractHeap.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/JavaScriptCore/ftl/FTLAbstractHeap.cpp')
-rw-r--r--Source/JavaScriptCore/ftl/FTLAbstractHeap.cpp176
1 files changed, 124 insertions, 52 deletions
diff --git a/Source/JavaScriptCore/ftl/FTLAbstractHeap.cpp b/Source/JavaScriptCore/ftl/FTLAbstractHeap.cpp
index eadd5af97..90211fd94 100644
--- a/Source/JavaScriptCore/ftl/FTLAbstractHeap.cpp
+++ b/Source/JavaScriptCore/ftl/FTLAbstractHeap.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013, 2015-2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,51 +28,114 @@
#if ENABLE(FTL_JIT)
-#include "FTLAbbreviations.h"
+#include "DFGCommon.h"
+#include "FTLAbbreviatedTypes.h"
#include "FTLAbstractHeapRepository.h"
#include "FTLOutput.h"
#include "FTLTypedPointer.h"
-#include "Operations.h"
+#include "JSCInlines.h"
#include "Options.h"
namespace JSC { namespace FTL {
-LValue AbstractHeap::tbaaMetadataSlow(const AbstractHeapRepository& repository) const
+using namespace B3;
+
+AbstractHeap::AbstractHeap(AbstractHeap* parent, const char* heapName, ptrdiff_t offset)
+ : m_offset(offset)
+ , m_heapName(heapName)
{
- m_tbaaMetadata = mdNode(
- repository.m_context,
- mdString(repository.m_context, m_heapName),
- m_parent->tbaaMetadata(repository));
- return m_tbaaMetadata;
+ changeParent(parent);
}
-void AbstractHeap::decorateInstruction(LValue instruction, const AbstractHeapRepository& repository) const
+void AbstractHeap::changeParent(AbstractHeap* parent)
{
- if (!Options::useFTLTBAA())
+ if (m_parent) {
+ bool result = m_parent->m_children.removeFirst(this);
+ RELEASE_ASSERT(result);
+ }
+
+ m_parent = parent;
+
+ if (parent) {
+ ASSERT(!m_parent->m_children.contains(this));
+ m_parent->m_children.append(this);
+ }
+}
+
+void AbstractHeap::compute(unsigned begin)
+{
+ // This recursively computes the ranges of the tree. This solves the following constraints
+ // in linear time:
+ //
+ // - A node's end is greater than its begin.
+ // - A node's begin is greater than or equal to its parent's begin.
+ // - A node's end is less than or equal to its parent's end.
+ // - The ranges are as small as possible.
+ //
+ // It's OK to recurse because we keep the depth of our abstract heap hierarchy fairly sane.
+ // I think that it gets 4 deep at most.
+
+ if (m_children.isEmpty()) {
+ // Must special-case leaves so that they use just one slot on the number line.
+ m_range = HeapRange(begin);
return;
- setMetadata(instruction, repository.m_tbaaKind, tbaaMetadata(repository));
+ }
+
+ unsigned current = begin;
+ for (AbstractHeap* child : m_children) {
+ child->compute(current);
+ current = child->range().end();
+ }
+
+ m_range = HeapRange(begin, current);
+}
+
+void AbstractHeap::shallowDump(PrintStream& out) const
+{
+ out.print(heapName(), "(", m_offset, ")");
+ if (m_range)
+ out.print("<", m_range, ">");
+}
+
+void AbstractHeap::dump(PrintStream& out) const
+{
+ shallowDump(out);
+ if (m_parent)
+ out.print("->", *m_parent);
}
-IndexedAbstractHeap::IndexedAbstractHeap(LContext context, AbstractHeap* parent, const char* heapName, size_t elementSize)
+void AbstractHeap::deepDump(PrintStream& out, unsigned indent) const
+{
+ auto printIndent = [&] () {
+ for (unsigned i = indent; i--;)
+ out.print(" ");
+ };
+
+ printIndent();
+ shallowDump(out);
+
+ if (m_children.isEmpty()) {
+ out.print("\n");
+ return;
+ }
+
+ out.print(":\n");
+ for (AbstractHeap* child : m_children)
+ child->deepDump(out, indent + 1);
+}
+
+void AbstractHeap::badRangeError() const
+{
+ dataLog("Heap does not have range: ", *this, "\n");
+ RELEASE_ASSERT_NOT_REACHED();
+}
+
+IndexedAbstractHeap::IndexedAbstractHeap(AbstractHeap* parent, const char* heapName, ptrdiff_t offset, size_t elementSize)
: m_heapForAnyIndex(parent, heapName)
, m_heapNameLength(strlen(heapName))
+ , m_offset(offset)
, m_elementSize(elementSize)
- , m_scaleTerm(0)
- , m_canShift(false)
-{
- // See if there is a common shift amount we could use instead of multiplying. Don't
- // try too hard. This is just a speculative optimization to reduce load on LLVM.
- for (unsigned i = 0; i < 4; ++i) {
- if ((1 << i) == m_elementSize) {
- if (i)
- m_scaleTerm = constInt(intPtrType(context), i, ZeroExtend);
- m_canShift = true;
- break;
- }
- }
-
- if (!m_canShift)
- m_scaleTerm = constInt(intPtrType(context), m_elementSize, ZeroExtend);
+{
}
IndexedAbstractHeap::~IndexedAbstractHeap()
@@ -83,36 +146,29 @@ TypedPointer IndexedAbstractHeap::baseIndex(Output& out, LValue base, LValue ind
{
if (indexAsConstant.isInt32())
return out.address(base, at(indexAsConstant.asInt32()), offset);
+
+ LValue result = out.add(base, out.mul(index, out.constIntPtr(m_elementSize)));
- LValue result;
- if (m_canShift) {
- if (!m_scaleTerm)
- result = out.add(base, index);
- else
- result = out.add(base, out.shl(index, m_scaleTerm));
- } else
- result = out.add(base, out.mul(index, m_scaleTerm));
-
- return TypedPointer(atAnyIndex(), out.addPtr(result, offset));
+ return TypedPointer(atAnyIndex(), out.addPtr(result, m_offset + offset));
}
-const AbstractField& IndexedAbstractHeap::atSlow(ptrdiff_t index)
+const AbstractHeap& IndexedAbstractHeap::atSlow(ptrdiff_t index)
{
ASSERT(static_cast<size_t>(index) >= m_smallIndices.size());
if (UNLIKELY(!m_largeIndices))
- m_largeIndices = adoptPtr(new MapType());
+ m_largeIndices = std::make_unique<MapType>();
- std::unique_ptr<AbstractField>& field = m_largeIndices->add(index, nullptr).iterator->value;
+ std::unique_ptr<AbstractHeap>& field = m_largeIndices->add(index, nullptr).iterator->value;
if (!field) {
- field = std::make_unique<AbstractField>();
+ field = std::make_unique<AbstractHeap>();
initialize(*field, index);
}
return *field;
}
-void IndexedAbstractHeap::initialize(AbstractField& field, ptrdiff_t signedIndex)
+void IndexedAbstractHeap::initialize(AbstractHeap& field, ptrdiff_t signedIndex)
{
// Build up a name of the form:
//
@@ -131,7 +187,10 @@ void IndexedAbstractHeap::initialize(AbstractField& field, ptrdiff_t signedIndex
//
// Blah_neg_A
//
- // This is important because LLVM uses the string to distinguish the types.
+ // This naming convention comes from our previous use of LLVM. It's not clear that we need
+ // it anymore, though it is sort of nifty. Basically, B3 doesn't need string names for
+ // abstract heaps, but the fact that we have a reasonably efficient way to always name the
+ // heaps will probably come in handy for debugging.
static const char* negSplit = "_neg_";
static const char* posSplit = "_";
@@ -168,16 +227,20 @@ void IndexedAbstractHeap::initialize(AbstractField& field, ptrdiff_t signedIndex
accumulator >>= 4;
}
- field.initialize(&m_heapForAnyIndex, characters, signedIndex * m_elementSize);
+ field.initialize(&m_heapForAnyIndex, characters, m_offset + signedIndex * m_elementSize);
return;
}
RELEASE_ASSERT_NOT_REACHED();
}
-NumberedAbstractHeap::NumberedAbstractHeap(
- LContext context, AbstractHeap* heap, const char* heapName)
- : m_indexedHeap(context, heap, heapName, 1)
+void IndexedAbstractHeap::dump(PrintStream& out) const
+{
+ out.print("Indexed:", atAnyIndex());
+}
+
+NumberedAbstractHeap::NumberedAbstractHeap(AbstractHeap* heap, const char* heapName)
+ : m_indexedHeap(heap, heapName, 0, 1)
{
}
@@ -185,9 +248,13 @@ NumberedAbstractHeap::~NumberedAbstractHeap()
{
}
-AbsoluteAbstractHeap::AbsoluteAbstractHeap(
- LContext context, AbstractHeap* heap, const char* heapName)
- : m_indexedHeap(context, heap, heapName, 1)
+void NumberedAbstractHeap::dump(PrintStream& out) const
+{
+ out.print("Numbered: ", atAnyNumber());
+}
+
+AbsoluteAbstractHeap::AbsoluteAbstractHeap(AbstractHeap* heap, const char* heapName)
+ : m_indexedHeap(heap, heapName, 0, 1)
{
}
@@ -195,6 +262,11 @@ AbsoluteAbstractHeap::~AbsoluteAbstractHeap()
{
}
+void AbsoluteAbstractHeap::dump(PrintStream& out) const
+{
+ out.print("Absolute:", atAnyAddress());
+}
+
} } // namespace JSC::FTL
#endif // ENABLE(FTL_JIT)