Skip to content

Commit 36687ca

Browse files
committed
Review feedback
1 parent 6c49bdd commit 36687ca

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

llvm/tools/llvm-mc/Disassembler.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "Disassembler.h"
15-
#include "llvm/ADT/Sequence.h"
1615
#include "llvm/ADT/StringExtras.h"
1716
#include "llvm/MC/MCAsmInfo.h"
1817
#include "llvm/MC/MCContext.h"
@@ -34,25 +33,29 @@ using namespace llvm;
3433
typedef std::pair<std::vector<unsigned char>, std::vector<const char *>>
3534
ByteArrayTy;
3635

36+
static MCDisassembler::DecodeStatus getInstruction(const MCDisassembler &DisAsm,
37+
const MCSubtargetInfo &STI,
38+
MCInst &Inst, uint64_t &Size,
39+
ArrayRef<uint8_t> Bytes,
40+
uint64_t Address) {
41+
if (STI.getTargetTriple().getArch() == Triple::hexagon)
42+
return DisAsm.getInstructionBundle(Inst, Size, Bytes, Address, nulls());
43+
return DisAsm.getInstruction(Inst, Size, Bytes, Address, nulls());
44+
}
45+
3746
static bool printInsts(const MCDisassembler &DisAsm, const ByteArrayTy &Bytes,
3847
SourceMgr &SM, MCStreamer &Streamer, bool InAtomicBlock,
39-
const MCSubtargetInfo &STI, unsigned BenchmarkNumRuns) {
48+
const MCSubtargetInfo &STI, unsigned NumBenchmarkRuns) {
4049
ArrayRef<uint8_t> Data(Bytes.first);
4150

4251
// Disassemble it to strings.
4352
uint64_t Size;
4453

4554
for (uint64_t Index = 0; Index < Bytes.first.size(); Index += Size) {
46-
auto getInstruction = [&](MCInst &Inst) -> MCDisassembler::DecodeStatus {
47-
if (STI.getTargetTriple().getArch() == Triple::hexagon)
48-
return DisAsm.getInstructionBundle(Inst, Size, Data.slice(Index), Index,
49-
nulls());
50-
return DisAsm.getInstruction(Inst, Size, Data.slice(Index), Index,
51-
nulls());
52-
};
5355

5456
MCInst Inst;
55-
MCDisassembler::DecodeStatus S = getInstruction(Inst);
57+
MCDisassembler::DecodeStatus S =
58+
getInstruction(DisAsm, STI, Inst, Size, Data.slice(Index), Index);
5659
switch (S) {
5760
case MCDisassembler::Fail:
5861
SM.PrintMessage(SMLoc::getFromPointer(Bytes.second[Index]),
@@ -78,23 +81,23 @@ static bool printInsts(const MCDisassembler &DisAsm, const ByteArrayTy &Bytes,
7881
break;
7982
}
8083

81-
if (S == MCDisassembler::Success && BenchmarkNumRuns != 0) {
84+
if (S == MCDisassembler::Success && NumBenchmarkRuns != 0) {
8285
// Benchmark mode, collect timing for decoding the instruction several
8386
// times.
8487
MCInst BMInst;
8588
TimeTraceScope timeScope("getInstruction");
86-
for (unsigned _ : llvm::seq<unsigned>(BenchmarkNumRuns)) {
89+
for (unsigned I = 0; I < NumBenchmarkRuns; ++I) {
8790
BMInst.clear();
8891
BMInst.setOpcode(0);
89-
S = getInstruction(BMInst);
92+
S = getInstruction(DisAsm, STI, BMInst, Size, Data.slice(Index), Index);
9093
}
9194
}
9295
}
9396

9497
return false;
9598
}
9699

97-
static bool skipToToken(StringRef &Str) {
100+
static bool SkipToToken(StringRef &Str) {
98101
for (;;) {
99102
if (Str.empty())
100103
return false;
@@ -116,7 +119,7 @@ static bool skipToToken(StringRef &Str) {
116119

117120
static bool byteArrayFromString(ByteArrayTy &ByteArray, StringRef &Str,
118121
SourceMgr &SM, bool HexBytes) {
119-
while (skipToToken(Str)) {
122+
while (SkipToToken(Str)) {
120123
// Handled by higher level
121124
if (Str[0] == '[' || Str[0] == ']')
122125
return false;
@@ -166,7 +169,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
166169
MCSubtargetInfo &STI, MCStreamer &Streamer,
167170
MemoryBuffer &Buffer, SourceMgr &SM,
168171
MCContext &Ctx, const MCTargetOptions &MCOptions,
169-
bool HexBytes, unsigned BenchmarkNumRuns) {
172+
bool HexBytes, unsigned NumBenchmarkRuns) {
170173
std::unique_ptr<const MCRegisterInfo> MRI(T.createMCRegInfo(Triple));
171174
if (!MRI) {
172175
errs() << "error: no register info for target " << Triple << "\n";
@@ -194,7 +197,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
194197
StringRef Str = Buffer.getBuffer();
195198
bool InAtomicBlock = false;
196199

197-
while (skipToToken(Str)) {
200+
while (SkipToToken(Str)) {
198201
ByteArray.first.clear();
199202
ByteArray.second.clear();
200203

@@ -223,7 +226,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
223226

224227
if (!ByteArray.first.empty())
225228
ErrorOccurred |= printInsts(*DisAsm, ByteArray, SM, Streamer,
226-
InAtomicBlock, STI, BenchmarkNumRuns);
229+
InAtomicBlock, STI, NumBenchmarkRuns);
227230
}
228231

229232
if (InAtomicBlock) {

llvm/tools/llvm-mc/Disassembler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Disassembler {
3333
MCSubtargetInfo &STI, MCStreamer &Streamer,
3434
MemoryBuffer &Buffer, SourceMgr &SM, MCContext &Ctx,
3535
const MCTargetOptions &MCOptions, bool HexBytes,
36-
unsigned BenchmarkNumRuns);
36+
unsigned NumBenchmarkRuns);
3737
};
3838

3939
} // namespace llvm

llvm/tools/llvm-mc/llvm-mc.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static cl::opt<ActionType> Action(
243243
cl::cat(MCCategory));
244244

245245
static cl::opt<unsigned>
246-
BenchmarkNumRuns("benchmark-num-runs",
246+
NumBenchmarkRuns("num-benchmark-runs",
247247
cl::desc("Number of runs for decoder benchmarking"),
248248
cl::cat(MCCategory));
249249

@@ -399,9 +399,7 @@ int main(int argc, char **argv) {
399399
if (!TimeTrace)
400400
return;
401401
if (auto E = timeTraceProfilerWrite(TimeTraceFile, OutputFilename)) {
402-
handleAllErrors(std::move(E), [&](const StringError &SE) {
403-
errs() << SE.getMessage() << "\n";
404-
});
402+
logAllUnhandledErrors(std::move(E), errs());
405403
return;
406404
}
407405
timeTraceProfilerCleanup();
@@ -639,7 +637,7 @@ int main(int argc, char **argv) {
639637
}
640638

641639
int Res = 1;
642-
bool Disassemble = false;
640+
bool disassemble = false;
643641
switch (Action) {
644642
case AC_AsLex:
645643
Res = AsLexInput(SrcMgr, *MAI, Out->os());
@@ -651,13 +649,13 @@ int main(int argc, char **argv) {
651649
case AC_MDisassemble:
652650
case AC_CDisassemble:
653651
case AC_Disassemble:
654-
Disassemble = true;
652+
disassemble = true;
655653
break;
656654
}
657-
if (Disassemble)
655+
if (disassemble)
658656
Res = Disassembler::disassemble(*TheTarget, TripleName, *STI, *Str, *Buffer,
659657
SrcMgr, Ctx, MCOptions, HexBytes,
660-
BenchmarkNumRuns);
658+
NumBenchmarkRuns);
661659

662660
// Keep output if no errors.
663661
if (Res == 0) {

0 commit comments

Comments
 (0)