1 : // Copyright 2013 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 : // The ChainedBasicBlockTransforms is a BlockTransform used to apply a series of
16 : // basic block transform to each Block. Each block is decomposed in a subgraph,
17 : // the sequence of transforms is applied on the subgraph and then the block is
18 : // reconstructed.
19 : //
20 : // It is intended to be used as follows:
21 : //
22 : // ChainedBasicBlockTransforms chains;
23 : // chains.AppendTransform(...);
24 : // chains.AppendTransform(...);
25 : // chains.AppendTransform(...);
26 : // chains.AppendTransform(...);
27 : // ApplyBlockGraphTransform(chains, ...);
28 :
29 : #ifndef SYZYGY_BLOCK_GRAPH_TRANSFORMS_CHAINED_BASIC_BLOCK_TRANSFORMS_H_
30 : #define SYZYGY_BLOCK_GRAPH_TRANSFORMS_CHAINED_BASIC_BLOCK_TRANSFORMS_H_
31 :
32 : #include "syzygy/block_graph/basic_block.h"
33 : #include "syzygy/block_graph/transform_policy.h"
34 : #include "syzygy/block_graph/transforms/iterative_transform.h"
35 :
36 : namespace block_graph {
37 : namespace transforms {
38 :
39 : // This class chains a series of BasicBlockTransforms to be applied on blocks.
40 : class ChainedBasicBlockTransforms
41 : : public block_graph::transforms::
42 : IterativeTransformImpl<ChainedBasicBlockTransforms> {
43 : public:
44 : typedef block_graph::BlockGraph BlockGraph;
45 : typedef block_graph::TransformPolicyInterface TransformPolicyInterface;
46 :
47 : // Constructor.
48 E : ChainedBasicBlockTransforms() {}
49 :
50 : // @name IterativeTransformImpl implementation.
51 : // @{
52 : bool OnBlock(const TransformPolicyInterface* policy,
53 : BlockGraph* block_graph,
54 : BlockGraph::Block* block);
55 : // @}
56 :
57 : // @param transform a transform to be applied.
58 : // @returns true on success, or false otherwise.
59 : bool AppendTransform(BasicBlockSubGraphTransformInterface* transform);
60 :
61 : // The transform name.
62 : static const char kTransformName[];
63 :
64 : protected:
65 : // Transforms to be applied, in order.
66 : std::vector<BasicBlockSubGraphTransformInterface*> transforms_;
67 :
68 : private:
69 : DISALLOW_COPY_AND_ASSIGN(ChainedBasicBlockTransforms);
70 : };
71 :
72 : } // namespace transforms
73 : } // namespace block_graph
74 :
75 : #endif // SYZYGY_BLOCK_GRAPH_TRANSFORMS_CHAINED_BASIC_BLOCK_TRANSFORMS_H_
|