Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "vm/intermediate_language.h"
|
|
|
|
|
|
|
|
#include "vm/object.h"
|
|
|
|
#include "vm/os.h"
|
|
|
|
#include "vm/scopes.h"
|
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
2012-02-28 08:58:49 +00:00
|
|
|
// ==== Support for visiting flow graphs.
|
|
|
|
#define DEFINE_ACCEPT(ShortName, ClassName) \
|
|
|
|
void ClassName::Accept(FlowGraphVisitor* visitor) { \
|
|
|
|
visitor->Visit##ShortName(this); \
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
2012-02-28 08:58:49 +00:00
|
|
|
FOR_EACH_COMPUTATION(DEFINE_ACCEPT)
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
|
2012-02-28 08:58:49 +00:00
|
|
|
#undef DEFINE_ACCEPT
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
|
|
|
|
|
2012-02-28 08:58:49 +00:00
|
|
|
Instruction* JoinEntryInstr::Accept(FlowGraphVisitor* visitor) {
|
2012-02-23 18:29:58 +00:00
|
|
|
visitor->VisitJoinEntry(this);
|
Recognize basic block entries in the flow graph.
Also, instead of keeping a list of all instructions, keep a list of only
block entries. The printing implementation is changed (for the better) to
use the new representation. With --use_new_compiler and --print_flow_graph
the function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
prints as:
0: [target]
StoreLocal(f, #1)
StoreLocal(n, #5) goto 1
1: [join]
t0 <-LoadLocal(n)
t0 <-InstanceCall(>, t0, #0)
if t0 goto(2, 3)
2: [target]
t0 <-LoadLocal(f)
t1 <-LoadLocal(n)
t0 <-InstanceCall(*, t0, t1)
StoreLocal(f, t0)
t0 <-LoadLocal(n)
t0 <-InstanceCall(-, t0, #1)
StoreLocal(n, t0) goto 1
3: [target]
t0 <-LoadLocal(f)
StaticCall(print, t0)
return #null
R=srdjan@google.com
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9429056
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4515 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-23 09:09:45 +00:00
|
|
|
return successor_;
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 08:58:49 +00:00
|
|
|
Instruction* TargetEntryInstr::Accept(FlowGraphVisitor* visitor) {
|
2012-02-23 18:29:58 +00:00
|
|
|
visitor->VisitTargetEntry(this);
|
Recognize basic block entries in the flow graph.
Also, instead of keeping a list of all instructions, keep a list of only
block entries. The printing implementation is changed (for the better) to
use the new representation. With --use_new_compiler and --print_flow_graph
the function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
prints as:
0: [target]
StoreLocal(f, #1)
StoreLocal(n, #5) goto 1
1: [join]
t0 <-LoadLocal(n)
t0 <-InstanceCall(>, t0, #0)
if t0 goto(2, 3)
2: [target]
t0 <-LoadLocal(f)
t1 <-LoadLocal(n)
t0 <-InstanceCall(*, t0, t1)
StoreLocal(f, t0)
t0 <-LoadLocal(n)
t0 <-InstanceCall(-, t0, #1)
StoreLocal(n, t0) goto 1
3: [target]
t0 <-LoadLocal(f)
StaticCall(print, t0)
return #null
R=srdjan@google.com
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9429056
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4515 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-23 09:09:45 +00:00
|
|
|
return successor_;
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-07 10:24:01 +00:00
|
|
|
Instruction* PickTempInstr::Accept(FlowGraphVisitor* visitor) {
|
|
|
|
visitor->VisitPickTemp(this);
|
|
|
|
return successor_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Instruction* TuckTempInstr::Accept(FlowGraphVisitor* visitor) {
|
|
|
|
visitor->VisitTuckTemp(this);
|
|
|
|
return successor_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 08:58:49 +00:00
|
|
|
Instruction* DoInstr::Accept(FlowGraphVisitor* visitor) {
|
2012-02-23 18:29:58 +00:00
|
|
|
visitor->VisitDo(this);
|
|
|
|
return successor_;
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 08:58:49 +00:00
|
|
|
Instruction* BindInstr::Accept(FlowGraphVisitor* visitor) {
|
2012-02-23 18:29:58 +00:00
|
|
|
visitor->VisitBind(this);
|
|
|
|
return successor_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 08:58:49 +00:00
|
|
|
Instruction* ReturnInstr::Accept(FlowGraphVisitor* visitor) {
|
2012-02-23 18:29:58 +00:00
|
|
|
visitor->VisitReturn(this);
|
Recognize basic block entries in the flow graph.
Also, instead of keeping a list of all instructions, keep a list of only
block entries. The printing implementation is changed (for the better) to
use the new representation. With --use_new_compiler and --print_flow_graph
the function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
prints as:
0: [target]
StoreLocal(f, #1)
StoreLocal(n, #5) goto 1
1: [join]
t0 <-LoadLocal(n)
t0 <-InstanceCall(>, t0, #0)
if t0 goto(2, 3)
2: [target]
t0 <-LoadLocal(f)
t1 <-LoadLocal(n)
t0 <-InstanceCall(*, t0, t1)
StoreLocal(f, t0)
t0 <-LoadLocal(n)
t0 <-InstanceCall(-, t0, #1)
StoreLocal(n, t0) goto 1
3: [target]
t0 <-LoadLocal(f)
StaticCall(print, t0)
return #null
R=srdjan@google.com
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9429056
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4515 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-23 09:09:45 +00:00
|
|
|
return NULL;
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 20:42:01 +00:00
|
|
|
Instruction* ThrowInstr::Accept(FlowGraphVisitor* visitor) {
|
|
|
|
visitor->VisitThrow(this);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Instruction* ReThrowInstr::Accept(FlowGraphVisitor* visitor) {
|
|
|
|
visitor->VisitReThrow(this);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 08:58:49 +00:00
|
|
|
Instruction* BranchInstr::Accept(FlowGraphVisitor* visitor) {
|
2012-02-23 18:29:58 +00:00
|
|
|
visitor->VisitBranch(this);
|
|
|
|
return NULL;
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-23 18:29:58 +00:00
|
|
|
// Default implementation of visiting basic blocks. Can be overridden.
|
2012-03-16 22:20:04 +00:00
|
|
|
void FlowGraphVisitor::VisitBlocks() {
|
|
|
|
for (intptr_t i = 0; i < block_order_.length(); ++i) {
|
|
|
|
Instruction* current = block_order_[i]->Accept(this);
|
2012-02-23 18:29:58 +00:00
|
|
|
while ((current != NULL) && !current->IsBlockEntry()) {
|
|
|
|
current = current->Accept(this);
|
|
|
|
}
|
|
|
|
}
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-23 18:29:58 +00:00
|
|
|
// ==== Postorder graph traversal.
|
2012-03-16 22:20:04 +00:00
|
|
|
void JoinEntryInstr::DepthFirstSearch(
|
|
|
|
GrowableArray<BlockEntryInstr*>* preorder,
|
|
|
|
GrowableArray<BlockEntryInstr*>* postorder) {
|
|
|
|
// JoinEntryInstr is the only instruction that can have more than one
|
|
|
|
// predecessor, so it is the only one that could be reached more than once
|
|
|
|
// during the traversal.
|
|
|
|
//
|
|
|
|
// Use the presence of a preorder number to indicate that it has already
|
|
|
|
// been reached.
|
|
|
|
if (preorder_number() >= 0) return;
|
|
|
|
set_preorder_number(preorder->length());
|
|
|
|
preorder->Add(this);
|
2012-03-14 21:47:43 +00:00
|
|
|
ASSERT(successor_ != NULL);
|
2012-03-16 22:20:04 +00:00
|
|
|
successor_->DepthFirstSearch(preorder, postorder);
|
|
|
|
set_postorder_number(postorder->length());
|
|
|
|
postorder->Add(this);
|
2012-03-07 10:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-16 22:20:04 +00:00
|
|
|
void TargetEntryInstr::DepthFirstSearch(
|
|
|
|
GrowableArray<BlockEntryInstr*>* preorder,
|
|
|
|
GrowableArray<BlockEntryInstr*>* postorder) {
|
|
|
|
ASSERT(preorder_number() == -1);
|
|
|
|
set_preorder_number(preorder->length());
|
|
|
|
preorder->Add(this);
|
2012-03-14 21:47:43 +00:00
|
|
|
ASSERT(successor_ != NULL);
|
2012-03-16 22:20:04 +00:00
|
|
|
successor_->DepthFirstSearch(preorder, postorder);
|
|
|
|
set_postorder_number(postorder->length());
|
|
|
|
postorder->Add(this);
|
2012-03-07 10:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-16 22:20:04 +00:00
|
|
|
void PickTempInstr::DepthFirstSearch(
|
|
|
|
GrowableArray<BlockEntryInstr*>* preorder,
|
|
|
|
GrowableArray<BlockEntryInstr*>* postorder) {
|
2012-03-14 21:47:43 +00:00
|
|
|
ASSERT(successor_ != NULL);
|
2012-03-16 22:20:04 +00:00
|
|
|
successor_->DepthFirstSearch(preorder, postorder);
|
2012-03-07 10:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-16 22:20:04 +00:00
|
|
|
void TuckTempInstr::DepthFirstSearch(
|
|
|
|
GrowableArray<BlockEntryInstr*>* preorder,
|
|
|
|
GrowableArray<BlockEntryInstr*>* postorder) {
|
2012-03-14 21:47:43 +00:00
|
|
|
ASSERT(successor_ != NULL);
|
2012-03-16 22:20:04 +00:00
|
|
|
successor_->DepthFirstSearch(preorder, postorder);
|
2012-03-07 10:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-16 22:20:04 +00:00
|
|
|
void DoInstr::DepthFirstSearch(
|
|
|
|
GrowableArray<BlockEntryInstr*>* preorder,
|
|
|
|
GrowableArray<BlockEntryInstr*>* postorder) {
|
2012-03-14 21:47:43 +00:00
|
|
|
ASSERT(successor_ != NULL);
|
2012-03-16 22:20:04 +00:00
|
|
|
successor_->DepthFirstSearch(preorder, postorder);
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-16 22:20:04 +00:00
|
|
|
void BindInstr::DepthFirstSearch(
|
|
|
|
GrowableArray<BlockEntryInstr*>* preorder,
|
|
|
|
GrowableArray<BlockEntryInstr*>* postorder) {
|
2012-03-14 21:47:43 +00:00
|
|
|
ASSERT(successor_ != NULL);
|
2012-03-16 22:20:04 +00:00
|
|
|
successor_->DepthFirstSearch(preorder, postorder);
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-16 22:20:04 +00:00
|
|
|
void ReturnInstr::DepthFirstSearch(
|
|
|
|
GrowableArray<BlockEntryInstr*>* preorder,
|
|
|
|
GrowableArray<BlockEntryInstr*>* postorder) {
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-16 22:20:04 +00:00
|
|
|
void ThrowInstr::DepthFirstSearch(
|
|
|
|
GrowableArray<BlockEntryInstr*>* preorder,
|
|
|
|
GrowableArray<BlockEntryInstr*>* postorder) {
|
2012-03-15 20:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-16 22:20:04 +00:00
|
|
|
void ReThrowInstr::DepthFirstSearch(
|
|
|
|
GrowableArray<BlockEntryInstr*>* preorder,
|
|
|
|
GrowableArray<BlockEntryInstr*>* postorder) {
|
2012-03-15 20:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-16 22:20:04 +00:00
|
|
|
void BranchInstr::DepthFirstSearch(
|
|
|
|
GrowableArray<BlockEntryInstr*>* preorder,
|
|
|
|
GrowableArray<BlockEntryInstr*>* postorder) {
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
// Visit the false successor before the true successor so they appear in
|
2012-03-16 22:20:04 +00:00
|
|
|
// true/false order in reverse postorder used as the block ordering in the
|
|
|
|
// nonoptimizing compiler.
|
2012-03-09 21:34:58 +00:00
|
|
|
ASSERT(true_successor_ != NULL);
|
2012-03-16 22:20:04 +00:00
|
|
|
ASSERT(false_successor_ != NULL);
|
|
|
|
false_successor_->DepthFirstSearch(preorder, postorder);
|
|
|
|
true_successor_->DepthFirstSearch(preorder, postorder);
|
Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace dart
|