Skip to content

Commit 024ab9f

Browse files
committed
blackbox saif
1 parent cacb089 commit 024ab9f

3 files changed

Lines changed: 59 additions & 4 deletions

File tree

power/Power.cc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Power::activitiesInvalid()
127127
{
128128
activities_valid_ = false;
129129
instance_powers_valid_ = false;
130+
instance_powers_.clear();
130131
}
131132

132133
void
@@ -474,14 +475,24 @@ Power::power(const Instance *inst,
474475
const Scene *scene)
475476
{
476477
ensureActivities(scene);
477-
ensureInstPowers();
478478
if (network_->isHierarchical(inst)) {
479+
// Hierarchical sums walk every leaf inside, so fill the whole cache.
480+
ensureInstPowers();
479481
PowerResult result;
480482
powerInside(inst, scene, result);
481483
return result;
482484
}
483-
else
484-
return instance_powers_[inst];
485+
// SILIMATE: price and cache this leaf only. findInstPowers() would walk the
486+
// whole netlist, which report_power -instances / -exclude_libs does not need.
487+
auto itr = instance_powers_.find(inst);
488+
if (itr != instance_powers_.end())
489+
return itr->second;
490+
PowerResult result;
491+
LibertyCell *cell = network_->libertyCell(inst);
492+
if (cell)
493+
result = power(inst, cell, scene_);
494+
instance_powers_[inst] = result;
495+
return result;
485496
}
486497

487498
void
@@ -904,6 +915,7 @@ Power::ensureActivities(const Scene *scene)
904915
if (scene != scene_) {
905916
scene_ = scene;
906917
activities_valid_ = false;
918+
instance_powers_valid_ = false;
907919
instance_powers_.clear();
908920
}
909921

@@ -1846,6 +1858,7 @@ void
18461858
Power::powerInvalid()
18471859
{
18481860
activities_valid_ = false;
1861+
instance_powers_valid_ = false;
18491862
instance_powers_.clear();
18501863
scene_ = nullptr;
18511864
}

power/Power.i

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
%{
2828
#include "power/Power.hh"
2929

30+
#include <string>
31+
32+
#include "Liberty.hh"
3033
#include "Mode.hh"
34+
#include "Network.hh"
35+
#include "PatternMatch.hh"
3136
#include "Sdc.hh"
3237
#include "Sta.hh"
3338
#include "power/SaifReader.hh"
@@ -86,6 +91,34 @@ report_power_insts_json(const InstanceSeq insts,
8691
sta->reportPowerInstsJson(insts, scene, digits);
8792
}
8893

94+
InstanceSeq
95+
power_insts_not_in_libs(StringSeq lib_patterns)
96+
{
97+
Sta *sta = Sta::sta();
98+
Network *network = sta->network();
99+
InstanceSeq insts;
100+
LeafInstanceIterator *iter = network->leafInstanceIterator();
101+
while (iter->hasNext()) {
102+
Instance *inst = iter->next();
103+
LibertyCell *cell = network->libertyCell(inst);
104+
if (cell == nullptr)
105+
continue;
106+
const std::string &lib_name = cell->libertyLibrary()->name();
107+
bool excluded = false;
108+
for (const std::string &pattern : lib_patterns) {
109+
if (patternMatch(pattern, lib_name)) {
110+
excluded = true;
111+
break;
112+
}
113+
}
114+
// Add instances that match none of the patterns.
115+
if (!excluded)
116+
insts.push_back(inst);
117+
}
118+
delete iter;
119+
return insts;
120+
}
121+
89122
////////////////////////////////////////////////////////////////
90123

91124
static void

power/Power.tcl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace eval sta {
3232

3333
define_cmd_args "report_power" \
3434
{ [-instances instances]\
35+
[-exclude_libs patterns]\
3536
[-highest_power_instances count]\
3637
[-scene scene]\
3738
[-digits digits]\
@@ -55,6 +56,7 @@ Total 3.48e-06 6.72e-08 3.12e-07 3.86e-06 100.0%
5556
```} \
5657
-arg_help {
5758
-instances {`instances`: Report the power for each instance of instances. If the instance is hierarchical the total power for the instances inside the hierarchical instance is reported.}
59+
-exclude_libs {`patterns`: Report power for each leaf instance whose Liberty library name matches none of patterns.}
5860
-highest_power_instances {`count`: Report the power for the count highest power instances.}
5961
-format {`text`: Print a text table (the default). `json`: Print JSON.}
6062
}
@@ -63,7 +65,7 @@ proc_redirect report_power {
6365
global sta_report_default_digits
6466

6567
parse_key_args "report_power" args \
66-
keys {-instances -highest_power_instances -corner -scene -format -digits}\
68+
keys {-instances -exclude_libs -highest_power_instances -corner -scene -format -digits}\
6769
flags {}
6870

6971
check_argc_eq0 "report_power" $args
@@ -95,6 +97,13 @@ proc_redirect report_power {
9597
} else {
9698
report_power_insts $insts $scene $digits
9799
}
100+
} elseif { [info exists keys(-exclude_libs)] } {
101+
set insts [power_insts_not_in_libs $keys(-exclude_libs)]
102+
if { $format == "json" } {
103+
report_power_insts_json $insts $scene $digits
104+
} else {
105+
report_power_insts $insts $scene $digits
106+
}
98107
} elseif { [info exists keys(-highest_power_instances)] } {
99108
set count $keys(-highest_power_instances)
100109
check_positive_integer "-highest_power_instances" $count

0 commit comments

Comments
 (0)