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

Side by Side Diff: src/sksl/SkSLCFGGenerator.h

Issue 2405383003: added basic dataflow analysis to skslc (Closed)
Patch Set: I have no idea what I was thinking Created 4 years, 2 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 | « src/sksl/README ('k') | src/sksl/SkSLCFGGenerator.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SKSL_CFGGENERATOR
9 #define SKSL_CFGGENERATOR
10
11 #include "ir/SkSLExpression.h"
12 #include "ir/SkSLFunctionDefinition.h"
13
14 #include <set>
15 #include <stack>
16
17 namespace SkSL {
18
19 // index of a block within CFG.fBlocks
20 typedef size_t BlockId;
21
22 struct BasicBlock {
23 struct Node {
24 enum Kind {
25 kStatement_Kind,
26 kExpression_Kind
27 };
28
29 Kind fKind;
30 const IRNode* fNode;
31 };
32
33 std::vector<Node> fNodes;
34 std::set<BlockId> fEntrances;
35 std::set<BlockId> fExits;
36 // variable definitions upon entering this basic block (null expression = un defined)
37 std::unordered_map<const Variable*, const Expression*> fBefore;
38 };
39
40 struct CFG {
41 BlockId fStart;
42 BlockId fExit;
43 std::vector<BasicBlock> fBlocks;
44
45 void dump();
46
47 private:
48 BlockId fCurrent;
49
50 // Adds a new block, adds an exit* from the current block to the new block, then marks the new
51 // block as the current block
52 // *see note in addExit()
53 BlockId newBlock();
54
55 // Adds a new block, but does not mark it current or add an exit from the cu rrent block
56 BlockId newIsolatedBlock();
57
58 // Adds an exit from the 'from' block to the 'to' block
59 // Note that we skip adding the exit if the 'from' block is itself unreachab le; this means that
60 // we don't actually have to trace the tree to see if a particular block is unreachable, we can
61 // just check to see if it has any entrances. This does require a bit of car e in the order in
62 // which we set the CFG up.
63 void addExit(BlockId from, BlockId to);
64
65 friend class CFGGenerator;
66 };
67
68 /**
69 * Converts functions into control flow graphs.
70 */
71 class CFGGenerator {
72 public:
73 CFGGenerator() {}
74
75 CFG getCFG(const FunctionDefinition& f);
76
77 private:
78 void addStatement(CFG& cfg, const Statement* s);
79
80 void addExpression(CFG& cfg, const Expression* e);
81
82 void addLValue(CFG& cfg, const Expression* e);
83
84 std::stack<BlockId> fLoopContinues;
85 std::stack<BlockId> fLoopExits;
86 };
87
88 }
89
90 #endif
OLDNEW
« no previous file with comments | « src/sksl/README ('k') | src/sksl/SkSLCFGGenerator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698