Commit 6ce44688 authored by oliver@apple.com's avatar oliver@apple.com

fourthTier: Add CFG simplification for Switch

https://bugs.webkit.org/show_bug.cgi?id=117677

Source/JavaScriptCore:

Reviewed by Mark Hahnenberg.

This is for completeness. It only speeds up a microbenchmark at this point.
Broadly, we want all control constructs to be known to the CFG simplifier.

* dfg/DFGCFGSimplificationPhase.cpp:
(JSC::DFG::CFGSimplificationPhase::run):
(JSC::DFG::CFGSimplificationPhase::convertToJump):
(CFGSimplificationPhase):
(JSC::DFG::CFGSimplificationPhase::noBlocks):
(JSC::DFG::CFGSimplificationPhase::oneBlock):
(JSC::DFG::CFGSimplificationPhase::mergeBlocks):
* runtime/JSCJSValue.h:
(JSValue):
* runtime/JSCJSValueInlines.h:
(JSC::JSValue::pureStrictEqual):
(JSC):

Source/WTF:

Reviewed by Mark Hahnenberg.

* wtf/TriState.h:
* wtf/text/StringImpl.h:

LayoutTests:

Reviewed by Mark Hahnenberg.

* fast/js/regress/script-tests/switch-constant.js: Added.
(foo):
(bar):
* fast/js/regress/script-tests/switch.js: Added.
(foo):
(bar):
* fast/js/regress/switch-constant-expected.txt: Added.
* fast/js/regress/switch-constant.html: Added.
* fast/js/regress/switch-expected.txt: Added.
* fast/js/regress/switch.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@153229 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9b7647ba
2013-06-15 Filip Pizlo <fpizlo@apple.com>
fourthTier: Add CFG simplification for Switch
https://bugs.webkit.org/show_bug.cgi?id=117677
Reviewed by Mark Hahnenberg.
* fast/js/regress/script-tests/switch-constant.js: Added.
(foo):
(bar):
* fast/js/regress/script-tests/switch.js: Added.
(foo):
(bar):
* fast/js/regress/switch-constant-expected.txt: Added.
* fast/js/regress/switch-constant.html: Added.
* fast/js/regress/switch-expected.txt: Added.
* fast/js/regress/switch.html: Added.
2013-06-11 Filip Pizlo <fpizlo@apple.com>
fourthTier: DFG should support op_in and it should use patching to make it fast
function foo(o) {
switch (o.f) {
case 1: return 5;
case 2: return 2;
case 3: return 7;
case 4: return 9;
case 5: return o.f + 1;
case 6: return 0;
case 7: return 89;
case 8: return 23;
case 9: return 12;
case 10: return 54;
case 11: return 53;
default: return 42;
}
}
function bar() {
var result = 0;
for (var i = 0; i < 1000000; ++i)
result += foo({f:5});
return result;
}
var result = bar();
if (result != 6000000)
throw "Error: bad result: " + result;
function foo(o) {
switch (o.f) {
case 1: return 5;
case 2: return 2;
case 3: return 7;
case 4: return 9;
case 5: return o.f + 1;
case 6: return 0;
case 7: return 89;
case 8: return 23;
case 9: return 12;
case 10: return 54;
case 11: return 53;
default: return 42;
}
}
function bar() {
var result = 0;
for (var i = 0; i < 1000000; ++i)
result ^= foo({f:i % 12});
return result;
}
var result = bar();
if (result != 78)
throw "Error: bad result: " + result;
JSRegress/switch-constant
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS no exception thrown
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../resources/js-test-pre.js"></script>
</head>
<body>
<script src="resources/regress-pre.js"></script>
<script src="script-tests/switch-constant.js"></script>
<script src="resources/regress-post.js"></script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>
JSRegress/switch
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS no exception thrown
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../resources/js-test-pre.js"></script>
</head>
<body>
<script src="resources/regress-pre.js"></script>
<script src="script-tests/switch.js"></script>
<script src="resources/regress-post.js"></script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>
2013-06-15 Filip Pizlo <fpizlo@apple.com>
fourthTier: Add CFG simplification for Switch
https://bugs.webkit.org/show_bug.cgi?id=117677
Reviewed by Mark Hahnenberg.
This is for completeness. It only speeds up a microbenchmark at this point.
Broadly, we want all control constructs to be known to the CFG simplifier.
* dfg/DFGCFGSimplificationPhase.cpp:
(JSC::DFG::CFGSimplificationPhase::run):
(JSC::DFG::CFGSimplificationPhase::convertToJump):
(CFGSimplificationPhase):
(JSC::DFG::CFGSimplificationPhase::noBlocks):
(JSC::DFG::CFGSimplificationPhase::oneBlock):
(JSC::DFG::CFGSimplificationPhase::mergeBlocks):
* runtime/JSCJSValue.h:
(JSValue):
* runtime/JSCJSValueInlines.h:
(JSC::JSValue::pureStrictEqual):
(JSC):
2013-06-13 Filip Pizlo <fpizlo@apple.com>
fourthTier: DFG should support op_switch_imm
......
......@@ -71,6 +71,12 @@ struct NewArrayBufferData {
// instead decide to do something different - this is entirely up to the DFG.
// These data structures give the DFG a higher-level semantic description of
// what is going on, which will allow it to make the right decision.
//
// Note that there will never be multiple SwitchCases in SwitchData::cases that
// have the same SwitchCase::value, since the bytecode's JumpTables never have
// duplicates - since the JumpTable maps a value to a target. It's a
// one-to-many mapping. So we may have duplicate targets, but never duplicate
// values.
struct SwitchCase {
SwitchCase()
: target(NoBlock)
......
......@@ -254,6 +254,7 @@ public:
static bool strictEqual(ExecState*, JSValue v1, JSValue v2);
static bool strictEqualSlowCase(ExecState*, JSValue v1, JSValue v2);
static bool strictEqualSlowCaseInline(ExecState*, JSValue v1, JSValue v2);
static TriState pureStrictEqual(JSValue v1, JSValue v2);
bool isCell() const;
JSCell* asCell() const;
......
......@@ -793,6 +793,28 @@ inline bool JSValue::strictEqual(ExecState* exec, JSValue v1, JSValue v2)
return strictEqualSlowCaseInline(exec, v1, v2);
}
inline TriState JSValue::pureStrictEqual(JSValue v1, JSValue v2)
{
if (v1.isInt32() && v2.isInt32())
return triState(v1 == v2);
if (v1.isNumber() && v2.isNumber())
return triState(v1.asNumber() == v2.asNumber());
if (!v1.isCell() || !v2.isCell())
return triState(v1 == v2);
if (v1.asCell()->isString() && v2.asCell()->isString()) {
const StringImpl* v1String = asString(v1)->tryGetValueImpl();
const StringImpl* v2String = asString(v2)->tryGetValueImpl();
if (!v1String || !v2String)
return MixedTriState;
return triState(WTF::equal(v1String, v2String));
}
return triState(v1 == v2);
}
inline TriState JSValue::pureToBoolean() const
{
if (isInt32())
......
2013-06-15 Filip Pizlo <fpizlo@apple.com>
fourthTier: Add CFG simplification for Switch
https://bugs.webkit.org/show_bug.cgi?id=117677
Reviewed by Mark Hahnenberg.
* wtf/TriState.h:
* wtf/text/StringImpl.h:
2013-06-15 Filip Pizlo <fpizlo@apple.com>
Printing a StringImpl* should really guard against NULL
......
......@@ -45,5 +45,6 @@ using WTF::TriState;
using WTF::FalseTriState;
using WTF::TrueTriState;
using WTF::MixedTriState;
using WTF::triState;
#endif // TriState_h
......@@ -1363,7 +1363,7 @@ template<> struct DefaultHash<RefPtr<StringImpl> > {
typedef StringHash Hash;
};
}
} // namespace WTF
using WTF::StringImpl;
using WTF::equal;
......
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