Skip to content
Permalink
Browse files
Adds fromCharCode intrinsic support.
https://bugs.webkit.org/show_bug.cgi?id=104807

Patch by Vahag Vardanyan <vaag@ispras.ru> on 2013-04-08
Reviewed by Oliver Hunt.

Switch to using fromCharCode intrinsic instead of call operation in some cases.

* dfg/DFGAbstractState.cpp:
(JSC::DFG::AbstractState::executeEffects):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::handleIntrinsic):
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupNode):
* dfg/DFGNodeType.h:
(DFG):
* dfg/DFGOperations.cpp:
* dfg/DFGOperations.h:
* dfg/DFGPredictionPropagationPhase.cpp:
(JSC::DFG::PredictionPropagationPhase::propagate):
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileFromCharCode):
(DFG):
* dfg/DFGSpeculativeJIT.h:
(JSC::DFG::SpeculativeJIT::callOperation):
(SpeculativeJIT):
* dfg/DFGSpeculativeJIT32_64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* dfg/DFGSpeculativeJIT64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* runtime/StringConstructor.cpp:
(JSC::stringFromCharCode):
(JSC):
* runtime/StringConstructor.h:
(JSC):

Canonical link: https://commits.webkit.org/132610@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@147985 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
VVaag authored and webkit-commit-queue committed Apr 9, 2013
1 parent 5f61677 commit f884160e7d3f56ee3fe7131179d9023a1827441a
Showing 14 changed files with 122 additions and 0 deletions.
@@ -1,3 +1,40 @@
2013-04-08 Vahag Vardanyan <vaag@ispras.ru>

Adds fromCharCode intrinsic support.
https://bugs.webkit.org/show_bug.cgi?id=104807

Reviewed by Oliver Hunt.

Switch to using fromCharCode intrinsic instead of call operation in some cases.

* dfg/DFGAbstractState.cpp:
(JSC::DFG::AbstractState::executeEffects):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::handleIntrinsic):
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupNode):
* dfg/DFGNodeType.h:
(DFG):
* dfg/DFGOperations.cpp:
* dfg/DFGOperations.h:
* dfg/DFGPredictionPropagationPhase.cpp:
(JSC::DFG::PredictionPropagationPhase::propagate):
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileFromCharCode):
(DFG):
* dfg/DFGSpeculativeJIT.h:
(JSC::DFG::SpeculativeJIT::callOperation):
(SpeculativeJIT):
* dfg/DFGSpeculativeJIT32_64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* dfg/DFGSpeculativeJIT64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* runtime/StringConstructor.cpp:
(JSC::stringFromCharCode):
(JSC):
* runtime/StringConstructor.h:
(JSC):

2013-04-08 Benjamin Poulain <benjamin@webkit.org>

Remove HTML Notification
@@ -861,6 +861,10 @@ bool AbstractState::executeEffects(unsigned indexInBlock, Node* node)
forNode(node).set(SpecInt32);
break;

case StringFromCharCode:
forNode(node).set(SpecString);
break;

case StringCharAt:
node->setCanExit(true);
forNode(node).set(m_graph.m_globalData.stringStructure.get());
@@ -1564,6 +1564,18 @@ bool ByteCodeParser::handleIntrinsic(bool usesResult, int resultOperand, Intrins
set(resultOperand, charCode);
return true;
}
case FromCharCodeIntrinsic: {
if (argumentCountIncludingThis != 2)
return false;

int indexOperand = registerOffset + argumentToOperand(1);
Node* charCode = addToGraph(StringFromCharCode, getToInt32(indexOperand));

if (usesResult)
set(resultOperand, charCode);

return true;
}

