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 ChainedSubgraphTransforms 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 : // ChainedSubgraphTransforms chains;
23 : // chains.AppendTransform(...);
24 : // chains.AppendTransform(...);
25 : // chains.AppendTransform(...);
26 : // chains.AppendTransform(...);
27 : // ApplyBlockGraphTransform(chains, ...);
28 :
29 : #ifndef SYZYGY_OPTIMIZE_TRANSFORMS_CHAINED_SUBGRAPH_TRANSFORMS_H_
30 : #define SYZYGY_OPTIMIZE_TRANSFORMS_CHAINED_SUBGRAPH_TRANSFORMS_H_
31 :
32 : #include "syzygy/block_graph/basic_block_subgraph.h"
33 : #include "syzygy/block_graph/block_graph.h"
34 : #include "syzygy/block_graph/transforms/named_transform.h"
35 : #include "syzygy/optimize/application_profile.h"
36 : #include "syzygy/optimize/transforms/subgraph_transform.h"
37 :
38 : namespace optimize {
39 : namespace transforms {
40 :
41 : class ChainedSubgraphTransforms
42 : : public block_graph::transforms::
43 : NamedBlockGraphTransformImpl<ChainedSubgraphTransforms> {
44 : public:
45 : typedef block_graph::BlockGraph BlockGraph;
46 : typedef block_graph::TransformPolicyInterface TransformPolicyInterface;
47 : typedef std::list<SubGraphTransformInterface*> TransformList;
48 :
49 : // Constructor.
50 E : explicit ChainedSubgraphTransforms(ApplicationProfile* profile)
51 : : profile_(profile) {
52 E : DCHECK_NE(reinterpret_cast<ApplicationProfile*>(NULL), profile);
53 E : }
54 :
55 : // This is the main body of the transform. The transform decomposes each
56 : // block into a subgraph, applies the series of transform and rebuilds the
57 : // subgraph into a block.
58 : //
59 : // @param policy The policy object restricting how the transform is applied.
60 : // @param block_graph the block graph being transformed.
61 : // @param block the block to process.
62 : // @returns true on success, false otherwise.
63 : virtual bool TransformBlockGraph(const TransformPolicyInterface* policy,
64 : BlockGraph* block_graph,
65 : BlockGraph::Block* header_block) override;
66 :
67 : // Insert a subgraph transform to the optimizing pipeline.
68 : // @param transform a transform to be applied.
69 : void AppendTransform(SubGraphTransformInterface* transform);
70 :
71 : // The transform name.
72 : static const char kTransformName[];
73 :
74 : protected:
75 : // Transforms to be applied, in order.
76 : TransformList transforms_;
77 :
78 : // Application profile information.
79 : ApplicationProfile* profile_;
80 :
81 : private:
82 : DISALLOW_COPY_AND_ASSIGN(ChainedSubgraphTransforms);
83 : };
84 :
85 : } // namespace transforms
86 : } // namespace optimize
87 :
88 : #endif // SYZYGY_OPTIMIZE_TRANSFORMS_CHAINED_SUBGRAPH_TRANSFORMS_H_
|