v8/test/unittests/compiler/sloppy-equality-unittest.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

144 lines
5.5 KiB
C++
Raw Normal View History

// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Reland "[no-wasm] Exclude src/wasm from compilation" This is a reland of 80f5dfda0147d6b078ae6c9d0eb947bd012bf72d. A condition in pipeline.cc was inverted, which lead to a CSA verifier error. Original change's description: > [no-wasm] Exclude src/wasm from compilation > > This is the biggest chunk, including > - all of src/wasm, > - torque file for wasm objects, > - torque file for wasm builtins, > - wasm builtins, > - wasm runtime functions, > - int64 lowering, > - simd scala lowering, > - WasmGraphBuilder (TF graph construction for wasm), > - wasm frame types, > - wasm interrupts, > - the JSWasmCall opcode, > - wasm backing store allocation. > > Those components are all recursively entangled, so I found no way to > split this change up further. > > Some includes that were recursively included by wasm headers needed to > be added explicitly now. > > backing-store-unittest.cc is renamed to wasm-backing-store-unittest.cc > because it only tests wasm backing stores. This file is excluded from > no-wasm builds then. > > R=jkummerow@chromium.org, jgruber@chromium.org, mlippautz@chromium.org, petermarshall@chromium.org > > Bug: v8:11238 > Change-Id: I7558f2d12d2dd6c65128c4de7b79173668c80b2b > Cq-Include-Trybots: luci.v8.try:v8_linux64_no_wasm_compile_rel > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2742955 > Commit-Queue: Clemens Backes <clemensb@chromium.org> > Reviewed-by: Peter Marshall <petermarshall@chromium.org> > Reviewed-by: Toon Verwaest <verwaest@chromium.org> > Reviewed-by: Michael Lippautz <mlippautz@chromium.org> > Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> > Reviewed-by: Jakob Gruber <jgruber@chromium.org> > Cr-Commit-Position: refs/heads/master@{#73344} TBR=jgruber@chromium.org Bug: v8:11238 Change-Id: I20bd2847a59c68738b5a336cd42582b7b1499585 Cq-Include-Trybots: luci.v8.try:v8_linux64_no_wasm_compile_rel Cq-Include-Trybots: luci.v8.try:v8_linux_verify_csa_rel_ng Cq-Include-Trybots: luci.v8.try:v8_linux64_verify_csa_rel_ng Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2752867 Reviewed-by: Clemens Backes <clemensb@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#73348}
2021-03-11 13:42:01 +00:00
#include "test/common/flag-utils.h"
#include "test/common/node-observer-tester.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace internal {
namespace compiler {
using SloppyEqualityTest = TestWithContextAndZone;
struct TestCase {
TestCase(const char* l, const char* r, NodeObserver* observer)
: warmup{std::make_pair(l, r)}, observer(observer) {
DCHECK_NOT_NULL(observer);
}
std::vector<std::pair<const char*, const char*>> warmup;
NodeObserver* observer;
};
class TestSloppyEqualityFactory {
public:
explicit TestSloppyEqualityFactory(Zone* zone) : zone_(zone) {}
NodeObserver* SpeculativeNumberEqual(NumberOperationHint hint) {
return zone_->New<CreationObserver>([hint](const Node* node) {
EXPECT_EQ(IrOpcode::kSpeculativeNumberEqual, node->opcode());
EXPECT_EQ(hint, NumberOperationHintOf(node->op()));
});
}
NodeObserver* JSEqual(CompareOperationHint /*hint*/) {
return zone_->New<CreationObserver>([](const Node* node) {
EXPECT_EQ(IrOpcode::kJSEqual, node->opcode());
// TODO(paolosev): compare hint
});
}
NodeObserver* OperatorChange(IrOpcode::Value created_op,
IrOpcode::Value modified_op) {
return zone_->New<ModificationObserver>(
[created_op](const Node* node) {
EXPECT_EQ(created_op, node->opcode());
},
[modified_op](const Node* node, const ObservableNodeState& old_state)
-> NodeObserver::Observation {
if (old_state.opcode() != node->opcode()) {
EXPECT_EQ(modified_op, node->opcode());
return NodeObserver::Observation::kStop;
}
return NodeObserver::Observation::kContinue;
});
}
private:
Zone* zone_;
};
TEST_F(SloppyEqualityTest, SloppyEqualityTest) {
FlagScope<bool> allow_natives_syntax(&i::v8_flags.allow_natives_syntax, true);
FlagScope<bool> always_turbofan(&i::v8_flags.always_turbofan, false);
TestSloppyEqualityFactory f(zone());
// TODO(nicohartmann@, v8:5660): Collect more precise feedback for some useful
// cases.
TestCase cases[] = {
{"3", "8", f.SpeculativeNumberEqual(NumberOperationHint::kSignedSmall)},
//{"3", "null",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
//{"3", "undefined",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
//{"3", "true",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
{"3", "\"abc\"", f.JSEqual(CompareOperationHint::kAny)},
{"3.14", "3", f.SpeculativeNumberEqual(NumberOperationHint::kNumber)},
//{"3.14", "null",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
//{"3.14", "undefined",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
//{"3.14", "true",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
{"3.14", "\"abc\"", f.JSEqual(CompareOperationHint::kAny)},
{"\"abc\"", "3", f.JSEqual(CompareOperationHint::kAny)},
{"\"abc\"", "null", f.JSEqual(CompareOperationHint::kAny)},
{"\"abc\"", "undefined", f.JSEqual(CompareOperationHint::kAny)},
{"\"abc\"", "true", f.JSEqual(CompareOperationHint::kAny)},
{"\"abc\"", "\"xy\"",
f.JSEqual(CompareOperationHint::kInternalizedString)},
//{"true", "3",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
//{"true", "null",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
//{"true", "undefined",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
//{"true", "true",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
{"true", "\"abc\"", f.JSEqual(CompareOperationHint::kAny)},
//{"undefined", "3",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
{"undefined", "null",
f.JSEqual(CompareOperationHint::kReceiverOrNullOrUndefined)},
{"undefined", "undefined",
f.JSEqual(CompareOperationHint::kReceiverOrNullOrUndefined)},
//{"undefined", "true",
// f.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball)},
{"undefined", "\"abc\"", f.JSEqual(CompareOperationHint::kAny)},
{"{}", "3", f.JSEqual(CompareOperationHint::kAny)},
{"{}", "null",
f.JSEqual(CompareOperationHint::kReceiverOrNullOrUndefined)},
{"{}", "undefined",
f.JSEqual(CompareOperationHint::kReceiverOrNullOrUndefined)},
{"{}", "true", f.JSEqual(CompareOperationHint::kAny)},
{"{}", "\"abc\"", f.JSEqual(CompareOperationHint::kAny)},
{"3.14", "3",
f.OperatorChange(IrOpcode::kSpeculativeNumberEqual,
IrOpcode::kFloat64Equal)}};
for (const auto& c : cases) {
std::ostringstream src;
src << "function test(a, b) {\n"
<< " return %ObserveNode(a == b);\n"
<< "}\n"
<< "%PrepareFunctionForOptimization(test);\n";
for (const auto& args : c.warmup) {
src << "test(" << args.first << ", " << args.second << ");\n"
<< "%OptimizeFunctionOnNextCall(test);"
<< "test(" << args.first << ", " << args.second << ");\n";
}
{
compiler::ObserveNodeScope scope(i_isolate(), c.observer);
TryRunJS(src.str().c_str());
}
}
}
} // namespace compiler
} // namespace internal
} // namespace v8