Skip to content

Commit 9c75a98

Browse files
authored
[SystemZ] Implement A, O and R inline assembly format flags (llvm#80685)
Implement the following assembly format flags, which are already supported by GCC: 'A': On z14 or higher: If operand is a mem print the alignment hint usable with vl/vst prefixed by a comma. 'O': print only the displacement of a memory reference or address. 'R': print only the base register of a memory reference or address. Implement 'A' conservatively, since the memory operand alignment information is not available for INLINEASM at the moment.
1 parent b89eb97 commit 9c75a98

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -889,14 +889,18 @@ static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
889889
OS << '%' << RegName;
890890
}
891891

892+
static void printReg(unsigned Reg, const MCAsmInfo *MAI, raw_ostream &OS) {
893+
if (!Reg)
894+
OS << '0';
895+
else
896+
printFormattedRegName(MAI, Reg, OS);
897+
}
898+
892899
static void printOperand(const MCOperand &MCOp, const MCAsmInfo *MAI,
893900
raw_ostream &OS) {
894-
if (MCOp.isReg()) {
895-
if (!MCOp.getReg())
896-
OS << '0';
897-
else
898-
printFormattedRegName(MAI, MCOp.getReg(), OS);
899-
} else if (MCOp.isImm())
901+
if (MCOp.isReg())
902+
printReg(MCOp.getReg(), MAI, OS);
903+
else if (MCOp.isImm())
900904
OS << MCOp.getImm();
901905
else if (MCOp.isExpr())
902906
MCOp.getExpr()->print(OS, MAI);
@@ -946,6 +950,21 @@ bool SystemZAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
946950
unsigned OpNo,
947951
const char *ExtraCode,
948952
raw_ostream &OS) {
953+
if (ExtraCode && ExtraCode[0] && !ExtraCode[1]) {
954+
switch (ExtraCode[0]) {
955+
case 'A':
956+
// Unlike EmitMachineNode(), EmitSpecialNode(INLINEASM) does not call
957+
// setMemRefs(), so MI->memoperands() is empty and the alignment
958+
// information is not available.
959+
return false;
960+
case 'O':
961+
OS << MI->getOperand(OpNo + 1).getImm();
962+
return false;
963+
case 'R':
964+
::printReg(MI->getOperand(OpNo).getReg(), MAI, OS);
965+
return false;
966+
}
967+
}
949968
printAddress(MAI, MI->getOperand(OpNo).getReg(),
950969
MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()),
951970
MI->getOperand(OpNo + 2).getReg(), OS);

llvm/test/CodeGen/SystemZ/asm-01.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,14 @@ define void @f5(i64 %base, i64 %index) {
5959
call void asm "blah $0", "=*Q" (ptr elementtype(i64) %addr)
6060
ret void
6161
}
62+
63+
; Check A, O and R format flags.
64+
define void @f6(i64 %base) {
65+
; CHECK-LABEL: f6:
66+
; CHECK: blah 111,%r2
67+
; CHECK: br %r14
68+
%add = add i64 %base, 111
69+
%addr = inttoptr i64 %add to ptr
70+
call void asm "blah ${0:O},${0:R}${0:A}", "=*Q" (ptr elementtype(i64) %addr)
71+
ret void
72+
}

0 commit comments

Comments
 (0)