Skip to content

Commit

Permalink
[Xtensa] Fix inline asm
Browse files Browse the repository at this point in the history
Fix inline asm printing of the
memory operands.
  • Loading branch information
andreisfr committed May 11, 2022
1 parent 38679f0 commit ee16f02
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
9 changes: 0 additions & 9 deletions llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ using namespace llvm;

#include "XtensaGenAsmWriter.inc"

void XtensaInstPrinter::printAddress(unsigned Base, int64_t Disp,
raw_ostream &O) {
O << Disp;
if (Base) {
O << '(';
O << getRegisterName(Base) << ')';
}
}

static void printExpr(const MCExpr *Expr, raw_ostream &OS) {
int Offset = 0;
const MCSymbolRefExpr *SRE;
Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class XtensaInstPrinter : public MCInstPrinter {
// Print the given operand.
static void printOperand(const MCOperand &MO, raw_ostream &O);

// Print an address
static void printAddress(unsigned Base, int64_t Disp, raw_ostream &O);

// Override MCInstPrinter.
void printRegName(raw_ostream &O, unsigned RegNo) const override;
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
Expand Down
27 changes: 16 additions & 11 deletions llvm/lib/Target/Xtensa/XtensaAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,23 @@ bool XtensaAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
unsigned OpNo,
const char *ExtraCode,
raw_ostream &OS) {
XtensaInstPrinter::printAddress(MI->getOperand(OpNo).getReg(),
MI->getOperand(OpNo + 1).getImm(), OS);
return false;
}
if (ExtraCode && ExtraCode[0])
return true; // Unknown modifier.

assert(OpNo + 1 < MI->getNumOperands() && "Insufficient operands");

const MachineOperand &Base = MI->getOperand(OpNo);
const MachineOperand &Offset = MI->getOperand(OpNo + 1);

void XtensaAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
raw_ostream &OS) {
OS << '%'
<< XtensaInstPrinter::getRegisterName(MI->getOperand(opNum).getReg());
OS << "(";
OS << MI->getOperand(opNum + 1).getImm();
OS << ")";
assert(Base.isReg() &&
"Unexpected base pointer for inline asm memory operand.");
assert(Offset.isImm() && "Unexpected offset for inline asm memory operand.");

OS << XtensaInstPrinter::getRegisterName(Base.getReg());
OS << ", ";
OS << Offset.getImm();

return false;
}

// Force static initialization.
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/Xtensa/XtensaAsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class LLVM_LIBRARY_VISIBILITY XtensaAsmPrinter : public AsmPrinter {
const char *ExtraCode, raw_ostream &O) override;
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
const char *ExtraCode, raw_ostream &OS) override;
void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &OS);
};
} // end namespace llvm

Expand Down
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/Xtensa/inline-asm.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: llc -mtriple=xtensa -mcpu=esp32 -verify-machineinstrs < %s \
; RUN: | FileCheck -check-prefix=Xtensa %s


define dso_local i32 @test_memptr(i32 noundef %0) local_unnamed_addr #0 {
; Xtensa-LABEL: test_memptr:
; Xtensa: # %bb.0:
; Xtensa-NEXT: entry a1, 32
; Xtensa-NEXT: #APP
; Xtensa-NEXT: l32i a2, a2, 0
; Xtensa-NEXT: #NO_APP
; Xtensa-NEXT: retw
%2 = inttoptr i32 %0 to i32*
%3 = call i32 asm sideeffect "l32i $0, $1", "=r,*m"(i32* elementtype(i32) %2)
ret i32 %3
}

attributes #0 = { nounwind }
attributes #1 = { nounwind }

0 comments on commit ee16f02

Please sign in to comment.