From 0b4018e45d0e48ec4139244cf12929d243e4d082 Mon Sep 17 00:00:00 2001 From: James Cherry Date: Wed, 18 Jan 2023 10:23:03 -0700 Subject: [PATCH] Table use make_shared Signed-off-by: James Cherry --- include/sta/Liberty.hh | 12 ++++++------ include/sta/LibertyClass.hh | 1 + include/sta/TableModel.hh | 9 ++++----- liberty/Liberty.cc | 25 +++--------------------- liberty/LibertyReader.cc | 38 +++++++++++++------------------------ liberty/LibertyReaderPvt.hh | 2 +- liberty/TableModel.cc | 11 +++-------- search/MakeTimingModel.cc | 11 ++++++----- 8 files changed, 37 insertions(+), 72 deletions(-) diff --git a/include/sta/Liberty.hh b/include/sta/Liberty.hh index a7e4e6bd..33cf9a38 100644 --- a/include/sta/Liberty.hh +++ b/include/sta/Liberty.hh @@ -179,7 +179,7 @@ public: float wire_delay) const; // Check for supported axis variables. // Return true if axes are supported. - static bool checkSlewDegradationAxes(Table *table); + static bool checkSlewDegradationAxes(TablePtr table); float defaultInputPinCap() const { return default_input_pin_cap_; } void setDefaultInputPinCap(float cap); @@ -1050,18 +1050,18 @@ public: OcvDerate(const char *name); ~OcvDerate(); const char *name() const { return name_; } - Table *derateTable(const RiseFall *rf, - const EarlyLate *early_late, - PathType path_type); + TablePtr derateTable(const RiseFall *rf, + const EarlyLate *early_late, + PathType path_type); void setDerateTable(const RiseFall *rf, const EarlyLate *early_late, PathType path_type, - Table *derate); + TablePtr derate); private: const char *name_; // [rf_type][derate_type][path_type] - Table *derate_[RiseFall::index_count][EarlyLate::index_count][path_type_count]; + TablePtr derate_[RiseFall::index_count][EarlyLate::index_count][path_type_count]; }; // Power/ground port. diff --git a/include/sta/LibertyClass.hh b/include/sta/LibertyClass.hh index 5ddb8485..0d6d2461 100644 --- a/include/sta/LibertyClass.hh +++ b/include/sta/LibertyClass.hh @@ -68,6 +68,7 @@ typedef std::pair LibertyPortPair; typedef Set LibertyCellSet; typedef Vector FloatSeq; typedef Vector FloatTable; +typedef std::shared_ptr TablePtr; typedef std::shared_ptr TimingArcAttrsPtr; typedef std::shared_ptr TableAxisPtr; diff --git a/include/sta/TableModel.hh b/include/sta/TableModel.hh index 49c34e25..0d905190 100644 --- a/include/sta/TableModel.hh +++ b/include/sta/TableModel.hh @@ -74,7 +74,7 @@ public: const TableModel *slewModel() const { return slew_model_; } // Check the axes before making the model. // Return true if the model axes are supported. - static bool checkAxes(const Table *table); + static bool checkAxes(const TablePtr table); protected: void maxCapSlew(const LibertyCell *cell, @@ -147,7 +147,7 @@ public: // Check the axes before making the model. // Return true if the model axes are supported. - static bool checkAxes(const Table *table); + static bool checkAxes(const TablePtr table); protected: virtual void setIsScaled(bool is_scaled); @@ -190,11 +190,10 @@ protected: class TableModel { public: - TableModel(Table *table, + TableModel(TablePtr table, TableTemplate *tbl_template, ScaleFactorType scale_factor_type, RiseFall *rf); - ~TableModel(); void setScaleFactorType(ScaleFactorType type); int order() const; TableTemplate *tblTemplate() const { return tbl_template_; } @@ -239,7 +238,7 @@ protected: int digits, string *result) const; - Table *table_; + TablePtr table_; TableTemplate *tbl_template_; // ScaleFactorType gcc barfs if this is dcl'd. unsigned scale_factor_type_:scale_factor_bits; diff --git a/liberty/Liberty.cc b/liberty/Liberty.cc index 5e075c69..6c649208 100644 --- a/liberty/Liberty.cc +++ b/liberty/Liberty.cc @@ -373,7 +373,7 @@ LibertyLibrary::degradeWireSlew(const LibertyCell *cell, // Check for supported axis variables. // Return true if axes are supported. bool -LibertyLibrary::checkSlewDegradationAxes(Table *table) +LibertyLibrary::checkSlewDegradationAxes(TablePtr table) { switch (table->order()) { case 0: @@ -2964,28 +2964,9 @@ OcvDerate::OcvDerate(const char *name) : OcvDerate::~OcvDerate() { stringDelete(name_); - // Derating table models can be shared in multiple places in derate_; - // Collect them in a set to avoid duplicate deletes. - Set models; - for (auto el_index : EarlyLate::rangeIndex()) { - for (auto tr_index : RiseFall::rangeIndex()) { - Table *derate; - derate = derate_[tr_index][el_index][int(PathType::clk)]; - if (derate) - models.insert(derate); - derate = derate_[tr_index][el_index][int(PathType::data)]; - if (derate) - models.insert(derate); - } - } - Set::Iterator model_iter(models); - while (model_iter.hasNext()) { - Table *model = model_iter.next(); - delete model; - } } -Table * +TablePtr OcvDerate::derateTable(const RiseFall *rf, const EarlyLate *early_late, PathType path_type) @@ -2997,7 +2978,7 @@ void OcvDerate::setDerateTable(const RiseFall *rf, const EarlyLate *early_late, const PathType path_type, - Table *derate) + TablePtr derate) { derate_[rf->index()][early_late->index()][int(path_type)] = derate; } diff --git a/liberty/LibertyReader.cc b/liberty/LibertyReader.cc index 48c5d779..ef92272b 100644 --- a/liberty/LibertyReader.cc +++ b/liberty/LibertyReader.cc @@ -44,6 +44,8 @@ extern int LibertyParse_debug; namespace sta { +using std::make_shared; + static void scaleFloats(FloatSeq *floats, float scale); @@ -3803,10 +3805,8 @@ LibertyReader::endCellRiseFall(LibertyGroup *group) scale_factor_type_, rf_); timing_->setCell(rf_, table_model); } - else { + else libWarn(118, group, "unsupported model axis."); - delete table_; - } } endTableModel(); } @@ -3832,10 +3832,8 @@ LibertyReader::endRiseFallTransition(LibertyGroup *group) scale_factor_type_, rf_); timing_->setTransition(rf_, table_model); } - else { + else libWarn(119, group, "unsupported model axis."); - delete table_; - } } endTableModel(); } @@ -3863,10 +3861,8 @@ LibertyReader::endRiseFallConstraint(LibertyGroup *group) scale_factor_type_, rf_); timing_->setConstraint(rf_, table_model); } - else { + else libWarn(120, group, "unsupported model axis."); - delete table_; - } } endTableModel(); } @@ -3900,10 +3896,8 @@ LibertyReader::endRiseFallTransitionDegredation(LibertyGroup *group) scale_factor_type_, rf_); library_->setWireSlewDegradationTable(table_model, rf_); } - else { + else libWarn(121, group, "unsupported model axis."); - delete table_; - } } endTableModel(); } @@ -4004,27 +3998,27 @@ LibertyReader::makeTable(LibertyAttr *attr, FloatTable *table = makeFloatTable(attr, axis_[0]->size()*axis_[1]->size(), axis_[2]->size(), scale); - table_ = new Table3(table, axis_[0], axis_[1], axis_[2]); + table_ = make_shared(table, axis_[0], axis_[1], axis_[2]); } else if (axis_[0] && axis_[1]) { // Row variable1/axis[0] // Column variable2/axis[1] FloatTable *table = makeFloatTable(attr, axis_[0]->size(), axis_[1]->size(), scale); - table_ = new Table2(table, axis_[0], axis_[1]); + table_ = make_shared(table, axis_[0], axis_[1]); } else if (axis_[0]) { FloatTable *table = makeFloatTable(attr, 1, axis_[0]->size(), scale); FloatSeq *values = (*table)[0]; delete table; - table_ = new Table1(values, axis_[0]); + table_ = make_shared(values, axis_[0]); } else { FloatTable *table = makeFloatTable(attr, 1, 1, scale); float value = (*(*table)[0])[0]; delete (*table)[0]; delete table; - table_ = new Table0(value); + table_ = make_shared(value); } } else @@ -4819,10 +4813,8 @@ LibertyReader::endOcvSigmaCell(LibertyGroup *group) else timing_->setDelaySigma(rf_, sigma_type_->asMinMax(), table_model); } - else { + else libWarn(152, group, "unsupported model axis."); - delete table_; - } } endTableModel(); } @@ -4853,10 +4845,8 @@ LibertyReader::endOcvSigmaTransition(LibertyGroup *group) else timing_->setSlewSigma(rf_, sigma_type_->asMinMax(), table_model); } - else { + else libWarn(153, group, "unsupported model axis."); - delete table_; - } } endTableModel(); } @@ -4887,10 +4877,8 @@ LibertyReader::endOcvSigmaConstraint(LibertyGroup *group) else timing_->setConstraintSigma(rf_, sigma_type_->asMinMax(), table_model); } - else { + else libWarn(154, group, "unsupported model axis."); - delete table_; - } } endTableModel(); } diff --git a/liberty/LibertyReaderPvt.hh b/liberty/LibertyReaderPvt.hh index 663f35f5..772b00d4 100644 --- a/liberty/LibertyReaderPvt.hh +++ b/liberty/LibertyReaderPvt.hh @@ -575,7 +575,7 @@ protected: LibertyPgPort *pg_port_; ScaleFactorType scale_factor_type_; TableAxisPtr axis_[3]; - Table *table_; + TablePtr table_; float table_model_scale_; ModeDef *mode_def_; ModeValueDef *mode_value_; diff --git a/liberty/TableModel.cc b/liberty/TableModel.cc index 03273205..dc18396c 100644 --- a/liberty/TableModel.cc +++ b/liberty/TableModel.cc @@ -320,7 +320,7 @@ GateTableModel::axisValue(TableAxisPtr axis, } bool -GateTableModel::checkAxes(const Table *table) +GateTableModel::checkAxes(const TablePtr table) { TableAxisPtr axis1 = table->axis1(); TableAxisPtr axis2 = table->axis2(); @@ -529,7 +529,7 @@ CheckTableModel::axisValue(TableAxisPtr axis, } bool -CheckTableModel::checkAxes(const Table *table) +CheckTableModel::checkAxes(const TablePtr table) { TableAxisPtr axis1 = table->axis1(); TableAxisPtr axis2 = table->axis2(); @@ -555,7 +555,7 @@ CheckTableModel::checkAxis(TableAxisPtr axis) //////////////////////////////////////////////////////////////// -TableModel::TableModel(Table *table, +TableModel::TableModel(TablePtr table, TableTemplate *tbl_template, ScaleFactorType scale_factor_type, RiseFall *rf) : @@ -567,11 +567,6 @@ TableModel::TableModel(Table *table, { } -TableModel::~TableModel() -{ - delete table_; -} - int TableModel::order() const { diff --git a/search/MakeTimingModel.cc b/search/MakeTimingModel.cc index 0b37ebe2..196378dc 100644 --- a/search/MakeTimingModel.cc +++ b/search/MakeTimingModel.cc @@ -43,6 +43,7 @@ namespace sta { using std::max; +using std::make_shared; MakeTimingModel::MakeTimingModel(const Corner *corner, Sta *sta) : @@ -500,7 +501,7 @@ MakeTimingModel::makeScalarCheckModel(float value, ScaleFactorType scale_factor_type, RiseFall *rf) { - Table *table = new Table0(value); + TablePtr table = make_shared(value); TableTemplate *tbl_template = library_->findTableTemplate("scalar", TableTemplateType::delay); TableModel *table_model = new TableModel(table, tbl_template, @@ -514,8 +515,8 @@ MakeTimingModel::makeGateModelScalar(Delay delay, Slew slew, RiseFall *rf) { - Table *delay_table = new Table0(delayAsFloat(delay)); - Table *slew_table = new Table0(delayAsFloat(slew)); + TablePtr delay_table = make_shared(delayAsFloat(delay)); + TablePtr slew_table = make_shared(delayAsFloat(slew)); TableTemplate *tbl_template = library_->findTableTemplate("scalar", TableTemplateType::delay); TableModel *delay_model = new TableModel(delay_table, tbl_template, @@ -590,8 +591,8 @@ MakeTimingModel::makeGateModelTable(const Pin *output_pin, std::make_shared(TableAxisVariable::total_output_net_capacitance, axis_values); - Table *delay_table = new Table1(load_values, load_axis); - Table *slew_table = new Table1(slew_values, load_axis); + TablePtr delay_table = make_shared(load_values, load_axis); + TablePtr slew_table = make_shared(slew_values, load_axis); string template_name = "template_"; template_name += std::to_string(tbl_template_index_++);