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 the jump table count instrumentation transform.
16 :
17 : #ifndef SYZYGY_INSTRUMENT_TRANSFORMS_JUMP_TABLE_COUNT_TRANSFORM_H_
18 : #define SYZYGY_INSTRUMENT_TRANSFORMS_JUMP_TABLE_COUNT_TRANSFORM_H_
19 :
20 : #include <string>
21 : #include <vector>
22 :
23 : #include "syzygy/block_graph/transforms/iterative_transform.h"
24 : #include "syzygy/block_graph/transforms/named_transform.h"
25 : #include "syzygy/instrument/transforms/add_indexed_frequency_data_transform.h"
26 :
27 m : namespace instrument {
28 m : namespace transforms {
29 :
30 : // An iterative transform that instruments the accesses to the jump/case tables
31 : // to measure the frequency of each case.
32 m : class JumpTableCaseCountTransform
33 m : : public block_graph::transforms::IterativeTransformImpl<
34 m : JumpTableCaseCountTransform>,
35 m : public block_graph::transforms::NamedBasicBlockSubGraphTransformImpl<
36 m : JumpTableCaseCountTransform> {
37 m : public:
38 m : typedef block_graph::BlockGraph BlockGraph;
39 m : typedef block_graph::BasicBlockSubGraph BasicBlockSubGraph;
40 :
41 : // Initialize a new JumpTableCaseCountTransform instance using the default
42 : // module and function names.
43 m : JumpTableCaseCountTransform();
44 :
45 m : protected:
46 m : typedef std::map<BlockGraph::Offset, BlockGraph::Block*> ThunkBlockMap;
47 :
48 m : friend NamedBlockGraphTransformImpl<JumpTableCaseCountTransform>;
49 m : friend IterativeTransformImpl<JumpTableCaseCountTransform>;
50 m : friend NamedBasicBlockSubGraphTransformImpl<JumpTableCaseCountTransform>;
51 :
52 : // @name IterativeTransformImpl implementation.
53 : // @{
54 m : bool PreBlockGraphIteration(BlockGraph* block_graph,
55 m : BlockGraph::Block* header_block);
56 m : bool OnBlock(BlockGraph* block_graph, BlockGraph::Block* block);
57 m : bool PostBlockGraphIteration(BlockGraph* block_graph,
58 m : BlockGraph::Block* header_block);
59 : // @}
60 :
61 : // @name BasicBlockSubGraphTransformInterface methods.
62 : // @{
63 m : virtual bool TransformBasicBlockSubGraph(
64 m : BlockGraph* block_graph,
65 m : BasicBlockSubGraph* basic_block_subgraph) OVERRIDE;
66 : // @}
67 :
68 : // The instrumentation dll used by this transform.
69 m : std::string instrument_dll_name_;
70 :
71 : // The name of this transform.
72 m : static const char kTransformName[];
73 :
74 m : private:
75 m : DISALLOW_COPY_AND_ASSIGN(JumpTableCaseCountTransform);
76 m : };
77 :
78 m : } // namespace transforms
79 m : } // namespace instrument
80 :
81 : #endif // SYZYGY_INSTRUMENT_TRANSFORMS_JUMP_TABLE_COUNT_TRANSFORM_H_
|