1/* Copyright (c) 2012 Massachusetts Institute of Technology
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
21
22#ifndef __DSENT_MODEL_ELECTRICAL_TIMING_TREE_H__
23#define __DSENT_MODEL_ELECTRICAL_TIMING_TREE_H__
24
25#include <vector>
26
27#include "util/CommonType.h"
28#include "model/timing_graph/ElectricalTimingNode.h"
29
30namespace DSENT
31{
32    using std::vector;
33
34    class ElectricalDriver;
35
36    class ElectricalTimingTree
37    {
38        public:
39            // The visited number for the next timing run. This needs to be
40            // global because several timing trees may be created to evaluate
41            // a single timing path, causing problems
42            static int msTreeNum;
43
44        public:
45            // Construct timing tree that watches over model_
46            ElectricalTimingTree(const String& instance_name_, ElectricalModel* model_);
47            ~ElectricalTimingTree();
48
49        public:
50            // Get tree name
51            const String& getInstanceName() const;
52
53            // A wrapper for extractCritPathDelay
54            // Update the tree num before do extract critical path delay recursively
55            double performCritPathExtract(ElectricalTimingNode* node_);
56            // Calculate the delay of the marked critical path from a starting node
57            double calculateCritPathDelay(ElectricalTimingNode* node_) const;
58            // Calculate the transition at a node
59            double calculateNodeTransition(ElectricalTimingNode* node_) const;
60            // Returns the optimal node to optimize timing (by sizing up) in the critical
61            // path to reduce critical path delay
62            ElectricalTimingNode* findNodeForTimingOpt(ElectricalTimingNode* node_) const;
63            // Perform incremental timing optimization to guarantee that all timing paths from a
64            // starting node meets a required delay
65            // Return false if the timing optimization fails to meet the required delay
66            bool performTimingOpt(ElectricalTimingNode* node_, double required_delay_);
67
68            // Return the model
69            ElectricalModel* getModel();
70
71        private:
72            // Disable the use of copy constructor
73            ElectricalTimingTree(const ElectricalTimingTree& graph_);
74
75            // Recursively calculate delay from a starting node, finding and marking the
76            // critical path along the way and returns the delay of the critical path
77            double extractCritPathDelay(ElectricalTimingNode* node_);
78
79        public:
80            // Set the sequence number of the timing tree
81            static void setTreeNum(int tree_num_);
82            static int getTreeNum();
83
84        private:
85            // Name of the timing tree
86            const String m_instance_name_;
87            // A pointer to the model that contains this node
88            ElectricalModel* m_model_;
89
90    }; // class ElectricalTimingTree
91} // namespace DSENT
92
93#endif // __DSENT_MODEL_ELECTRICAL_TIMING_TREE_H__
94
95