Skip to content

Commit c588110

Browse files
committed
[ARM][Asm] Debug trace for the processInstruction loop
In the Arm assembly parser, we first match an instruction, then call processInstruction to possibly change it to a different encoding, to match rules in the architecture manual which can't be expressed by the table-generated matcher. This adds debug printing so that this process is visible when using the -debug option. To support this, I've added a new overload of MCInst::dump_pretty which takes the opcode name as a StringRef, since we don't have an InstPrinter instance in the assembly parser. Instead, we can get the same information directly from the MCInstrInfo. Differential revision: https://reviews.llvm.org/D54852 llvm-svn: 348113
1 parent 7502e5f commit c588110

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

llvm/include/llvm/MC/MCInst.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ class MCInst {
208208
/// string.
209209
void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer = nullptr,
210210
StringRef Separator = " ") const;
211+
void dump_pretty(raw_ostream &OS, StringRef Name,
212+
StringRef Separator = " ") const;
211213
};
212214

213215
inline raw_ostream& operator<<(raw_ostream &OS, const MCOperand &MO) {

llvm/lib/MC/MCInst.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,17 @@ void MCInst::print(raw_ostream &OS) const {
7272

7373
void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer,
7474
StringRef Separator) const {
75+
StringRef InstName = Printer ? Printer->getOpcodeName(getOpcode()) : "";
76+
dump_pretty(OS, InstName, Separator);
77+
}
78+
79+
void MCInst::dump_pretty(raw_ostream &OS, StringRef Name,
80+
StringRef Separator) const {
7581
OS << "<MCInst #" << getOpcode();
7682

77-
// Show the instruction opcode name if we have access to a printer.
78-
if (Printer)
79-
OS << ' ' << Printer->getOpcodeName(getOpcode());
83+
// Show the instruction opcode name if we have it.
84+
if (!Name.empty())
85+
OS << ' ' << Name;
8086

8187
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
8288
OS << Separator;

llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9310,6 +9310,10 @@ bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
93109310

93119311
switch (MatchResult) {
93129312
case Match_Success:
9313+
LLVM_DEBUG(dbgs() << "Parsed as: ";
9314+
Inst.dump_pretty(dbgs(), MII.getName(Inst.getOpcode()));
9315+
dbgs() << "\n");
9316+
93139317
// Context sensitive operand constraints aren't handled by the matcher,
93149318
// so check them here.
93159319
if (validateInstruction(Inst, Operands)) {
@@ -9327,7 +9331,9 @@ bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
93279331
// individual transformations can chain off each other. E.g.,
93289332
// tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
93299333
while (processInstruction(Inst, Operands, Out))
9330-
;
9334+
LLVM_DEBUG(dbgs() << "Changed to: ";
9335+
Inst.dump_pretty(dbgs(), MII.getName(Inst.getOpcode()));
9336+
dbgs() << "\n");
93319337

93329338
// Only after the instruction is fully processed, we can validate it
93339339
if (wasInITBlock && hasV8Ops() && isThumb() &&

0 commit comments

Comments
 (0)