[llvm] [LoongArch] Support parsing register names in CFI instructions (PR #117120)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 20 23:12:28 PST 2024
https://github.com/wangleiat created https://github.com/llvm/llvm-project/pull/117120
None
>From 6299ec710d63771a0a6919b5fc02755b655960b4 Mon Sep 17 00:00:00 2001
From: wanglei <wanglei at loongson.cn>
Date: Thu, 21 Nov 2024 15:12:16 +0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.5-bogner
---
.../AsmParser/LoongArchAsmParser.cpp | 24 ++++++++++-
llvm/test/MC/LoongArch/Directives/cfi.s | 40 +++++++++++++------
2 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp b/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp
index 96eb8b1b0528ac..efc8b77f8d8fab 100644
--- a/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp
+++ b/llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp
@@ -669,13 +669,33 @@ static bool matchRegisterNameHelper(MCRegister &RegNo, StringRef Name) {
bool LoongArchAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
SMLoc &EndLoc) {
- return Error(getLoc(), "invalid register number");
+ if (!tryParseRegister(Reg, StartLoc, EndLoc).isSuccess())
+ return Error(getLoc(), "invalid register name");
+
+ if (!LoongArchMCRegisterClasses[LoongArch::GPRRegClassID].contains(Reg) &&
+ !LoongArchMCRegisterClasses[LoongArch::FPR32RegClassID].contains(Reg))
+ return Error(getLoc(), "invalid register name");
+
+ return false;
}
ParseStatus LoongArchAsmParser::tryParseRegister(MCRegister &Reg,
SMLoc &StartLoc,
SMLoc &EndLoc) {
- llvm_unreachable("Unimplemented function.");
+ const AsmToken &Tok = getParser().getTok();
+ StartLoc = Tok.getLoc();
+ EndLoc = Tok.getEndLoc();
+
+ parseOptionalToken(AsmToken::Dollar);
+ if (getLexer().getKind() != AsmToken::Identifier)
+ return ParseStatus::NoMatch;
+
+ StringRef Name = Tok.getIdentifier();
+ if (matchRegisterNameHelper(Reg, Name))
+ return ParseStatus::NoMatch;
+
+ getParser().Lex(); // Eat identifier token.
+ return ParseStatus::Success;
}
bool LoongArchAsmParser::classifySymbolRef(const MCExpr *Expr,
diff --git a/llvm/test/MC/LoongArch/Directives/cfi.s b/llvm/test/MC/LoongArch/Directives/cfi.s
index 7101fc90729067..978028dfd66e6d 100644
--- a/llvm/test/MC/LoongArch/Directives/cfi.s
+++ b/llvm/test/MC/LoongArch/Directives/cfi.s
@@ -1,10 +1,10 @@
## Test cfi directives.
-# RUN: llvm-mc %s --triple=loongarch32 | FileCheck %s
-# RUN: llvm-mc %s --triple=loongarch64 | FileCheck %s
-# RUN: not llvm-mc --triple=loongarch32 --defsym=ERR=1 < %s 2>&1 \
+# RUN: llvm-mc %s --triple=loongarch32 --mattr=+lasx | FileCheck %s
+# RUN: llvm-mc %s --triple=loongarch64 --mattr=+lasx | FileCheck %s
+# RUN: not llvm-mc --triple=loongarch32 --mattr=+lasx --defsym=ERR=1 < %s 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-ERR
-# RUN: not llvm-mc --triple=loongarch64 --defsym=ERR=1 < %s 2>&1 \
+# RUN: not llvm-mc --triple=loongarch64 --mattr=+lasx --defsym=ERR=1 < %s 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-ERR
# CHECK: .cfi_startproc
@@ -15,20 +15,36 @@
.cfi_offset 9, 8
# CHECK-NEXT: .cfi_offset 31, 16
.cfi_offset 31, 16
+# CHECK-NEXT: .cfi_offset 22, -8
+.cfi_offset r22, -8
+# CHECK-NEXT: .cfi_offset 22, -8
+.cfi_offset $r22, -8
+# CHECK-NEXT: .cfi_offset 22, -8
+.cfi_offset fp, -8
+# CHECK-NEXT: .cfi_offset 22, -8
+.cfi_offset $fp, -8
+# CHECK-NEXT: .cfi_offset 42, 8
+.cfi_offset f10, 8
+# CHECK-NEXT: .cfi_offset 56, 8
+.cfi_offset fs0, 8
# CHECK-NEXT: .cfi_endproc
.cfi_endproc
.ifdef ERR
.cfi_startproc
-# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number
+# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register name
.cfi_offset -22, -8
-# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number
-.cfi_offset fp, -8
-# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number
+# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register name
+.cfi_offset lr, -8
+# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register name
+.cfi_offset r32, -8
+# CHECK-ERR: :[[#@LINE+1]]:14: error: invalid register name
+.cfi_offset $r32, -8
+# CHECK-ERR: :[[#@LINE+1]]:14: error: invalid register name
.cfi_offset $22, -8
-# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number
-.cfi_offset $r22, -8
-# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number
-.cfi_offset $fp, -8
+# CHECK-ERR: :[[#@LINE+1]]:16: error: invalid register name
+.cfi_offset vr0, 8
+# CHECK-ERR: :[[#@LINE+1]]:16: error: invalid register name
+.cfi_offset xr0, 8
.cfi_endproc
.endif
More information about the llvm-commits
mailing list