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 : #include "syzygy/optimize/transforms/block_alignment_transform.h"
16 :
17 : #include "syzygy/block_graph/block_graph.h"
18 :
19 : namespace optimize {
20 : namespace transforms {
21 :
22 : namespace {
23 : using block_graph::BasicBlock;
24 : using block_graph::BasicCodeBlock;
25 : } // namespace
26 :
27 : bool BlockAlignmentTransform::TransformBasicBlockSubGraph(
28 : const TransformPolicyInterface* policy,
29 : BlockGraph* block_graph,
30 : BasicBlockSubGraph* subgraph,
31 : ApplicationProfile* profile,
32 E : SubGraphProfile* subgraph_profile) {
33 E : DCHECK_NE(reinterpret_cast<TransformPolicyInterface*>(NULL), policy);
34 E : DCHECK_NE(reinterpret_cast<BlockGraph*>(NULL), block_graph);
35 E : DCHECK_NE(reinterpret_cast<BasicBlockSubGraph*>(NULL), subgraph);
36 E : DCHECK_NE(reinterpret_cast<ApplicationProfile*>(NULL), profile);
37 E : DCHECK_NE(reinterpret_cast<SubGraphProfile*>(NULL), subgraph_profile);
38 :
39 : // Iterates through each basic block.
40 : BasicBlockSubGraph::BBCollection::iterator bb_iter =
41 E : subgraph->basic_blocks().begin();
42 E : for (; bb_iter != subgraph->basic_blocks().end(); ++bb_iter) {
43 E : BasicCodeBlock* bb = BasicCodeBlock::Cast(*bb_iter);
44 E : if (bb == NULL)
45 E : continue;
46 : // TODO(etienneb): Basic block alignment based on frequencies (PGO).
47 E : }
48 :
49 : // Apply function alignment.
50 E : if (!subgraph->block_descriptions().empty()) {
51 : BasicBlockSubGraph::BlockDescription& description =
52 E : subgraph->block_descriptions().front();
53 : // TODO(etienneb): Function alignment based on frequencies (PGO).
54 E : if (description.alignment <= 1)
55 E : description.alignment = 32;
56 : }
57 :
58 E : return true;
59 E : }
60 :
61 : } // namespace transforms
62 : } // namespace optimize
|