Commit 49ca64b8 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Add GraphAssembler to WasmGraphBuilder

This is a pure refactoring to make the {GraphAssembler} available in all
of {WasmGraphBuilder}, including {WasmWrapperGraphBuilder}.
Future CLs will use more features of the {GraphAssembler} for building
wasm graphs.

The {WasmGraphAssembler} class will be extended to contain functionality
only needed (or making sense) in the context of wasm.

Drive-by: Move fields to the end of the {WasmGraphBuilder} class.

R=jkummerow@chromium.org

Bug: v8:10123
Change-Id: Idf44915944882adec75ef002ec577f63b2317a17
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2011825Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65902}
parent faccc95b
......@@ -163,11 +163,18 @@ bool ContainsInt64(wasm::FunctionSig* sig) {
}
} // namespace
class WasmGraphAssembler : public GraphAssembler {
public:
WasmGraphAssembler(MachineGraph* mcgraph, Zone* zone)
: GraphAssembler(mcgraph, zone) {}
};
WasmGraphBuilder::WasmGraphBuilder(
wasm::CompilationEnv* env, Zone* zone, MachineGraph* mcgraph,
wasm::FunctionSig* sig,
compiler::SourcePositionTable* source_position_table)
: zone_(zone),
: gasm_(std::make_unique<WasmGraphAssembler>(mcgraph, zone)),
zone_(zone),
mcgraph_(mcgraph),
env_(env),
has_simd_(ContainsSimd(sig)),
......@@ -178,6 +185,10 @@ WasmGraphBuilder::WasmGraphBuilder(
DCHECK_NOT_NULL(mcgraph_);
}
// Destructor define here where the definition of {WasmGraphAssembler} is
// available.
WasmGraphBuilder::~WasmGraphBuilder() = default;
Node* WasmGraphBuilder::Error() { return mcgraph()->Dead(); }
Node* WasmGraphBuilder::Start(unsigned params) {
......@@ -5510,9 +5521,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
break;
}
// TODO(wasm): Use GraphAssembler more widely.
GraphAssembler gasm(mcgraph(), mcgraph()->zone());
gasm.InitializeEffectControl(Effect(), Control());
gasm_->InitializeEffectControl(Effect(), Control());
// Handle Smis first. The rest goes through the ToNumber stub.
// TODO(clemensb): Also handle HeapNumbers specially.
......@@ -5525,12 +5534,12 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
// ├─ true: ─┘ │
// └─ false: load -> f64-to-int32 ─┘
auto smi_to_int32 = gasm.MakeLabel(MachineRepresentation::kTaggedSigned);
auto smi_to_int32 = gasm_->MakeLabel(MachineRepresentation::kTaggedSigned);
auto done =
gasm.MakeLabel(wasm::ValueTypes::MachineRepresentationFor(type));
gasm_->MakeLabel(wasm::ValueTypes::MachineRepresentationFor(type));
// If the input is Smi, directly convert to int32.
gasm.GotoIf(BuildTestSmi(input), &smi_to_int32, input);
gasm_->GotoIf(BuildTestSmi(input), &smi_to_int32, input);
// Otherwise, call ToNumber which returns a Smi or HeapNumber.
auto to_number_descriptor = Linkage::GetStubCallDescriptor(
......@@ -5540,28 +5549,28 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
GetTargetForBuiltinCall(wasm::WasmCode::kToNumber, Builtins::kToNumber);
Node* number =
gasm.Call(to_number_descriptor, to_number_target, input, js_context);
gasm_->Call(to_number_descriptor, to_number_target, input, js_context);
SetSourcePosition(number, 1);
// If the ToNumber result is Smi, convert to int32.
gasm.GotoIf(BuildTestSmi(number), &smi_to_int32, number);
gasm_->GotoIf(BuildTestSmi(number), &smi_to_int32, number);
// Otherwise the ToNumber result is a HeapNumber. Load its value and convert
// to {type}.
Node* heap_number_value = gasm.LoadHeapNumberValue(number);
Node* heap_number_value = gasm_->LoadHeapNumberValue(number);
Node* converted_heap_number_value =
BuildFloat64ToWasm(heap_number_value, type);
gasm.Goto(&done, converted_heap_number_value);
gasm_->Goto(&done, converted_heap_number_value);
// Now implement the smi to int32 conversion.
gasm.Bind(&smi_to_int32);
gasm_->Bind(&smi_to_int32);
Node* smi_int32 = BuildSmiToWasm(smi_to_int32.PhiAt(0), type);
gasm.Goto(&done, smi_int32);
gasm_->Goto(&done, smi_int32);
// Done. Update effect and control and return the final Phi.
gasm.Bind(&done);
SetEffect(gasm.effect());
SetControl(gasm.control());
gasm_->Bind(&done);
SetEffect(gasm_->effect());
SetControl(gasm_->control());
return done.PhiAt(0);
}
......
......@@ -33,6 +33,7 @@ class NodeOriginTable;
class Operator;
class SourcePositionTable;
class WasmDecorator;
class WasmGraphAssembler;
enum class TrapId : uint32_t;
struct Int64LoweringSpecialCase;
} // namespace compiler
......@@ -175,6 +176,8 @@ class WasmGraphBuilder {
wasm::CompilationEnv* env, Zone* zone, MachineGraph* mcgraph,
wasm::FunctionSig* sig, compiler::SourcePositionTable* spt = nullptr);
V8_EXPORT_PRIVATE ~WasmGraphBuilder();
//-----------------------------------------------------------------------
// Operations independent of {control} or {effect}.
//-----------------------------------------------------------------------
......@@ -402,33 +405,6 @@ class WasmGraphBuilder {
void RemoveBytecodePositionDecorator();
protected:
Zone* const zone_;
MachineGraph* const mcgraph_;
wasm::CompilationEnv* const env_;
Node** control_ = nullptr;
Node** effect_ = nullptr;
WasmInstanceCacheNodes* instance_cache_ = nullptr;
SetOncePointer<Node> instance_node_;
SetOncePointer<Node> globals_start_;
SetOncePointer<Node> imported_mutable_globals_;
SetOncePointer<Node> stack_check_code_node_;
SetOncePointer<Node> isolate_root_node_;
SetOncePointer<const Operator> stack_check_call_operator_;
bool has_simd_ = false;
bool needs_stack_check_ = false;
const bool untrusted_code_mitigations_ = true;
wasm::FunctionSig* const sig_;
compiler::WasmDecorator* decorator_ = nullptr;
compiler::SourcePositionTable* const source_position_table_ = nullptr;
std::unique_ptr<Int64LoweringSpecialCase> lowering_special_case_;
Node* NoContextConstant();
Node* BuildLoadIsolateRoot();
......@@ -587,6 +563,34 @@ class WasmGraphBuilder {
Node** parameters, int parameter_count,
Node** effect, Node* control);
TrapId GetTrapIdForTrap(wasm::TrapReason reason);
std::unique_ptr<WasmGraphAssembler> gasm_;
Zone* const zone_;
MachineGraph* const mcgraph_;
wasm::CompilationEnv* const env_;
Node** control_ = nullptr;
Node** effect_ = nullptr;
WasmInstanceCacheNodes* instance_cache_ = nullptr;
SetOncePointer<Node> instance_node_;
SetOncePointer<Node> globals_start_;
SetOncePointer<Node> imported_mutable_globals_;
SetOncePointer<Node> stack_check_code_node_;
SetOncePointer<Node> isolate_root_node_;
SetOncePointer<const Operator> stack_check_call_operator_;
bool has_simd_ = false;
bool needs_stack_check_ = false;
const bool untrusted_code_mitigations_ = true;
wasm::FunctionSig* const sig_;
compiler::WasmDecorator* decorator_ = nullptr;
compiler::SourcePositionTable* const source_position_table_ = nullptr;
std::unique_ptr<Int64LoweringSpecialCase> lowering_special_case_;
};
enum WasmCallKind { kWasmFunction, kWasmImportWrapper, kWasmCapiFunction };
......
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