[llvm] 9c75a98 - [SystemZ] Implement A, O and R inline assembly format flags (#80685)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 11:41:44 PST 2024
Author: Ilya Leoshkevich
Date: 2024-02-07T20:41:40+01:00
New Revision: 9c75a981554d5de4b909e6493f2c3dda03395aa2
URL: https://github.com/llvm/llvm-project/commit/9c75a981554d5de4b909e6493f2c3dda03395aa2
DIFF: https://github.com/llvm/llvm-project/commit/9c75a981554d5de4b909e6493f2c3dda03395aa2.diff
LOG: [SystemZ] Implement A, O and R inline assembly format flags (#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.
Added:
Modified:
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
llvm/test/CodeGen/SystemZ/asm-01.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index 243461c0316e53..81917706872676 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -889,14 +889,18 @@ static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
OS << '%' << RegName;
}
+static void printReg(unsigned Reg, const MCAsmInfo *MAI, raw_ostream &OS) {
+ if (!Reg)
+ OS << '0';
+ else
+ printFormattedRegName(MAI, Reg, OS);
+}
+
static void printOperand(const MCOperand &MCOp, const MCAsmInfo *MAI,
raw_ostream &OS) {
- if (MCOp.isReg()) {
- if (!MCOp.getReg())
- OS << '0';
- else
- printFormattedRegName(MAI, MCOp.getReg(), OS);
- } else if (MCOp.isImm())
+ if (MCOp.isReg())
+ printReg(MCOp.getReg(), MAI, OS);
+ else if (MCOp.isImm())
OS << MCOp.getImm();
else if (MCOp.isExpr())
MCOp.getExpr()->print(OS, MAI);
@@ -946,6 +950,21 @@ bool SystemZAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
unsigned OpNo,
const char *ExtraCode,
raw_ostream &OS) {
+ if (ExtraCode && ExtraCode[0] && !ExtraCode[1]) {
+ switch (ExtraCode[0]) {
+ case 'A':
+ // Unlike EmitMachineNode(), EmitSpecialNode(INLINEASM) does not call
+ // setMemRefs(), so MI->memoperands() is empty and the alignment
+ // information is not available.
+ return false;
+ case 'O':
+ OS << MI->getOperand(OpNo + 1).getImm();
+ return false;
+ case 'R':
+ ::printReg(MI->getOperand(OpNo).getReg(), MAI, OS);
+ return false;
+ }
+ }
printAddress(MAI, MI->getOperand(OpNo).getReg(),
MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()),
MI->getOperand(OpNo + 2).getReg(), OS);
diff --git a/llvm/test/CodeGen/SystemZ/asm-01.ll b/llvm/test/CodeGen/SystemZ/asm-01.ll
index 2c4613cacb07c5..28278d75b4e757 100644
--- a/llvm/test/CodeGen/SystemZ/asm-01.ll
+++ b/llvm/test/CodeGen/SystemZ/asm-01.ll
@@ -59,3 +59,14 @@ define void @f5(i64 %base, i64 %index) {
call void asm "blah $0", "=*Q" (ptr elementtype(i64) %addr)
ret void
}
+
+; Check A, O and R format flags.
+define void @f6(i64 %base) {
+; CHECK-LABEL: f6:
+; CHECK: blah 111,%r2
+; CHECK: br %r14
+ %add = add i64 %base, 111
+ %addr = inttoptr i64 %add to ptr
+ call void asm "blah ${0:O},${0:R}${0:A}", "=*Q" (ptr elementtype(i64) %addr)
+ ret void
+}
More information about the llvm-commits
mailing list