|
17 | 17 | #include "rsz/Resizer.hh" |
18 | 18 | #include "sta/ArcDelayCalc.hh" |
19 | 19 | #include "sta/Delay.hh" |
| 20 | +#include "sta/Fuzzy.hh" |
20 | 21 | #include "sta/Graph.hh" |
| 22 | +#include "sta/GraphDelayCalc.hh" |
21 | 23 | #include "sta/Liberty.hh" |
22 | 24 | #include "sta/MinMax.hh" |
23 | 25 | #include "sta/NetworkClass.hh" |
| 26 | +#include "sta/PortDirection.hh" |
24 | 27 | #include "sta/TimingArc.hh" |
25 | 28 | #include "sta/Transition.hh" |
26 | 29 | #include "sta/Vector.hh" |
27 | 30 | #include "utl/Logger.h" |
28 | 31 |
|
29 | 32 | namespace rsz { |
30 | | - |
31 | 33 | using std::max; |
32 | 34 | using std::string; |
33 | 35 | using std::vector; |
@@ -403,8 +405,8 @@ Instance* BaseMove::makeBuffer(LibertyCell* cell, |
403 | 405 | // Acceptance criteria are as follows: |
404 | 406 | // For direct fanout paths (fanout paths of drvr_pin), accept buffer removal |
405 | 407 | // if slack improves (may still be violating) |
406 | | -// For side fanout paths (fanout paths of side_out_pin*), accept buffer removal |
407 | | -// if slack doesn't become violating (no new violations) |
| 408 | +// For side fanout paths (fanout paths of side_out_pin*), accept buffer |
| 409 | +// removal if slack doesn't become violating (no new violations) |
408 | 410 | // |
409 | 411 | // input_net output_net |
410 | 412 | // prev_drv_pin ------> (drvr_input_pin drvr_pin) ------> |
@@ -699,21 +701,198 @@ bool BaseMove::replaceCell(Instance* inst, const LibertyCell* replacement) |
699 | 701 | } |
700 | 702 | return false; |
701 | 703 | } |
| 704 | +Slack BaseMove::getWorstInputSlack(Instance* inst) |
| 705 | +{ |
| 706 | + Slack worst_slack = INF; |
| 707 | + auto pin_iter |
| 708 | + = std::unique_ptr<InstancePinIterator>(network_->pinIterator(inst)); |
| 709 | + while (pin_iter->hasNext()) { |
| 710 | + const Pin* pin = pin_iter->next(); |
| 711 | + if (network_->direction(pin)->isInput()) { |
| 712 | + Vertex* vertex = graph_->pinDrvrVertex(pin); |
| 713 | + if (vertex) { |
| 714 | + worst_slack |
| 715 | + = std::min(worst_slack, sta_->vertexSlack(vertex, resizer_->max_)); |
| 716 | + } |
| 717 | + } |
| 718 | + } |
| 719 | + return worst_slack; |
| 720 | +} |
| 721 | + |
| 722 | +Slack BaseMove::getWorstOutputSlack(Instance* inst) |
| 723 | +{ |
| 724 | + Slack worst_slack = INF; |
| 725 | + |
| 726 | + // Iterate through all pins of the instance to find output pins |
| 727 | + auto pin_iter |
| 728 | + = std::unique_ptr<InstancePinIterator>(network_->pinIterator(inst)); |
| 729 | + while (pin_iter->hasNext()) { |
| 730 | + const Pin* inst_pin = pin_iter->next(); |
| 731 | + if (network_->direction(inst_pin)->isOutput()) { |
| 732 | + Vertex* vertex = graph_->pinLoadVertex(inst_pin); |
| 733 | + if (vertex) { |
| 734 | + worst_slack |
| 735 | + = std::min(worst_slack, sta_->vertexSlack(vertex, resizer_->max_)); |
| 736 | + } |
| 737 | + } |
| 738 | + } |
| 739 | + return worst_slack; |
| 740 | +} |
| 741 | + |
| 742 | +ArcDelay BaseMove::getWorstIntrinsicDelay(const LibertyPort* input_port) |
| 743 | +{ |
| 744 | + const LibertyCell* cell = input_port->libertyCell(); |
| 745 | + vector<const LibertyPort*> output_ports = getOutputPorts(cell); |
| 746 | + |
| 747 | + // Just return the worst of all the outputs, if there's more than one |
| 748 | + ArcDelay worst_intrinsic_delay = -INF; |
| 749 | + for (const LibertyPort* output_port : output_ports) { |
| 750 | + if (output_port->direction()->isOutput()) { |
| 751 | + worst_intrinsic_delay |
| 752 | + = max(worst_intrinsic_delay, output_port->intrinsicDelay(nullptr)); |
| 753 | + } |
| 754 | + } |
| 755 | + return worst_intrinsic_delay; |
| 756 | +} |
| 757 | + |
| 758 | +vector<const LibertyPort*> BaseMove::getOutputPorts(const LibertyCell* cell) |
| 759 | +{ |
| 760 | + vector<const LibertyPort*> fanouts; |
| 761 | + |
| 762 | + sta::LibertyCellPortIterator port_iter(cell); |
| 763 | + while (port_iter.hasNext()) { |
| 764 | + const LibertyPort* port = port_iter.next(); |
| 765 | + if (port->direction()->isOutput()) { |
| 766 | + fanouts.push_back(port); |
| 767 | + } |
| 768 | + } |
| 769 | + |
| 770 | + return fanouts; |
| 771 | +} |
702 | 772 |
|
703 | | -vector<const Pin*> BaseMove::getFanouts(const Instance* inst) |
| 773 | +vector<const Pin*> BaseMove::getOutputPins(const Instance* inst) |
704 | 774 | { |
705 | | - vector<const Pin*> fanouts; |
| 775 | + vector<const Pin*> outputs; |
706 | 776 |
|
707 | 777 | auto pin_iter |
708 | 778 | = std::unique_ptr<InstancePinIterator>(network_->pinIterator(inst)); |
709 | 779 | while (pin_iter->hasNext()) { |
710 | 780 | const Pin* pin = pin_iter->next(); |
711 | 781 | if (network_->direction(pin)->isOutput()) { |
712 | | - fanouts.push_back(pin); |
| 782 | + outputs.push_back(pin); |
713 | 783 | } |
714 | 784 | } |
715 | 785 |
|
716 | | - return fanouts; |
| 786 | + return outputs; |
| 787 | +} |
| 788 | + |
| 789 | +bool BaseMove::checkMaxCapViolation(const Pin* output_pin, |
| 790 | + LibertyPort* output_port, |
| 791 | + float output_cap) |
| 792 | +{ |
| 793 | + float max_cap; |
| 794 | + bool cap_limit_exists; |
| 795 | + // FIXME: Can we update to consider multiple corners? |
| 796 | + output_port->capacitanceLimit(resizer_->max_, max_cap, cap_limit_exists); |
| 797 | + |
| 798 | + debugPrint(logger_, |
| 799 | + RSZ, |
| 800 | + "opt_moves", |
| 801 | + 3, |
| 802 | + " fanout pin {} cap {} output_cap {} ", |
| 803 | + output_port->name(), |
| 804 | + max_cap, |
| 805 | + output_cap); |
| 806 | + |
| 807 | + if (cap_limit_exists && max_cap > 0.0 && output_cap > max_cap) { |
| 808 | + debugPrint(logger_, |
| 809 | + RSZ, |
| 810 | + "opt_moves", |
| 811 | + 2, |
| 812 | + " skip based on max cap {} gate={} cap={} max_cap={}", |
| 813 | + network_->pathName(output_pin), |
| 814 | + output_port->libertyCell()->name(), |
| 815 | + output_cap, |
| 816 | + max_cap); |
| 817 | + return true; |
| 818 | + } |
| 819 | + |
| 820 | + return false; |
| 821 | +} |
| 822 | + |
| 823 | +bool BaseMove::checkMaxSlewViolation(const Pin* output_pin, |
| 824 | + LibertyPort* output_port, |
| 825 | + float output_slew_factor, |
| 826 | + float output_cap, |
| 827 | + const DcalcAnalysisPt* dcalc_ap) |
| 828 | +{ |
| 829 | + float output_res = output_port->driveResistance(); |
| 830 | + float output_slew = output_slew_factor * output_res * output_cap; |
| 831 | + float max_slew; |
| 832 | + bool slew_limit_exists; |
| 833 | + |
| 834 | + sta_->findSlewLimit(output_port, |
| 835 | + dcalc_ap->corner(), |
| 836 | + resizer_->max_, |
| 837 | + max_slew, |
| 838 | + slew_limit_exists); |
| 839 | + |
| 840 | + if (output_slew > max_slew) { |
| 841 | + debugPrint(logger_, |
| 842 | + RSZ, |
| 843 | + "opt_moves", |
| 844 | + 2, |
| 845 | + " skip based on max slew {} gate={} slew={} max_slew={}", |
| 846 | + network_->pathName(output_pin), |
| 847 | + output_port->libertyCell()->name(), |
| 848 | + output_slew, |
| 849 | + max_slew); |
| 850 | + return true; |
| 851 | + } |
| 852 | + |
| 853 | + return false; |
| 854 | +} |
| 855 | + |
| 856 | +float BaseMove::computeElmoreSlewFactor(const Pin* output_pin, |
| 857 | + LibertyPort* output_port, |
| 858 | + float output_load_cap) |
| 859 | +{ |
| 860 | + float elmore_slew_factor = 0.0; |
| 861 | + |
| 862 | + // Get the vertex for the output pin |
| 863 | + Vertex* output_vertex = graph_->pinDrvrVertex(output_pin); |
| 864 | + |
| 865 | + // Get the output slew |
| 866 | + const Slew output_slew = sta_->vertexSlew(output_vertex, resizer_->max_); |
| 867 | + |
| 868 | + // Get the output resistance |
| 869 | + float output_res = output_port->driveResistance(); |
| 870 | + |
| 871 | + // Can have gates without fanout (e.g. QN of flop) which have no load |
| 872 | + if (output_res > 0.0 && output_load_cap > 0.0) { |
| 873 | + elmore_slew_factor = output_slew / (output_res * output_load_cap); |
| 874 | + } |
| 875 | + |
| 876 | + return elmore_slew_factor; |
717 | 877 | } |
718 | 878 |
|
| 879 | +//////////////////////////////////////////////////////////////// |
| 880 | + |
| 881 | +LibertyCellSeq BaseMove::getSwappableCells(LibertyCell* base) |
| 882 | +{ |
| 883 | + LibertyCellSeq buffer_sizes; |
| 884 | + if (base->isBuffer()) { |
| 885 | + for (LibertyCell* buffer : resizer_->buffer_fast_sizes_) { |
| 886 | + buffer_sizes.push_back(buffer); |
| 887 | + } |
| 888 | + if (resizer_->buffer_fast_sizes_.count(base) == 0) { |
| 889 | + return LibertyCellSeq(); |
| 890 | + } |
| 891 | + return buffer_sizes; |
| 892 | + } |
| 893 | + return resizer_->getSwappableCells(base); |
| 894 | +} |
| 895 | + |
| 896 | +//////////////////////////////////////////////////////////////// |
| 897 | +// namespace rsz |
719 | 898 | } // namespace rsz |
0 commit comments