Skip to content

Commit 7c40f7b

Browse files
authored
Move customization logic to InstrumentManager
1 parent 5029c24 commit 7c40f7b

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

llvm/include/llvm/MCA/CustomBehaviour.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ class Instrument {
130130

131131
virtual ~Instrument() = default;
132132

133-
virtual bool canCustomize() const { return false; }
134-
virtual void customize(InstrDesc &) const {}
135-
136133
StringRef getDesc() const { return Desc; }
137134
StringRef getData() const { return Data; }
138135
};
@@ -154,15 +151,8 @@ class LatencyInstrument : public Instrument {
154151
Latency = L;
155152
}
156153

157-
bool canCustomize() const override { return bool(Latency); }
158-
void customize(InstrDesc &ID) const override {
159-
if (Latency) {
160-
// TODO Allow to customize a subset of ID.Writes
161-
for (auto &W : ID.Writes)
162-
W.Latency = *Latency;
163-
ID.MaxLatency = *Latency;
164-
}
165-
}
154+
bool hasValue() const { return bool(Latency); }
155+
unsigned getLatency() { return *Latency; }
166156
};
167157

168158
using UniqueInstrument = std::unique_ptr<Instrument>;
@@ -178,7 +168,7 @@ class LLVM_ABI InstrumentManager {
178168

179169
public:
180170
InstrumentManager(const MCSubtargetInfo &STI, const MCInstrInfo &MCII,
181-
bool EnableInstruments = false)
171+
bool EnableInstruments = true)
182172
: STI(STI), MCII(MCII), EnableInstruments(EnableInstruments) {};
183173

184174
virtual ~InstrumentManager() = default;

llvm/lib/MCA/CustomBehaviour.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,36 @@ bool InstrumentManager::supportsInstrumentType(StringRef Type) const {
5252
bool InstrumentManager::canCustomize(
5353
const llvm::SmallVector<Instrument *> &IVec) const {
5454
for (const auto I : IVec) {
55-
if (I->canCustomize())
56-
return true;
55+
if (I->getDesc() == LatencyInstrument::DESC_NAME) {
56+
auto LatInst = static_cast<LatencyInstrument*>(I);
57+
return LatInst->hasValue();
58+
}
5759
}
5860
return false;
5961
}
6062

6163
void InstrumentManager::customize(const llvm::SmallVector<Instrument *> &IVec,
6264
InstrDesc &ID) const {
6365
for (const auto I : IVec) {
64-
if (I->canCustomize())
65-
I->customize(ID);
66+
if (I->getDesc() == LatencyInstrument::DESC_NAME) {
67+
auto LatInst = static_cast<LatencyInstrument*>(I);
68+
if (LatInst->hasValue()) {
69+
auto Latency = LatInst->getLatency();
70+
// TODO Allow to customize a subset of ID.Writes
71+
for (auto &W : ID.Writes)
72+
W.Latency = Latency;
73+
ID.MaxLatency = Latency;
74+
}
75+
}
6676
}
6777
}
6878

6979
UniqueInstrument InstrumentManager::createInstrument(llvm::StringRef Desc,
7080
llvm::StringRef Data) {
71-
if (!EnableInstruments)
72-
return std::make_unique<Instrument>(Desc, Data);
73-
if (Desc == LatencyInstrument::DESC_NAME)
74-
return std::make_unique<LatencyInstrument>(Data);
81+
if (EnableInstruments) {
82+
if (Desc == LatencyInstrument::DESC_NAME)
83+
return std::make_unique<LatencyInstrument>(Data);
84+
}
7585
return std::make_unique<Instrument>(Desc, Data);
7686
}
7787

llvm/tools/llvm-mca/llvm-mca.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,12 @@ int main(int argc, char **argv) {
516516
if (!IM) {
517517
// If the target doesn't have its own IM implemented we use base class
518518
// with instruments enabled.
519-
IM = std::make_unique<mca::InstrumentManager>(*STI, *MCII, true);
519+
IM = std::make_unique<mca::InstrumentManager>(*STI, *MCII);
520520
}
521521
} else {
522-
// If the -disable-cb flag is set then we use the default base class
523-
// implementation (which does nothing).
524-
IM = std::make_unique<mca::InstrumentManager>(*STI, *MCII);
522+
// If the -disable-im flag is set then we use the default base class
523+
// implementation and disable the instruments.
524+
IM = std::make_unique<mca::InstrumentManager>(*STI, *MCII, /*EnableInstruments=*/false);
525525
}
526526

527527
// Parse the input and create InstrumentRegion that llvm-mca

0 commit comments

Comments
 (0)