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 : // Implementation of ChainedBasicBlockTransform.
16 :
17 : #include "syzygy/block_graph/transforms/chained_basic_block_transforms.h"
18 :
19 : namespace block_graph {
20 : namespace transforms {
21 :
22 : const char ChainedBasicBlockTransforms::kTransformName[] =
23 : "ChainedBasicBlockTransforms";
24 :
25 : bool ChainedBasicBlockTransforms::AppendTransform(
26 E : BasicBlockSubGraphTransformInterface* transform) {
27 : DCHECK_NE(reinterpret_cast<BasicBlockSubGraphTransformInterface*>(NULL),
28 E : transform);
29 E : transforms_.push_back(transform);
30 E : return true;
31 E : }
32 :
33 : bool ChainedBasicBlockTransforms::OnBlock(
34 : const TransformPolicyInterface* policy,
35 : BlockGraph* block_graph,
36 E : BlockGraph::Block* block) {
37 E : DCHECK_NE(reinterpret_cast<TransformPolicyInterface*>(NULL), policy);
38 E : DCHECK_NE(reinterpret_cast<BlockGraph*>(NULL), block_graph);
39 E : DCHECK_NE(reinterpret_cast<BlockGraph::Block*>(NULL), block);
40 :
41 : // Avoid decomposition if no transforms are applied.
42 E : if (transforms_.empty())
43 i : return true;
44 :
45 : // Use the decomposition policy to skip blocks that aren't eligible for
46 : // basic-block decomposition.
47 E : if (!policy->BlockIsSafeToBasicBlockDecompose(block))
48 E : return true;
49 :
50 : // Apply the series of basic block transforms to this block.
51 : if (!ApplyBasicBlockSubGraphTransforms(
52 E : transforms_, policy, block_graph, block, NULL)) {
53 i : return false;
54 : }
55 :
56 E : return true;
57 E : }
58 :
59 : } // namespace transforms
60 : } // namespace block_graph
|