Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit f20ce37

Browse files
author
Hemant Kulkarni
committed
llvm-objdump: Add Hexagon printer changes for -S/-l options
Differential Revision: https://reviews.llvm.org/D23521 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279161 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 26b9220 commit f20ce37

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

include/llvm/Object/RelocVisitor.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ class RelocVisitor {
208208
HasError = true;
209209
return RelocToApply();
210210
}
211+
case Triple::hexagon:
212+
switch (RelocType) {
213+
case llvm::ELF::R_HEX_32:
214+
return visitELF_HEX_32(R, Value);
215+
default:
216+
HasError = true;
217+
return RelocToApply();
218+
}
211219
default:
212220
HasError = true;
213221
return RelocToApply();
@@ -411,6 +419,11 @@ class RelocVisitor {
411419
return RelocToApply(static_cast<uint32_t>(Res), 4);
412420
}
413421

422+
RelocToApply visitELF_HEX_32(RelocationRef R, uint64_t Value) {
423+
int64_t Addend = getELFAddend(R);
424+
return RelocToApply(Value + Addend, 4);
425+
}
426+
414427
RelocToApply visitELF_AMDGPU_ABS32(RelocationRef R, uint64_t Value) {
415428
int64_t Addend = getELFAddend(R);
416429
return RelocToApply(Value + Addend, 4);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int a = 1;
2+
int foo() {
3+
return a;
4+
}
5+
6+
int main() {
7+
int *b = &a;
8+
return *b + foo();
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import platform
2+
3+
if not 'Hexagon' in config.root.targets:
4+
config.unsupported = True
5+
6+
if platform.system() in ['Windows']:
7+
config.unsupported = True
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
; RUN: sed -e "s,SRC_COMPDIR,%p/Inputs,g" %s > %t.ll
2+
; RUN: llc -o %t.o -filetype=obj -mtriple=hexagon-unknown-elf %t.ll
3+
; RUN: llvm-objdump -d -l %t.o | FileCheck --check-prefix="LINES" %t.ll
4+
; RUN: llvm-objdump -d -S %t.o | FileCheck --check-prefix="SOURCE" %t.ll
5+
; ModuleID = 'source-interleave-hexagon.bc'
6+
source_filename = "source-interleave-hexagon.c"
7+
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
8+
target triple = "hexagon-unknown--elf"
9+
10+
@a = global i32 1, align 4
11+
12+
; Function Attrs: nounwind
13+
define i32 @foo() #0 !dbg !9 {
14+
entry:
15+
%0 = load i32, i32* @a, align 4, !dbg !12
16+
ret i32 %0, !dbg !13
17+
}
18+
19+
; Function Attrs: nounwind
20+
define i32 @main() #0 !dbg !14 {
21+
entry:
22+
%retval = alloca i32, align 4
23+
%b = alloca i32*, align 4
24+
store i32 0, i32* %retval, align 4
25+
call void @llvm.dbg.declare(metadata i32** %b, metadata !15, metadata !17), !dbg !18
26+
store i32* @a, i32** %b, align 4, !dbg !18
27+
%0 = load i32*, i32** %b, align 4, !dbg !19
28+
%1 = load i32, i32* %0, align 4, !dbg !20
29+
%call = call i32 @foo(), !dbg !21
30+
%add = add nsw i32 %1, %call, !dbg !22
31+
ret i32 %add, !dbg !23
32+
}
33+
34+
; Function Attrs: nounwind readnone
35+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
36+
37+
attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="hexagonv60" "target-features"="-hvx,-hvx-double" "unsafe-fp-math"="false" "use-soft-float"="false" }
38+
attributes #1 = { nounwind readnone }
39+
40+
!llvm.dbg.cu = !{!0}
41+
!llvm.module.flags = !{!6, !7}
42+
!llvm.ident = !{!8}
43+
44+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 (http://llvm.org/git/clang d19a95e94dc57c5a72fd25d64f26134aa7d25fa0) (http://llvm.org/git/llvm.git 313924e6ff8a332063f61d3fda03812c220762f6)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
45+
!1 = !DIFile(filename: "source-interleave-hexagon.c", directory: "SRC_COMPDIR")
46+
!2 = !{}
47+
!3 = !{!4}
48+
!4 = distinct !DIGlobalVariable(name: "a", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, variable: i32* @a)
49+
!5 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
50+
!6 = !{i32 2, !"Dwarf Version", i32 4}
51+
!7 = !{i32 2, !"Debug Info Version", i32 3}
52+
!8 = !{!"clang version 4.0.0 (http://llvm.org/git/clang d19a95e94dc57c5a72fd25d64f26134aa7d25fa0) (http://llvm.org/git/llvm.git 313924e6ff8a332063f61d3fda03812c220762f6)"}
53+
!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, variables: !2)
54+
!10 = !DISubroutineType(types: !11)
55+
!11 = !{!5}
56+
!12 = !DILocation(line: 3, column: 10, scope: !9)
57+
!13 = !DILocation(line: 3, column: 3, scope: !9)
58+
!14 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !10, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: false, unit: !0, variables: !2)
59+
!15 = !DILocalVariable(name: "b", scope: !14, file: !1, line: 7, type: !16)
60+
!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 32, align: 32)
61+
!17 = !DIExpression()
62+
!18 = !DILocation(line: 7, column: 8, scope: !14)
63+
!19 = !DILocation(line: 8, column: 11, scope: !14)
64+
!20 = !DILocation(line: 8, column: 10, scope: !14)
65+
!21 = !DILocation(line: 8, column: 15, scope: !14)
66+
!22 = !DILocation(line: 8, column: 13, scope: !14)
67+
!23 = !DILocation(line: 8, column: 3, scope: !14)
68+
; LINES: main:
69+
; LINES-NEXT: SRC_COMPDIR/source-interleave-hexagon.c:6
70+
71+
; SOURCE: main:
72+
; SOURCE-NEXT: int main() {

tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ class HexagonPrettyPrinter : public PrettyPrinter {
494494
void printInst(MCInstPrinter &IP, const MCInst *MI, ArrayRef<uint8_t> Bytes,
495495
uint64_t Address, raw_ostream &OS, StringRef Annot,
496496
MCSubtargetInfo const &STI, SourcePrinter *SP) override {
497+
if (SP && (PrintSource || PrintLines))
498+
SP->printSourceLine(OS, Address, "");
497499
if (!MI) {
498500
printLead(Bytes, Address, OS);
499501
OS << " <unknown>";
@@ -514,6 +516,8 @@ class HexagonPrettyPrinter : public PrettyPrinter {
514516
while(!HeadTail.first.empty()) {
515517
OS << Separator;
516518
Separator = "\n";
519+
if (SP && (PrintSource || PrintLines))
520+
SP->printSourceLine(OS, Address, "");
517521
printLead(Bytes, Address, OS);
518522
OS << Preamble;
519523
Preamble = " ";

0 commit comments

Comments
 (0)