diff options
Diffstat (limited to 'deps/v8/test/cctest/compiler')
14 files changed, 293 insertions, 166 deletions
diff --git a/deps/v8/test/cctest/compiler/call-tester.h b/deps/v8/test/cctest/compiler/call-tester.h index 8a0ea70a2a..4bf06a9ba3 100644 --- a/deps/v8/test/cctest/compiler/call-tester.h +++ b/deps/v8/test/cctest/compiler/call-tester.h @@ -21,7 +21,7 @@ class CallHelper { : csig_(csig), isolate_(isolate) { USE(isolate_); } - virtual ~CallHelper() {} + virtual ~CallHelper() = default; template <typename... Params> R Call(Params... args) { @@ -46,7 +46,7 @@ class CodeRunner : public CallHelper<T> { public: CodeRunner(Isolate* isolate, Handle<Code> code, MachineSignature* csig) : CallHelper<T>(isolate, csig), code_(code) {} - virtual ~CodeRunner() {} + ~CodeRunner() override = default; Address Generate() override { return code_->entry(); } diff --git a/deps/v8/test/cctest/compiler/codegen-tester.h b/deps/v8/test/cctest/compiler/codegen-tester.h index c58eb3b485..f9fbd4af3a 100644 --- a/deps/v8/test/cctest/compiler/codegen-tester.h +++ b/deps/v8/test/cctest/compiler/codegen-tester.h @@ -39,7 +39,25 @@ class RawMachineAssemblerTester : public HandleAndZoneScope, InstructionSelector::SupportedMachineOperatorFlags(), InstructionSelector::AlignmentRequirements()) {} - virtual ~RawMachineAssemblerTester() {} + template <typename... ParamMachTypes> + RawMachineAssemblerTester(Code::Kind kind, ParamMachTypes... p) + : HandleAndZoneScope(), + CallHelper<ReturnType>( + main_isolate(), + CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p...)), + RawMachineAssembler( + main_isolate(), new (main_zone()) Graph(main_zone()), + Linkage::GetSimplifiedCDescriptor( + main_zone(), + CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), + p...), + true), + MachineType::PointerRepresentation(), + InstructionSelector::SupportedMachineOperatorFlags(), + InstructionSelector::AlignmentRequirements()), + kind_(kind) {} + + ~RawMachineAssemblerTester() override = default; void CheckNumber(double expected, Object* number) { CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number)); @@ -59,13 +77,12 @@ class RawMachineAssemblerTester : public HandleAndZoneScope, } protected: - virtual Address Generate() { + Address Generate() override { if (code_.is_null()) { Schedule* schedule = this->Export(); auto call_descriptor = this->call_descriptor(); Graph* graph = this->graph(); - OptimizedCompilationInfo info(ArrayVector("testing"), main_zone(), - Code::STUB); + OptimizedCompilationInfo info(ArrayVector("testing"), main_zone(), kind_); code_ = Pipeline::GenerateCodeForTesting( &info, main_isolate(), call_descriptor, graph, AssemblerOptions::Default(main_isolate()), schedule); @@ -74,6 +91,7 @@ class RawMachineAssemblerTester : public HandleAndZoneScope, } private: + Code::Kind kind_ = Code::Kind::STUB; MaybeHandle<Code> code_; }; @@ -395,7 +413,7 @@ class BinopGen { public: virtual void gen(RawMachineAssemblerTester<int32_t>* m, Node* a, Node* b) = 0; virtual T expected(T a, T b) = 0; - virtual ~BinopGen() {} + virtual ~BinopGen() = default; }; // A helper class to generate various combination of input shape combinations diff --git a/deps/v8/test/cctest/compiler/graph-builder-tester.h b/deps/v8/test/cctest/compiler/graph-builder-tester.h index c16feae340..e0045979d4 100644 --- a/deps/v8/test/cctest/compiler/graph-builder-tester.h +++ b/deps/v8/test/cctest/compiler/graph-builder-tester.h @@ -62,7 +62,7 @@ class GraphBuilderTester : public HandleAndZoneScope, Begin(static_cast<int>(parameter_count())); InitParameters(); } - virtual ~GraphBuilderTester() {} + ~GraphBuilderTester() override = default; void GenerateCode() { Generate(); } Node* Parameter(size_t index) { diff --git a/deps/v8/test/cctest/compiler/test-branch-combine.cc b/deps/v8/test/cctest/compiler/test-branch-combine.cc index ab17ff0992..090a0f23cd 100644 --- a/deps/v8/test/cctest/compiler/test-branch-combine.cc +++ b/deps/v8/test/cctest/compiler/test-branch-combine.cc @@ -309,12 +309,12 @@ class CmpMaterializeBoolGen : public BinopGen<int32_t> { CmpMaterializeBoolGen(IrOpcode::Value opcode, bool i) : w(opcode), invert(i) {} - virtual void gen(RawMachineAssemblerTester<int32_t>* m, Node* a, Node* b) { + void gen(RawMachineAssemblerTester<int32_t>* m, Node* a, Node* b) override { Node* cond = w.MakeNode(m, a, b); if (invert) cond = m->Word32Equal(cond, m->Int32Constant(0)); m->Return(cond); } - virtual int32_t expected(int32_t a, int32_t b) { + int32_t expected(int32_t a, int32_t b) override { if (invert) return !w.Int32Compare(a, b) ? 1 : 0; return w.Int32Compare(a, b) ? 1 : 0; } @@ -333,7 +333,7 @@ class CmpBranchGen : public BinopGen<int32_t> { CmpBranchGen(IrOpcode::Value opcode, bool i, bool t, int32_t eq, int32_t ne) : w(opcode), invert(i), true_first(t), eq_constant(eq), ne_constant(ne) {} - virtual void gen(RawMachineAssemblerTester<int32_t>* m, Node* a, Node* b) { + void gen(RawMachineAssemblerTester<int32_t>* m, Node* a, Node* b) override { RawMachineLabel blocka, blockb; Node* cond = w.MakeNode(m, a, b); if (invert) cond = m->Word32Equal(cond, m->Int32Constant(0)); @@ -350,7 +350,7 @@ class CmpBranchGen : public BinopGen<int32_t> { m->Return(m->Int32Constant(eq_constant)); } } - virtual int32_t expected(int32_t a, int32_t b) { + int32_t expected(int32_t a, int32_t b) override { if (invert) return !w.Int32Compare(a, b) ? eq_constant : ne_constant; return w.Int32Compare(a, b) ? eq_constant : ne_constant; } diff --git a/deps/v8/test/cctest/compiler/test-code-assembler.cc b/deps/v8/test/cctest/compiler/test-code-assembler.cc index 91065cd546..a2243e6edd 100644 --- a/deps/v8/test/cctest/compiler/test-code-assembler.cc +++ b/deps/v8/test/cctest/compiler/test-code-assembler.cc @@ -30,7 +30,7 @@ Node* SmiTag(CodeAssembler& m, Node* value) { } Node* UndefinedConstant(CodeAssembler& m) { - return m.LoadRoot(Heap::kUndefinedValueRootIndex); + return m.LoadRoot(RootIndex::kUndefinedValue); } Node* SmiFromInt32(CodeAssembler& m, Node* value) { diff --git a/deps/v8/test/cctest/compiler/test-code-generator.cc b/deps/v8/test/cctest/compiler/test-code-generator.cc index a3b80bc887..8bf29dca69 100644 --- a/deps/v8/test/cctest/compiler/test-code-generator.cc +++ b/deps/v8/test/cctest/compiler/test-code-generator.cc @@ -50,7 +50,7 @@ Handle<Code> BuildTeardownFunction(Isolate* isolate, // arguments: // ~~~ // FixedArray setup(CodeObject* test, FixedArray state_in) { -// FixedArray state_out = AllocateFixedArray(state_in.length()); +// FixedArray state_out = AllocateZeroedFixedArray(state_in.length()); // // `test` will tail-call to its first parameter which will be `teardown`. // return test(teardown, state_out, state_in[0], state_in[1], // state_in[2], ...); @@ -83,8 +83,8 @@ Handle<Code> BuildSetupFunction(Isolate* isolate, // First allocate the FixedArray which will hold the final results. Here we // should take care of all allocations, meaning we allocate HeapNumbers and // FixedArrays representing Simd128 values. - TNode<FixedArray> state_out = __ Cast(__ AllocateFixedArray( - PACKED_ELEMENTS, __ IntPtrConstant(parameters.size()))); + TNode<FixedArray> state_out = + __ AllocateZeroedFixedArray(__ IntPtrConstant(parameters.size())); for (int i = 0; i < static_cast<int>(parameters.size()); i++) { switch (parameters[i].representation()) { case MachineRepresentation::kTagged: @@ -94,8 +94,8 @@ Handle<Code> BuildSetupFunction(Isolate* isolate, __ StoreFixedArrayElement(state_out, i, __ AllocateHeapNumber()); break; case MachineRepresentation::kSimd128: { - TNode<FixedArray> vector = __ Cast( - __ AllocateFixedArray(PACKED_SMI_ELEMENTS, __ IntPtrConstant(4))); + TNode<FixedArray> vector = + __ AllocateZeroedFixedArray(__ IntPtrConstant(4)); for (int lane = 0; lane < 4; lane++) { __ StoreFixedArrayElement(vector, lane, __ SmiConstant(0)); } @@ -361,7 +361,11 @@ class TestEnvironment : public HandleAndZoneScope { public: // These constants may be tuned to experiment with different environments. +#if defined(V8_TARGET_ARCH_IA32) && defined(V8_EMBEDDED_BUILTINS) + static constexpr int kGeneralRegisterCount = 3; +#else static constexpr int kGeneralRegisterCount = 4; +#endif static constexpr int kDoubleRegisterCount = 6; static constexpr int kTaggedSlotCount = 64; @@ -431,13 +435,10 @@ class TestEnvironment : public HandleAndZoneScope { // kReturnRegister0 as the first parameter, and the call will need a // register to hold the CodeObject address. So the maximum number of // registers left to test with is the number of available registers minus 2. - DCHECK_LE( - kGeneralRegisterCount, - RegisterConfiguration::Default()->num_allocatable_general_registers() - - 2); + DCHECK_LE(kGeneralRegisterCount, + GetRegConfig()->num_allocatable_general_registers() - 2); - int32_t general_mask = - RegisterConfiguration::Default()->allocatable_general_codes_mask(); + int32_t general_mask = GetRegConfig()->allocatable_general_codes_mask(); // kReturnRegister0 is used to hold the "teardown" code object, do not // generate moves using it. std::unique_ptr<const RegisterConfiguration> registers( @@ -639,18 +640,21 @@ class TestEnvironment : public HandleAndZoneScope { case MachineRepresentation::kTagged: state->set(i, Smi::FromInt(rng_->NextInt(Smi::kMaxValue))); break; - case MachineRepresentation::kFloat32: + case MachineRepresentation::kFloat32: { // HeapNumbers are Float64 values. However, we will convert it to a // Float32 and back inside `setup` and `teardown`. Make sure the value // we pick fits in a Float32. - state->set( - i, *main_isolate()->factory()->NewHeapNumber( - static_cast<double>(DoubleToFloat32(rng_->NextDouble())))); + Handle<HeapNumber> num = main_isolate()->factory()->NewHeapNumber( + static_cast<double>(DoubleToFloat32(rng_->NextDouble()))); + state->set(i, *num); break; - case MachineRepresentation::kFloat64: - state->set( - i, *main_isolate()->factory()->NewHeapNumber(rng_->NextDouble())); + } + case MachineRepresentation::kFloat64: { + Handle<HeapNumber> num = + main_isolate()->factory()->NewHeapNumber(rng_->NextDouble()); + state->set(i, *num); break; + } case MachineRepresentation::kSimd128: { Handle<FixedArray> vector = main_isolate()->factory()->NewFixedArray(4); @@ -968,7 +972,7 @@ class CodeGeneratorTester { linkage_(environment->test_descriptor()), frame_(environment->test_descriptor()->CalculateFixedFrameSize()) { // Pick half of the stack parameters at random and move them into spill - // slots, seperated by `extra_stack_space` bytes. + // slots, separated by `extra_stack_space` bytes. // When testing a move with stack slots using CheckAssembleMove or // CheckAssembleSwap, we'll transparently make use of local spill slots // instead of stack parameters for those that were picked. This allows us to @@ -1285,7 +1289,7 @@ TEST(FuzzAssembleMoveAndSwap) { } TEST(AssembleTailCallGap) { - const RegisterConfiguration* conf = RegisterConfiguration::Default(); + const RegisterConfiguration* conf = GetRegConfig(); TestEnvironment env; // This test assumes at least 4 registers are allocatable. diff --git a/deps/v8/test/cctest/compiler/test-js-typed-lowering.cc b/deps/v8/test/cctest/compiler/test-js-typed-lowering.cc index eec562cf36..559ed1088c 100644 --- a/deps/v8/test/cctest/compiler/test-js-typed-lowering.cc +++ b/deps/v8/test/cctest/compiler/test-js-typed-lowering.cc @@ -32,7 +32,7 @@ class JSTypedLoweringTester : public HandleAndZoneScope { simplified(main_zone()), common(main_zone()), graph(main_zone()), - typer(main_isolate(), &js_heap_broker, Typer::kNoFlags, &graph), + typer(&js_heap_broker, Typer::kNoFlags, &graph), context_node(nullptr) { graph.SetStart(graph.NewNode(common.Start(num_parameters))); graph.SetEnd(graph.NewNode(common.End(1), graph.start())); diff --git a/deps/v8/test/cctest/compiler/test-multiple-return.cc b/deps/v8/test/cctest/compiler/test-multiple-return.cc index b591d193e7..dccdbd9b92 100644 --- a/deps/v8/test/cctest/compiler/test-multiple-return.cc +++ b/deps/v8/test/cctest/compiler/test-multiple-return.cc @@ -190,11 +190,10 @@ void TestReturnMultipleValues(MachineType type) { std::unique_ptr<wasm::NativeModule> module = AllocateNativeModule( handles.main_isolate(), code->raw_instruction_size()); - byte* code_start = module->AddCodeCopy(code, wasm::WasmCode::kFunction, 0) - ->instructions() - .start(); + byte* code_start = + module->AddCodeForTesting(code)->instructions().start(); - RawMachineAssemblerTester<int32_t> mt; + RawMachineAssemblerTester<int32_t> mt(Code::Kind::JS_TO_WASM_FUNCTION); const int input_count = 2 + param_count; Node* call_inputs[2 + kMaxParamCount]; call_inputs[0] = mt.PointerConstant(code_start); @@ -280,9 +279,7 @@ void ReturnLastValue(MachineType type) { std::unique_ptr<wasm::NativeModule> module = AllocateNativeModule( handles.main_isolate(), code->raw_instruction_size()); - byte* code_start = module->AddCodeCopy(code, wasm::WasmCode::kFunction, 0) - ->instructions() - .start(); + byte* code_start = module->AddCodeForTesting(code)->instructions().start(); // Generate caller. int expect = return_count - 1; @@ -343,9 +340,7 @@ void ReturnSumOfReturns(MachineType type) { std::unique_ptr<wasm::NativeModule> module = AllocateNativeModule( handles.main_isolate(), code->raw_instruction_size()); - byte* code_start = module->AddCodeCopy(code, wasm::WasmCode::kFunction, 0) - ->instructions() - .start(); + byte* code_start = module->AddCodeForTesting(code)->instructions().start(); // Generate caller. RawMachineAssemblerTester<int32_t> mt; diff --git a/deps/v8/test/cctest/compiler/test-representation-change.cc b/deps/v8/test/cctest/compiler/test-representation-change.cc index 894338b3e2..c334ecb383 100644 --- a/deps/v8/test/cctest/compiler/test-representation-change.cc +++ b/deps/v8/test/cctest/compiler/test-representation-change.cc @@ -6,6 +6,7 @@ #include "src/compiler/node-matchers.h" #include "src/compiler/representation-change.h" +#include "src/compiler/type-cache.h" #include "src/objects-inl.h" #include "test/cctest/cctest.h" #include "test/cctest/compiler/codegen-tester.h" @@ -46,6 +47,12 @@ class RepresentationChangerTester : public HandleAndZoneScope, CHECK_EQ(expected, m.Value()); } + void CheckInt64Constant(Node* n, int64_t expected) { + Int64Matcher m(n); + CHECK(m.HasValue()); + CHECK_EQ(expected, m.Value()); + } + void CheckUint32Constant(Node* n, uint32_t expected) { Uint32Matcher m(n); CHECK(m.HasValue()); @@ -267,6 +274,18 @@ TEST(ToUint32_constant) { } } +TEST(ToInt64_constant) { + RepresentationChangerTester r; + FOR_INT32_INPUTS(i) { + Node* n = r.jsgraph()->Constant(*i); + Node* use = r.Return(n); + Node* c = r.changer()->GetRepresentationFor( + n, MachineRepresentation::kTagged, TypeCache::Get().kSafeInteger, use, + UseInfo(MachineRepresentation::kWord64, Truncation::None())); + r.CheckInt64Constant(c, *i); + } +} + static void CheckChange(IrOpcode::Value expected, MachineRepresentation from, Type from_type, UseInfo use_info) { RepresentationChangerTester r; @@ -291,7 +310,7 @@ static void CheckChange(IrOpcode::Value expected, MachineRepresentation from, static void CheckChange(IrOpcode::Value expected, MachineRepresentation from, Type from_type, MachineRepresentation to) { - CheckChange(expected, from, from_type, UseInfo(to, Truncation::None())); + CheckChange(expected, from, from_type, UseInfo(to, Truncation::Any())); } static void CheckTwoChanges(IrOpcode::Value expected2, @@ -328,6 +347,132 @@ static void CheckChange(IrOpcode::Value expected, MachineRepresentation from, CHECK_EQ(n, c->InputAt(0)); } +TEST(Word64) { + CheckChange(IrOpcode::kChangeInt32ToInt64, MachineRepresentation::kWord8, + TypeCache::Get().kInt8, MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeUint32ToUint64, MachineRepresentation::kWord8, + TypeCache::Get().kUint8, MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeInt32ToInt64, MachineRepresentation::kWord16, + TypeCache::Get().kInt16, MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeUint32ToUint64, MachineRepresentation::kWord16, + TypeCache::Get().kUint16, MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeInt32ToInt64, MachineRepresentation::kWord32, + Type::Signed32(), MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeUint32ToUint64, MachineRepresentation::kWord32, + Type::Unsigned32(), MachineRepresentation::kWord64); + + CheckChange(IrOpcode::kTruncateInt64ToInt32, MachineRepresentation::kWord64, + Type::Signed32(), MachineRepresentation::kWord32); + CheckChange(IrOpcode::kTruncateInt64ToInt32, MachineRepresentation::kWord64, + Type::Unsigned32(), MachineRepresentation::kWord32); + CheckChange(IrOpcode::kTruncateInt64ToInt32, MachineRepresentation::kWord64, + TypeCache::Get().kSafeInteger, MachineRepresentation::kWord32, + UseInfo::TruncatingWord32()); + CheckChange( + IrOpcode::kCheckedInt64ToInt32, MachineRepresentation::kWord64, + TypeCache::Get().kSafeInteger, MachineRepresentation::kWord32, + UseInfo::CheckedSigned32AsWord32(kIdentifyZeros, VectorSlotPair())); + CheckChange( + IrOpcode::kCheckedUint64ToInt32, MachineRepresentation::kWord64, + TypeCache::Get().kPositiveSafeInteger, MachineRepresentation::kWord32, + UseInfo::CheckedSigned32AsWord32(kIdentifyZeros, VectorSlotPair())); + + CheckChange(IrOpcode::kChangeFloat64ToInt64, MachineRepresentation::kFloat64, + Type::Signed32(), MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeFloat64ToInt64, MachineRepresentation::kFloat64, + Type::Unsigned32(), MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeFloat64ToInt64, MachineRepresentation::kFloat64, + TypeCache::Get().kSafeInteger, MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeFloat64ToInt64, MachineRepresentation::kFloat64, + TypeCache::Get().kInt64, MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeFloat64ToUint64, MachineRepresentation::kFloat64, + TypeCache::Get().kUint64, MachineRepresentation::kWord64); + + CheckChange(IrOpcode::kChangeInt64ToFloat64, MachineRepresentation::kWord64, + Type::Signed32(), MachineRepresentation::kFloat64); + CheckChange(IrOpcode::kChangeInt64ToFloat64, MachineRepresentation::kWord64, + Type::Unsigned32(), MachineRepresentation::kFloat64); + CheckChange(IrOpcode::kChangeInt64ToFloat64, MachineRepresentation::kWord64, + TypeCache::Get().kSafeInteger, MachineRepresentation::kFloat64); + + CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64, + IrOpcode::kChangeFloat64ToInt64, + MachineRepresentation::kFloat32, Type::Signed32(), + MachineRepresentation::kWord64); + CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64, + IrOpcode::kChangeFloat64ToInt64, + MachineRepresentation::kFloat32, Type::Unsigned32(), + MachineRepresentation::kWord64); + CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64, + IrOpcode::kChangeFloat64ToInt64, + MachineRepresentation::kFloat32, TypeCache::Get().kInt64, + MachineRepresentation::kWord64); + CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64, + IrOpcode::kChangeFloat64ToUint64, + MachineRepresentation::kFloat32, TypeCache::Get().kUint64, + MachineRepresentation::kWord64); + + CheckTwoChanges(IrOpcode::kChangeInt64ToFloat64, + IrOpcode::kTruncateFloat64ToFloat32, + MachineRepresentation::kWord64, Type::Signed32(), + MachineRepresentation::kFloat32); + + CheckChange(IrOpcode::kChangeTaggedToInt64, MachineRepresentation::kTagged, + Type::Signed32(), MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeTaggedToInt64, MachineRepresentation::kTagged, + Type::Unsigned32(), MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeTaggedToInt64, MachineRepresentation::kTagged, + TypeCache::Get().kSafeInteger, MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeTaggedToInt64, MachineRepresentation::kTagged, + TypeCache::Get().kInt64, MachineRepresentation::kWord64); + CheckChange(IrOpcode::kChangeTaggedSignedToInt64, + MachineRepresentation::kTaggedSigned, Type::SignedSmall(), + MachineRepresentation::kWord64); + + CheckTwoChanges(IrOpcode::kTruncateInt64ToInt32, + IrOpcode::kChangeInt31ToTaggedSigned, + MachineRepresentation::kWord64, Type::Signed31(), + MachineRepresentation::kTagged); + CheckTwoChanges(IrOpcode::kTruncateInt64ToInt32, + IrOpcode::kChangeInt32ToTagged, + MachineRepresentation::kWord64, Type::Signed32(), + MachineRepresentation::kTagged); + CheckTwoChanges(IrOpcode::kTruncateInt64ToInt32, + IrOpcode::kChangeUint32ToTagged, + MachineRepresentation::kWord64, Type::Unsigned32(), + MachineRepresentation::kTagged); + CheckChange(IrOpcode::kChangeInt64ToTagged, MachineRepresentation::kWord64, + TypeCache::Get().kSafeInteger, MachineRepresentation::kTagged); + CheckChange(IrOpcode::kChangeUint64ToTagged, MachineRepresentation::kWord64, + TypeCache::Get().kPositiveSafeInteger, + MachineRepresentation::kTagged); + + CheckTwoChanges(IrOpcode::kTruncateInt64ToInt32, + IrOpcode::kChangeInt31ToTaggedSigned, + MachineRepresentation::kWord64, Type::Signed31(), + MachineRepresentation::kTaggedSigned); + if (SmiValuesAre32Bits()) { + CheckTwoChanges(IrOpcode::kTruncateInt64ToInt32, + IrOpcode::kChangeInt32ToTagged, + MachineRepresentation::kWord64, Type::Signed32(), + MachineRepresentation::kTaggedSigned); + } + CheckChange(IrOpcode::kCheckedInt64ToTaggedSigned, + MachineRepresentation::kWord64, TypeCache::Get().kSafeInteger, + MachineRepresentation::kTaggedSigned, + UseInfo::CheckedSignedSmallAsTaggedSigned(VectorSlotPair())); + CheckChange(IrOpcode::kCheckedUint64ToTaggedSigned, + MachineRepresentation::kWord64, + TypeCache::Get().kPositiveSafeInteger, + MachineRepresentation::kTaggedSigned, + UseInfo::CheckedSignedSmallAsTaggedSigned(VectorSlotPair())); + + CheckTwoChanges(IrOpcode::kChangeInt64ToFloat64, + IrOpcode::kChangeFloat64ToTaggedPointer, + MachineRepresentation::kWord64, TypeCache::Get().kSafeInteger, + MachineRepresentation::kTaggedPointer); +} + TEST(SingleChanges) { CheckChange(IrOpcode::kChangeTaggedToBit, MachineRepresentation::kTagged, Type::Boolean(), MachineRepresentation::kBit); @@ -371,6 +516,10 @@ TEST(SingleChanges) { // Int32,Uint32 <-> Float64 are actually machine conversions. CheckChange(IrOpcode::kChangeInt32ToFloat64, MachineRepresentation::kWord32, Type::Signed32(), MachineRepresentation::kFloat64); + CheckChange(IrOpcode::kChangeInt32ToFloat64, MachineRepresentation::kWord32, + Type::Signed32OrMinusZero(), MachineRepresentation::kFloat64, + UseInfo(MachineRepresentation::kFloat64, + Truncation::Any(kIdentifyZeros))); CheckChange(IrOpcode::kChangeUint32ToFloat64, MachineRepresentation::kWord32, Type::Unsigned32(), MachineRepresentation::kFloat64); CheckChange(IrOpcode::kChangeFloat64ToInt32, MachineRepresentation::kFloat64, @@ -425,7 +574,8 @@ TEST(SignednessInWord32) { Type::Signed32(), MachineRepresentation::kWord32); CheckChange(IrOpcode::kTruncateFloat64ToWord32, MachineRepresentation::kFloat64, Type::Number(), - MachineRepresentation::kWord32); + MachineRepresentation::kWord32, + UseInfo(MachineRepresentation::kWord32, Truncation::Word32())); CheckChange(IrOpcode::kCheckedTruncateTaggedToWord32, MachineRepresentation::kTagged, Type::NonInternal(), MachineRepresentation::kWord32, @@ -523,16 +673,10 @@ TEST(TypeErrors) { MachineRepresentation::kWord64); r.CheckTypeError(MachineRepresentation::kTagged, Type::Boolean(), MachineRepresentation::kWord64); - - // Word64 / Word32 shouldn't be implicitly converted. r.CheckTypeError(MachineRepresentation::kWord64, Type::Internal(), MachineRepresentation::kWord32); r.CheckTypeError(MachineRepresentation::kWord32, Type::Number(), MachineRepresentation::kWord64); - r.CheckTypeError(MachineRepresentation::kWord32, Type::Signed32(), - MachineRepresentation::kWord64); - r.CheckTypeError(MachineRepresentation::kWord32, Type::Unsigned32(), - MachineRepresentation::kWord64); } } // namespace compiler diff --git a/deps/v8/test/cctest/compiler/test-run-bytecode-graph-builder.cc b/deps/v8/test/cctest/compiler/test-run-bytecode-graph-builder.cc index c62ed69105..681669f334 100644 --- a/deps/v8/test/cctest/compiler/test-run-bytecode-graph-builder.cc +++ b/deps/v8/test/cctest/compiler/test-run-bytecode-graph-builder.cc @@ -60,7 +60,7 @@ class BytecodeGraphCallable { public: BytecodeGraphCallable(Isolate* isolate, Handle<JSFunction> function) : isolate_(isolate), function_(function) {} - virtual ~BytecodeGraphCallable() {} + virtual ~BytecodeGraphCallable() = default; MaybeHandle<Object> operator()(A... args) { return CallFunction(isolate_, function_, args...); @@ -79,7 +79,7 @@ class BytecodeGraphTester { i::FLAG_always_opt = false; i::FLAG_allow_natives_syntax = true; } - virtual ~BytecodeGraphTester() {} + virtual ~BytecodeGraphTester() = default; template <class... A> BytecodeGraphCallable<A...> GetCallable( diff --git a/deps/v8/test/cctest/compiler/test-run-intrinsics.cc b/deps/v8/test/cctest/compiler/test-run-intrinsics.cc index efae91343f..82c4c447f2 100644 --- a/deps/v8/test/cctest/compiler/test-run-intrinsics.cc +++ b/deps/v8/test/cctest/compiler/test-run-intrinsics.cc @@ -20,21 +20,6 @@ TEST(Call) { T.CheckCall(T.Val("6x"), T.NewObject("({d:'x'})"), T.NewObject("f")); } - -TEST(ClassOf) { - FunctionTester T("(function(a) { return %_ClassOf(a); })", flags); - - T.CheckCall(T.Val("Function"), T.NewObject("(function() {})")); - T.CheckCall(T.Val("Array"), T.NewObject("([1])")); - T.CheckCall(T.Val("Object"), T.NewObject("({})")); - T.CheckCall(T.Val("RegExp"), T.NewObject("(/x/)")); - T.CheckCall(T.null(), T.undefined()); - T.CheckCall(T.null(), T.null()); - T.CheckCall(T.null(), T.Val("x")); - T.CheckCall(T.null(), T.Val(1)); -} - - TEST(IsArray) { FunctionTester T("(function(a) { return %_IsArray(a); })", flags); @@ -50,36 +35,6 @@ TEST(IsArray) { } -TEST(IsDate) { - FunctionTester T("(function(a) { return %_IsDate(a); })", flags); - - T.CheckTrue(T.NewObject("new Date()")); - T.CheckFalse(T.NewObject("(function() {})")); - T.CheckFalse(T.NewObject("([1])")); - T.CheckFalse(T.NewObject("({})")); - T.CheckFalse(T.NewObject("(/x/)")); - T.CheckFalse(T.undefined()); - T.CheckFalse(T.null()); - T.CheckFalse(T.Val("x")); - T.CheckFalse(T.Val(1)); -} - - -TEST(IsFunction) { - FunctionTester T("(function(a) { return %_IsFunction(a); })", flags); - - T.CheckFalse(T.NewObject("new Date()")); - T.CheckTrue(T.NewObject("(function() {})")); - T.CheckFalse(T.NewObject("([1])")); - T.CheckFalse(T.NewObject("({})")); - T.CheckFalse(T.NewObject("(/x/)")); - T.CheckFalse(T.undefined()); - T.CheckFalse(T.null()); - T.CheckFalse(T.Val("x")); - T.CheckFalse(T.Val(1)); -} - - TEST(IsSmi) { FunctionTester T("(function(a) { return %_IsSmi(a); })", flags); @@ -96,15 +51,6 @@ TEST(IsSmi) { T.CheckFalse(T.Val(-2.3)); } - -TEST(StringAdd) { - FunctionTester T("(function(a,b) { return %_StringAdd(a,b); })", flags); - - T.CheckCall(T.Val("aaabbb"), T.Val("aaa"), T.Val("bbb")); - T.CheckCall(T.Val("aaa"), T.Val("aaa"), T.Val("")); - T.CheckCall(T.Val("bbb"), T.Val(""), T.Val("bbb")); -} - } // namespace compiler } // namespace internal } // namespace v8 diff --git a/deps/v8/test/cctest/compiler/test-run-machops.cc b/deps/v8/test/cctest/compiler/test-run-machops.cc index 71adbc738d..419d1b0699 100644 --- a/deps/v8/test/cctest/compiler/test-run-machops.cc +++ b/deps/v8/test/cctest/compiler/test-run-machops.cc @@ -4174,7 +4174,6 @@ TEST(RunChangeFloat64ToInt32_B) { } } - TEST(RunChangeFloat64ToUint32) { BufferedRawMachineAssemblerTester<uint32_t> m(MachineType::Float64()); m.Return(m.ChangeFloat64ToUint32(m.Parameter(0))); @@ -6340,6 +6339,29 @@ TEST(RunCallCFunction9) { #if V8_TARGET_ARCH_64_BIT // TODO(titzer): run int64 tests on all platforms when supported. +TEST(RunChangeFloat64ToInt64) { + BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Float64()); + m.Return(m.ChangeFloat64ToInt64(m.Parameter(0))); + + FOR_INT64_INPUTS(i) { + double input = static_cast<double>(*i); + if (static_cast<int64_t>(input) == *i) { + CHECK_EQ(static_cast<int64_t>(input), m.Call(input)); + } + } +} + +TEST(RunChangeInt64ToFloat64) { + BufferedRawMachineAssemblerTester<double> m(MachineType::Int64()); + m.Return(m.ChangeInt64ToFloat64(m.Parameter(0))); + FOR_INT64_INPUTS(i) { + double output = static_cast<double>(*i); + if (static_cast<int64_t>(output) == *i) { + CHECK_EQ(output, m.Call(*i)); + } + } +} + TEST(RunBitcastInt64ToFloat64) { int64_t input = 1; Float64 output; diff --git a/deps/v8/test/cctest/compiler/test-run-native-calls.cc b/deps/v8/test/cctest/compiler/test-run-native-calls.cc index b23bd500c6..2ddaa1bc07 100644 --- a/deps/v8/test/cctest/compiler/test-run-native-calls.cc +++ b/deps/v8/test/cctest/compiler/test-run-native-calls.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <vector> + #include "src/assembler.h" #include "src/codegen.h" #include "src/compiler/linkage.h" @@ -9,6 +11,7 @@ #include "src/machine-type.h" #include "src/objects-inl.h" #include "src/register-configuration.h" +#include "src/wasm/wasm-linkage.h" #include "test/cctest/cctest.h" #include "test/cctest/compiler/codegen-tester.h" @@ -20,8 +23,6 @@ namespace internal { namespace compiler { namespace test_run_native_calls { -const auto GetRegConfig = RegisterConfiguration::Default; - namespace { typedef float float32; typedef double float64; @@ -84,21 +85,12 @@ class RegisterPairs : public Pairs { GetRegConfig()->allocatable_general_codes()) {} }; - -// Pairs of double registers. +// Pairs of float registers. class Float32RegisterPairs : public Pairs { public: Float32RegisterPairs() - : Pairs( - 100, -#if V8_TARGET_ARCH_ARM - // TODO(bbudge) Modify wasm linkage to allow use of all float regs. - GetRegConfig()->num_allocatable_double_registers() / 2 - 2, -#else - GetRegConfig()->num_allocatable_double_registers(), -#endif - GetRegConfig()->allocatable_double_codes()) { - } + : Pairs(100, GetRegConfig()->num_allocatable_float_registers(), + GetRegConfig()->allocatable_float_codes()) {} }; @@ -112,48 +104,39 @@ class Float64RegisterPairs : public Pairs { // Helper for allocating either an GP or FP reg, or the next stack slot. -struct Allocator { - Allocator(int* gp, int gpc, int* fp, int fpc) - : gp_count(gpc), - gp_offset(0), - gp_regs(gp), - fp_count(fpc), - fp_offset(0), - fp_regs(fp), - stack_offset(0) {} - - int gp_count; - int gp_offset; - int* gp_regs; - - int fp_count; - int fp_offset; - int* fp_regs; - - int stack_offset; +class Allocator { + public: + Allocator(int* gp, int gpc, int* fp, int fpc) : stack_offset_(0) { + for (int i = 0; i < gpc; ++i) { + gp_.push_back(Register::from_code(gp[i])); + } + for (int i = 0; i < fpc; ++i) { + fp_.push_back(DoubleRegister::from_code(fp[i])); + } + Reset(); + } + + int stack_offset() const { return stack_offset_; } LinkageLocation Next(MachineType type) { if (IsFloatingPoint(type.representation())) { // Allocate a floating point register/stack location. - if (fp_offset < fp_count) { - int code = fp_regs[fp_offset++]; -#if V8_TARGET_ARCH_ARM - // TODO(bbudge) Modify wasm linkage to allow use of all float regs. - if (type.representation() == MachineRepresentation::kFloat32) code *= 2; -#endif + if (reg_allocator_->CanAllocateFP(type.representation())) { + int code = reg_allocator_->NextFpReg(type.representation()); return LinkageLocation::ForRegister(code, type); } else { - int offset = -1 - stack_offset; - stack_offset += StackWords(type); + int offset = -1 - stack_offset_; + stack_offset_ += StackWords(type); return LinkageLocation::ForCallerFrameSlot(offset, type); } } else { // Allocate a general purpose register/stack location. - if (gp_offset < gp_count) { - return LinkageLocation::ForRegister(gp_regs[gp_offset++], type); + if (reg_allocator_->CanAllocateGP()) { + int code = reg_allocator_->NextGpReg(); + return LinkageLocation::ForRegister(code, type); } else { - int offset = -1 - stack_offset; - stack_offset += StackWords(type); + int offset = -1 - stack_offset_; + stack_offset_ += StackWords(type); return LinkageLocation::ForCallerFrameSlot(offset, type); } } @@ -163,10 +146,17 @@ struct Allocator { return size <= kPointerSize ? 1 : size / kPointerSize; } void Reset() { - fp_offset = 0; - gp_offset = 0; - stack_offset = 0; + stack_offset_ = 0; + reg_allocator_.reset( + new wasm::LinkageAllocator(gp_.data(), static_cast<int>(gp_.size()), + fp_.data(), static_cast<int>(fp_.size()))); } + + private: + std::vector<Register> gp_; + std::vector<DoubleRegister> fp_; + std::unique_ptr<wasm::LinkageAllocator> reg_allocator_; + int stack_offset_; }; @@ -197,7 +187,7 @@ class RegisterConfig { MachineType target_type = MachineType::AnyTagged(); LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); - int stack_param_count = params.stack_offset; + int stack_param_count = params.stack_offset(); return new (zone) CallDescriptor( // -- CallDescriptor::kCallCodeObject, // kind target_type, // target MachineType @@ -868,7 +858,7 @@ TEST(Float32Select_registers) { return; } - int rarray[] = {GetRegConfig()->GetAllocatableDoubleCode(0)}; + int rarray[] = {GetRegConfig()->GetAllocatableFloatCode(0)}; ArgsBuffer<float32>::Sig sig(2); Float32RegisterPairs pairs; @@ -912,7 +902,7 @@ TEST(Float64Select_registers) { TEST(Float32Select_stack_params_return_reg) { - int rarray[] = {GetRegConfig()->GetAllocatableDoubleCode(0)}; + int rarray[] = {GetRegConfig()->GetAllocatableFloatCode(0)}; Allocator params(nullptr, 0, nullptr, 0); Allocator rets(nullptr, 0, rarray, 1); RegisterConfig config(params, rets); diff --git a/deps/v8/test/cctest/compiler/value-helper.h b/deps/v8/test/cctest/compiler/value-helper.h index e66c1ff454..8e652ec3b5 100644 --- a/deps/v8/test/cctest/compiler/value-helper.h +++ b/deps/v8/test/cctest/compiler/value-helper.h @@ -345,29 +345,37 @@ template <typename type> struct FloatCompareWrapper { type value; explicit FloatCompareWrapper(type x) : value(x) {} - bool operator==(type other) const { + bool operator==(FloatCompareWrapper<type> const& other) const { return std::isnan(value) - ? std::isnan(other) - : value == other && std::signbit(value) == std::signbit(other); + ? std::isnan(other.value) + : value == other.value && + std::signbit(value) == std::signbit(other.value); } }; template <typename type> std::ostream& operator<<(std::ostream& out, FloatCompareWrapper<type> wrapper) { - return out << wrapper.value; + uint8_t bytes[sizeof(type)]; + memcpy(bytes, &wrapper.value, sizeof(type)); + out << wrapper.value << " (0x"; + const char* kHexDigits = "0123456789ABCDEF"; + for (unsigned i = 0; i < sizeof(type); ++i) { + out << kHexDigits[bytes[i] >> 4] << kHexDigits[bytes[i] & 15]; + } + return out << ")"; } #define CHECK_FLOAT_EQ(lhs, rhs) \ do { \ using FloatWrapper = ::v8::internal::compiler::FloatCompareWrapper<float>; \ - CHECK_EQ(FloatWrapper(lhs), rhs); \ + CHECK_EQ(FloatWrapper(lhs), FloatWrapper(rhs)); \ } while (false) #define CHECK_DOUBLE_EQ(lhs, rhs) \ do { \ using DoubleWrapper = \ ::v8::internal::compiler::FloatCompareWrapper<double>; \ - CHECK_EQ(DoubleWrapper(lhs), rhs); \ + CHECK_EQ(DoubleWrapper(lhs), DoubleWrapper(rhs)); \ } while (false) } // namespace compiler |