[PATCH] D44851: [AArch64] Decorate AArch64 instrs with OPERAND_PCREL

Rafael Auler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 27 10:00:58 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL328638: [AArch64] Decorate AArch64 instrs with OPERAND_PCREL (authored by rafauler, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44851?vs=139664&id=139952#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44851

Files:
  llvm/trunk/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
  llvm/trunk/test/tools/llvm-objdump/AArch64/pc-rel-targets.test


Index: llvm/trunk/test/tools/llvm-objdump/AArch64/pc-rel-targets.test
===================================================================
--- llvm/trunk/test/tools/llvm-objdump/AArch64/pc-rel-targets.test
+++ llvm/trunk/test/tools/llvm-objdump/AArch64/pc-rel-targets.test
@@ -0,0 +1,3 @@
+// RUN: llvm-objdump -d %p/Inputs/kextbundle.macho-aarch64 | FileCheck %s
+
+CHECK:  4008:       03 00 00 94     bl      #12 <_bar.stub>
Index: llvm/trunk/lib/Target/AArch64/AArch64InstrFormats.td
===================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstrFormats.td
+++ llvm/trunk/lib/Target/AArch64/AArch64InstrFormats.td
@@ -1244,6 +1244,7 @@
   let DecoderMethod = "DecodePCRelLabel19";
   let PrintMethod = "printAlignedLabel";
   let ParserMatchClass = PCRelLabel19Operand;
+  let OperandType = "OPERAND_PCREL";
 }
 
 class BranchCond : I<(outs), (ins ccode:$cond, am_brcond:$target),
@@ -1299,6 +1300,7 @@
   let EncoderMethod = "getTestBranchTargetOpValue";
   let PrintMethod = "printAlignedLabel";
   let ParserMatchClass = BranchTarget14Operand;
+  let OperandType = "OPERAND_PCREL";
 }
 
 // AsmOperand classes to emit (or not) special diagnostics
@@ -1375,11 +1377,13 @@
   let EncoderMethod = "getBranchTargetOpValue";
   let PrintMethod = "printAlignedLabel";
   let ParserMatchClass = BranchTarget26Operand;
+  let OperandType = "OPERAND_PCREL";
 }
 def am_bl_target : Operand<i64> {
   let EncoderMethod = "getBranchTargetOpValue";
   let PrintMethod = "printAlignedLabel";
   let ParserMatchClass = BranchTarget26Operand;
+  let OperandType = "OPERAND_PCREL";
 }
 
 class BImm<bit op, dag iops, string asm, list<dag> pattern>
@@ -2667,6 +2671,7 @@
   let DecoderMethod = "DecodePCRelLabel19";
   let PrintMethod = "printAlignedLabel";
   let ParserMatchClass = PCRelLabel19Operand;
+  let OperandType = "OPERAND_PCREL";
 }
 
 let mayLoad = 1, mayStore = 0, hasSideEffects = 0 in
Index: llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
===================================================================
--- llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
+++ llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
@@ -131,8 +131,29 @@
                                       IncrementalLinkerCompatible);
 }
 
+namespace {
+
+class AArch64MCInstrAnalysis : public MCInstrAnalysis {
+public:
+  AArch64MCInstrAnalysis(const MCInstrInfo *Info) : MCInstrAnalysis(Info) {}
+
+  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
+                      uint64_t &Target) const override {
+    if (Inst.getNumOperands() == 0 ||
+        Info->get(Inst.getOpcode()).OpInfo[0].OperandType !=
+            MCOI::OPERAND_PCREL)
+      return false;
+
+    int64_t Imm = Inst.getOperand(0).getImm() * 4;
+    Target = Addr + Imm;
+    return true;
+  }
+};
+
+} // end anonymous namespace
+
 static MCInstrAnalysis *createAArch64InstrAnalysis(const MCInstrInfo *Info) {
-  return new MCInstrAnalysis(Info);
+  return new AArch64MCInstrAnalysis(Info);
 }
 
 // Force static initialization.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44851.139952.patch
Type: text/x-patch
Size: 3107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180327/a17213a8/attachment.bin>


More information about the llvm-commits mailing list