case RegExpExecIntrinsic: {
if (argumentCountIncludingThis != 2)
@@ -356,6 +356,10 @@ class FixupPhase : public Phase {
break;
}

case StringFromCharCode:
setUseKindAndUnboxIfProfitable<Int32Use>(node->child1());
break;

case StringCharAt:
case StringCharCodeAt: {
// Currently we have no good way of refining these.
@@ -181,6 +181,7 @@ namespace JSC { namespace DFG {
/* Optimizations for string access */ \
macro(StringCharCodeAt, NodeResultInt32) \
macro(StringCharAt, NodeResultJS) \
macro(StringFromCharCode, NodeResultJS) \
\
/* Nodes for comparison operations. */\
macro(CompareLess, NodeResultBoolean | NodeMustGenerate | NodeMightClobber) \
@@ -44,6 +44,7 @@
#include "NameInstance.h"
#include "ObjectConstructor.h"
#include "Operations.h"
#include "StringConstructor.h"
#include <wtf/InlineASM.h>

#if ENABLE(JIT)
@@ -1601,6 +1602,13 @@ double DFG_OPERATION operationFModOnInts(int32_t a, int32_t b)
return fmod(a, b);
}

JSCell* DFG_OPERATION operationStringFromCharCode(ExecState* exec, int32_t op1)
{
JSGlobalData* globalData = &exec->globalData();
NativeCallFrameTracer tracer(globalData, exec);
return JSC::stringFromCharCode(exec, op1);
}

DFGHandlerEncoded DFG_OPERATION lookupExceptionHandler(ExecState* exec, uint32_t callIndex)
{
JSGlobalData* globalData = &exec->globalData();
@@ -82,6 +82,7 @@ typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EZ)(ExecState*, int32_t);
typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EZIcfZ)(ExecState*, int32_t, InlineCallFrame*, int32_t);
typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EZZ)(ExecState*, int32_t, int32_t);
typedef JSCell* DFG_OPERATION (*C_DFGOperation_E)(ExecState*);
typedef JSCell* DFG_OPERATION (*C_DFGOperation_EZ)(ExecState*, int32_t);
typedef JSCell* DFG_OPERATION (*C_DFGOperation_EC)(ExecState*, JSCell*);
typedef JSCell* DFG_OPERATION (*C_DFGOperation_ECC)(ExecState*, JSCell*, JSCell*);
typedef JSCell* DFG_OPERATION (*C_DFGOperation_EIcf)(ExecState*, InlineCallFrame*);
@@ -91,6 +92,7 @@ typedef JSCell* DFG_OPERATION (*C_DFGOperation_EJssJss)(ExecState*, JSString*, J
typedef JSCell* DFG_OPERATION (*C_DFGOperation_EJssJssJss)(ExecState*, JSString*, JSString*, JSString*);
typedef JSCell* DFG_OPERATION (*C_DFGOperation_EOZ)(ExecState*, JSObject*, int32_t);
typedef JSCell* DFG_OPERATION (*C_DFGOperation_ESt)(ExecState*, Structure*);
typedef JSCell* DFG_OPERATION (*C_DFGOperation_EZ)(ExecState*, int32_t);
typedef double DFG_OPERATION (*D_DFGOperation_DD)(double, double);
typedef double DFG_OPERATION (*D_DFGOperation_ZZ)(int32_t, int32_t);
typedef double DFG_OPERATION (*D_DFGOperation_EJ)(ExecState*, EncodedJSValue);
@@ -124,6 +126,7 @@ typedef char* DFG_OPERATION (*P_DFGOperation_EStPS)(ExecState*, Structure*, void
typedef char* DFG_OPERATION (*P_DFGOperation_EStSS)(ExecState*, Structure*, size_t, size_t);
typedef char* DFG_OPERATION (*P_DFGOperation_EStZ)(ExecState*, Structure*, int32_t);
typedef StringImpl* DFG_OPERATION (*Str_DFGOperation_EJss)(ExecState*, JSString*);
JSCell* DFG_OPERATION operationStringFromCharCode(ExecState*, int32_t) WTF_INTERNAL;

// These routines are provide callbacks out to C++ implementations of operations too complex to JIT.
JSCell* DFG_OPERATION operationNewObject(ExecState*, Structure*) WTF_INTERNAL;
@@ -423,6 +423,11 @@ class PredictionPropagationPhase : public Phase {
break;
}

case StringFromCharCode: {
changed |= setPrediction(SpecString);
changed |= node->child1()->mergeFlags(NodeUsedAsNumber | NodeUsedAsInt);
break;
}
case StringCharAt:
case ToString:
case MakeRope: {
@@ -2088,6 +2088,25 @@ void SpeculativeJIT::compileGetByValOnString(Node* node)
cellResult(scratchReg, m_currentNode);
}

void SpeculativeJIT::compileFromCharCode(Node* node)
{
SpeculateStrictInt32Operand property(this, node->child1());
GPRReg propertyReg = property.gpr();
GPRTemporary smallStrings(this);
GPRTemporary scratch(this);
GPRReg scratchReg = scratch.gpr();
GPRReg smallStringsReg = smallStrings.gpr();

JITCompiler::JumpList slowCases;
slowCases.append(m_jit.branch32(MacroAssembler::AboveOrEqual, propertyReg, TrustedImm32(0xff)));
m_jit.move(MacroAssembler::TrustedImmPtr(m_jit.globalData()->smallStrings.singleCharacterStrings()), smallStringsReg);
m_jit.loadPtr(MacroAssembler::BaseIndex(smallStringsReg, propertyReg, MacroAssembler::ScalePtr, 0), scratchReg);

slowCases.append(m_jit.branchTest32(MacroAssembler::Zero, scratchReg));
addSlowPathGenerator(slowPathCall(slowCases, this, operationStringFromCharCode, scratchReg, propertyReg));
cellResult(scratchReg, m_currentNode);
}

GeneratedOperandType SpeculativeJIT::checkGeneratedTypeForToInt32(Node* node)
{
#if DFG_ENABLE(DEBUG_VERBOSE)
@@ -1263,6 +1263,11 @@ class SpeculativeJIT {
m_jit.setupArgumentsWithExecState(arg1);
return appendCallWithExceptionCheckSetResult(operation, result);
}
JITCompiler::Call callOperation(C_DFGOperation_EZ operation, GPRReg result, GPRReg arg1)
{
m_jit.setupArgumentsWithExecState(arg1);
return appendCallWithExceptionCheckSetResult(operation, result);
}
#else

// EncodedJSValue in JSVALUE32_64 is a 64-bit integer. When being compiled in ARM EABI, it must be aligned even-numbered register (r0, r2 or [sp]).
@@ -1686,6 +1691,12 @@ class SpeculativeJIT {
m_jit.setupArgumentsWithExecState(arg1);
return appendCallWithExceptionCheckSetResult(operation, result);
}
JITCompiler::Call callOperation(C_DFGOperation_EZ operation, GPRReg result, GPRReg arg1)
{
m_jit.setupArgumentsWithExecState(arg1);
return appendCallWithExceptionCheckSetResult(operation, result);
}


#undef EABI_32BIT_DUMMY_ARG

@@ -2105,6 +2116,7 @@ class SpeculativeJIT {

void compileGetCharCodeAt(Node*);
void compileGetByValOnString(Node*);
void compileFromCharCode(Node*);

void compileGetByValOnArguments(Node*);
void compileGetArgumentsLength(Node*);
@@ -2451,6 +2451,11 @@ void SpeculativeJIT::compile(Node* node)
compileGetByValOnString(node);
break;
}

case StringFromCharCode: {
compileFromCharCode(node);
break;
}

case CheckArray: {
checkArray(node);
@@ -2378,6 +2378,11 @@ void SpeculativeJIT::compile(Node* node)
compileGetByValOnString(node);
break;
}

case StringFromCharCode: {
compileFromCharCode(node);
break;
}

case CheckArray: {
checkArray(node);
@@ -89,6 +89,11 @@ static EncodedJSValue JSC_HOST_CALL stringFromCharCode(ExecState* exec)
return JSValue::encode(stringFromCharCodeSlowCase(exec));
}

JSCell* JSC_HOST_CALL stringFromCharCode(ExecState* exec, int32_t arg)
{
return jsSingleCharacterString(exec, arg);
}

static EncodedJSValue JSC_HOST_CALL constructWithStringConstructor(ExecState* exec)
{
JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject();
@@ -57,6 +57,8 @@ namespace JSC {
static bool getOwnPropertySlot(JSCell*, ExecState*, PropertyName, PropertySlot&);
static bool getOwnPropertyDescriptor(JSObject*, ExecState*, PropertyName, PropertyDescriptor&);
};

JSCell* JSC_HOST_CALL stringFromCharCode(ExecState*, int32_t);

} // namespace JSC

0 comments on commit f884160

Please sign in to comment.