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 : // Declaration of the BlockBuilder class.
16 :
17 : #ifndef SYZYGY_BLOCK_GRAPH_BLOCK_BUILDER_H_
18 : #define SYZYGY_BLOCK_GRAPH_BLOCK_BUILDER_H_
19 :
20 : #include "syzygy/block_graph/basic_block_subgraph.h"
21 : #include "syzygy/block_graph/block_graph.h"
22 : #include "syzygy/block_graph/tags.h"
23 :
24 : namespace block_graph {
25 :
26 : // This class incorporates a BasicBlockSubGraph into a BlockGraph.
27 : class BlockBuilder {
28 : public:
29 : explicit BlockBuilder(BlockGraph* block_graph);
30 :
31 : // Merge the @p subgraph into the block graph. This will create all blocks
32 : // and block relationships described by the subgraph and remove the
33 : // original block (if any) from which the subgraph was derived.
34 : // @param subgraph The subgraph to be merged.
35 : // @returns true on success, false otherwise.
36 : bool Merge(BasicBlockSubGraph* subgraph);
37 :
38 : // @returns the set of new blocks created upon merging in one or more
39 : // subgraphs.
40 E : const BlockVector& new_blocks() const { return new_blocks_; }
41 :
42 : // @returns the tag info map. This is populated by a successful call to Merge.
43 E : const TagInfoMap& tag_info_map() const { return tag_info_map_; }
44 :
45 : private:
46 : // The block-graph that subgraphs will be merged into.
47 : BlockGraph* const block_graph_;
48 :
49 : // The set of blocks created so far.
50 : BlockVector new_blocks_;
51 :
52 : // The tag info map tracking all user data in the subgraph.
53 : TagInfoMap tag_info_map_;
54 :
55 : DISALLOW_COPY_AND_ASSIGN(BlockBuilder);
56 : };
57 :
58 : } // namespace block_graph
59 :
60 : #endif // SYZYGY_BLOCK_GRAPH_BLOCK_BUILDER_H_
|