Commit 1ad3d77c authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm-gc] Refactor type checks in wasm-compiler

ref.test, ref.cast, and br_on_cast instructions all need to type check
a value against an rtt. With new classification functions on the
horizon, the wasm-compiler code needed to be refactored to avoid
excessive code duplication.
This CL factors out a function TypeCheck that takes as arguments a set
of three callbacks functions: a conditional success, a conditional
failure, and a negated conditional failure. Each of RefTest, RefCast,
and BrOnCast call TypeCheck with a different set of callbacks.

Bug: v8:7748
Change-Id: I1dd8893fc26d5b0228f85587c9250706d0ce16cf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2647262
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72362}
parent 8dacbacb
This diff is collapsed.
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
// Clients of this interface shouldn't depend on lots of compiler internals. // Clients of this interface shouldn't depend on lots of compiler internals.
// Do not include anything from src/compiler here! // Do not include anything from src/compiler here!
#include "src/base/small-vector.h"
#include "src/runtime/runtime.h" #include "src/runtime/runtime.h"
#include "src/wasm/function-body-decoder.h" #include "src/wasm/function-body-decoder.h"
#include "src/wasm/function-compiler.h" #include "src/wasm/function-compiler.h"
...@@ -36,6 +37,8 @@ class WasmDecorator; ...@@ -36,6 +37,8 @@ class WasmDecorator;
class WasmGraphAssembler; class WasmGraphAssembler;
enum class TrapId : uint32_t; enum class TrapId : uint32_t;
struct Int64LoweringSpecialCase; struct Int64LoweringSpecialCase;
template <size_t VarCount>
class GraphAssemblerLabel;
} // namespace compiler } // namespace compiler
namespace wasm { namespace wasm {
...@@ -582,6 +585,30 @@ class WasmGraphBuilder { ...@@ -582,6 +585,30 @@ class WasmGraphBuilder {
// generates {index > max ? Smi(max) : Smi(index)} // generates {index > max ? Smi(max) : Smi(index)}
Node* BuildConvertUint32ToSmiWithSaturation(Node* index, uint32_t maxval); Node* BuildConvertUint32ToSmiWithSaturation(Node* index, uint32_t maxval);
using NodeConsumer = std::function<void(Node*)>;
struct Callbacks {
NodeConsumer succeed_if;
NodeConsumer fail_if;
NodeConsumer fail_if_not;
};
// This type is used to collect control/effect nodes we need to merge at the
// end of BrOn* functions. Nodes are collected in {TypeCheck} etc. by calling
// the passed callbacks succeed_if, fail_if and fail_if_not. We have up to 5
// control nodes to merge; the EffectPhi needs an additional input.
using SmallNodeVector = base::SmallVector<Node*, 6>;
Callbacks TestCallbacks(GraphAssemblerLabel<1>* label);
Callbacks CastCallbacks(GraphAssemblerLabel<0>* label,
wasm::WasmCodePosition position);
Callbacks BranchCallbacks(SmallNodeVector& no_match_controls,
SmallNodeVector& no_match_effects,
SmallNodeVector& match_controls,
SmallNodeVector& match_effects);
void TypeCheck(Node* object, Node* rtt, ObjectReferenceKnowledge config,
bool null_succeeds, Callbacks callbacks);
// Asm.js specific functionality. // Asm.js specific functionality.
Node* BuildI32AsmjsSConvertF32(Node* input); Node* BuildI32AsmjsSConvertF32(Node* input);
Node* BuildI32AsmjsSConvertF64(Node* input); Node* BuildI32AsmjsSConvertF64(Node* input);
......
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