[llvm] 73a1179 - [llvm-mc] Add -M to replace -riscv-no-aliases and -riscv-arch-reg-names
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed May 26 10:43:37 PDT 2021
Author: Fangrui Song
Date: 2021-05-26T10:43:32-07:00
New Revision: 73a117953599af58645d944e68076ec8fb052540
URL: https://github.com/llvm/llvm-project/commit/73a117953599af58645d944e68076ec8fb052540
DIFF: https://github.com/llvm/llvm-project/commit/73a117953599af58645d944e68076ec8fb052540.diff
LOG: [llvm-mc] Add -M to replace -riscv-no-aliases and -riscv-arch-reg-names
In objdump, many targets support `-M no-aliases`. Instead of having a
`-*-no-aliases` for each target when LLVM adds the support, it makes more sense
to introduce objdump style `-M`.
-riscv-arch-reg-names is removed. -riscv-no-aliases has too many uses and thus is retained for now.
Reviewed By: luismarques
Differential Revision: https://reviews.llvm.org/D103004
Added:
llvm/test/tools/llvm-mc/disassembler-options.test
Modified:
llvm/include/llvm/MC/MCInstPrinter.h
llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
llvm/test/MC/RISCV/numeric-reg-names-d.s
llvm/test/MC/RISCV/numeric-reg-names-f.s
llvm/test/MC/RISCV/numeric-reg-names.s
llvm/test/MC/RISCV/rvi-aliases-valid.s
llvm/tools/llvm-mc/llvm-mc.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCInstPrinter.h b/llvm/include/llvm/MC/MCInstPrinter.h
index 8b9ef178e33c1..93b6a4fb225a4 100644
--- a/llvm/include/llvm/MC/MCInstPrinter.h
+++ b/llvm/include/llvm/MC/MCInstPrinter.h
@@ -54,6 +54,9 @@ class MCInstPrinter {
/// True if we are printing marked up assembly.
bool UseMarkup = false;
+ /// True if we prefer aliases (e.g. nop) to raw mnemonics.
+ bool PrintAliases = true;
+
/// True if we are printing immediates as hex.
bool PrintImmHex = false;
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
index 5f8d6e1375187..d1979b5456ce2 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
@@ -39,11 +39,11 @@ static cl::opt<bool>
cl::desc("Disable the emission of assembler pseudo instructions"),
cl::init(false), cl::Hidden);
-static cl::opt<bool>
- ArchRegNames("riscv-arch-reg-names",
- cl::desc("Print architectural register names rather than the "
- "ABI names (such as x2 instead of sp)"),
- cl::init(false), cl::Hidden);
+// Print architectural register names rather than the ABI names (such as x2
+// instead of sp).
+// TODO: Make RISCVInstPrinter::getRegisterName non-static so that this can a
+// member.
+static bool ArchRegNames;
// The command-line flags above are used by llvm-mc and llc. They can be used by
// `llvm-objdump`, but we override their values here to handle options passed to
@@ -52,7 +52,7 @@ static cl::opt<bool>
// this way.
bool RISCVInstPrinter::applyTargetSpecificCLOption(StringRef Opt) {
if (Opt == "no-aliases") {
- NoAliases = true;
+ PrintAliases = false;
return true;
}
if (Opt == "numeric") {
@@ -69,11 +69,11 @@ void RISCVInstPrinter::printInst(const MCInst *MI, uint64_t Address,
bool Res = false;
const MCInst *NewMI = MI;
MCInst UncompressedMI;
- if (!NoAliases)
+ if (PrintAliases && !NoAliases)
Res = uncompressInst(UncompressedMI, *MI, MRI, STI);
if (Res)
NewMI = const_cast<MCInst *>(&UncompressedMI);
- if (NoAliases || !printAliasInstr(NewMI, Address, STI, O))
+ if (!PrintAliases || NoAliases || !printAliasInstr(NewMI, Address, STI, O))
printInstruction(NewMI, Address, STI, O);
printAnnotation(O, Annot);
}
diff --git a/llvm/test/MC/RISCV/numeric-reg-names-d.s b/llvm/test/MC/RISCV/numeric-reg-names-d.s
index 44bbb0ee46097..a212a50f9cd8c 100644
--- a/llvm/test/MC/RISCV/numeric-reg-names-d.s
+++ b/llvm/test/MC/RISCV/numeric-reg-names-d.s
@@ -1,4 +1,4 @@
-# RUN: llvm-mc -triple riscv32 -mattr=+f,+d < %s -riscv-arch-reg-names \
+# RUN: llvm-mc -triple riscv32 -mattr=+f,+d -M numeric < %s \
# RUN: | FileCheck -check-prefix=CHECK-NUMERIC %s
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f,+d < %s \
# RUN: | llvm-objdump --mattr=+f,+d -d -M numeric - \
diff --git a/llvm/test/MC/RISCV/numeric-reg-names-f.s b/llvm/test/MC/RISCV/numeric-reg-names-f.s
index 1bc984fdc3707..60867a4622043 100644
--- a/llvm/test/MC/RISCV/numeric-reg-names-f.s
+++ b/llvm/test/MC/RISCV/numeric-reg-names-f.s
@@ -1,4 +1,4 @@
-# RUN: llvm-mc -triple riscv32 -mattr=+f < %s -riscv-arch-reg-names \
+# RUN: llvm-mc -triple riscv32 -mattr=+f -M numeric < %s \
# RUN: | FileCheck -check-prefix=CHECK-NUMERIC %s
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \
# RUN: | llvm-objdump --mattr=+f -d -M numeric - \
diff --git a/llvm/test/MC/RISCV/numeric-reg-names.s b/llvm/test/MC/RISCV/numeric-reg-names.s
index e7a2d889d31b8..3ca2bf6006061 100644
--- a/llvm/test/MC/RISCV/numeric-reg-names.s
+++ b/llvm/test/MC/RISCV/numeric-reg-names.s
@@ -1,4 +1,4 @@
-# RUN: llvm-mc -triple riscv32 < %s -riscv-arch-reg-names \
+# RUN: llvm-mc -triple riscv32 -M numeric %s \
# RUN: | FileCheck -check-prefix=CHECK-NUMERIC %s
# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
# RUN: | llvm-objdump -d -M numeric - \
diff --git a/llvm/test/MC/RISCV/rvi-aliases-valid.s b/llvm/test/MC/RISCV/rvi-aliases-valid.s
index af5c08a8b581b..e6bb6fb5a2d47 100644
--- a/llvm/test/MC/RISCV/rvi-aliases-valid.s
+++ b/llvm/test/MC/RISCV/rvi-aliases-valid.s
@@ -1,8 +1,8 @@
-# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases \
+# RUN: llvm-mc %s -triple=riscv32 -M no-aliases \
# RUN: | FileCheck -check-prefixes=CHECK-S-NOALIAS,CHECK-S-OBJ-NOALIAS %s
# RUN: llvm-mc %s -triple=riscv32 \
# RUN: | FileCheck -check-prefixes=CHECK-S,CHECK-S-OBJ %s
-# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases\
+# RUN: llvm-mc %s -triple=riscv64 -M no-aliases \
# RUN: | FileCheck -check-prefixes=CHECK-S-NOALIAS,CHECK-S-OBJ-NOALIAS %s
# RUN: llvm-mc %s -triple=riscv64 \
# RUN: | FileCheck -check-prefixes=CHECK-S,CHECK-S-OBJ %s
diff --git a/llvm/test/tools/llvm-mc/disassembler-options.test b/llvm/test/tools/llvm-mc/disassembler-options.test
new file mode 100644
index 0000000000000..f9dc2eceac67c
--- /dev/null
+++ b/llvm/test/tools/llvm-mc/disassembler-options.test
@@ -0,0 +1,3 @@
+# RUN: not llvm-mc -M invalid /dev/null 2>&1 | FileCheck %s
+
+# CHECK: error: invalid disassembler option 'invalid'
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index 73a3a05c5a012..71940a7d0ae5a 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -46,6 +46,9 @@ static mc::RegisterMCTargetOptionsFlags MOF;
static cl::opt<std::string>
InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
+static cl::list<std::string>
+ DisassemblerOptions("M", cl::desc("Disassembler options"));
+
static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
cl::value_desc("filename"),
cl::init("-"));
@@ -496,6 +499,12 @@ int main(int argc, char **argv) {
return 1;
}
+ for (StringRef Opt : DisassemblerOptions)
+ if (!IP->applyTargetSpecificCLOption(Opt)) {
+ WithColor::error() << "invalid disassembler option '" << Opt << "'\n";
+ return 1;
+ }
+
// Set the display preference for hex vs. decimal immediates.
IP->setPrintImmHex(PrintImmHex);
More information about the llvm-commits
mailing list