diff --git a/src/mpl2/include/mpl2/rtl_mp.h b/src/mpl2/include/mpl2/rtl_mp.h index 77de4babafe..f034a7cfb2a 100644 --- a/src/mpl2/include/mpl2/rtl_mp.h +++ b/src/mpl2/include/mpl2/rtl_mp.h @@ -41,7 +41,7 @@ namespace odb { class dbDatabase; class dbInst; class dbOrientType; -} +} // namespace odb namespace sta { class dbNetwork; @@ -107,6 +107,7 @@ class MacroPlacer2 const std::string& orientation_string); odb::dbOrientType stringToOrientType(const std::string& orientation_string); + void setMacroPlacementFile(const char* file_name); void writeMacroPlacement(const char* file_name); void setDebug(std::unique_ptr& graphics); diff --git a/src/mpl2/src/hier_rtlmp.cpp b/src/mpl2/src/hier_rtlmp.cpp index e5f1b09b8ce..5891e0ab832 100644 --- a/src/mpl2/src/hier_rtlmp.cpp +++ b/src/mpl2/src/hier_rtlmp.cpp @@ -643,6 +643,8 @@ void HierRTLMP::hierRTLMacroPlacer() correctAllMacrosOrientation(); + writeMacroPlacement(macro_placement_file_.c_str()); + // Clear the memory to avoid memory leakage // release all the pointers // metrics map @@ -6064,6 +6066,36 @@ void HierRTLMP::correctAllMacrosOrientation() } } +void HierRTLMP::setMacroPlacementFile(const char* file_name) +{ + macro_placement_file_ = file_name; +} + +void HierRTLMP::writeMacroPlacement(const char* file_name) +{ + std::string filename = file_name; + + if (filename.empty()) { + return; + } + + std::ofstream out(filename); + + if (!out) { + logger_->error(MPL, 11, "Cannot open file {}.", filename); + } + + // Use only insts that were placed by mpl2 + for (auto& [inst, hard_macro] : hard_macro_map_) { + float x = dbuToMicron(inst->getLocation().x(), dbu_); + float y = dbuToMicron(inst->getLocation().y(), dbu_); + + out << "place_macro -macro_name " << inst->getName() << " -location {" << x + << " " << y << "} -orientation " << inst->getOrient().getString() + << '\n'; + } +} + void HierRTLMP::setDebug(std::unique_ptr& graphics) { graphics_ = std::move(graphics); diff --git a/src/mpl2/src/hier_rtlmp.h b/src/mpl2/src/hier_rtlmp.h index ea376e0e0f2..e763751161d 100644 --- a/src/mpl2/src/hier_rtlmp.h +++ b/src/mpl2/src/hier_rtlmp.h @@ -145,6 +145,9 @@ class HierRTLMP bus_planning_flag_ = bus_planning_flag; } + void setMacroPlacementFile(const char* file_name); + void writeMacroPlacement(const char* file_name); + private: void setDefaultThresholds(); void createDataFlow(); @@ -290,6 +293,8 @@ class HierRTLMP // Parameters related to macro placement std::string report_directory_; + std::string macro_placement_file_; + // User can specify a global region for some designs float global_fence_lx_ = std::numeric_limits::max(); float global_fence_ly_ = std::numeric_limits::max(); diff --git a/src/mpl2/src/mpl.i b/src/mpl2/src/mpl.i index a5bbaecb180..dc5bac0b01b 100644 --- a/src/mpl2/src/mpl.i +++ b/src/mpl2/src/mpl.i @@ -137,6 +137,12 @@ place_macro(odb::dbInst* macro_name, float x_origin, float y_origin, const char* getMacroPlacer2()->placeMacro(macro_name, x_origin, y_origin, orientation_string); } +void +set_macro_placement_file(const char* file_name) +{ + getMacroPlacer2()->setMacroPlacementFile(file_name); +} + void write_macro_placement(const char* file_name) { diff --git a/src/mpl2/src/mpl.tcl b/src/mpl2/src/mpl.tcl index 1e08637ac86..520a7da095f 100644 --- a/src/mpl2/src/mpl.tcl +++ b/src/mpl2/src/mpl.tcl @@ -62,6 +62,7 @@ sta::define_cmd_args "rtl_macro_placer" { -max_num_macro max_num_macro \ -snap_layer snap_layer \ -bus_planning_flag bus_planning_flag \ -report_directory report_directory \ + -write_macro_placement file_name \ } proc rtl_macro_placer { args } { sta::parse_key_args "rtl_macro_placer" args keys { @@ -75,6 +76,7 @@ proc rtl_macro_placer { args } { -target_dead_space -min_ar -snap_layer \ -bus_planning_flag \ -report_directory \ + -write_macro_placement \ } flag { } # # Check for valid design @@ -216,11 +218,15 @@ proc rtl_macro_placer { args } { set bus_planning_flag $keys(-bus_planning_flag) } if { [info exists keys(-report_directory)] } { - set report_directory $keys(-report_directory) + set report_directory $keys(-report_directory) } file mkdir $report_directory + if { [info exists keys(-write_macro_placement)] } { + mpl2::set_macro_placement_file $keys(-write_macro_placement) + } + if {![mpl2::rtl_macro_placer_cmd $max_num_macro \ $min_num_macro \ $max_num_inst \ diff --git a/src/mpl2/src/rtl_mp.cpp b/src/mpl2/src/rtl_mp.cpp index a84b22ba9b7..1f3ece7acd0 100644 --- a/src/mpl2/src/rtl_mp.cpp +++ b/src/mpl2/src/rtl_mp.cpp @@ -157,7 +157,7 @@ void MacroPlacer2::placeMacro(odb::dbInst* inst, odb::Rect macro_new_bbox(x1, y1, x2, y2); odb::Rect core_area = inst->getBlock()->getCoreArea(); - + if (!core_area.contains(macro_new_bbox)) { logger_->error(MPL, 34, @@ -176,31 +176,29 @@ void MacroPlacer2::placeMacro(odb::dbInst* inst, HardMacro macro(inst, dbu_per_micron, manufacturing_grid, 0, 0); - mpl2::Rect macro_new_bbox_micron(x_origin, - y_origin, - dbuToMicron(macro_new_bbox.xMax(), dbu_per_micron), - dbuToMicron(macro_new_bbox.yMax(), dbu_per_micron)); + mpl2::Rect macro_new_bbox_micron( + x_origin, + y_origin, + dbuToMicron(macro_new_bbox.xMax(), dbu_per_micron), + dbuToMicron(macro_new_bbox.yMax(), dbu_per_micron)); float pitch_x = 0.0; float pitch_y = 0.0; - macro.alignOriginWithGrids(macro_new_bbox_micron, orientation, pitch_x, pitch_y, inst->getBlock()); + macro.alignOriginWithGrids( + macro_new_bbox_micron, orientation, pitch_x, pitch_y, inst->getBlock()); inst->setPlacementStatus(odb::dbPlacementStatus::LOCKED); } -void MacroPlacer2::writeMacroPlacement(const char* file_name) +void MacroPlacer2::setMacroPlacementFile(const char* file_name) { - std::string filename = file_name; - if (filename.empty()) { - return; - } - - std::ofstream out(filename); + hier_rtlmp_->setMacroPlacementFile(file_name); +} - if (!out) { - logger_->error(MPL, 11, "Cannot open file {}.", filename); - } +void MacroPlacer2::writeMacroPlacement(const char* file_name) +{ + hier_rtlmp_->writeMacroPlacement(file_name); } void MacroPlacer2::setDebug(std::unique_ptr& graphics)