summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/BPF
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2017-11-16 00:52:30 +0000
committerYonghong Song <yhs@fb.com>2017-11-16 00:52:30 +0000
commit4c3ce59e61fbda78503e7073ce9daa91a7287783 (patch)
tree4d376da08da98452cceefdb9b2daa55907d27ad5 /llvm/lib/Target/BPF
parent4f34614beb5d94ee11244d466411655e234f50a5 (diff)
downloadbcm5719-llvm-4c3ce59e61fbda78503e7073ce9daa91a7287783.tar.gz
bcm5719-llvm-4c3ce59e61fbda78503e7073ce9daa91a7287783.zip
bpf: enable llvm-objdump to print out symbolized jmp target
Add hook in BPF backend so that llvm-objdump can print out the jmp target with label names, e.g., ... if r1 != 2 goto 6 <LBB0_2> ... goto 7 <LBB0_4> ... LBB0_2: ... LBB0_4: ... Signed-off-by: Yonghong Song <yhs@fb.com> Acked-by: Alexei Starovoitov <ast@kernel.org> llvm-svn: 318358
Diffstat (limited to 'llvm/lib/Target/BPF')
-rw-r--r--llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp
index c8fbc0c2207..5c3bba6e669 100644
--- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp
+++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp
@@ -15,6 +15,7 @@
#include "BPF.h"
#include "InstPrinter/BPFInstPrinter.h"
#include "MCTargetDesc/BPFMCAsmInfo.h"
+#include "llvm/MC/MCInstrAnalysis.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
@@ -68,6 +69,35 @@ static MCInstPrinter *createBPFMCInstPrinter(const Triple &T,
return nullptr;
}
+namespace {
+
+class BPFMCInstrAnalysis : public MCInstrAnalysis {
+public:
+ explicit BPFMCInstrAnalysis(const MCInstrInfo *Info)
+ : MCInstrAnalysis(Info) {}
+
+ bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
+ uint64_t &Target) const override {
+ // The target is the 3rd operand of cond inst and the 1st of uncond inst.
+ int64_t Imm;
+ if (isConditionalBranch(Inst)) {
+ Imm = Inst.getOperand(2).getImm();
+ } else if (isUnconditionalBranch(Inst))
+ Imm = Inst.getOperand(0).getImm();
+ else
+ return false;
+
+ Target = Addr + Size + Imm * Size;
+ return true;
+ }
+};
+
+} // end anonymous namespace
+
+static MCInstrAnalysis *createBPFInstrAnalysis(const MCInstrInfo *Info) {
+ return new BPFMCInstrAnalysis(Info);
+}
+
extern "C" void LLVMInitializeBPFTargetMC() {
for (Target *T :
{&getTheBPFleTarget(), &getTheBPFbeTarget(), &getTheBPFTarget()}) {
@@ -89,6 +119,9 @@ extern "C" void LLVMInitializeBPFTargetMC() {
// Register the MCInstPrinter.
TargetRegistry::RegisterMCInstPrinter(*T, createBPFMCInstPrinter);
+
+ // Register the MC instruction analyzer.
+ TargetRegistry::RegisterMCInstrAnalysis(*T, createBPFInstrAnalysis);
}
// Register the MC code emitter
@@ -114,4 +147,5 @@ extern "C" void LLVMInitializeBPFTargetMC() {
TargetRegistry::RegisterMCAsmBackend(getTheBPFTarget(),
createBPFbeAsmBackend);
}
+
}
OpenPOWER on IntegriCloud