1 ///////////////////////////////////////////////////////////////////////////// 2 // 3 // BSD 3-Clause License 4 // 5 // Copyright (c) 2019, The Regents of the University of California 6 // All rights reserved. 7 // 8 // Redistribution and use in source and binary forms, with or without 9 // modification, are permitted provided that the following conditions are met: 10 // 11 // * Redistributions of source code must retain the above copyright notice, this 12 // list of conditions and the following disclaimer. 13 // 14 // * Redistributions in binary form must reproduce the above copyright notice, 15 // this list of conditions and the following disclaimer in the documentation 16 // and/or other materials provided with the distribution. 17 // 18 // * Neither the name of the copyright holder nor the names of its 19 // contributors may be used to endorse or promote products derived from 20 // this software without specific prior written permission. 21 // 22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 // POSSIBILITY OF SUCH DAMAGE. 33 // 34 /////////////////////////////////////////////////////////////////////////////// 35 36 #pragma once 37 38 #include <functional> 39 #include <iostream> 40 #include <limits> 41 #include <string> 42 #include <vector> 43 44 #include "opendb/db.h" 45 46 namespace ppl { 47 48 using odb::Point; 49 using odb::Rect; 50 51 struct Constraint; 52 struct Section; 53 struct Slot; 54 enum class Edge; 55 56 enum class Orientation 57 { 58 north, 59 south, 60 east, 61 west 62 }; 63 64 enum class Direction 65 { 66 input, 67 output, 68 inout, 69 feedthru, 70 invalid 71 }; 72 73 class InstancePin 74 { 75 public: InstancePin(const std::string & name,const odb::Point & pos)76 InstancePin(const std::string& name, const odb::Point& pos) 77 : name_(name), pos_(pos) 78 { 79 } getName()80 std::string getName() const { return name_; } getPos()81 odb::Point getPos() const { return pos_; } getX()82 int getX() const { return pos_.getX(); } getY()83 int getY() const { return pos_.getY(); } 84 85 private: 86 std::string name_; 87 odb::Point pos_; 88 }; 89 90 class IOPin 91 { 92 public: IOPin(odb::dbBTerm * bterm,const odb::Point & pos,Direction dir,odb::Point lower_bound,odb::Point upper_bound,odb::dbPlacementStatus placement_status)93 IOPin(odb::dbBTerm* bterm, 94 const odb::Point& pos, 95 Direction dir, 96 odb::Point lower_bound, 97 odb::Point upper_bound, 98 odb::dbPlacementStatus placement_status) 99 : bterm_(bterm), 100 pos_(pos), 101 orientation_(Orientation::north), 102 direction_(dir), 103 lower_bound_(lower_bound), 104 upper_bound_(upper_bound), 105 placement_status_(placement_status), 106 layer_(-1), 107 is_placed_(false), 108 in_group_(false), 109 assigned_to_section_(false) 110 { 111 } 112 setOrientation(const Orientation o)113 void setOrientation(const Orientation o) { orientation_ = o; } getOrientation()114 Orientation getOrientation() const { return orientation_; } getPosition()115 odb::Point getPosition() const { return pos_; } setX(const int x)116 void setX(const int x) { pos_.setX(x); } setY(const int y)117 void setY(const int y) { pos_.setY(y); } setPos(const odb::Point pos)118 void setPos(const odb::Point pos) { pos_ = pos; } setPos(const int x,const int y)119 void setPos(const int x, const int y) { pos_ = odb::Point(x, y); } setLowerBound(const int x,const int y)120 void setLowerBound(const int x, const int y) 121 { 122 lower_bound_ = odb::Point(x, y); 123 }; setUpperBound(const int x,const int y)124 void setUpperBound(const int x, const int y) 125 { 126 upper_bound_ = odb::Point(x, y); 127 }; setLayer(const int layer)128 void setLayer(const int layer) { layer_ = layer; } getName()129 std::string getName() const { return bterm_->getName(); } getPos()130 odb::Point getPos() const { return pos_; } getX()131 int getX() const { return pos_.getX(); } getY()132 int getY() const { return pos_.getY(); } getDirection()133 Direction getDirection() const { return direction_; } getLowerBound()134 odb::Point getLowerBound() const { return lower_bound_; }; getUpperBound()135 odb::Point getUpperBound() const { return upper_bound_; }; getNetName()136 std::string getNetName() const { return bterm_->getNet()->getName(); } getPlacementStatus()137 odb::dbPlacementStatus getPlacementStatus() const { return placement_status_; }; getBTerm()138 odb::dbBTerm* getBTerm() const { return bterm_; } getLayer()139 int getLayer() const { return layer_; } isPlaced()140 bool isPlaced() const { return is_placed_; } setPlaced()141 void setPlaced() { is_placed_ = true; } isInGroup()142 bool isInGroup() const { return in_group_; } setInGroup()143 void setInGroup() { in_group_ = true; } assignToSection()144 void assignToSection() { assigned_to_section_ = true; } isAssignedToSection()145 bool isAssignedToSection() { return assigned_to_section_; } 146 147 private: 148 odb::dbBTerm* bterm_; 149 odb::Point pos_; 150 Orientation orientation_; 151 Direction direction_; 152 odb::Point lower_bound_; 153 odb::Point upper_bound_; 154 odb::dbPlacementStatus placement_status_; 155 int layer_; 156 bool is_placed_; 157 bool in_group_; 158 bool assigned_to_section_; 159 }; 160 161 class Netlist 162 { 163 public: 164 Netlist(); 165 166 void addIONet(const IOPin&, const std::vector<InstancePin>&); 167 int createIOGroup(const std::vector<odb::dbBTerm*>& pin_list); 168 void addIOGroup(const std::vector<int>& pin_group); getIOGroups()169 std::vector<std::vector<int>>& getIOGroups() { return io_groups_; } setIOGroups(const std::vector<std::vector<int>> & io_groups)170 void setIOGroups(const std::vector<std::vector<int>>& io_groups) { io_groups_ = io_groups; } 171 int numSinksOfIO(int); 172 int numIOPins(); numIOGroups()173 int numIOGroups() { return io_groups_.size(); } getIOPins()174 std::vector<IOPin>& getIOPins() { return io_pins_; } getIoPin(int idx)175 IOPin& getIoPin(int idx) { return io_pins_[idx]; } getIoPinIdx(odb::dbBTerm * bterm)176 int getIoPinIdx(odb::dbBTerm* bterm) { return _db_pin_idx_map[bterm]; } 177 void getSinksOfIO(int idx, std::vector<InstancePin>& sinks); 178 179 int computeIONetHPWL(int, odb::Point); 180 int computeIONetHPWL(int, odb::Point, Edge, const std::vector<Constraint>&); 181 int computeIONetHPWL(int, const Section&, const std::vector<Constraint>&, const std::vector<Slot>&); 182 int computeDstIOtoPins(int, odb::Point); 183 odb::Rect getBB(int, odb::Point); 184 void clear(); 185 186 private: 187 std::vector<InstancePin> inst_pins_; 188 std::vector<int> net_pointer_; 189 std::vector<IOPin> io_pins_; 190 std::vector<std::vector<int>> io_groups_; 191 std::map<odb::dbBTerm*, int> _db_pin_idx_map; 192 }; 193 194 } // namespace ppl 195