1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Declares a simple API for transforming BlockGraphs in situ.
16 :
17 : #ifndef SYZYGY_BLOCK_GRAPH_TRANSFORM_H_
18 : #define SYZYGY_BLOCK_GRAPH_TRANSFORM_H_
19 :
20 : #include "syzygy/block_graph/basic_block_subgraph.h"
21 : #include "syzygy/block_graph/block_graph.h"
22 :
23 : namespace block_graph {
24 :
25 : // A BlockGraphTransform is a pure virtual base class defining the transform
26 : // API.
27 : class BlockGraphTransformInterface {
28 : public:
29 E : virtual ~BlockGraphTransformInterface() { }
30 :
31 : // Gets the name of this transform.
32 : //
33 : // @returns the name of this transform.
34 : virtual const char* name() const = 0;
35 :
36 : // Applies this transform to the provided block graph.
37 : //
38 : // @param block_graph The block graph to transform.
39 : // @param header_block The header block of the block graph to transform.
40 : // @returns true on success, false otherwise.
41 : virtual bool TransformBlockGraph(BlockGraph* block_graph,
42 : BlockGraph::Block* header_block) = 0;
43 : };
44 :
45 : // This applies the provided BlockGraphTransform and checks that invariant has
46 : // been satisfied; namely, that the header block has not been deleted from the
47 : // block graph.
48 : //
49 : // @param transform the transform to apply.
50 : // @param block_graph the block graph to transform.
51 : // @param header_block the header block from block_graph.
52 : // @returns true on success, false otherwise.
53 : bool ApplyBlockGraphTransform(BlockGraphTransformInterface* transform,
54 : BlockGraph* block_graph,
55 : BlockGraph::Block* header_block);
56 :
57 : // A BasicBlockSubGraphTransform is a pure virtual base class defining the
58 : // basic-block transform API.
59 : class BasicBlockSubGraphTransformInterface {
60 : public:
61 E : virtual ~BasicBlockSubGraphTransformInterface() { }
62 :
63 : // Gets the name of this transform.
64 : //
65 : // @returns the name of this transform.
66 : virtual const char* name() const = 0;
67 :
68 : // Applies this transform to the provided block.
69 : //
70 : // @param block_graph the block-graph of which the basic block subgraph
71 : // is a part.
72 : // @param basic_block_subgraph the basic block subgraph to be transformed.
73 : // @returns true on success, false otherwise.
74 : virtual bool TransformBasicBlockSubGraph(
75 : BlockGraph* block_graph,
76 : BasicBlockSubGraph* basic_block_subgraph) = 0;
77 : };
78 :
79 : // Applies the provided BasicBlockSubGraphTransform to a single block. Takes
80 : // care of basic-block decomposing the block, passes it to the transform, and
81 : // recomposes the block.
82 : //
83 : // @param transform the transform to apply.
84 : // @param block_graph the block containing the block to be transformed.
85 : // @param block the block to be transformed.
86 : // @param new_blocks On success, any newly created blocks will be returned
87 : // here. Note that this parameter may be NULL if you are not interested
88 : // in retrieving the set of new blocks.
89 : // @pre block must be a code block.
90 : // @returns true on success, false otherwise.
91 : bool ApplyBasicBlockSubGraphTransform(
92 : BasicBlockSubGraphTransformInterface* transform,
93 : BlockGraph* block_graph,
94 : BlockGraph::Block* block,
95 : BlockVector* new_blocks);
96 :
97 : } // namespace block_graph
98 :
99 : #endif // SYZYGY_BLOCK_GRAPH_TRANSFORM_H_
|