<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[214592] trunk/Source/JavaScriptCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/214592">214592</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2017-03-29 19:39:51 -0700 (Wed, 29 Mar 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>WebAssembly: B3IRGenerator should pool constants
https://bugs.webkit.org/show_bug.cgi?id=170266
Reviewed by Filip Pizlo.
This patch adds a HashMap to B3IRGenerator that contains all the constants used in a function.
B3IRGenerator then uses an InsertionSet to add all those constants to the root BB. This doesn't
appear to be a compile time improvement but it could be valuable in the future.
* b3/B3Opcode.h:
(JSC::B3::opcodeForConstant):
* b3/B3Procedure.cpp:
(JSC::B3::Procedure::addConstant):
* b3/B3Procedure.h:
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::B3IRGenerator):
(JSC::Wasm::B3IRGenerator::constant):
(JSC::Wasm::B3IRGenerator::insertConstants):
(JSC::Wasm::B3IRGenerator::addConstant):
(JSC::Wasm::B3IRGenerator::dump):
(JSC::Wasm::parseAndCompile):
(JSC::Wasm::B3IRGenerator::emitChecksForModOrDiv):
(JSC::Wasm::B3IRGenerator::zeroForType): Deleted.
* wasm/generateWasmB3IRGeneratorInlinesHeader.py:
(generateConstCode):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3Opcodeh">trunk/Source/JavaScriptCore/b3/B3Opcode.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3Procedurecpp">trunk/Source/JavaScriptCore/b3/B3Procedure.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3Procedureh">trunk/Source/JavaScriptCore/b3/B3Procedure.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmB3IRGeneratorcpp">trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmgenerateWasmB3IRGeneratorInlinesHeaderpy">trunk/Source/JavaScriptCore/wasm/generateWasmB3IRGeneratorInlinesHeader.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (214591 => 214592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2017-03-30 01:41:11 UTC (rev 214591)
+++ trunk/Source/JavaScriptCore/ChangeLog        2017-03-30 02:39:51 UTC (rev 214592)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2017-03-29 Keith Miller <keith_miller@apple.com>
+
+ WebAssembly: B3IRGenerator should pool constants
+ https://bugs.webkit.org/show_bug.cgi?id=170266
+
+ Reviewed by Filip Pizlo.
+
+ This patch adds a HashMap to B3IRGenerator that contains all the constants used in a function.
+ B3IRGenerator then uses an InsertionSet to add all those constants to the root BB. This doesn't
+ appear to be a compile time improvement but it could be valuable in the future.
+
+ * b3/B3Opcode.h:
+ (JSC::B3::opcodeForConstant):
+ * b3/B3Procedure.cpp:
+ (JSC::B3::Procedure::addConstant):
+ * b3/B3Procedure.h:
+ * wasm/WasmB3IRGenerator.cpp:
+ (JSC::Wasm::B3IRGenerator::B3IRGenerator):
+ (JSC::Wasm::B3IRGenerator::constant):
+ (JSC::Wasm::B3IRGenerator::insertConstants):
+ (JSC::Wasm::B3IRGenerator::addConstant):
+ (JSC::Wasm::B3IRGenerator::dump):
+ (JSC::Wasm::parseAndCompile):
+ (JSC::Wasm::B3IRGenerator::emitChecksForModOrDiv):
+ (JSC::Wasm::B3IRGenerator::zeroForType): Deleted.
+ * wasm/generateWasmB3IRGeneratorInlinesHeader.py:
+ (generateConstCode):
+
</ins><span class="cx"> 2017-03-29 Saam Barati <sbarati@apple.com>
</span><span class="cx">
</span><span class="cx"> LinkBuffer and ExecutableAllocator shouldn't have anything to do with VM
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3Opcodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3Opcode.h (214591 => 214592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3Opcode.h        2017-03-30 01:41:11 UTC (rev 214591)
+++ trunk/Source/JavaScriptCore/b3/B3Opcode.h        2017-03-30 02:39:51 UTC (rev 214592)
</span><span class="lines">@@ -391,6 +391,18 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+inline Opcode opcodeForConstant(Type type)
+{
+ switch (type) {
+ case Int32: return Const32;
+ case Int64: return Const64;
+ case Float: return ConstFloat;
+ case Double: return ConstDouble;
+ default:
+ RELEASE_ASSERT_NOT_REACHED();
+ }
+}
+
</ins><span class="cx"> inline bool isDefinitelyTerminal(Opcode opcode)
</span><span class="cx"> {
</span><span class="cx"> switch (opcode) {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3Procedurecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3Procedure.cpp (214591 => 214592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3Procedure.cpp        2017-03-30 01:41:11 UTC (rev 214591)
+++ trunk/Source/JavaScriptCore/b3/B3Procedure.cpp        2017-03-30 02:39:51 UTC (rev 214592)
</span><span class="lines">@@ -89,6 +89,7 @@
</span><span class="cx"> return m_values.add(WTFMove(clone));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> Value* Procedure::addIntConstant(Origin origin, Type type, int64_t value)
</span><span class="cx"> {
</span><span class="cx"> switch (type) {
</span><span class="lines">@@ -111,6 +112,23 @@
</span><span class="cx"> return addIntConstant(likeValue->origin(), likeValue->type(), value);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+Value* Procedure::addConstant(Origin origin, Type type, uint64_t bits)
+{
+ switch (type) {
+ case Int32:
+ return add<Const32Value>(origin, static_cast<int32_t>(bits));
+ case Int64:
+ return add<Const64Value>(origin, bits);
+ case Float:
+ return add<ConstFloatValue>(origin, bitwise_cast<float>(static_cast<int32_t>(bits)));
+ case Double:
+ return add<ConstDoubleValue>(origin, bitwise_cast<double>(bits));
+ default:
+ RELEASE_ASSERT_NOT_REACHED();
+ return nullptr;
+ }
+}
+
</ins><span class="cx"> Value* Procedure::addBottom(Origin origin, Type type)
</span><span class="cx"> {
</span><span class="cx"> return addIntConstant(origin, type, 0);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3Procedureh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3Procedure.h (214591 => 214592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3Procedure.h        2017-03-30 01:41:11 UTC (rev 214591)
+++ trunk/Source/JavaScriptCore/b3/B3Procedure.h        2017-03-30 02:39:51 UTC (rev 214592)
</span><span class="lines">@@ -117,6 +117,9 @@
</span><span class="cx"> Value* addIntConstant(Origin, Type, int64_t value);
</span><span class="cx"> Value* addIntConstant(Value*, int64_t value);
</span><span class="cx">
</span><ins>+ // bits is a bitwise_cast of the constant you want.
+ Value* addConstant(Origin, Type, uint64_t bits);
+
</ins><span class="cx"> // You're guaranteed that bottom is zero.
</span><span class="cx"> Value* addBottom(Origin, Type);
</span><span class="cx"> Value* addBottom(Value*);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmB3IRGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp (214591 => 214592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp        2017-03-30 01:41:11 UTC (rev 214591)
+++ trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp        2017-03-30 02:39:51 UTC (rev 214592)
</span><span class="lines">@@ -35,11 +35,13 @@
</span><span class="cx"> #include "B3ConstPtrValue.h"
</span><span class="cx"> #include "B3FixSSA.h"
</span><span class="cx"> #include "B3Generate.h"
</span><ins>+#include "B3InsertionSet.h"
</ins><span class="cx"> #include "B3SlotBaseValue.h"
</span><span class="cx"> #include "B3StackmapGenerationParams.h"
</span><span class="cx"> #include "B3SwitchValue.h"
</span><span class="cx"> #include "B3Validate.h"
</span><span class="cx"> #include "B3ValueInlines.h"
</span><ins>+#include "B3ValueKey.h"
</ins><span class="cx"> #include "B3Variable.h"
</span><span class="cx"> #include "B3VariableValue.h"
</span><span class="cx"> #include "B3WasmAddressValue.h"
</span><span class="lines">@@ -207,6 +209,9 @@
</span><span class="cx"> void dump(const Vector<ControlEntry>& controlStack, const ExpressionList* expressionStack);
</span><span class="cx"> void setParser(FunctionParser<B3IRGenerator>* parser) { m_parser = parser; };
</span><span class="cx">
</span><ins>+ Value* constant(B3::Type, uint64_t bits);
+ void insertConstants();
+
</ins><span class="cx"> private:
</span><span class="cx"> void emitExceptionCheck(CCallHelpers&, ExceptionType);
</span><span class="cx">
</span><span class="lines">@@ -217,7 +222,6 @@
</span><span class="cx">
</span><span class="cx"> void unify(Variable* target, const ExpressionType source);
</span><span class="cx"> void unifyValuesWithBlock(const ExpressionList& resultStack, ResultList& stack);
</span><del>- Value* zeroForType(Type);
</del><span class="cx">
</span><span class="cx"> void emitChecksForModOrDiv(B3::Opcode, ExpressionType left, ExpressionType right);
</span><span class="cx">
</span><span class="lines">@@ -235,10 +239,11 @@
</span><span class="cx"> BasicBlock* m_currentBlock;
</span><span class="cx"> Vector<Variable*> m_locals;
</span><span class="cx"> Vector<UnlinkedWasmToWasmCall>& m_unlinkedWasmToWasmCalls; // List each call site and the function index whose address it should be patched with.
</span><ins>+ HashMap<ValueKey, Value*> m_constantPool;
+ InsertionSet m_constantInsertionValues;
</ins><span class="cx"> GPRReg m_memoryBaseGPR;
</span><span class="cx"> GPRReg m_memorySizeGPR;
</span><span class="cx"> GPRReg m_wasmContextGPR;
</span><del>- Value* m_zeroValues[numTypes];
</del><span class="cx"> Value* m_instanceValue; // FIXME: make this lazy https://bugs.webkit.org/show_bug.cgi?id=169792
</span><span class="cx"> };
</span><span class="cx">
</span><span class="lines">@@ -302,23 +307,10 @@
</span><span class="cx"> , m_mode(mode)
</span><span class="cx"> , m_proc(procedure)
</span><span class="cx"> , m_unlinkedWasmToWasmCalls(unlinkedWasmToWasmCalls)
</span><ins>+ , m_constantInsertionValues(m_proc)
</ins><span class="cx"> {
</span><span class="cx"> m_currentBlock = m_proc.addBlock();
</span><span class="cx">
</span><del>- for (unsigned i = 0; i < numTypes; ++i) {
- switch (B3::Type b3Type = toB3Type(linearizedToType(i))) {
- case B3::Int32:
- case B3::Int64:
- case B3::Float:
- case B3::Double:
- m_zeroValues[i] = m_currentBlock->appendIntConstant(m_proc, Origin(), b3Type, 0);
- break;
- case B3::Void:
- m_zeroValues[i] = nullptr;
- break;
- }
- }
-
</del><span class="cx"> // FIXME we don't really need to pin registers here if there's no memory. It makes wasm -> wasm thunks simpler for now. https://bugs.webkit.org/show_bug.cgi?id=166623
</span><span class="cx"> const PinnedRegisterInfo& pinnedRegs = PinnedRegisterInfo::get();
</span><span class="cx"> m_memoryBaseGPR = pinnedRegs.baseMemoryPointer;
</span><span class="lines">@@ -389,14 +381,21 @@
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span><del>-Value* B3IRGenerator::zeroForType(Type type)
</del><ins>+Value* B3IRGenerator::constant(B3::Type type, uint64_t bits)
</ins><span class="cx"> {
</span><del>- ASSERT(type != Void);
- Value* zeroValue = m_zeroValues[linearizeType(type)];
- ASSERT(zeroValue);
- return zeroValue;
</del><ins>+ auto result = m_constantPool.ensure(ValueKey(opcodeForConstant(type), type, static_cast<int64_t>(bits)), [&] {
+ Value* result = m_proc.addConstant(origin(), type, bits);
+ m_constantInsertionValues.insertValue(0, result);
+ return result;
+ });
+ return result.iterator->value;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+void B3IRGenerator::insertConstants()
+{
+ m_constantInsertionValues.execute(m_proc.at(0));
+}
+
</ins><span class="cx"> auto B3IRGenerator::addLocal(Type type, uint32_t count) -> PartialResult
</span><span class="cx"> {
</span><span class="cx"> WASM_COMPILE_FAIL_IF(!m_locals.tryReserveCapacity(m_locals.size() + count), "can't allocate memory for ", m_locals.size() + count, " locals");
</span><span class="lines">@@ -404,7 +403,7 @@
</span><span class="cx"> for (uint32_t i = 0; i < count; ++i) {
</span><span class="cx"> Variable* local = m_proc.addVariable(toB3Type(type));
</span><span class="cx"> m_locals.uncheckedAppend(local);
</span><del>- m_currentBlock->appendNew<VariableValue>(m_proc, Set, origin(), local, zeroForType(type));
</del><ins>+ m_currentBlock->appendNew<VariableValue>(m_proc, Set, origin(), local, addConstant(type, 0));
</ins><span class="cx"> }
</span><span class="cx"> return { };
</span><span class="cx"> }
</span><span class="lines">@@ -644,7 +643,7 @@
</span><span class="cx"> case LoadOpType::I32Load:
</span><span class="cx"> case LoadOpType::I32Load16U:
</span><span class="cx"> case LoadOpType::I32Load8U:
</span><del>- result = zeroForType(I32);
</del><ins>+ result = constant(Int32, 0);
</ins><span class="cx"> break;
</span><span class="cx"> case LoadOpType::I64Load8S:
</span><span class="cx"> case LoadOpType::I64Load8U:
</span><span class="lines">@@ -653,13 +652,13 @@
</span><span class="cx"> case LoadOpType::I64Load32S:
</span><span class="cx"> case LoadOpType::I64Load:
</span><span class="cx"> case LoadOpType::I64Load16U:
</span><del>- result = zeroForType(I64);
</del><ins>+ result = constant(Int64, 0);
</ins><span class="cx"> break;
</span><span class="cx"> case LoadOpType::F32Load:
</span><del>- result = zeroForType(F32);
</del><ins>+ result = constant(Float, 0);
</ins><span class="cx"> break;
</span><span class="cx"> case LoadOpType::F64Load:
</span><del>- result = zeroForType(F64);
</del><ins>+ result = constant(Double, 0);
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -748,22 +747,7 @@
</span><span class="cx">
</span><span class="cx"> B3IRGenerator::ExpressionType B3IRGenerator::addConstant(Type type, uint64_t value)
</span><span class="cx"> {
</span><del>- switch (type) {
- case Wasm::I32:
- return m_currentBlock->appendNew<Const32Value>(m_proc, origin(), static_cast<int32_t>(value));
- case Wasm::I64:
- return m_currentBlock->appendNew<Const64Value>(m_proc, origin(), value);
- case Wasm::F32:
- return m_currentBlock->appendNew<ConstFloatValue>(m_proc, origin(), bitwise_cast<float>(static_cast<int32_t>(value)));
- case Wasm::F64:
- return m_currentBlock->appendNew<ConstDoubleValue>(m_proc, origin(), bitwise_cast<double>(value));
- case Wasm::Void:
- case Wasm::Func:
- case Wasm::Anyfunc:
- break;
- }
- RELEASE_ASSERT_NOT_REACHED();
- return nullptr;
</del><ins>+ return constant(toB3Type(type), value);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> B3IRGenerator::ControlData B3IRGenerator::addTopLevel(Type signature)
</span><span class="lines">@@ -1007,7 +991,7 @@
</span><span class="cx"> // Compute the offset in the table index space we are looking for.
</span><span class="cx"> ExpressionType offset = m_currentBlock->appendNew<Value>(m_proc, Mul, origin(),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, ZExt32, origin(), calleeIndex),
</span><del>- m_currentBlock->appendIntConstant(m_proc, origin(), pointerType(), sizeof(CallableFunction)));
</del><ins>+ constant(pointerType(), sizeof(CallableFunction)));
</ins><span class="cx"> ExpressionType callableFunction = m_currentBlock->appendNew<Value>(m_proc, Add, origin(), callableFunctionBuffer, offset);
</span><span class="cx">
</span><span class="cx"> // Check that the CallableFunction is initialized. We trap if it isn't. An "invalid" SignatureIndex indicates it's not initialized.
</span><span class="lines">@@ -1079,6 +1063,10 @@
</span><span class="cx">
</span><span class="cx"> void B3IRGenerator::dump(const Vector<ControlEntry>& controlStack, const ExpressionList* expressionStack)
</span><span class="cx"> {
</span><ins>+ dataLogLn("Constants:");
+ for (const auto& constant : m_constantPool)
+ dataLogLn(deepDump(m_proc, constant.value));
+
</ins><span class="cx"> dataLogLn("Processing Graph:");
</span><span class="cx"> dataLog(m_proc);
</span><span class="cx"> dataLogLn("With current block:", *m_currentBlock);
</span><span class="lines">@@ -1292,6 +1280,8 @@
</span><span class="cx"> FunctionParser<B3IRGenerator> parser(&vm, context, functionStart, functionLength, signature, info, moduleSignatureIndicesToUniquedSignatureIndices);
</span><span class="cx"> WASM_FAIL_IF_HELPER_FAILS(parser.parse());
</span><span class="cx">
</span><ins>+ context.insertConstants();
+
</ins><span class="cx"> procedure.resetReachability();
</span><span class="cx"> if (!ASSERT_DISABLED)
</span><span class="cx"> validate(procedure, "After parsing:\n");
</span><span class="lines">@@ -1320,8 +1310,7 @@
</span><span class="cx">
</span><span class="cx"> {
</span><span class="cx"> CheckValue* check = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(),
</span><del>- m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), right,
- m_currentBlock->appendIntConstant(m_proc, origin(), type, 0)));
</del><ins>+ m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), right, constant(type, 0)));
</ins><span class="cx">
</span><span class="cx"> check->setGenerator([=] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
</span><span class="cx"> this->emitExceptionCheck(jit, ExceptionType::DivisionByZero);
</span><span class="lines">@@ -1333,10 +1322,8 @@
</span><span class="cx">
</span><span class="cx"> CheckValue* check = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, BitAnd, origin(),
</span><del>- m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), left,
- m_currentBlock->appendIntConstant(m_proc, origin(), type, min)),
- m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), right,
- m_currentBlock->appendIntConstant(m_proc, origin(), type, -1))));
</del><ins>+ m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), left, constant(type, min)),
+ m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), right, constant(type, -1))));
</ins><span class="cx">
</span><span class="cx"> check->setGenerator([=] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
</span><span class="cx"> this->emitExceptionCheck(jit, ExceptionType::IntegerOverflow);
</span><span class="lines">@@ -1559,12 +1546,12 @@
</span><span class="cx"> template<>
</span><span class="cx"> auto B3IRGenerator::addOp<OpType::I32TruncSF64>(ExpressionType arg, ExpressionType& result) -> PartialResult
</span><span class="cx"> {
</span><del>- Value* max = m_currentBlock->appendNew<ConstDoubleValue>(m_proc, origin(), -static_cast<double>(std::numeric_limits<int32_t>::min()));
- Value* min = m_currentBlock->appendNew<ConstDoubleValue>(m_proc, origin(), static_cast<double>(std::numeric_limits<int32_t>::min()));
</del><ins>+ Value* max = constant(Double, bitwise_cast<uint64_t>(-static_cast<double>(std::numeric_limits<int32_t>::min())));
+ Value* min = constant(Double, bitwise_cast<uint64_t>(static_cast<double>(std::numeric_limits<int32_t>::min())));
</ins><span class="cx"> Value* outOfBounds = m_currentBlock->appendNew<Value>(m_proc, BitAnd, origin(),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, LessThan, origin(), arg, max),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, GreaterEqual, origin(), arg, min));
</span><del>- outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, zeroForType(I32));
</del><ins>+ outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, constant(Int32, 0));
</ins><span class="cx"> CheckValue* trap = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(), outOfBounds);
</span><span class="cx"> trap->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams&) {
</span><span class="cx"> this->emitExceptionCheck(jit, ExceptionType::OutOfBoundsTrunc);
</span><span class="lines">@@ -1582,12 +1569,12 @@
</span><span class="cx"> template<>
</span><span class="cx"> auto B3IRGenerator::addOp<OpType::I32TruncSF32>(ExpressionType arg, ExpressionType& result) -> PartialResult
</span><span class="cx"> {
</span><del>- Value* max = m_currentBlock->appendNew<ConstFloatValue>(m_proc, origin(), -static_cast<float>(std::numeric_limits<int32_t>::min()));
- Value* min = m_currentBlock->appendNew<ConstFloatValue>(m_proc, origin(), static_cast<float>(std::numeric_limits<int32_t>::min()));
</del><ins>+ Value* max = constant(Float, bitwise_cast<uint32_t>(-static_cast<float>(std::numeric_limits<int32_t>::min())));
+ Value* min = constant(Float, bitwise_cast<uint32_t>(static_cast<float>(std::numeric_limits<int32_t>::min())));
</ins><span class="cx"> Value* outOfBounds = m_currentBlock->appendNew<Value>(m_proc, BitAnd, origin(),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, LessThan, origin(), arg, max),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, GreaterEqual, origin(), arg, min));
</span><del>- outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, zeroForType(I32));
</del><ins>+ outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, constant(Int32, 0));
</ins><span class="cx"> CheckValue* trap = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(), outOfBounds);
</span><span class="cx"> trap->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams&) {
</span><span class="cx"> this->emitExceptionCheck(jit, ExceptionType::OutOfBoundsTrunc);
</span><span class="lines">@@ -1606,12 +1593,12 @@
</span><span class="cx"> template<>
</span><span class="cx"> auto B3IRGenerator::addOp<OpType::I32TruncUF64>(ExpressionType arg, ExpressionType& result) -> PartialResult
</span><span class="cx"> {
</span><del>- Value* max = m_currentBlock->appendNew<ConstDoubleValue>(m_proc, origin(), static_cast<double>(std::numeric_limits<int32_t>::min()) * -2.0);
- Value* min = m_currentBlock->appendNew<ConstDoubleValue>(m_proc, origin(), -1.0);
</del><ins>+ Value* max = constant(Double, bitwise_cast<uint64_t>(static_cast<double>(std::numeric_limits<int32_t>::min()) * -2.0));
+ Value* min = constant(Double, bitwise_cast<uint64_t>(-1.0));
</ins><span class="cx"> Value* outOfBounds = m_currentBlock->appendNew<Value>(m_proc, BitAnd, origin(),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, LessThan, origin(), arg, max),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, GreaterThan, origin(), arg, min));
</span><del>- outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, zeroForType(I32));
</del><ins>+ outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, constant(Int32, 0));
</ins><span class="cx"> CheckValue* trap = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(), outOfBounds);
</span><span class="cx"> trap->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams&) {
</span><span class="cx"> this->emitExceptionCheck(jit, ExceptionType::OutOfBoundsTrunc);
</span><span class="lines">@@ -1629,12 +1616,12 @@
</span><span class="cx"> template<>
</span><span class="cx"> auto B3IRGenerator::addOp<OpType::I32TruncUF32>(ExpressionType arg, ExpressionType& result) -> PartialResult
</span><span class="cx"> {
</span><del>- Value* max = m_currentBlock->appendNew<ConstFloatValue>(m_proc, origin(), static_cast<float>(std::numeric_limits<int32_t>::min()) * -2.0);
- Value* min = m_currentBlock->appendNew<ConstFloatValue>(m_proc, origin(), -1.0);
</del><ins>+ Value* max = constant(Float, bitwise_cast<uint32_t>(static_cast<float>(std::numeric_limits<int32_t>::min()) * static_cast<float>(-2.0)));
+ Value* min = constant(Float, bitwise_cast<uint32_t>(static_cast<float>(-1.0)));
</ins><span class="cx"> Value* outOfBounds = m_currentBlock->appendNew<Value>(m_proc, BitAnd, origin(),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, LessThan, origin(), arg, max),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, GreaterThan, origin(), arg, min));
</span><del>- outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, zeroForType(I32));
</del><ins>+ outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, constant(Int32, 0));
</ins><span class="cx"> CheckValue* trap = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(), outOfBounds);
</span><span class="cx"> trap->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams&) {
</span><span class="cx"> this->emitExceptionCheck(jit, ExceptionType::OutOfBoundsTrunc);
</span><span class="lines">@@ -1652,12 +1639,12 @@
</span><span class="cx"> template<>
</span><span class="cx"> auto B3IRGenerator::addOp<OpType::I64TruncSF64>(ExpressionType arg, ExpressionType& result) -> PartialResult
</span><span class="cx"> {
</span><del>- Value* max = m_currentBlock->appendNew<ConstDoubleValue>(m_proc, origin(), -static_cast<double>(std::numeric_limits<int64_t>::min()));
- Value* min = m_currentBlock->appendNew<ConstDoubleValue>(m_proc, origin(), static_cast<double>(std::numeric_limits<int64_t>::min()));
</del><ins>+ Value* max = constant(Double, bitwise_cast<uint64_t>(-static_cast<double>(std::numeric_limits<int64_t>::min())));
+ Value* min = constant(Double, bitwise_cast<uint64_t>(static_cast<double>(std::numeric_limits<int64_t>::min())));
</ins><span class="cx"> Value* outOfBounds = m_currentBlock->appendNew<Value>(m_proc, BitAnd, origin(),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, LessThan, origin(), arg, max),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, GreaterEqual, origin(), arg, min));
</span><del>- outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, zeroForType(I32));
</del><ins>+ outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, constant(Int32, 0));
</ins><span class="cx"> CheckValue* trap = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(), outOfBounds);
</span><span class="cx"> trap->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams&) {
</span><span class="cx"> this->emitExceptionCheck(jit, ExceptionType::OutOfBoundsTrunc);
</span><span class="lines">@@ -1675,28 +1662,28 @@
</span><span class="cx"> template<>
</span><span class="cx"> auto B3IRGenerator::addOp<OpType::I64TruncUF64>(ExpressionType arg, ExpressionType& result) -> PartialResult
</span><span class="cx"> {
</span><del>- Value* max = m_currentBlock->appendNew<ConstDoubleValue>(m_proc, origin(), static_cast<double>(std::numeric_limits<int64_t>::min()) * -2.0);
- Value* min = m_currentBlock->appendNew<ConstDoubleValue>(m_proc, origin(), -1.0);
</del><ins>+ Value* max = constant(Double, bitwise_cast<uint64_t>(static_cast<double>(std::numeric_limits<int64_t>::min()) * -2.0));
+ Value* min = constant(Double, bitwise_cast<uint64_t>(-1.0));
</ins><span class="cx"> Value* outOfBounds = m_currentBlock->appendNew<Value>(m_proc, BitAnd, origin(),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, LessThan, origin(), arg, max),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, GreaterThan, origin(), arg, min));
</span><del>- outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, zeroForType(I32));
</del><ins>+ outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, constant(Int32, 0));
</ins><span class="cx"> CheckValue* trap = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(), outOfBounds);
</span><span class="cx"> trap->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams&) {
</span><span class="cx"> this->emitExceptionCheck(jit, ExceptionType::OutOfBoundsTrunc);
</span><span class="cx"> });
</span><span class="cx">
</span><del>- Value* constant;
</del><ins>+ Value* signBitConstant;
</ins><span class="cx"> if (isX86()) {
</span><span class="cx"> // Since x86 doesn't have an instruction to convert floating points to unsigned integers, we at least try to do the smart thing if
</span><span class="cx"> // the numbers are would be positive anyway as a signed integer. Since we cannot materialize constants into fprs we have b3 do it
</span><span class="cx"> // so we can pool them if needed.
</span><del>- constant = m_currentBlock->appendNew<ConstDoubleValue>(m_proc, origin(), static_cast<double>(std::numeric_limits<uint64_t>::max() - std::numeric_limits<int64_t>::max()));
</del><ins>+ signBitConstant = constant(Double, bitwise_cast<uint64_t>(static_cast<double>(std::numeric_limits<uint64_t>::max() - std::numeric_limits<int64_t>::max())));
</ins><span class="cx"> }
</span><span class="cx"> PatchpointValue* patchpoint = m_currentBlock->appendNew<PatchpointValue>(m_proc, Int64, origin());
</span><span class="cx"> patchpoint->append(arg, ValueRep::SomeRegister);
</span><span class="cx"> if (isX86()) {
</span><del>- patchpoint->append(constant, ValueRep::SomeRegister);
</del><ins>+ patchpoint->append(signBitConstant, ValueRep::SomeRegister);
</ins><span class="cx"> patchpoint->numFPScratchRegisters = 1;
</span><span class="cx"> }
</span><span class="cx"> patchpoint->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
</span><span class="lines">@@ -1717,12 +1704,12 @@
</span><span class="cx"> template<>
</span><span class="cx"> auto B3IRGenerator::addOp<OpType::I64TruncSF32>(ExpressionType arg, ExpressionType& result) -> PartialResult
</span><span class="cx"> {
</span><del>- Value* max = m_currentBlock->appendNew<ConstFloatValue>(m_proc, origin(), -static_cast<float>(std::numeric_limits<int64_t>::min()));
- Value* min = m_currentBlock->appendNew<ConstFloatValue>(m_proc, origin(), static_cast<float>(std::numeric_limits<int64_t>::min()));
</del><ins>+ Value* max = constant(Float, bitwise_cast<uint32_t>(-static_cast<float>(std::numeric_limits<int64_t>::min())));
+ Value* min = constant(Float, bitwise_cast<uint32_t>(static_cast<float>(std::numeric_limits<int64_t>::min())));
</ins><span class="cx"> Value* outOfBounds = m_currentBlock->appendNew<Value>(m_proc, BitAnd, origin(),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, LessThan, origin(), arg, max),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, GreaterEqual, origin(), arg, min));
</span><del>- outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, zeroForType(I32));
</del><ins>+ outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, constant(Int32, 0));
</ins><span class="cx"> CheckValue* trap = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(), outOfBounds);
</span><span class="cx"> trap->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams&) {
</span><span class="cx"> this->emitExceptionCheck(jit, ExceptionType::OutOfBoundsTrunc);
</span><span class="lines">@@ -1740,28 +1727,28 @@
</span><span class="cx"> template<>
</span><span class="cx"> auto B3IRGenerator::addOp<OpType::I64TruncUF32>(ExpressionType arg, ExpressionType& result) -> PartialResult
</span><span class="cx"> {
</span><del>- Value* max = m_currentBlock->appendNew<ConstFloatValue>(m_proc, origin(), static_cast<float>(std::numeric_limits<int64_t>::min()) * -2.0);
- Value* min = m_currentBlock->appendNew<ConstFloatValue>(m_proc, origin(), -1.0);
</del><ins>+ Value* max = constant(Float, bitwise_cast<uint32_t>(static_cast<float>(std::numeric_limits<int64_t>::min()) * static_cast<float>(-2.0)));
+ Value* min = constant(Float, bitwise_cast<uint32_t>(static_cast<float>(-1.0)));
</ins><span class="cx"> Value* outOfBounds = m_currentBlock->appendNew<Value>(m_proc, BitAnd, origin(),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, LessThan, origin(), arg, max),
</span><span class="cx"> m_currentBlock->appendNew<Value>(m_proc, GreaterThan, origin(), arg, min));
</span><del>- outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, zeroForType(I32));
</del><ins>+ outOfBounds = m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), outOfBounds, constant(Int32, 0));
</ins><span class="cx"> CheckValue* trap = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(), outOfBounds);
</span><span class="cx"> trap->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams&) {
</span><span class="cx"> this->emitExceptionCheck(jit, ExceptionType::OutOfBoundsTrunc);
</span><span class="cx"> });
</span><span class="cx">
</span><del>- Value* constant;
</del><ins>+ Value* signBitConstant;
</ins><span class="cx"> if (isX86()) {
</span><span class="cx"> // Since x86 doesn't have an instruction to convert floating points to unsigned integers, we at least try to do the smart thing if
</span><del>- // the numbers are would be positive anyway as a signed integer. Since we cannot materialize constants into fprs we have b3 do it
</del><ins>+ // the numbers would be positive anyway as a signed integer. Since we cannot materialize constants into fprs we have b3 do it
</ins><span class="cx"> // so we can pool them if needed.
</span><del>- constant = m_currentBlock->appendNew<ConstFloatValue>(m_proc, origin(), static_cast<float>(std::numeric_limits<uint64_t>::max() - std::numeric_limits<int64_t>::max()));
</del><ins>+ signBitConstant = constant(Float, bitwise_cast<uint32_t>(static_cast<float>(std::numeric_limits<uint64_t>::max() - std::numeric_limits<int64_t>::max())));
</ins><span class="cx"> }
</span><span class="cx"> PatchpointValue* patchpoint = m_currentBlock->appendNew<PatchpointValue>(m_proc, Int64, origin());
</span><span class="cx"> patchpoint->append(arg, ValueRep::SomeRegister);
</span><span class="cx"> if (isX86()) {
</span><del>- patchpoint->append(constant, ValueRep::SomeRegister);
</del><ins>+ patchpoint->append(signBitConstant, ValueRep::SomeRegister);
</ins><span class="cx"> patchpoint->numFPScratchRegisters = 1;
</span><span class="cx"> }
</span><span class="cx"> patchpoint->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmgenerateWasmB3IRGeneratorInlinesHeaderpy"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/generateWasmB3IRGeneratorInlinesHeader.py (214591 => 214592)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/generateWasmB3IRGeneratorInlinesHeader.py        2017-03-30 01:41:11 UTC (rev 214591)
+++ trunk/Source/JavaScriptCore/wasm/generateWasmB3IRGeneratorInlinesHeader.py        2017-03-30 02:39:51 UTC (rev 214592)
</span><span class="lines">@@ -174,7 +174,7 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def generateConstCode(index, value, type):
</span><del>- return "Value* " + temp(index) + " = m_currentBlock->appendIntConstant(m_proc, origin(), B3::" + type + ", " + value + ");"
</del><ins>+ return "Value* " + temp(index) + " = constant(" + type + ", " + value + ");"
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def generateB3Code(wasmOp, source):
</span></span></pre>
</div>
</div>
</body>
</html>