-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0084-Xtensa-Fix-inline-asm.patch
130 lines (121 loc) · 4.95 KB
/
0084-Xtensa-Fix-inline-asm.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
From cc39d8990839e198b76fafae4616b56586500719 Mon Sep 17 00:00:00 2001
From: Andrei Safronov <safronov@espressif.com>
Date: Wed, 5 Apr 2023 00:59:20 +0300
Subject: [PATCH 084/158] [Xtensa] Fix inline asm
Fix inline asm printing of the
memory operands.
---
.../Xtensa/MCTargetDesc/XtensaInstPrinter.cpp | 9 -------
.../Xtensa/MCTargetDesc/XtensaInstPrinter.h | 3 ---
llvm/lib/Target/Xtensa/XtensaAsmPrinter.cpp | 27 +++++++++++--------
llvm/lib/Target/Xtensa/XtensaAsmPrinter.h | 1 -
llvm/test/CodeGen/Xtensa/inline-asm.ll | 20 ++++++++++++++
5 files changed, 36 insertions(+), 24 deletions(-)
create mode 100644 llvm/test/CodeGen/Xtensa/inline-asm.ll
diff --git a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp
index 0960c73dba93..0a0d298ad267 100644
--- a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp
+++ b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp
@@ -27,15 +27,6 @@ using namespace llvm;
#include "XtensaGenAsmWriter.inc"
-void XtensaInstPrinter::printAddress(unsigned Base, int64_t Disp,
- raw_ostream &O) {
- O << Disp;
- if (Base) {
- O << '(';
- O << getRegisterName(Base) << ')';
- }
-}
-
static void printExpr(const MCExpr *Expr, raw_ostream &OS) {
int Offset = 0;
const MCSymbolRefExpr *SRE;
diff --git a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.h b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.h
index b103fb5dc9e0..3e8c752bc442 100644
--- a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.h
+++ b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.h
@@ -35,9 +35,6 @@ public:
// Print the given operand.
static void printOperand(const MCOperand &MO, raw_ostream &O);
- // Print an address
- static void printAddress(unsigned Base, int64_t Disp, raw_ostream &O);
-
// Override MCInstPrinter.
void printRegName(raw_ostream &O, MCRegister Reg) const override;
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
diff --git a/llvm/lib/Target/Xtensa/XtensaAsmPrinter.cpp b/llvm/lib/Target/Xtensa/XtensaAsmPrinter.cpp
index 9c483a68f358..18f87c250a33 100644
--- a/llvm/lib/Target/Xtensa/XtensaAsmPrinter.cpp
+++ b/llvm/lib/Target/Xtensa/XtensaAsmPrinter.cpp
@@ -259,18 +259,23 @@ bool XtensaAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
unsigned OpNo,
const char *ExtraCode,
raw_ostream &OS) {
- XtensaInstPrinter::printAddress(MI->getOperand(OpNo).getReg(),
- MI->getOperand(OpNo + 1).getImm(), OS);
- return false;
-}
+ if (ExtraCode && ExtraCode[0])
+ return true; // Unknown modifier.
+
+ assert(OpNo + 1 < MI->getNumOperands() && "Insufficient operands");
+
+ const MachineOperand &Base = MI->getOperand(OpNo);
+ const MachineOperand &Offset = MI->getOperand(OpNo + 1);
-void XtensaAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
- raw_ostream &OS) {
- OS << '%'
- << XtensaInstPrinter::getRegisterName(MI->getOperand(opNum).getReg());
- OS << "(";
- OS << MI->getOperand(opNum + 1).getImm();
- OS << ")";
+ assert(Base.isReg() &&
+ "Unexpected base pointer for inline asm memory operand.");
+ assert(Offset.isImm() && "Unexpected offset for inline asm memory operand.");
+
+ OS << XtensaInstPrinter::getRegisterName(Base.getReg());
+ OS << ", ";
+ OS << Offset.getImm();
+
+ return false;
}
// Force static initialization.
diff --git a/llvm/lib/Target/Xtensa/XtensaAsmPrinter.h b/llvm/lib/Target/Xtensa/XtensaAsmPrinter.h
index 50feaa0fcd2c..e17059a2d4c3 100644
--- a/llvm/lib/Target/Xtensa/XtensaAsmPrinter.h
+++ b/llvm/lib/Target/Xtensa/XtensaAsmPrinter.h
@@ -43,7 +43,6 @@ public:
const char *ExtraCode, raw_ostream &O) override;
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
const char *ExtraCode, raw_ostream &OS) override;
- void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &OS);
};
} // end namespace llvm
diff --git a/llvm/test/CodeGen/Xtensa/inline-asm.ll b/llvm/test/CodeGen/Xtensa/inline-asm.ll
new file mode 100644
index 000000000000..7a267d514598
--- /dev/null
+++ b/llvm/test/CodeGen/Xtensa/inline-asm.ll
@@ -0,0 +1,20 @@
+; RUN: llc -mtriple=xtensa -mcpu=esp32 -verify-machineinstrs < %s \
+; RUN: | FileCheck -check-prefix=Xtensa %s
+
+
+define dso_local i32 @test_memptr(i32 noundef %0) local_unnamed_addr #0 {
+; Xtensa-LABEL: test_memptr:
+; Xtensa: # %bb.0:
+; Xtensa-NEXT: entry a1, 32
+; Xtensa-NEXT: #APP
+; Xtensa-NEXT: l32i a2, a2, 0
+; Xtensa-NEXT: #NO_APP
+; Xtensa-NEXT: retw
+ %2 = inttoptr i32 %0 to i32*
+ %3 = call i32 asm sideeffect "l32i $0, $1", "=r,*m"(i32* elementtype(i32) %2)
+ ret i32 %3
+}
+
+attributes #0 = { nounwind }
+attributes #1 = { nounwind }
+
--
2.40.1