Skip to content

Commit 043c5ea

Browse files
committed
[RISCV] Handle globals and block addresses in asm operands
Summary: These seem to be the machine operand types currently needed by the RISC-V target. Reviewers: asb, lenary Reviewed By: lenary Tags: #llvm Differential Revision: https://reviews.llvm.org/D72275
1 parent b11027a commit 043c5ea

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ bool RISCVAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
121121
case MachineOperand::MO_Register:
122122
OS << RISCVInstPrinter::getRegisterName(MO.getReg());
123123
return false;
124+
case MachineOperand::MO_GlobalAddress:
125+
PrintSymbolOperand(MO, OS);
126+
return false;
127+
case MachineOperand::MO_BlockAddress: {
128+
MCSymbol *Sym = GetBlockAddressSymbol(MO.getBlockAddress());
129+
Sym->print(OS, MAI);
130+
return false;
131+
}
124132
default:
125133
break;
126134
}

llvm/test/CodeGen/RISCV/inline-asm.ll

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ define i32 @constraint_m2(i32* %a) nounwind {
7878
; RV64I-NEXT: lw a0, 0(a0)
7979
; RV64I-NEXT: #NO_APP
8080
; RV64I-NEXT: ret
81-
%1 = tail call i32 asm "lw $0, $1", "=r,*m"(i32* %a) nounwind
81+
%1 = tail call i32 asm "lw $0, $1", "=r,*m"(i32* %a)
8282
ret i32 %1
8383
}
8484

@@ -249,4 +249,46 @@ define i32 @modifier_i_reg(i32 %a, i32 %b) nounwind {
249249
ret i32 %1
250250
}
251251

252-
; TODO: expend tests for more complex constraints, out of range immediates etc
252+
define void @operand_global() nounwind {
253+
; RV32I-LABEL: operand_global:
254+
; RV32I: # %bb.0:
255+
; RV32I-NEXT: #APP
256+
; RV32I-NEXT: .8byte gi
257+
; RV32I-NEXT: #NO_APP
258+
; RV32I-NEXT: ret
259+
;
260+
; RV64I-LABEL: operand_global:
261+
; RV64I: # %bb.0:
262+
; RV64I-NEXT: #APP
263+
; RV64I-NEXT: .8byte gi
264+
; RV64I-NEXT: #NO_APP
265+
; RV64I-NEXT: ret
266+
tail call void asm sideeffect ".8byte $0", "i"(i32* @gi)
267+
ret void
268+
}
269+
270+
define void @operand_block_address() nounwind {
271+
; RV32I-LABEL: operand_block_address:
272+
; RV32I: # %bb.0:
273+
; RV32I-NEXT: #APP
274+
; RV32I-NEXT: j .Ltmp0
275+
; RV32I-NEXT: #NO_APP
276+
; RV32I-NEXT: .Ltmp0: # Block address taken
277+
; RV32I-NEXT: # %bb.1: # %bb
278+
; RV32I-NEXT: ret
279+
;
280+
; RV64I-LABEL: operand_block_address:
281+
; RV64I: # %bb.0:
282+
; RV64I-NEXT: #APP
283+
; RV64I-NEXT: j .Ltmp0
284+
; RV64I-NEXT: #NO_APP
285+
; RV64I-NEXT: .Ltmp0: # Block address taken
286+
; RV64I-NEXT: # %bb.1: # %bb
287+
; RV64I-NEXT: ret
288+
call void asm sideeffect "j $0", "i"(i8* blockaddress(@operand_block_address, %bb))
289+
br label %bb
290+
bb:
291+
ret void
292+
}
293+
294+
; TODO: expand tests for more complex constraints, out of range immediates etc

0 commit comments

Comments
 (0)