Commit 6e589034 authored by jgruber's avatar jgruber Committed by Commit Bot

[builtins] Generalize the constant lookup mechanism

Moves the decision whether to embed the constant or perform a lookup
through the builtins constants table to
CodeAssembler::UntypedHeapConstant.

Root constants continue to be embedded (and are later turned into
loads through root-register by the backend); non-root constants are
added to the constants table at generation-time and loaded from there
at runtime.

This allows us to remove the recently added boilerplate around
CallStub and CallRuntime in a follow-up.

Bug: v8:6666
Change-Id: Id981088e4b9d665c678acc9718383179f681f063
Reviewed-on: https://chromium-review.googlesource.com/931122
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51495}
parent 0b1a36cb
......@@ -300,6 +300,7 @@ bool Builtins::IsIsolateIndependent(int index) {
case kLoadIC_StringWrapperLength:
case kLoadICTrampoline:
case kOrderedHashTableHealIndex:
case kPromiseFulfillReactionJob:
case kStoreGlobalICTrampoline:
case kStoreICTrampoline:
case kStringRepeat:
......
......@@ -4,7 +4,6 @@
#include "src/code-stub-assembler.h"
#include "src/builtins/constants-table-builder.h"
#include "src/code-factory.h"
#include "src/frames-inl.h"
#include "src/frames.h"
......@@ -7315,23 +7314,6 @@ void CodeStubAssembler::TryGetOwnProperty(
}
}
#ifdef V8_EMBEDDED_BUILTINS
TNode<Code> CodeStubAssembler::LookupConstantCodeTarget(Handle<Code> code) {
DCHECK(isolate()->serializer_enabled());
// The builtins constants table is loaded through the root register on all
// supported platforms. This is checked by the
// VerifyBuiltinsIsolateIndependence cctest, which disallows embedded objects
// in isolate-independent builtins.
BuiltinsConstantsTableBuilder* builder =
isolate()->builtins_constants_table_builder();
uint32_t index = builder->AddObject(code);
DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(
Heap::kBuiltinsConstantsTableRootIndex));
TNode<FixedArray> cache = BuiltinsConstantsTableConstant();
return CAST(LoadFixedArrayElement(cache, index));
}
#endif // V8_EMBEDDED_BUILTINS
void CodeStubAssembler::TryLookupElement(Node* object, Node* map,
Node* instance_type,
Node* intptr_index, Label* if_found,
......
......@@ -27,7 +27,6 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol };
V(AccessorPairMap, accessor_pair_map, AccessorPairMap) \
V(AllocationSiteMap, allocation_site_map, AllocationSiteMap) \
V(BooleanMap, boolean_map, BooleanMap) \
V(BuiltinsConstantsTable, builtins_constants_table, BuiltinsConstantsTable) \
V(CodeMap, code_map, CodeMap) \
V(EmptyPropertyDictionary, empty_property_dictionary, \
EmptyPropertyDictionary) \
......@@ -1610,15 +1609,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
#error "ia32 does not yet support embedded builtins"
#endif
// Off-heap builtins cannot embed constants within the code object itself,
// and thus need to load them from the root list.
bool ShouldLoadConstantsFromRootList() const {
return (isolate()->serializer_enabled() &&
isolate()->builtins_constants_table_builder() != nullptr);
}
TNode<Code> LookupConstantCodeTarget(Handle<Code> code);
template <class... TArgs>
Node* CallStub(Callable const& callable, Node* context, TArgs... args) {
if (ShouldLoadConstantsFromRootList()) {
......
......@@ -6,6 +6,7 @@
#include <ostream>
#include "src/builtins/constants-table-builder.h"
#include "src/code-factory.h"
#include "src/compiler/graph.h"
#include "src/compiler/instruction-selector.h"
......@@ -234,6 +235,37 @@ bool CodeAssembler::IsIntPtrAbsWithOverflowSupported() const {
: IsInt32AbsWithOverflowSupported();
}
#ifdef V8_EMBEDDED_BUILTINS
TNode<Code> CodeAssembler::LookupConstantCodeTarget(Handle<Code> code) {
return CAST(LookupConstant(code));
}
TNode<HeapObject> CodeAssembler::LookupConstant(Handle<HeapObject> object) {
DCHECK(isolate()->serializer_enabled());
// Ensure the given object is in the builtins constants table and fetch its
// index.
BuiltinsConstantsTableBuilder* builder =
isolate()->builtins_constants_table_builder();
uint32_t index = builder->AddObject(object);
// The builtins constants table is loaded through the root register on all
// supported platforms. This is checked by the
// VerifyBuiltinsIsolateIndependence cctest, which disallows embedded objects
// in isolate-independent builtins.
DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(
Heap::kBuiltinsConstantsTableRootIndex));
TNode<FixedArray> builtins_constants_table = UncheckedCast<FixedArray>(
LoadRoot(Heap::kBuiltinsConstantsTableRootIndex));
// Generate the lookup.
const int32_t header_size = FixedArray::kHeaderSize - kHeapObjectTag;
TNode<IntPtrT> offset = IntPtrConstant(header_size + kPointerSize * index);
return UncheckedCast<HeapObject>(
Load(MachineType::AnyTagged(), builtins_constants_table, offset));
}
#endif // V8_EMBEDDED_BUILTINS
TNode<Int32T> CodeAssembler::Int32Constant(int32_t value) {
return UncheckedCast<Int32T>(raw_assembler()->Int32Constant(value));
}
......@@ -266,6 +298,16 @@ TNode<Smi> CodeAssembler::SmiConstant(int value) {
TNode<HeapObject> CodeAssembler::UntypedHeapConstant(
Handle<HeapObject> object) {
#ifdef V8_EMBEDDED_BUILTINS
// Root constants are simply loaded from the root list, while non-root
// constants must be looked up from the builtins constants table.
if (ShouldLoadConstantsFromRootList()) {
Heap::RootListIndex root_index;
if (!isolate()->heap()->IsRootHandle(object, &root_index)) {
return LookupConstant(object);
}
}
#endif // V8_EMBEDDED_BUILTINS
return UncheckedCast<HeapObject>(raw_assembler()->HeapConstant(object));
}
......
......@@ -634,6 +634,18 @@ class V8_EXPORT_PRIVATE CodeAssembler {
#define CAST(x) Cast(x, "")
#endif
#ifdef V8_EMBEDDED_BUILTINS
// Off-heap builtins cannot embed constants within the code object itself,
// and thus need to load them from the root list.
bool ShouldLoadConstantsFromRootList() const {
return (isolate()->serializer_enabled() &&
isolate()->builtins_constants_table_builder() != nullptr);
}
TNode<Code> LookupConstantCodeTarget(Handle<Code> code);
TNode<HeapObject> LookupConstant(Handle<HeapObject> object);
#endif
// Constants.
TNode<Int32T> Int32Constant(int32_t value);
TNode<Int64T> Int64Constant(int64_t value);
......
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