Skip to content

Commit 8918f69

Browse files
wangpc-pptru
authored andcommitted
[RISCV] Support global address as inline asm memory operand of m
In D146245, we have supported lowering inline asm `m` with offset to `register+imm`, but we didn't handle the case that the offset is the low part of global address. This patch will emit `%lo(g)` when `g` is a global address. Fixes llvm#64656 Reviewed By: asb Differential Revision: https://reviews.llvm.org/D157839 (cherry picked from commit dc60003)
1 parent 8890f0f commit 8918f69

File tree

2 files changed

+522
-4
lines changed

2 files changed

+522
-4
lines changed

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,23 @@ bool RISCVAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
225225

226226
const MachineOperand &AddrReg = MI->getOperand(OpNo);
227227
assert(MI->getNumOperands() > OpNo + 1 && "Expected additional operand");
228-
const MachineOperand &DispImm = MI->getOperand(OpNo + 1);
228+
const MachineOperand &Offset = MI->getOperand(OpNo + 1);
229229
// All memory operands should have a register and an immediate operand (see
230230
// RISCVDAGToDAGISel::SelectInlineAsmMemoryOperand).
231231
if (!AddrReg.isReg())
232232
return true;
233-
if (!DispImm.isImm())
233+
if (!Offset.isImm() && !Offset.isGlobal())
234234
return true;
235235

236-
OS << DispImm.getImm() << "("
237-
<< RISCVInstPrinter::getRegisterName(AddrReg.getReg()) << ")";
236+
MCOperand MCO;
237+
if (!lowerOperand(Offset, MCO))
238+
return true;
239+
240+
if (Offset.isImm())
241+
OS << MCO.getImm();
242+
else if (Offset.isGlobal())
243+
OS << *MCO.getExpr();
244+
OS << "(" << RISCVInstPrinter::getRegisterName(AddrReg.getReg()) << ")";
238245
return false;
239246
}
240247

0 commit comments

Comments
 (0)