Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: test/cctest/compiler/test-run-stubs.cc

Issue 925373002: Test StringLengthStub generation via TurboFan. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cctest Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/code-stubs.h"
6 #include "src/compiler/graph.h"
7 #include "src/compiler/linkage.h"
8 #include "src/compiler/pipeline.h"
9 #include "src/compiler/raw-machine-assembler.h"
10 #include "src/globals.h"
11 #include "src/handles.h"
12 #include "test/cctest/compiler/function-tester.h"
13
14 #if V8_TURBOFAN_TARGET
15
16 using namespace v8::internal;
17 using namespace v8::internal::compiler;
18
19
20 class StringLengthStubTF : public CodeStub {
21 public:
22 explicit StringLengthStubTF(Isolate* isolate) : CodeStub(isolate) {}
23
24 StringLengthStubTF(uint32_t key, Isolate* isolate) : CodeStub(key, isolate) {}
25
26 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE {
27 return LoadDescriptor(isolate());
28 };
29
30 Handle<Code> GenerateCode() OVERRIDE {
31 CompilationInfoWithZone info(this, isolate());
32 Graph graph(info.zone());
33 CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
34 RawMachineAssembler m(isolate(), &graph, descriptor->GetMachineSignature());
35
36 Node* str = m.Load(kMachAnyTagged, m.Parameter(0),
37 m.Int32Constant(JSValue::kValueOffset - kHeapObjectTag));
38 Node* len = m.Load(kMachAnyTagged, str,
39 m.Int32Constant(String::kLengthOffset - kHeapObjectTag));
40 m.Return(len);
41
42 return Pipeline::GenerateCodeForTesting(&info, &graph, m.Export());
43 }
44
45 Major MajorKey() const OVERRIDE { return StringLength; };
46 Code::Kind GetCodeKind() const OVERRIDE { return Code::HANDLER; }
47 InlineCacheState GetICState() const OVERRIDE { return MONOMORPHIC; }
48 ExtraICState GetExtraICState() const OVERRIDE { return Code::LOAD_IC; }
49 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; }
50
51 private:
52 DISALLOW_COPY_AND_ASSIGN(StringLengthStubTF);
53 };
54
55
56 TEST(RunStringLengthStubTF) {
57 HandleAndZoneScope scope;
58 Isolate* isolate = scope.main_isolate();
59 Zone* zone = scope.main_zone();
60
61 // Create code and an accompanying descriptor.
62 StringLengthStubTF stub(isolate);
63 Handle<Code> code = stub.GenerateCode();
64 CompilationInfo info(&stub, isolate, zone);
65 CallDescriptor* descriptor = Linkage::ComputeIncoming(zone, &info);
66
67 // Create a function to call the code using the descriptor.
68 Graph graph(zone);
69 CommonOperatorBuilder common(zone);
70 // FunctionTester (ab)uses a 2-argument function
71 Node* start = graph.NewNode(common.Start(2));
72 // Parameter 0 is the receiver
73 Node* receiverParam = graph.NewNode(common.Parameter(1), start);
74 Node* nameParam = graph.NewNode(common.Parameter(2), start);
75 Unique<HeapObject> u = Unique<HeapObject>::CreateImmovable(code);
76 Node* theCode = graph.NewNode(common.HeapConstant(u));
77 Node* dummyContext = graph.NewNode(common.NumberConstant(0.0));
78 Node* call = graph.NewNode(common.Call(descriptor), theCode, receiverParam,
79 nameParam, dummyContext, start, start);
80 Node* ret = graph.NewNode(common.Return(), call, call, start);
81 Node* end = graph.NewNode(common.End(), ret);
82 graph.SetStart(start);
83 graph.SetEnd(end);
84 FunctionTester ft(&graph);
85
86 // Actuall call through to the stub, verifying its result.
87 const char* testString = "Und das Lamm schrie HURZ!";
88 Handle<JSReceiver> receiverArg =
89 Object::ToObject(isolate, ft.Val(testString)).ToHandleChecked();
90 Handle<String> nameArg = ft.Val("length");
91 Handle<Object> result = ft.Call(receiverArg, nameArg).ToHandleChecked();
92 CHECK_EQ(static_cast<int>(strlen(testString)), Smi::cast(*result)->value());
93 }
94
95 #endif // V8_TURBOFAN_TARGET
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698