Skip to content

Commit dc60003

Browse files
committed
[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
1 parent a3b11ce commit dc60003

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
@@ -232,16 +232,23 @@ bool RISCVAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
232232

233233
const MachineOperand &AddrReg = MI->getOperand(OpNo);
234234
assert(MI->getNumOperands() > OpNo + 1 && "Expected additional operand");
235-
const MachineOperand &DispImm = MI->getOperand(OpNo + 1);
235+
const MachineOperand &Offset = MI->getOperand(OpNo + 1);
236236
// All memory operands should have a register and an immediate operand (see
237237
// RISCVDAGToDAGISel::SelectInlineAsmMemoryOperand).
238238
if (!AddrReg.isReg())
239239
return true;
240-
if (!DispImm.isImm())
240+
if (!Offset.isImm() && !Offset.isGlobal())
241241
return true;
242242

243-
OS << DispImm.getImm() << "("
244-
<< RISCVInstPrinter::getRegisterName(AddrReg.getReg()) << ")";
243+
MCOperand MCO;
244+
if (!lowerOperand(Offset, MCO))
245+
return true;
246+
247+
if (Offset.isImm())
248+
OS << MCO.getImm();
249+
else if (Offset.isGlobal())
250+
OS << *MCO.getExpr();
251+
OS << "(" << RISCVInstPrinter::getRegisterName(AddrReg.getReg()) << ")";
245252
return false;
246253
}
247254

0 commit comments

Comments
 (0)