1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (c) 2019-2020, The Regents of the University of California
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright notice, this
11 //   list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above copyright notice,
14 //   this list of conditions and the following disclaimer in the documentation
15 //   and/or other materials provided with the distribution.
16 //
17 // * Neither the name of the copyright holder nor the names of its
18 //   contributors may be used to endorse or promote products derived from
19 //   this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE
25 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ///////////////////////////////////////////////////////////////////////////////
33 
34 #pragma once
35 
36 #include <array>
37 #include <string>
38 #include <unordered_map>
39 #include <vector>
40 
41 namespace utl {
42 class Logger;
43 }
44 
45 namespace parquetfp {
46 class Nets;
47 }
48 
49 namespace mpl {
50 
51 using std::array;
52 using std::pair;
53 using std::string;
54 using std::vector;
55 
56 namespace pfp = parquetfp;
57 
58 class MacroPlacer;
59 class Macro;
60 
61 enum PartClass
62 {
63   S,
64   N,
65   W,
66   E,
67   NW,
68   NE,
69   SW,
70   SE,
71   ALL,
72   None
73 };
74 
75 constexpr int part_class_count = None + 1;
76 
77 // PartClass -> macro indices
78 typedef array<vector<int>, part_class_count> MacroPartMap;
79 
80 class Partition
81 {
82  public:
83   Partition(PartClass _partClass,
84             double _lx,
85             double _ly,
86             double _width,
87             double _height,
88             MacroPlacer* macro_placer,
89             utl::Logger* log);
90   Partition(const Partition& prev) = default;
91 
92   void fillNetlistTable(MacroPartMap& macroPartMap);
93   // Call Parquet to have annealing solution
94   bool anneal();
95 
96   PartClass partClass;
97   vector<Macro> macros_;
98   double lx, ly;
99   double width, height;
100   double solution_width, solution_height;
101   vector<double> net_tbl_;
102 
103  private:
104   string getName(int macroIdx);
105   int globalIndex(int macro_idx);
106   void makePins(int macro_idx1,
107                 int macro_idx2,
108                 int cost,
109                 int pnet_idx,
110                 pfp::Nets* pfp_nets);
111 
112   utl::Logger* logger_;
113   MacroPlacer* macro_placer_;
114 };
115 
116 }  // namespace mpl
117