[llvm] 231bfaa - [Lanai] fix MC / objdump

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 03:46:22 PDT 2021


Author: Serge Bazanski
Date: 2021-09-10T10:46:13Z
New Revision: 231bfaab31a91ee956312a7c730b41da376fa322

URL: https://github.com/llvm/llvm-project/commit/231bfaab31a91ee956312a7c730b41da376fa322
DIFF: https://github.com/llvm/llvm-project/commit/231bfaab31a91ee956312a7c730b41da376fa322.diff

LOG: [Lanai] fix MC / objdump

D78776 removed is{Call,Branch,UnconditionalBranch} guards in objdump
before calling MCInstrAnalysis::evaluateBranch. This is fine for other
architectures as they gracefully handle evaluateBranch being called on
non-branches. However, the Lanai MCInstrAnalysis implementation didn't
and that change caused it to crash.

This inserts the same guards back into Lanai's evaluateBranch
implementation and adds a smoke test that exercises `llc | objdump` so
this kind of regression is hopefully caught next time.

Reviewed By: jpienaar, MaskRay

Differential Revision: https://reviews.llvm.org/D107593

Added: 
    llvm/test/tools/llvm-objdump/ELF/Lanai/lit.local.cfg
    llvm/test/tools/llvm-objdump/ELF/Lanai/smoke.ll

Modified: 
    llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp
index e850b98de8060..97f1b13ed360a 100644
--- a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp
+++ b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp
@@ -97,6 +97,9 @@ class LanaiMCInstrAnalysis : public MCInstrAnalysis {
                       uint64_t &Target) const override {
     if (Inst.getNumOperands() == 0)
       return false;
+    if (!isConditionalBranch(Inst) && !isUnconditionalBranch(Inst) &&
+        !isCall(Inst))
+      return false;
 
     if (Info->get(Inst.getOpcode()).OpInfo[0].OperandType ==
         MCOI::OPERAND_PCREL) {

diff  --git a/llvm/test/tools/llvm-objdump/ELF/Lanai/lit.local.cfg b/llvm/test/tools/llvm-objdump/ELF/Lanai/lit.local.cfg
new file mode 100644
index 0000000000000..2e12e267e0ac0
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/ELF/Lanai/lit.local.cfg
@@ -0,0 +1,4 @@
+import platform
+
+if not 'Lanai' in config.root.targets:
+    config.unsupported = True

diff  --git a/llvm/test/tools/llvm-objdump/ELF/Lanai/smoke.ll b/llvm/test/tools/llvm-objdump/ELF/Lanai/smoke.ll
new file mode 100644
index 0000000000000..753151449f258
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/ELF/Lanai/smoke.ll
@@ -0,0 +1,13 @@
+; RUN: llc -o %t.bc -filetype=obj -mtriple=lanai %s
+; RUN: llvm-objdump -d -S %t.bc | FileCheck %s
+
+;; Ensure that Lanai can be compiled using llc and then objdumped to
+;; assembly. This is a smoke test to exercise the basics of the MC
+;; implementation in Lanai.
+
+; CHECK-LABEL: smoketest
+; CHECK: st %fp, [--%sp]
+define i32 @smoketest(i32 %x, i32 %y)  {
+  %z = add i32 %x, %y
+  ret i32 %z
+}


        


More information about the llvm-commits mailing list