| #include <ot/timer/timer.hpp> |
|
|
| namespace ot { |
|
|
| |
|
|
| |
| Timer& Timer::set_num_threads(unsigned n) { |
| std::scoped_lock lock(_mutex); |
| unsigned w = (n == 0) ? 0 : n-1; |
| OT_LOGI("using ", n, " threads (", w, " worker)"); |
| |
| |
| return *this; |
| } |
|
|
| |
| void Timer::_add_to_lineage(tf::Task task) { |
| _lineage | [&] (auto& p) { p.precede(task); }; |
| _lineage = task; |
| } |
|
|
| |
| size_t Timer::_max_pin_name_size() const { |
| if(_pins.empty()) { |
| return 0; |
| } |
| else { |
| return std::max_element(_pins.begin(), _pins.end(), |
| [] (const auto& l, const auto& r) { |
| return l.second._name.size() < r.second._name.size(); |
| } |
| )->second._name.size(); |
| } |
| } |
|
|
| |
| size_t Timer::_max_net_name_size() const { |
| if(_nets.empty()) { |
| return 0; |
| } |
| else { |
| return std::max_element(_nets.begin(), _nets.end(), |
| [] (const auto& l, const auto& r) { |
| return l.second._name.size() < r.second._name.size(); |
| } |
| )->second._name.size(); |
| } |
| } |
|
|
| |
| |
| |
| |
| Timer& Timer::repower_gate(std::string gate, std::string cell) { |
|
|
| std::scoped_lock lock(_mutex); |
|
|
| auto task = _taskflow.emplace([this, gate=std::move(gate), cell=std::move(cell)] () { |
| _repower_gate(gate, cell); |
| }); |
| |
| _add_to_lineage(task); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_repower_gate(const std::string& gname, const std::string& cname) { |
| |
| OT_LOGE_RIF(!_celllib[MIN] || !_celllib[MAX], "celllib not found"); |
|
|
| |
| if(auto gitr = _gates.find(gname); gitr == _gates.end()) { |
| OT_LOGW("gate ", gname, " doesn't exist (insert instead)"); |
| _insert_gate(gname, cname); |
| return; |
| } |
| else { |
|
|
| auto cell = CellView {_celllib[MIN]->cell(cname), _celllib[MAX]->cell(cname)}; |
|
|
| OT_LOGE_RIF(!cell[MIN] || !cell[MAX], "cell ", cname, " not found"); |
|
|
| auto& gate = gitr->second; |
|
|
| |
| for(auto pin : gate._pins) { |
| FOR_EACH_EL(el) { |
| assert(pin->cellpin(el)); |
| if(const auto cpin = cell[el]->cellpin(pin->cellpin(el)->name)) { |
| pin->_remap_cellpin(el, *cpin); |
| } |
| else { |
| OT_LOGE( |
| "repower ", gname, " with ", cname, " failed (cellpin mismatched)" |
| ); |
| } |
| } |
| } |
| |
| gate._cell = cell; |
|
|
| |
| _remove_gate_arcs(gate); |
| _insert_gate_arcs(gate); |
|
|
| |
| for(auto pin : gate._pins) { |
| _insert_frontier(*pin); |
| for(auto arc : pin->_fanin) { |
| _insert_frontier(arc->_from); |
| } |
| } |
| } |
| } |
|
|
| |
| |
| |
| Timer& Timer::insert_gate(std::string gate, std::string cell) { |
| |
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, gate=std::move(gate), cell=std::move(cell)] () { |
| _insert_gate(gate, cell); |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_insert_gate(const std::string& gname, const std::string& cname) { |
|
|
| OT_LOGE_RIF(!_celllib[MIN] || !_celllib[MAX], "celllib not found"); |
|
|
| if(_gates.find(gname) != _gates.end()) { |
| OT_LOGW("gate ", gname, " already existed"); |
| return; |
| } |
|
|
| auto cell = CellView {_celllib[MIN]->cell(cname), _celllib[MAX]->cell(cname)}; |
|
|
| if(!cell[MIN] || !cell[MAX]) { |
| OT_LOGE("cell ", cname, " not found in celllib"); |
| return; |
| } |
| |
| auto& gate = _gates.try_emplace(gname, gname, cell).first->second; |
| |
| |
| for(const auto& [cpname, ecpin] : cell[MIN]->cellpins) { |
|
|
| CellpinView cpv {&ecpin, cell[MAX]->cellpin(cpname)}; |
|
|
| if(!cpv[MIN] || !cpv[MAX]) { |
| OT_LOGF("cellpin ", cpname, " mismatched in celllib"); |
| } |
|
|
| auto& pin = _insert_pin(gname + ':' + cpname); |
| pin._handle = cpv; |
| pin._gate = &gate; |
| |
| gate._pins.push_back(&pin); |
| } |
| |
| _insert_gate_arcs(gate); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| Timer& Timer::remove_gate(std::string gate) { |
| |
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, gate=std::move(gate)] () { |
| if(auto gitr = _gates.find(gate); gitr != _gates.end()) { |
| _remove_gate(gitr->second); |
| } |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_remove_gate(Gate& gate) { |
|
|
| |
| for(auto pin : gate._pins) { |
| _disconnect_pin(*pin); |
| } |
|
|
| |
| for(auto test : gate._tests) { |
| _remove_test(*test); |
| } |
|
|
| |
| for(auto arc : gate._arcs) { |
| _remove_arc(*arc); |
| } |
|
|
| |
| for(auto pin : gate._pins) { |
| _remove_pin(*pin); |
| } |
|
|
| |
| _gates.erase(gate._name); |
| } |
|
|
| |
| void Timer::_remove_gate_arcs(Gate& gate) { |
|
|
| |
| for(auto test : gate._tests) { |
| _remove_test(*test); |
| } |
| gate._tests.clear(); |
| |
| |
| for(auto arc : gate._arcs) { |
| _remove_arc(*arc); |
| } |
| gate._arcs.clear(); |
| } |
|
|
| |
| void Timer::_insert_gate_arcs(Gate& gate) { |
|
|
| assert(gate._tests.empty() && gate._arcs.empty()); |
|
|
| FOR_EACH_EL(el) { |
| for(const auto& [cpname, cp] : gate._cell[el]->cellpins) { |
| auto& to_pin = _insert_pin(gate._name + ':' + cpname); |
|
|
| for(const auto& tm : cp.timings) { |
|
|
| if(_is_redundant_timing(tm, el)) { |
| continue; |
| } |
|
|
| TimingView tv{nullptr, nullptr}; |
| tv[el] = &tm; |
|
|
| auto& from_pin = _insert_pin(gate._name + ':' + tm.related_pin); |
| auto& arc = _insert_arc(from_pin, to_pin, tv); |
| |
| gate._arcs.push_back(&arc); |
| if(tm.is_constraint()) { |
| auto& test = _insert_test(arc); |
| gate._tests.push_back(&test); |
| } |
| } |
| } |
| } |
| } |
|
|
| |
| |
| |
| |
| Timer& Timer::connect_pin(std::string pin, std::string net) { |
|
|
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, pin=std::move(pin), net=std::move(net)] () { |
| auto p = _pins.find(pin); |
| auto n = _nets.find(net); |
| OT_LOGE_RIF(p==_pins.end() || n == _nets.end(), |
| "can't connect pin ", pin, " to net ", net, " (pin/net not found)" |
| ) |
| _connect_pin(p->second, n->second); |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_connect_pin(Pin& pin, Net& net) { |
| |
| |
| net._insert_pin(pin); |
| |
| |
| if(&pin == net._root) { |
| for(auto leaf : net._pins) { |
| if(leaf != &pin) { |
| _insert_arc(pin, *leaf, net); |
| } |
| } |
| } |
| |
| else { |
| if(net._root) { |
| _insert_arc(*net._root, pin, net); |
| } |
| } |
|
|
| |
| } |
|
|
| |
| |
| |
| Timer& Timer::disconnect_pin(std::string name) { |
| |
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, name=std::move(name)] () { |
| if(auto itr = _pins.find(name); itr != _pins.end()) { |
| _disconnect_pin(itr->second); |
| } |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| |
| |
| void Timer::_disconnect_pin(Pin& pin) { |
|
|
| auto net = pin._net; |
|
|
| if(net == nullptr) return; |
|
|
| |
| if(&pin == net->_root) { |
| |
| |
| for(auto leaf : net->_pins) { |
| if(leaf != net->_root) { |
| auto arc = leaf->_find_fanin(*net->_root); |
| assert(arc); |
| _remove_arc(*arc); |
| } |
| } |
| } |
| |
| else { |
| if(net->_root) { |
| auto arc = pin._find_fanin(*net->_root); |
| assert(arc); |
| _remove_arc(*arc); |
| } |
| } |
| |
| |
| |
| |
| net->_remove_pin(pin); |
| } |
|
|
| |
| |
| |
| |
| Timer& Timer::insert_net(std::string name) { |
|
|
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, name=std::move(name)] () { |
| _insert_net(name); |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| Net& Timer::_insert_net(const std::string& name) { |
| return _nets.try_emplace(name, name).first->second; |
| } |
|
|
| |
| |
| Timer& Timer::remove_net(std::string name) { |
|
|
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, name=std::move(name)] () { |
| if(auto itr = _nets.find(name); itr != _nets.end()) { |
| _remove_net(itr->second); |
| } |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_remove_net(Net& net) { |
|
|
| if(net.num_pins() > 0) { |
| auto fetch = net._pins; |
| for(auto pin : fetch) { |
| _disconnect_pin(*pin); |
| } |
| } |
|
|
| _nets.erase(net._name); |
| } |
|
|
| |
| Pin& Timer::_insert_pin(const std::string& name) { |
| |
| |
| if(auto [itr, inserted] = _pins.try_emplace(name, name); !inserted) { |
| return itr->second; |
| } |
| |
| else { |
| |
| |
| auto& pin = itr->second; |
| |
| |
| pin._idx = _pin_idx_gen.get(); |
| resize_to_fit(pin._idx + 1, _idx2pin); |
| _idx2pin[pin._idx] = &pin; |
|
|
| |
| _insert_frontier(pin); |
|
|
| return pin; |
| } |
| } |
|
|
| |
| void Timer::_remove_pin(Pin& pin) { |
|
|
| assert(pin.num_fanouts() == 0 && pin.num_fanins() == 0 && pin.net() == nullptr); |
|
|
| _remove_frontier(pin); |
|
|
| |
| _idx2pin[pin._idx] = nullptr; |
| _pin_idx_gen.recycle(pin._idx); |
|
|
| |
| _pins.erase(pin._name); |
| } |
|
|
| |
| Timer& Timer::cppr(bool flag) { |
| |
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, flag] () { |
| _cppr(flag); |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| |
| void Timer::_cppr(bool enable) { |
| |
| |
| if((enable && _cppr_analysis) || (!enable && !_cppr_analysis)) { |
| return; |
| } |
|
|
| if(enable) { |
| OT_LOGI("enable cppr analysis"); |
| _cppr_analysis.emplace(); |
| } |
| else { |
| OT_LOGI("disable cppr analysis"); |
| _cppr_analysis.reset(); |
| } |
| |
| for(auto& test : _tests) { |
| _insert_frontier(test._constrained_pin()); |
| } |
| } |
|
|
| |
| Timer& Timer::create_clock(std::string c, std::string s, float p) { |
| |
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, c=std::move(c), s=std::move(s), p] () { |
| if(auto itr = _pins.find(s); itr != _pins.end()) { |
| _create_clock(c, itr->second, p); |
| } |
| else { |
| OT_LOGE("can't create clock ", c, " on source ", s, " (pin not found)"); |
| } |
| }); |
|
|
| _add_to_lineage(op); |
| |
| return *this; |
| } |
|
|
| |
| Timer& Timer::create_clock(std::string c, float p) { |
| |
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, c=std::move(c), p] () { |
| _create_clock(c, p); |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| Clock& Timer::_create_clock(const std::string& name, Pin& pin, float period) { |
| auto& clock = _clocks.try_emplace(name, name, pin, period).first->second; |
| _insert_frontier(pin); |
| return clock; |
| } |
|
|
| |
| Clock& Timer::_create_clock(const std::string& name, float period) { |
| auto& clock = _clocks.try_emplace(name, name, period).first->second; |
| return clock; |
| } |
|
|
| |
| Timer& Timer::insert_primary_input(std::string name) { |
|
|
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, name=std::move(name)] () { |
| _insert_primary_input(name); |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_insert_primary_input(const std::string& name) { |
|
|
| if(_pis.find(name) != _pis.end()) { |
| OT_LOGW("can't insert PI ", name, " (already existed)"); |
| return; |
| } |
|
|
| assert(_pins.find(name) == _pins.end()); |
|
|
| |
| auto& pin = _insert_pin(name); |
| auto& pi = _pis.try_emplace(name, pin).first->second; |
| |
| |
| pin._handle = π |
|
|
| |
| _insert_frontier(pin); |
|
|
| |
| auto& net = _insert_net(name); |
| |
| |
| _connect_pin(pin, net); |
| } |
|
|
| |
| Timer& Timer::insert_primary_output(std::string name) { |
|
|
| std::scoped_lock lock(_mutex); |
|
|
| auto op = _taskflow.emplace([this, name=std::move(name)] () { |
| _insert_primary_output(name); |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_insert_primary_output(const std::string& name) { |
|
|
| if(_pos.find(name) != _pos.end()) { |
| OT_LOGW("can't insert PO ", name, " (already existed)"); |
| return; |
| } |
|
|
| assert(_pins.find(name) == _pins.end()); |
|
|
| |
| auto& pin = _insert_pin(name); |
| auto& po = _pos.try_emplace(name, pin).first->second; |
| |
| |
| pin._handle = &po; |
|
|
| |
| _insert_frontier(pin); |
|
|
| |
| auto& net = _insert_net(name); |
|
|
| |
| _connect_pin(pin, net); |
| } |
|
|
| |
| Test& Timer::_insert_test(Arc& arc) { |
| auto& test = _tests.emplace_front(arc); |
| test._satellite = _tests.begin(); |
| test._pin_satellite = arc._to._tests.insert(arc._to._tests.end(), &test); |
| return test; |
| } |
|
|
| |
| void Timer::_remove_test(Test& test) { |
| assert(test._satellite); |
| if(test._pin_satellite) { |
| test._arc._to._tests.erase(*test._pin_satellite); |
| } |
| _tests.erase(*test._satellite); |
| } |
|
|
| |
| |
| |
| |
| void Timer::_remove_arc(Arc& arc) { |
|
|
| assert(arc._satellite); |
| |
| arc._from._remove_fanout(arc); |
| arc._to._remove_fanin(arc); |
|
|
| |
| _insert_frontier(arc._from, arc._to); |
| |
| |
| _idx2arc[arc._idx] = nullptr; |
| _arc_idx_gen.recycle(arc._idx); |
|
|
| |
| _arcs.erase(*arc._satellite); |
| } |
|
|
| |
| |
| Arc& Timer::_insert_arc(Pin& from, Pin& to, Net& net) { |
|
|
| OT_LOGF_IF(&from == &to, "net arc is a self loop at ", to._name); |
|
|
| |
| auto& arc = _arcs.emplace_front(from, to, net); |
| arc._satellite = _arcs.begin(); |
|
|
| from._insert_fanout(arc); |
| to._insert_fanin(arc); |
|
|
| |
| _insert_frontier(from, to); |
| |
| |
| arc._idx = _arc_idx_gen.get(); |
| resize_to_fit(arc._idx + 1, _idx2arc); |
| _idx2arc[arc._idx] = &arc; |
|
|
| return arc; |
| } |
|
|
| |
| |
| Arc& Timer::_insert_arc(Pin& from, Pin& to, TimingView tv) { |
| |
| |
|
|
| |
| auto& arc = _arcs.emplace_front(from, to, tv); |
| arc._satellite = _arcs.begin(); |
| from._insert_fanout(arc); |
| to._insert_fanin(arc); |
|
|
| |
| _insert_frontier(from, to); |
| |
| |
| arc._idx = _arc_idx_gen.get(); |
| resize_to_fit(arc._idx + 1, _idx2arc); |
| _idx2arc[arc._idx] = &arc; |
|
|
| return arc; |
| } |
|
|
| |
| void Timer::_fprop_rc_timing(Pin& pin) { |
| if(auto net = pin._net; net) { |
| net->_update_rc_timing(); |
| } |
| } |
|
|
| |
| void Timer::_fprop_slew(Pin& pin) { |
| |
| |
| pin._reset_slew(); |
|
|
| |
| if(auto pi = pin.primary_input(); pi) { |
| FOR_EACH_EL_RF_IF(el, rf, pi->_slew[el][rf]) { |
| pin._relax_slew(nullptr, el, rf, el, rf, *(pi->_slew[el][rf])); |
| } |
| } |
| |
| |
| for(auto arc : pin._fanin) { |
| arc->_fprop_slew(); |
| } |
| } |
|
|
| |
| void Timer::_fprop_delay(Pin& pin) { |
|
|
| |
| for(auto arc : pin._fanin) { |
| arc->_reset_delay(); |
| } |
|
|
| |
| for(auto arc : pin._fanin) { |
| arc->_fprop_delay(); |
| } |
| } |
|
|
| |
| void Timer::_fprop_at(Pin& pin) { |
| |
| |
| pin._reset_at(); |
|
|
| |
| if(auto pi = pin.primary_input(); pi) { |
| FOR_EACH_EL_RF_IF(el, rf, pi->_at[el][rf]) { |
| pin._relax_at(nullptr, el, rf, el, rf, *(pi->_at[el][rf])); |
| } |
| } |
|
|
| |
| for(auto arc : pin._fanin) { |
| arc->_fprop_at(); |
| } |
| } |
|
|
| |
| void Timer::_fprop_test(Pin& pin) { |
| |
| |
| for(auto test : pin._tests) { |
| test->_reset(); |
| } |
| |
| |
| if(!_clocks.empty()) { |
|
|
| |
| for(auto test : pin._tests) { |
| |
| test->_fprop_rat(_clocks.begin()->second._period); |
| |
| |
| if(_cppr_analysis) { |
| FOR_EACH_EL_RF_IF(el, rf, test->raw_slack(el, rf)) { |
| test->_cppr_credit[el][rf] = _cppr_credit(*test, el, rf); |
| } |
| } |
| } |
| } |
| } |
|
|
| |
| void Timer::_bprop_rat(Pin& pin) { |
|
|
| pin._reset_rat(); |
|
|
| |
| if(auto po = pin.primary_output(); po) { |
| FOR_EACH_EL_RF_IF(el, rf, po->_rat[el][rf]) { |
| pin._relax_rat(nullptr, el, rf, el, rf, *(po->_rat[el][rf])); |
| } |
| } |
|
|
| |
| for(auto test : pin._tests) { |
| FOR_EACH_EL_RF_IF(el, rf, test->_rat[el][rf]) { |
| if(test->_cppr_credit[el][rf]) { |
| pin._relax_rat( |
| &test->_arc, el, rf, el, rf, *test->_rat[el][rf] + *test->_cppr_credit[el][rf] |
| ); |
| } |
| else { |
| pin._relax_rat(&test->_arc, el, rf, el, rf, *test->_rat[el][rf]); |
| } |
| } |
| } |
|
|
| |
| for(auto arc : pin._fanout) { |
| arc->_bprop_rat(); |
| } |
| } |
|
|
| |
| |
| void Timer::_build_fprop_cands(Pin& from) { |
| |
| assert(!from._has_state(Pin::FPROP_CAND) && !from._has_state(Pin::IN_FPROP_STACK)); |
|
|
| from._insert_state(Pin::FPROP_CAND | Pin::IN_FPROP_STACK); |
|
|
| for(auto arc : from._fanout) { |
| if(auto& to = arc->_to; !to._has_state(Pin::FPROP_CAND)) { |
| _build_fprop_cands(to); |
| } |
| else if(to._has_state(Pin::IN_FPROP_STACK)) { |
| _scc_analysis = true; |
| } |
| } |
| |
| _fprop_cands.push_front(&from); |
| from._remove_state(Pin::IN_FPROP_STACK); |
| } |
|
|
| |
| |
| void Timer::_build_bprop_cands(Pin& to) { |
| |
| assert(!to._has_state(Pin::BPROP_CAND) && !to._has_state(Pin::IN_BPROP_STACK)); |
|
|
| to._insert_state(Pin::BPROP_CAND | Pin::IN_BPROP_STACK); |
|
|
| |
| if(_scc_analysis && to._has_state(Pin::FPROP_CAND) && !to._scc) { |
| _scc_cands.push_back(&to); |
| } |
|
|
| for(auto arc : to._fanin) { |
| if(auto& from=arc->_from; !from._has_state(Pin::BPROP_CAND)) { |
| _build_bprop_cands(from); |
| } |
| } |
| |
| _bprop_cands.push_front(&to); |
| to._remove_state(Pin::IN_BPROP_STACK); |
| } |
|
|
| |
| void Timer::_build_prop_cands() { |
|
|
| _scc_analysis = false; |
|
|
| |
| for(const auto& ftr : _frontiers) { |
| if(ftr->_has_state(Pin::FPROP_CAND)) { |
| continue; |
| } |
| _build_fprop_cands(*ftr); |
| } |
|
|
| |
| for(auto fcand : _fprop_cands) { |
|
|
| if(fcand->_has_state(Pin::BPROP_CAND)) { |
| continue; |
| } |
|
|
| _scc_cands.clear(); |
| _build_bprop_cands(*fcand); |
|
|
| if(!_scc_analysis) { |
| assert(_scc_cands.empty()); |
| } |
| |
| |
| if(auto& c = _scc_cands; c.size() >= 2 || (c.size() == 1 && c[0]->has_self_loop())) { |
| auto& scc = _insert_scc(c); |
| scc._unloop(); |
| } |
| } |
| } |
|
|
| |
| void Timer::_build_prop_tasks() { |
| |
| |
| _build_prop_cands(); |
|
|
| |
| |
| |
| |
| |
| for(auto pin : _fprop_cands) { |
| assert(!pin->_ftask); |
| pin->_ftask = _taskflow.emplace([this, pin] () { |
| _fprop_rc_timing(*pin); |
| _fprop_slew(*pin); |
| _fprop_delay(*pin); |
| _fprop_at(*pin); |
| _fprop_test(*pin); |
| }); |
| } |
| |
| |
| for(auto to : _fprop_cands) { |
| for(auto arc : to->_fanin) { |
| if(arc->_has_state(Arc::LOOP_BREAKER)) { |
| continue; |
| } |
| if(auto& from = arc->_from; from._has_state(Pin::FPROP_CAND)) { |
| from._ftask->precede(to->_ftask.value()); |
| } |
| } |
| } |
|
|
| |
| |
| for(auto pin : _bprop_cands) { |
| assert(!pin->_btask); |
| pin->_btask = _taskflow.emplace([this, pin] () { |
| _bprop_rat(*pin); |
| }); |
| } |
|
|
| |
| for(auto to : _bprop_cands) { |
| for(auto arc : to->_fanin) { |
| if(arc->_has_state(Arc::LOOP_BREAKER)) { |
| continue; |
| } |
| if(auto& from = arc->_from; from._has_state(Pin::BPROP_CAND)) { |
| to->_btask->precede(from._btask.value()); |
| } |
| } |
| } |
|
|
| |
| for(auto pin : _bprop_cands) { |
| if(pin->_btask->num_predecessors() == 0 && pin->_ftask) { |
| pin->_ftask->precede(pin->_btask.value()); |
| } |
| } |
|
|
| } |
|
|
| |
| void Timer::_clear_prop_tasks() { |
| |
| |
| for(auto pin : _bprop_cands) { |
| pin->_ftask.reset(); |
| pin->_btask.reset(); |
| pin->_remove_state(); |
| } |
|
|
| _fprop_cands.clear(); |
| _bprop_cands.clear(); |
| } |
|
|
| |
| |
| |
| |
| void Timer::update_timing() { |
| std::scoped_lock lock(_mutex); |
| _update_timing(); |
| } |
|
|
| |
| void Timer::_update_timing() { |
| |
| |
| if(!_lineage) { |
| assert(_frontiers.size() == 0); |
| return; |
| } |
|
|
| |
| _executor.run(_taskflow).wait(); |
| _taskflow.clear(); |
| _lineage.reset(); |
| |
| |
| if(_has_state(FULL_TIMING)) { |
| _insert_full_timing_frontiers(); |
| } |
|
|
| |
| _build_prop_tasks(); |
|
|
| |
| |
|
|
| |
| _executor.run(_taskflow).wait(); |
| _taskflow.clear(); |
| |
| |
| _clear_prop_tasks(); |
|
|
| |
| _clear_frontiers(); |
|
|
| |
| _remove_state(); |
| } |
|
|
| |
| void Timer::_update_area() { |
| |
| _update_timing(); |
|
|
| if(_has_state(AREA_UPDATED)) { |
| return; |
| } |
| |
| _area = 0.0f; |
|
|
| for(const auto& kvp : _gates) { |
| if(const auto& c = kvp.second._cell[MIN]; c->area) { |
| _area = *_area + *c->area; |
| } |
| else { |
| OT_LOGE("cell ", c->name, " has no area defined"); |
| _area.reset(); |
| break; |
| } |
| } |
|
|
| _insert_state(AREA_UPDATED); |
| } |
|
|
| |
| void Timer::_update_power() { |
|
|
| _update_timing(); |
|
|
| if(_has_state(POWER_UPDATED)) { |
| return; |
| } |
|
|
| |
| _leakage_power = 0.0f; |
| |
| for(const auto& kvp : _gates) { |
| if(const auto& c = kvp.second._cell[MIN]; c->leakage_power) { |
| _leakage_power = *_leakage_power + *c->leakage_power; |
| } |
| else { |
| OT_LOGE("cell ", c->name, " has no leakage_power defined"); |
| _leakage_power.reset(); |
| break; |
| } |
| } |
|
|
| _insert_state(POWER_UPDATED); |
| } |
|
|
| |
| void Timer::_update_endpoints() { |
|
|
| _update_timing(); |
|
|
| if(_has_state(EPTS_UPDATED)) { |
| return; |
| } |
|
|
| |
| FOR_EACH_EL_RF(el, rf) { |
|
|
| _endpoints[el][rf].clear(); |
| |
| _taskflow.emplace([this, el=el, rf=rf] () { |
|
|
| |
| for(auto& po : _pos) { |
| if(po.second.slack(el, rf).has_value()) { |
| _endpoints[el][rf].emplace_back(el, rf, po.second); |
| } |
| } |
|
|
| |
| for(auto& test : _tests) { |
| if(test.slack(el, rf).has_value()) { |
| _endpoints[el][rf].emplace_back(el, rf, test); |
| } |
| } |
| |
| |
| std::sort(_endpoints[el][rf].begin(), _endpoints[el][rf].end()); |
|
|
| |
| if(!_endpoints[el][rf].empty()) { |
| _wns[el][rf] = _endpoints[el][rf].front().slack(); |
| } |
| else { |
| _wns[el][rf] = std::nullopt; |
| } |
|
|
| |
| if(!_endpoints[el][rf].empty()) { |
| _tns[el][rf] = 0.0f; |
| _fep[el][rf] = 0; |
| for(const auto& ept : _endpoints[el][rf]) { |
| if(auto slack = ept.slack(); slack < 0.0f) { |
| _tns[el][rf] = *_tns[el][rf] + slack; |
| _fep[el][rf] = *_fep[el][rf] + 1; |
| } |
| } |
| } |
| else { |
| _tns[el][rf] = std::nullopt; |
| _fep[el][rf] = std::nullopt; |
| } |
| }); |
| } |
|
|
| |
| _executor.run(_taskflow).wait(); |
| _taskflow.clear(); |
|
|
| _insert_state(EPTS_UPDATED); |
| } |
|
|
| |
| |
| |
| std::optional<float> Timer::report_tns(std::optional<Split> el, std::optional<Tran> rf) { |
|
|
| std::scoped_lock lock(_mutex); |
|
|
| _update_endpoints(); |
|
|
| std::optional<float> v; |
|
|
| if(!el && !rf) { |
| FOR_EACH_EL_RF_IF(s, t, _tns[s][t]) { |
| v = !v ? _tns[s][t] : *v + *(_tns[s][t]); |
| } |
| } |
| else if(el && !rf) { |
| FOR_EACH_RF_IF(t, _tns[*el][t]) { |
| v = !v ? _tns[*el][t] : *v + *(_tns[*el][t]); |
| } |
| } |
| else if(!el && rf) { |
| FOR_EACH_EL_IF(s, _tns[s][*rf]) { |
| v = !v ? _tns[s][*rf] : *v + *(_tns[s][*rf]); |
| } |
| } |
| else { |
| v = _tns[*el][*rf]; |
| } |
|
|
| return v; |
| } |
|
|
| |
| |
| |
| std::optional<float> Timer::report_wns(std::optional<Split> el, std::optional<Tran> rf) { |
|
|
| std::scoped_lock lock(_mutex); |
|
|
| _update_endpoints(); |
|
|
| std::optional<float> v; |
| |
| if(!el && !rf) { |
| FOR_EACH_EL_RF_IF(s, t, _wns[s][t]) { |
| v = !v ? _wns[s][t] : std::min(*v, *(_wns[s][t])); |
| } |
| } |
| else if(el && !rf) { |
| FOR_EACH_RF_IF(t, _wns[*el][t]) { |
| v = !v ? _wns[*el][t] : std::min(*v, *(_wns[*el][t])); |
| } |
| } |
| else if(!el && rf) { |
| FOR_EACH_EL_IF(s, _wns[s][*rf]) { |
| v = !v ? _wns[s][*rf] : std::min(*v, *(_wns[s][*rf])); |
| } |
| } |
| else { |
| v = _wns[*el][*rf]; |
| } |
|
|
| return v; |
| } |
|
|
| |
| |
| std::optional<size_t> Timer::report_fep(std::optional<Split> el, std::optional<Tran> rf) { |
| |
| std::scoped_lock lock(_mutex); |
|
|
| _update_endpoints(); |
|
|
| std::optional<size_t> v; |
|
|
| if(!el && !rf) { |
| FOR_EACH_EL_RF_IF(s, t, _fep[s][t]) { |
| v = !v ? _fep[s][t] : *v + *(_fep[s][t]); |
| } |
| } |
| else if(el && !rf) { |
| FOR_EACH_RF_IF(t, _fep[*el][t]) { |
| v = !v ? _fep[*el][t] : *v + *(_fep[*el][t]); |
| } |
| } |
| else if(!el && rf) { |
| FOR_EACH_EL_IF(s, _fep[s][*rf]) { |
| v = !v ? _fep[s][*rf] : *v + *(_fep[s][*rf]); |
| } |
| } |
| else { |
| v = _fep[*el][*rf]; |
| } |
|
|
| return v; |
| } |
|
|
| |
| std::optional<float> Timer::report_leakage_power() { |
| std::scoped_lock lock(_mutex); |
| _update_power(); |
| return _leakage_power; |
| } |
|
|
| |
| |
| std::optional<float> Timer::report_area() { |
| std::scoped_lock lock(_mutex); |
| _update_area(); |
| return _area; |
| } |
| |
| |
| void Timer::_enable_full_timing_update() { |
| _insert_state(FULL_TIMING); |
| } |
|
|
| |
| void Timer::_insert_full_timing_frontiers() { |
|
|
| |
| for(auto& kvp : _pins) { |
| _insert_frontier(kvp.second); |
| } |
|
|
| |
| for(auto& kvp : _nets) { |
| kvp.second._rc_timing_updated = false; |
| } |
| } |
|
|
| |
| void Timer::_insert_frontier(Pin& pin) { |
| |
| if(pin._frontier_satellite) { |
| return; |
| } |
|
|
| pin._frontier_satellite = _frontiers.insert(_frontiers.end(), &pin); |
| |
| |
| if(pin._scc) { |
| _remove_scc(*pin._scc); |
| } |
| } |
|
|
| |
| void Timer::_remove_frontier(Pin& pin) { |
| if(pin._frontier_satellite) { |
| _frontiers.erase(*pin._frontier_satellite); |
| pin._frontier_satellite.reset(); |
| } |
| } |
|
|
| |
| void Timer::_clear_frontiers() { |
| for(auto& ftr : _frontiers) { |
| ftr->_frontier_satellite.reset(); |
| } |
| _frontiers.clear(); |
| } |
|
|
| |
| SCC& Timer::_insert_scc(std::vector<Pin*>& cands) { |
| |
| |
| auto& scc = _sccs.emplace_front(std::move(cands)); |
| scc._satellite = _sccs.begin(); |
|
|
| return scc; |
| } |
|
|
| |
| void Timer::_remove_scc(SCC& scc) { |
| assert(scc._satellite); |
| scc._clear(); |
| _sccs.erase(*scc._satellite); |
| } |
|
|
| |
| |
| std::optional<float> Timer::report_at(const std::string& name, Split m, Tran t) { |
| std::scoped_lock lock(_mutex); |
| return _report_at(name, m, t); |
| } |
|
|
| |
| std::optional<float> Timer::_report_at(const std::string& name, Split m, Tran t) { |
| _update_timing(); |
| if(auto itr = _pins.find(name); itr != _pins.end() && itr->second._at[m][t]) { |
| return itr->second._at[m][t]->numeric; |
| } |
| else return std::nullopt; |
| } |
|
|
| |
| |
| std::optional<float> Timer::report_rat(const std::string& name, Split m, Tran t) { |
| std::scoped_lock lock(_mutex); |
| return _report_rat(name, m, t); |
| } |
|
|
| |
| std::optional<float> Timer::_report_rat(const std::string& name, Split m, Tran t) { |
| _update_timing(); |
| if(auto itr = _pins.find(name); itr != _pins.end() && itr->second._at[m][t]) { |
| return itr->second._rat[m][t]; |
| } |
| else return std::nullopt; |
| } |
|
|
| |
| |
| std::optional<float> Timer::report_slew(const std::string& name, Split m, Tran t) { |
| std::scoped_lock lock(_mutex); |
| return _report_slew(name, m, t); |
| } |
|
|
| |
| std::optional<float> Timer::_report_slew(const std::string& name, Split m, Tran t) { |
| _update_timing(); |
| if(auto itr = _pins.find(name); itr != _pins.end() && itr->second._slew[m][t]) { |
| return itr->second._slew[m][t]->numeric; |
| } |
| else return std::nullopt; |
| } |
|
|
| |
| std::optional<float> Timer::report_slack(const std::string& pin, Split m, Tran t) { |
| std::scoped_lock lock(_mutex); |
| return _report_slack(pin, m, t); |
| } |
|
|
| |
| std::optional<float> Timer::_report_slack(const std::string& pin, Split m, Tran t) { |
| _update_timing(); |
| if(auto itr = _pins.find(pin); itr != _pins.end()) { |
| return itr->second.slack(m, t); |
| } |
| else return std::nullopt; |
| } |
|
|
| |
| |
| std::optional<float> Timer::report_load(const std::string& name, Split m, Tran t) { |
| std::scoped_lock lock(_mutex); |
| return _report_load(name, m, t); |
| } |
|
|
| |
| std::optional<float> Timer::_report_load(const std::string& name, Split m, Tran t) { |
| _update_timing(); |
| if(auto itr = _nets.find(name); itr != _nets.end()) { |
| return itr->second._load(m, t); |
| } |
| else return std::nullopt; |
| } |
|
|
| |
| Timer& Timer::set_at(std::string name, Split m, Tran t, std::optional<float> v) { |
|
|
| std::scoped_lock lock(_mutex); |
|
|
| auto task = _taskflow.emplace([this, name=std::move(name), m, t, v] () { |
| if(auto itr = _pis.find(name); itr != _pis.end()) { |
| _set_at(itr->second, m, t, v); |
| } |
| else { |
| OT_LOGE("can't set at (PI ", name, " not found)"); |
| } |
| }); |
|
|
| _add_to_lineage(task); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_set_at(PrimaryInput& pi, Split m, Tran t, std::optional<float> v) { |
| pi._at[m][t] = v; |
| _insert_frontier(pi._pin); |
| } |
|
|
| |
| Timer& Timer::set_rat(std::string name, Split m, Tran t, std::optional<float> v) { |
|
|
| std::scoped_lock lock(_mutex); |
| |
| auto op = _taskflow.emplace([this, name=std::move(name), m, t, v] () { |
| if(auto itr = _pos.find(name); itr != _pos.end()) { |
| _set_rat(itr->second, m, t, v); |
| } |
| else { |
| OT_LOGE("can't set rat (PO ", name, " not found)"); |
| } |
| }); |
|
|
| _add_to_lineage(op); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_set_rat(PrimaryOutput& po, Split m, Tran t, std::optional<float> v) { |
| po._rat[m][t] = v; |
| _insert_frontier(po._pin); |
| } |
|
|
| |
| Timer& Timer::set_slew(std::string name, Split m, Tran t, std::optional<float> v) { |
|
|
| std::scoped_lock lock(_mutex); |
| |
| auto task = _taskflow.emplace([this, name=std::move(name), m, t, v] () { |
| if(auto itr = _pis.find(name); itr != _pis.end()) { |
| _set_slew(itr->second, m, t, v); |
| } |
| else { |
| OT_LOGE("can't set slew (PI ", name, " not found)"); |
| } |
| }); |
|
|
| _add_to_lineage(task); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_set_slew(PrimaryInput& pi, Split m, Tran t, std::optional<float> v) { |
| pi._slew[m][t] = v; |
| _insert_frontier(pi._pin); |
| } |
|
|
| |
| Timer& Timer::set_load(std::string name, Split m, Tran t, std::optional<float> v) { |
|
|
| std::scoped_lock lock(_mutex); |
| |
| auto task = _taskflow.emplace([this, name=std::move(name), m, t, v] () { |
| if(auto itr = _pos.find(name); itr != _pos.end()) { |
| _set_load(itr->second, m, t, v); |
| } |
| else { |
| OT_LOGE("can't set load (PO ", name, " not found)"); |
| } |
| }); |
|
|
| _add_to_lineage(task); |
|
|
| return *this; |
| } |
|
|
| |
| void Timer::_set_load(PrimaryOutput& po, Split m, Tran t, std::optional<float> v) { |
|
|
| po._load[m][t] = v ? *v : 0.0f; |
|
|
| |
| if(auto net = po._pin._net) { |
| net->_rc_timing_updated = false; |
| } |
| |
| |
| for(auto arc : po._pin._fanin) { |
| _insert_frontier(arc->_from); |
| } |
| _insert_frontier(po._pin); |
| } |
|
|
|
|
| }; |
|
|
|
|
|
|
|
|
|
|