Commit 0e76a9c3 authored by jgruber's avatar jgruber Committed by Commit bot

[stubs] Add IsCallableMap predicate to CSA

Add an IsCallableMap predicate to code-stub-assembler which tests
whether the given map is callable, and adjust all use sites.

BUG=

Review-Url: https://chromiumcodereview.appspot.com/2435283002
Cr-Commit-Position: refs/heads/master@{#40502}
parent eb10dc4c
......@@ -250,13 +250,8 @@ void Generate_OrdinaryToPrimitive(CodeStubAssembler* assembler,
if_methodisnotcallable(assembler, Label::kDeferred);
assembler->GotoIf(assembler->TaggedIsSmi(method), &if_methodisnotcallable);
Node* method_map = assembler->LoadMap(method);
Node* method_bit_field = assembler->LoadMapBitField(method_map);
assembler->Branch(
assembler->Word32Equal(
assembler->Word32And(method_bit_field, assembler->Int32Constant(
1 << Map::kIsCallable)),
assembler->Int32Constant(0)),
&if_methodisnotcallable, &if_methodiscallable);
assembler->Branch(assembler->IsCallableMap(method_map),
&if_methodiscallable, &if_methodisnotcallable);
assembler->Bind(&if_methodiscallable);
{
......
......@@ -443,13 +443,8 @@ void Builtins::Generate_ObjectProtoToString(CodeStubAssembler* assembler) {
Node* map = assembler->LoadMap(receiver);
// Return object if the proxy {receiver} is not callable.
assembler->Branch(
assembler->Word32Equal(
assembler->Word32And(
assembler->LoadMapBitField(map),
assembler->Int32Constant(1 << Map::kIsCallable)),
assembler->Int32Constant(0)),
&return_object, &return_function);
assembler->Branch(assembler->IsCallableMap(map), &return_function,
&return_object);
}
// Default
......
......@@ -1599,11 +1599,8 @@ void Builtins::Generate_RegExpPrototypeReplace(CodeStubAssembler* a) {
a->GotoIf(a->TaggedIsSmi(replace_value), &checkreplacestring);
Node* const replace_value_map = a->LoadMap(replace_value);
a->Branch(
a->Word32Equal(a->Word32And(a->LoadMapBitField(replace_value_map),
a->Int32Constant(1 << Map::kIsCallable)),
a->Int32Constant(0)),
&checkreplacestring, &if_iscallable);
a->Branch(a->IsCallableMap(replace_value_map), &if_iscallable,
&checkreplacestring);
// 3. Does ToString({replace_value}) contain '$'?
a->Bind(&checkreplacestring);
......
......@@ -2569,6 +2569,12 @@ Node* CodeStubAssembler::IsJSReceiverInstanceType(Node* instance_type) {
Int32Constant(FIRST_JS_RECEIVER_TYPE));
}
Node* CodeStubAssembler::IsCallableMap(Node* map) {
return Word32NotEqual(
Word32And(LoadMapBitField(map), Int32Constant(1 << Map::kIsCallable)),
Int32Constant(0));
}
Node* CodeStubAssembler::StringCharCodeAt(Node* string, Node* index) {
// Translate the {index} into a Word.
index = SmiToWord(index);
......@@ -4295,10 +4301,7 @@ Node* CodeStubAssembler::CallGetterIfAccessor(Node* value, Node* details,
// Return undefined if the {getter} is not callable.
var_value.Bind(UndefinedConstant());
GotoIf(Word32Equal(Word32And(LoadMapBitField(getter_map),
Int32Constant(1 << Map::kIsCallable)),
Int32Constant(0)),
&done);
GotoUnless(IsCallableMap(getter_map), &done);
// Call the accessor.
Callable callable = CodeFactory::Call(isolate());
......@@ -8096,10 +8099,7 @@ compiler::Node* CodeStubAssembler::InstanceOf(compiler::Node* object,
// Check if {callable} is a valid receiver.
GotoIf(TaggedIsSmi(callable), &return_runtime);
GotoIf(Word32Equal(Word32And(LoadMapBitField(LoadMap(callable)),
Int32Constant(1 << Map::kIsCallable)),
Int32Constant(0)),
&return_runtime);
GotoUnless(IsCallableMap(LoadMap(callable)), &return_runtime);
// Use the inline OrdinaryHasInstance directly.
result.Bind(OrdinaryHasInstance(context, callable, object));
......
......@@ -595,6 +595,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* IsStringInstanceType(compiler::Node* instance_type);
compiler::Node* IsJSReceiverInstanceType(compiler::Node* instance_type);
compiler::Node* IsCallableMap(compiler::Node* map);
// String helpers.
// Load a character from a String (might flatten a ConsString).
compiler::Node* StringCharCodeAt(compiler::Node* string,
......
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