Skip to content

Commit 7e90de7

Browse files
authored
Addressed minor comments
1 parent e28c48c commit 7e90de7

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

llvm/include/llvm/MCA/CustomBehaviour.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,19 @@ class LatencyInstrument : public Instrument {
138138
std::optional<unsigned> Latency;
139139

140140
public:
141-
static const llvm::StringRef DESC_NAME;
141+
static const StringRef DESC_NAME;
142142
LatencyInstrument(StringRef Data) : Instrument(DESC_NAME, Data) {
143143
// Skip spaces and tabs.
144-
unsigned Position = Data.find_first_not_of(" \t");
145-
if (Position >= Data.size())
146-
// We reached the end of the comment. Bail out.
144+
Data = Data.trim();
145+
if (Data.empty()) // Empty description. Bail out.
147146
return;
148-
Data = Data.drop_front(Position);
149147
unsigned L = 0;
150148
if (!Data.getAsInteger(10, L))
151149
Latency = L;
152150
}
153151

154152
bool hasValue() const { return bool(Latency); }
155-
unsigned getLatency() { return *Latency; }
153+
unsigned getLatency() const { return *Latency; }
156154
};
157155

158156
using UniqueInstrument = std::unique_ptr<Instrument>;
@@ -200,10 +198,10 @@ class LLVM_ABI InstrumentManager {
200198
const SmallVector<Instrument *> &IVec) const;
201199

202200
// Return true if instruments can modify instruction description
203-
virtual bool canCustomize(const SmallVector<Instrument *> &IVec) const;
201+
virtual bool canCustomize(const ArrayRef<Instrument *> IVec) const;
204202

205203
// Customize instruction description
206-
virtual void customize(const SmallVector<Instrument *> &IVec,
204+
virtual void customize(const ArrayRef<Instrument *> IVec,
207205
llvm::mca::InstrDesc &Desc) const;
208206
};
209207

llvm/lib/MCA/CustomBehaviour.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool InstrumentManager::supportsInstrumentType(StringRef Type) const {
5050
}
5151

5252
bool InstrumentManager::canCustomize(
53-
const llvm::SmallVector<Instrument *> &IVec) const {
53+
const ArrayRef<Instrument *> IVec) const {
5454
for (const auto I : IVec) {
5555
if (I->getDesc() == LatencyInstrument::DESC_NAME) {
5656
auto LatInst = static_cast<LatencyInstrument *>(I);
@@ -60,13 +60,13 @@ bool InstrumentManager::canCustomize(
6060
return false;
6161
}
6262

63-
void InstrumentManager::customize(const llvm::SmallVector<Instrument *> &IVec,
63+
void InstrumentManager::customize(const ArrayRef<Instrument *> IVec,
6464
InstrDesc &ID) const {
6565
for (const auto I : IVec) {
6666
if (I->getDesc() == LatencyInstrument::DESC_NAME) {
6767
auto LatInst = static_cast<LatencyInstrument *>(I);
6868
if (LatInst->hasValue()) {
69-
auto Latency = LatInst->getLatency();
69+
unsigned Latency = LatInst->getLatency();
7070
// TODO Allow to customize a subset of ID.Writes
7171
for (auto &W : ID.Writes)
7272
W.Latency = Latency;
@@ -76,8 +76,8 @@ void InstrumentManager::customize(const llvm::SmallVector<Instrument *> &IVec,
7676
}
7777
}
7878

79-
UniqueInstrument InstrumentManager::createInstrument(llvm::StringRef Desc,
80-
llvm::StringRef Data) {
79+
UniqueInstrument InstrumentManager::createInstrument(StringRef Desc,
80+
StringRef Data) {
8181
if (EnableInstruments) {
8282
if (Desc == LatencyInstrument::DESC_NAME)
8383
return std::make_unique<LatencyInstrument>(Data);

llvm/unittests/tools/llvm-mca/MCATestBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void MCATestBase::SetUp() {
6060
Error MCATestBase::runBaselineMCA(
6161
json::Object &Result, ArrayRef<MCInst> Insts, ArrayRef<mca::View *> Views,
6262
const mca::PipelineOptions *PO,
63-
SmallVector<std::pair<StringRef, StringRef>> Descs) {
63+
ArrayRef<std::pair<StringRef, StringRef>> Descs) {
6464
mca::Context MCA(*MRI, *STI);
6565

6666
// Enable instruments when descriptions are provided

llvm/unittests/tools/llvm-mca/MCATestBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class MCATestBase : public ::testing::Test {
7878
runBaselineMCA(json::Object &Result, ArrayRef<MCInst> Insts,
7979
ArrayRef<mca::View *> Views = {},
8080
const mca::PipelineOptions *PO = nullptr,
81-
SmallVector<std::pair<StringRef, StringRef>> Descs = {});
81+
ArrayRef<std::pair<StringRef, StringRef>> Descs = {});
8282
};
8383

8484
} // end namespace mca

llvm/unittests/tools/llvm-mca/X86/TestIncrementalMCA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ TEST_F(X86TestBase, TestInstructionCustomization) {
246246
MCIs.push_back(InstructionToAdd);
247247
SmallVector<std::pair<StringRef, StringRef>> InstrDescs;
248248
auto LatStr = std::to_string(ExplicitLatency);
249-
InstrDescs.push_back(std::make_pair(StringRef("LATENCY"), StringRef(LatStr)));
249+
InstrDescs.push_back(std::make_pair("LATENCY", LatStr));
250250

251251
// Run the baseline.
252252
json::Object BaselineResult;

0 commit comments

Comments
 (0)