Commit e847124b authored by Ben L. Titzer's avatar Ben L. Titzer Committed by Commit Bot

[wasm] Refactor WasmGraphBuilder to use MachineGraph

This CL removes the JSGraph from WasmGraphBuilder and uses MachineGraph,
which is independent of the isolate, instead. In addition to using
the machine graph in the WasmGraphBuilder, this CL splits off a subclass
for compiling wrappers that does have a JSGraph and encapsulates it in
the .cc file. This makes the separation of WASM function graphs and WASM
wrapper graphs more explicit.

R=mstarzinger@chromium.org
CC=ahaas@chromium.org
BUG=v8:7721

Change-Id: I3c190baef2084919d22a9a89a8c9f11d2ddcf3d0
Reviewed-on: https://chromium-review.googlesource.com/1050266
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53086}
parent 3e9f8a4f
......@@ -2089,11 +2089,11 @@ OptimizedCompilationJob* Pipeline::NewCompilationJob(
// static
OptimizedCompilationJob* Pipeline::NewWasmCompilationJob(
OptimizedCompilationInfo* info, Isolate* isolate, JSGraph* jsgraph,
OptimizedCompilationInfo* info, Isolate* isolate, MachineGraph* mcgraph,
CallDescriptor* call_descriptor, SourcePositionTable* source_positions,
WasmCompilationData* wasm_compilation_data,
wasm::ModuleOrigin asmjs_origin) {
return new PipelineWasmCompilationJob(info, isolate, jsgraph, call_descriptor,
return new PipelineWasmCompilationJob(info, isolate, mcgraph, call_descriptor,
source_positions, wasm_compilation_data,
asmjs_origin);
}
......
......@@ -27,9 +27,9 @@ enum ModuleOrigin : uint8_t;
namespace compiler {
class CallDescriptor;
class JSGraph;
class Graph;
class InstructionSequence;
class MachineGraph;
class Schedule;
class SourcePositionTable;
class WasmCompilationData;
......@@ -42,7 +42,7 @@ class Pipeline : public AllStatic {
// Returns a new compilation job for the WebAssembly compilation info.
static OptimizedCompilationJob* NewWasmCompilationJob(
OptimizedCompilationInfo* info, Isolate* isolate, JSGraph* jsgraph,
OptimizedCompilationInfo* info, Isolate* isolate, MachineGraph* mcgraph,
CallDescriptor* call_descriptor, SourcePositionTable* source_positions,
WasmCompilationData* wasm_compilation_data,
wasm::ModuleOrigin wasm_origin);
......
......@@ -26,10 +26,10 @@ static const int32_t kShift8 = 24;
} // anonymous
SimdScalarLowering::SimdScalarLowering(
JSGraph* jsgraph, Signature<MachineRepresentation>* signature)
: jsgraph_(jsgraph),
state_(jsgraph->graph(), 3),
stack_(jsgraph_->zone()),
MachineGraph* mcgraph, Signature<MachineRepresentation>* signature)
: mcgraph_(mcgraph),
state_(mcgraph->graph(), 3),
stack_(mcgraph_->zone()),
replacements_(nullptr),
signature_(signature),
placeholder_(graph()->NewNode(common()->Parameter(-2, "placeholder"),
......@@ -454,13 +454,13 @@ void SimdScalarLowering::LowerCompareOp(Node* node, SimdType input_rep_type,
}
Diamond d_cmp(graph(), common(),
graph()->NewNode(machine()->Word32Equal(), cmp_result,
jsgraph_->Int32Constant(0)));
mcgraph_->Int32Constant(0)));
MachineRepresentation rep =
(input_rep_type == SimdType::kFloat32x4)
? MachineRepresentation::kWord32
: MachineTypeFrom(input_rep_type).representation();
rep_node[i] =
d_cmp.Phi(rep, jsgraph_->Int32Constant(0), jsgraph_->Int32Constant(-1));
d_cmp.Phi(rep, mcgraph_->Int32Constant(0), mcgraph_->Int32Constant(-1));
}
ReplaceNode(node, rep_node, num_lanes);
}
......@@ -468,8 +468,8 @@ void SimdScalarLowering::LowerCompareOp(Node* node, SimdType input_rep_type,
Node* SimdScalarLowering::FixUpperBits(Node* input, int32_t shift) {
return graph()->NewNode(machine()->Word32Sar(),
graph()->NewNode(machine()->Word32Shl(), input,
jsgraph_->Int32Constant(shift)),
jsgraph_->Int32Constant(shift));
mcgraph_->Int32Constant(shift)),
mcgraph_->Int32Constant(shift));
}
void SimdScalarLowering::LowerBinaryOpForSmallInt(Node* node,
......@@ -514,7 +514,7 @@ void SimdScalarLowering::LowerBinaryOpForSmallInt(Node* node,
Node* SimdScalarLowering::Mask(Node* input, int32_t mask) {
return graph()->NewNode(machine()->Word32And(), input,
jsgraph_->Int32Constant(mask));
mcgraph_->Int32Constant(mask));
}
void SimdScalarLowering::LowerSaturateBinaryOp(Node* node,
......@@ -563,12 +563,12 @@ void SimdScalarLowering::LowerSaturateBinaryOp(Node* node,
op_result = graph()->NewNode(op, left, right);
Diamond d_min(graph(), common(),
graph()->NewNode(machine()->Int32LessThan(), op_result,
jsgraph_->Int32Constant(min)));
rep_node[i] = d_min.Phi(phi_rep, jsgraph_->Int32Constant(min), op_result);
mcgraph_->Int32Constant(min)));
rep_node[i] = d_min.Phi(phi_rep, mcgraph_->Int32Constant(min), op_result);
Diamond d_max(graph(), common(),
graph()->NewNode(machine()->Int32LessThan(),
jsgraph_->Int32Constant(max), rep_node[i]));
rep_node[i] = d_max.Phi(phi_rep, jsgraph_->Int32Constant(max), rep_node[i]);
mcgraph_->Int32Constant(max), rep_node[i]));
rep_node[i] = d_max.Phi(phi_rep, mcgraph_->Int32Constant(max), rep_node[i]);
rep_node[i] =
is_signed ? rep_node[i] : FixUpperBits(rep_node[i], shift_val);
}
......@@ -626,7 +626,7 @@ Node* SimdScalarLowering::BuildF64Trunc(Node* input) {
const Operator* store_op = machine()->Store(
StoreRepresentation(MachineRepresentation::kFloat64, kNoWriteBarrier));
Node* effect =
graph()->NewNode(store_op, stack_slot, jsgraph_->Int32Constant(0),
graph()->NewNode(store_op, stack_slot, mcgraph_->Int32Constant(0),
input, graph()->start(), graph()->start());
Node* function = graph()->NewNode(common()->ExternalConstant(ref));
Node** args = zone()->NewArray<Node*>(4);
......@@ -640,7 +640,7 @@ Node* SimdScalarLowering::BuildF64Trunc(Node* input) {
Linkage::GetSimplifiedCDescriptor(zone(), sig_builder.Build());
Node* call = graph()->NewNode(common()->Call(call_descriptor), 4, args);
return graph()->NewNode(machine()->Load(LoadRepresentation::Float64()),
stack_slot, jsgraph_->Int32Constant(0), call,
stack_slot, mcgraph_->Int32Constant(0), call,
graph()->start());
}
}
......@@ -692,10 +692,10 @@ void SimdScalarLowering::LowerPack(Node* node, SimdType input_rep_type,
if (output_rep_type == SimdType::kInt16x8) {
DCHECK(input_rep_type == SimdType::kInt32x4);
if (is_signed) {
min = jsgraph_->Int32Constant(std::numeric_limits<int16_t>::min());
max = jsgraph_->Int32Constant(std::numeric_limits<int16_t>::max());
min = mcgraph_->Int32Constant(std::numeric_limits<int16_t>::min());
max = mcgraph_->Int32Constant(std::numeric_limits<int16_t>::max());
} else {
max = jsgraph_->Uint32Constant(std::numeric_limits<uint16_t>::max());
max = mcgraph_->Uint32Constant(std::numeric_limits<uint16_t>::max());
shift_val = kShift16;
}
phi_rep = MachineRepresentation::kWord16;
......@@ -703,10 +703,10 @@ void SimdScalarLowering::LowerPack(Node* node, SimdType input_rep_type,
DCHECK(output_rep_type == SimdType::kInt8x16 &&
input_rep_type == SimdType::kInt16x8);
if (is_signed) {
min = jsgraph_->Int32Constant(std::numeric_limits<int8_t>::min());
max = jsgraph_->Int32Constant(std::numeric_limits<int8_t>::max());
min = mcgraph_->Int32Constant(std::numeric_limits<int8_t>::min());
max = mcgraph_->Int32Constant(std::numeric_limits<int8_t>::max());
} else {
max = jsgraph_->Uint32Constant(std::numeric_limits<uint8_t>::max());
max = mcgraph_->Uint32Constant(std::numeric_limits<uint8_t>::max());
shift_val = kShift8;
}
phi_rep = MachineRepresentation::kWord8;
......@@ -802,7 +802,7 @@ void SimdScalarLowering::LowerNotEqual(Node* node, SimdType input_rep_type,
? MachineRepresentation::kWord32
: MachineTypeFrom(input_rep_type).representation();
rep_node[i] =
d.Phi(rep, jsgraph_->Int32Constant(0), jsgraph_->Int32Constant(-1));
d.Phi(rep, mcgraph_->Int32Constant(0), mcgraph_->Int32Constant(-1));
}
ReplaceNode(node, rep_node, num_lanes);
}
......@@ -1294,8 +1294,8 @@ void SimdScalarLowering::LowerNode(Node* node) {
int input_num_lanes = NumLanes(input_rep_type);
Node** rep = GetReplacements(node->InputAt(0));
Node** rep_node = zone()->NewArray<Node*>(num_lanes);
Node* true_node = jsgraph_->Int32Constant(-1);
Node* false_node = jsgraph_->Int32Constant(0);
Node* true_node = mcgraph_->Int32Constant(-1);
Node* false_node = mcgraph_->Int32Constant(0);
Node* tmp_result = false_node;
if (node->opcode() == IrOpcode::kS1x4AllTrue ||
node->opcode() == IrOpcode::kS1x8AllTrue ||
......
......@@ -7,7 +7,7 @@
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/machine-graph.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node-marker.h"
#include "src/zone/zone-containers.h"
......@@ -22,7 +22,7 @@ namespace compiler {
class SimdScalarLowering {
public:
SimdScalarLowering(JSGraph* jsgraph,
SimdScalarLowering(MachineGraph* mcgraph,
Signature<MachineRepresentation>* signature);
void LowerGraph();
......@@ -52,10 +52,10 @@ class SimdScalarLowering {
int input_index;
};
Zone* zone() const { return jsgraph_->zone(); }
Graph* graph() const { return jsgraph_->graph(); }
MachineOperatorBuilder* machine() const { return jsgraph_->machine(); }
CommonOperatorBuilder* common() const { return jsgraph_->common(); }
Zone* zone() const { return mcgraph_->zone(); }
Graph* graph() const { return mcgraph_->graph(); }
MachineOperatorBuilder* machine() const { return mcgraph_->machine(); }
CommonOperatorBuilder* common() const { return mcgraph_->common(); }
Signature<MachineRepresentation>* signature() const { return signature_; }
void LowerNode(Node* node);
......@@ -98,7 +98,7 @@ class SimdScalarLowering {
void LowerNotEqual(Node* node, SimdType input_rep_type, const Operator* op);
MachineType MachineTypeFrom(SimdType simdType);
JSGraph* const jsgraph_;
MachineGraph* const mcgraph_;
NodeMarker<State> state_;
ZoneDeque<NodeState> stack_;
Replacement* replacements_;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -27,7 +27,7 @@ namespace compiler {
// Forward declarations for some compiler data structures.
class CallDescriptor;
class Graph;
class JSGraph;
class MachineGraph;
class Node;
class Operator;
class SourcePositionTable;
......@@ -38,7 +38,7 @@ struct DecodeStruct;
class SignatureMap;
// Expose {Node} and {Graph} opaquely as {wasm::TFNode} and {wasm::TFGraph}.
typedef compiler::Node TFNode;
typedef compiler::JSGraph TFGraph;
typedef compiler::MachineGraph TFGraph;
class NativeModule;
class WasmCode;
} // namespace wasm
......@@ -90,7 +90,7 @@ class TurbofanWasmCompilationUnit {
bool ok_ = true;
// The graph zone is deallocated at the end of {ExecuteCompilation} by virtue
// of it being zone allocated.
JSGraph* jsgraph_ = nullptr;
MachineGraph* mcgraph_ = nullptr;
// The compilation_zone_, info_, and job_ fields need to survive past
// {ExecuteCompilation}, onto {FinishCompilation} (which happens on the main
// thread).
......@@ -157,9 +157,9 @@ class WasmGraphBuilder {
};
enum UseRetpoline : bool { kRetpoline = true, kNoRetpoline = false };
WasmGraphBuilder(wasm::ModuleEnv* env, Zone* zone, JSGraph* graph,
Handle<Code> centry_stub, Handle<Oddball> anyref_null,
wasm::FunctionSig* sig,
WasmGraphBuilder(Isolate* isolate, wasm::ModuleEnv* env, Zone* zone,
MachineGraph* mcgraph, Handle<Code> centry_stub,
Handle<Oddball> anyref_null, wasm::FunctionSig* sig,
compiler::SourcePositionTable* spt = nullptr);
Node** Buffer(size_t count) {
......@@ -186,15 +186,13 @@ class WasmGraphBuilder {
Node* tnode, Node* fnode);
Node* CreateOrMergeIntoEffectPhi(Node* merge, Node* tnode, Node* fnode);
Node* EffectPhi(unsigned count, Node** effects, Node* control);
Node* NumberConstant(int32_t value);
Node* RefNull();
Node* Uint32Constant(uint32_t value);
Node* Int32Constant(int32_t value);
Node* Int64Constant(int64_t value);
Node* IntPtrConstant(intptr_t value);
Node* Float32Constant(float value);
Node* Float64Constant(double value);
Node* RefNull() { return anyref_null_node_; }
Node* HeapConstant(Handle<HeapObject> value);
Node* Binop(wasm::WasmOpcode opcode, Node* left, Node* right,
wasm::WasmCodePosition position = wasm::kNoCodePosition);
Node* Unop(wasm::WasmOpcode opcode, Node* input,
......@@ -253,14 +251,6 @@ class WasmGraphBuilder {
Node* CallIndirect(uint32_t index, Node** args, Node*** rets,
wasm::WasmCodePosition position);
void BuildJSToWasmWrapper(wasm::WasmCode* wasm_code);
bool BuildWasmToJSWrapper(Handle<JSReceiver> target,
int index);
void BuildWasmInterpreterEntry(uint32_t func_index);
void BuildCWasmEntry();
Node* ToJS(Node* node, wasm::ValueType type);
Node* FromJS(Node* node, Node* js_context, wasm::ValueType type);
Node* Invert(Node* node);
//-----------------------------------------------------------------------
......@@ -338,29 +328,32 @@ class WasmGraphBuilder {
bool use_trap_handler() const { return env_ && env_->use_trap_handler; }
JSGraph* jsgraph() { return jsgraph_; }
MachineGraph* mcgraph() { return mcgraph_; }
Graph* graph();
private:
protected:
static const int kDefaultBufferSize = 16;
Isolate* const isolate_;
Zone* const zone_;
JSGraph* const jsgraph_;
Node* const centry_stub_node_;
Node* const anyref_null_node_;
// env_ == nullptr means we're not compiling Wasm functions, such as for
// wrappers or interpreter stubs.
wasm::ModuleEnv* const env_ = nullptr;
SetOncePointer<Node> instance_node_;
struct FunctionTableNodes {
Node* table_addr;
Node* size;
};
MachineGraph* const mcgraph_;
wasm::ModuleEnv* const env_;
Node** control_ = nullptr;
Node** effect_ = nullptr;
WasmInstanceCacheNodes* instance_cache_ = nullptr;
Handle<Code> centry_stub_;
Handle<Oddball> anyref_null_;
SetOncePointer<Node> instance_node_;
SetOncePointer<Node> globals_start_;
SetOncePointer<Node> imported_mutable_globals_;
SetOncePointer<Node> centry_stub_node_;
SetOncePointer<Node> anyref_null_node_;
SetOncePointer<Node> stack_check_builtin_code_node_;
const Operator* stack_check_call_operator_ = nullptr;
Node** cur_buffer_;
size_t cur_bufsize_;
Node* def_buffer_[kDefaultBufferSize];
......@@ -369,11 +362,12 @@ class WasmGraphBuilder {
const bool untrusted_code_mitigations_ = true;
wasm::FunctionSig* const sig_;
SetOncePointer<const Operator> allocate_heap_number_operator_;
compiler::SourcePositionTable* const source_position_table_ = nullptr;
Node* String(const char* string);
Node* CEntryStub();
Node* NoContextConstant();
Node* MemBuffer(uint32_t offset);
// BoundsCheckMem receives a uint32 {index} node and returns a ptrsize index.
Node* BoundsCheckMem(uint8_t access_size, Node* index, uint32_t offset,
......@@ -450,22 +444,10 @@ class WasmGraphBuilder {
MachineType result_type, wasm::TrapReason trap_zero,
wasm::WasmCodePosition position);
Node* BuildJavaScriptToNumber(Node* node, Node* js_context);
Node* BuildChangeInt32ToTagged(Node* value);
Node* BuildChangeFloat64ToTagged(Node* value);
Node* BuildChangeTaggedToFloat64(Node* value);
Node* BuildChangeInt32ToSmi(Node* value);
Node* BuildChangeSmiToInt32(Node* value);
Node* BuildChangeUint32ToSmi(Node* value);
Node* BuildChangeSmiToFloat64(Node* value);
Node* BuildTestNotSmi(Node* value);
Node* BuildChangeUint31ToSmi(Node* value);
Node* BuildSmiShiftBitsConstant();
Node* BuildAllocateHeapNumberWithValue(Node* value, Node* control);
Node* BuildLoadHeapNumberValue(Node* value, Node* control);
Node* BuildHeapNumberValueIndexConstant();
Node* BuildChangeSmiToInt32(Node* value);
Node* BuildLoadInstanceFromExportedFunction(Node* closure);
......@@ -491,9 +473,6 @@ class WasmGraphBuilder {
return buf;
}
int AddParameterNodes(Node** args, int pos, int param_count,
wasm::FunctionSig* sig);
void SetNeedsStackCheck() { needs_stack_check_ = true; }
//-----------------------------------------------------------------------
......@@ -509,7 +488,6 @@ class WasmGraphBuilder {
Node* js_context,
Node* const* parameters,
int parameter_count);
Node* BuildModifyThreadInWasmFlag(bool new_value);
Builtins::Name GetBuiltinIdForTrap(wasm::TrapReason reason);
};
......
......@@ -270,13 +270,15 @@ void TestBuildingGraph(Zone* zone, compiler::JSGraph* jsgraph,
const byte* start, const byte* end) {
if (module) {
compiler::WasmGraphBuilder builder(
module, zone, jsgraph, CodeFactory::CEntry(jsgraph->isolate(), 1),
jsgraph->isolate(), module, zone, jsgraph,
CodeFactory::CEntry(jsgraph->isolate(), 1),
jsgraph->isolate()->factory()->null_value(), sig,
source_position_table);
TestBuildingGraphWithBuilder(&builder, zone, sig, start, end);
} else {
compiler::WasmGraphBuilder builder(
nullptr, zone, jsgraph, CodeFactory::CEntry(jsgraph->isolate(), 1),
jsgraph->isolate(), nullptr, zone, jsgraph,
CodeFactory::CEntry(jsgraph->isolate(), 1),
jsgraph->isolate()->factory()->null_value(), sig,
source_position_table);
TestBuildingGraphWithBuilder(&builder, zone, sig, start, end);
......
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