Last active
August 17, 2018 13:52
-
-
Save rschatz/5fd3a3a19512e4ba19b78cb5a88b5c5d to your computer and use it in GitHub Desktop.
small sample C++ program compiled to bitcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compile with `clang++ -stdlib=libc++ -emit-llvm -c -O1 -g test.cc -I <path-to-polyglot-h>` | |
// disassemble with `llvm-dis test.bc` | |
#include <polyglot.h> | |
class Test { | |
public: | |
Test(); | |
~Test(); | |
static void foo(); | |
}; | |
POLYGLOT_DECLARE_TYPE(Test); | |
Test::Test() { | |
} | |
Test::~Test() { | |
} | |
void Test::foo() { | |
} | |
polyglot_typeid getTestClass() { | |
return polyglot_Test_typeid(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ModuleID = 'test.cc' | |
source_filename = "test.cc" | |
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | |
target triple = "x86_64-pc-linux-gnu" | |
%class.Test = type { i8 } | |
%struct.__polyglot_typeid = type opaque | |
@_ZZL20polyglot_Test_typeidvE22__polyglot_typeid_Test = internal global [0 x %class.Test] zeroinitializer, align 1, !dbg !0 | |
@_ZGVZL20polyglot_Test_typeidvE22__polyglot_typeid_Test = internal global i64 0, align 8 | |
@_ZN4TestC1Ev = alias void (%class.Test*), void (%class.Test*)* @_ZN4TestC2Ev | |
@_ZN4TestD1Ev = alias void (%class.Test*), void (%class.Test*)* @_ZN4TestD2Ev | |
; Function Attrs: nounwind readnone sspstrong uwtable | |
define void @_ZN4TestC2Ev(%class.Test* nocapture) unnamed_addr #0 align 2 !dbg !32 { | |
call void @llvm.dbg.value(metadata %class.Test* %0, metadata !34, metadata !DIExpression()), !dbg !36 | |
ret void, !dbg !37 | |
} | |
; Function Attrs: nounwind readnone sspstrong uwtable | |
define void @_ZN4TestD2Ev(%class.Test* nocapture) unnamed_addr #0 align 2 !dbg !38 { | |
call void @llvm.dbg.value(metadata %class.Test* %0, metadata !40, metadata !DIExpression()), !dbg !41 | |
ret void, !dbg !42 | |
} | |
; Function Attrs: norecurse nounwind readnone sspstrong uwtable | |
define void @_ZN4Test3fooEv() local_unnamed_addr #1 align 2 !dbg !43 { | |
ret void, !dbg !44 | |
} | |
; Function Attrs: sspstrong uwtable | |
define %struct.__polyglot_typeid* @_Z12getTestClassv() local_unnamed_addr #2 !dbg !45 { | |
%1 = load atomic i8, i8* bitcast (i64* @_ZGVZL20polyglot_Test_typeidvE22__polyglot_typeid_Test to i8*) acquire, align 8, !dbg !46 | |
%2 = icmp eq i8 %1, 0, !dbg !46 | |
br i1 %2, label %3, label %7, !dbg !46, !prof !48 | |
; <label>:3: ; preds = %0 | |
%4 = tail call i32 @__cxa_guard_acquire(i64* nonnull @_ZGVZL20polyglot_Test_typeidvE22__polyglot_typeid_Test) #3, !dbg !46 | |
%5 = icmp eq i32 %4, 0, !dbg !46 | |
br i1 %5, label %7, label %6, !dbg !46 | |
; <label>:6: ; preds = %3 | |
tail call void @__cxa_guard_release(i64* nonnull @_ZGVZL20polyglot_Test_typeidvE22__polyglot_typeid_Test) #3, !dbg !46 | |
br label %7, !dbg !46 | |
; <label>:7: ; preds = %0, %3, %6 | |
%8 = tail call %struct.__polyglot_typeid* @__polyglot_as_typeid(i8* getelementptr inbounds ([0 x %class.Test], [0 x %class.Test]* @_ZZL20polyglot_Test_typeidvE22__polyglot_typeid_Test, i64 0, i64 0, i32 0)), !dbg !46 | |
ret %struct.__polyglot_typeid* %8, !dbg !49 | |
} | |
; Function Attrs: nounwind | |
declare i32 @__cxa_guard_acquire(i64*) local_unnamed_addr #3 | |
; Function Attrs: nounwind | |
declare void @__cxa_guard_release(i64*) local_unnamed_addr #3 | |
declare %struct.__polyglot_typeid* @__polyglot_as_typeid(i8*) local_unnamed_addr #4 | |
; Function Attrs: nounwind readnone speculatable | |
declare void @llvm.dbg.value(metadata, metadata, metadata) #5 | |
attributes #0 = { nounwind readnone sspstrong uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
attributes #1 = { norecurse nounwind readnone sspstrong uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
attributes #2 = { sspstrong uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
attributes #3 = { nounwind } | |
attributes #4 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
attributes #5 = { nounwind readnone speculatable } | |
!llvm.dbg.cu = !{!10} | |
!llvm.module.flags = !{!26, !27, !28, !29, !30} | |
!llvm.ident = !{!31} | |
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) | |
!1 = distinct !DIGlobalVariable(name: "__polyglot_typeid_Test", scope: !2, file: !3, line: 11, type: !13, isLocal: true, isDefinition: true) | |
!2 = distinct !DISubprogram(name: "polyglot_Test_typeid", linkageName: "_ZL20polyglot_Test_typeidv", scope: !3, file: !3, line: 11, type: !4, isLocal: true, isDefinition: true, scopeLine: 11, flags: DIFlagPrototyped, isOptimized: true, unit: !10, variables: !11) | |
!3 = !DIFile(filename: "test.cc", directory: "/home/roland/test/c++") | |
!4 = !DISubroutineType(types: !5) | |
!5 = !{!6} | |
!6 = !DIDerivedType(tag: DW_TAG_typedef, name: "polyglot_typeid", file: !7, line: 528, baseType: !8) | |
!7 = !DIFile(filename: "/home/roland/git/graalvm/sulong/mxbuild/linux-amd64/SULONG_LIBS/polyglot.h", directory: "/home/roland/test/c++") | |
!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64) | |
!9 = !DICompositeType(tag: DW_TAG_structure_type, name: "__polyglot_typeid", file: !7, line: 528, flags: DIFlagFwdDecl, identifier: "_ZTS17__polyglot_typeid") | |
!10 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 6.0.1 (tags/RELEASE_601/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !11, globals: !12) | |
!11 = !{} | |
!12 = !{!0} | |
!13 = !DICompositeType(tag: DW_TAG_array_type, baseType: !14, elements: !24) | |
!14 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "Test", file: !3, line: 3, size: 8, elements: !15, identifier: "_ZTS4Test") | |
!15 = !{!16, !20, !21} | |
!16 = !DISubprogram(name: "Test", scope: !14, file: !3, line: 5, type: !17, isLocal: false, isDefinition: false, scopeLine: 5, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true) | |
!17 = !DISubroutineType(types: !18) | |
!18 = !{null, !19} | |
!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) | |
!20 = !DISubprogram(name: "~Test", scope: !14, file: !3, line: 6, type: !17, isLocal: false, isDefinition: false, scopeLine: 6, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true) | |
!21 = !DISubprogram(name: "foo", linkageName: "_ZN4Test3fooEv", scope: !14, file: !3, line: 8, type: !22, isLocal: false, isDefinition: false, scopeLine: 8, flags: DIFlagPublic | DIFlagPrototyped | DIFlagStaticMember, isOptimized: true) | |
!22 = !DISubroutineType(types: !23) | |
!23 = !{null} | |
!24 = !{!25} | |
!25 = !DISubrange(count: 0) | |
!26 = !{i32 2, !"Dwarf Version", i32 4} | |
!27 = !{i32 2, !"Debug Info Version", i32 3} | |
!28 = !{i32 1, !"wchar_size", i32 4} | |
!29 = !{i32 7, !"PIC Level", i32 2} | |
!30 = !{i32 7, !"PIE Level", i32 2} | |
!31 = !{!"clang version 6.0.1 (tags/RELEASE_601/final)"} | |
!32 = distinct !DISubprogram(name: "Test", linkageName: "_ZN4TestC2Ev", scope: !14, file: !3, line: 13, type: !17, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: true, unit: !10, declaration: !16, variables: !33) | |
!33 = !{!34} | |
!34 = !DILocalVariable(name: "this", arg: 1, scope: !32, type: !35, flags: DIFlagArtificial | DIFlagObjectPointer) | |
!35 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64) | |
!36 = !DILocation(line: 0, scope: !32) | |
!37 = !DILocation(line: 14, column: 1, scope: !32) | |
!38 = distinct !DISubprogram(name: "~Test", linkageName: "_ZN4TestD2Ev", scope: !14, file: !3, line: 16, type: !17, isLocal: false, isDefinition: true, scopeLine: 16, flags: DIFlagPrototyped, isOptimized: true, unit: !10, declaration: !20, variables: !39) | |
!39 = !{!40} | |
!40 = !DILocalVariable(name: "this", arg: 1, scope: !38, type: !35, flags: DIFlagArtificial | DIFlagObjectPointer) | |
!41 = !DILocation(line: 0, scope: !38) | |
!42 = !DILocation(line: 17, column: 1, scope: !38) | |
!43 = distinct !DISubprogram(name: "foo", linkageName: "_ZN4Test3fooEv", scope: !14, file: !3, line: 19, type: !22, isLocal: false, isDefinition: true, scopeLine: 19, flags: DIFlagPrototyped, isOptimized: true, unit: !10, declaration: !21, variables: !11) | |
!44 = !DILocation(line: 20, column: 1, scope: !43) | |
!45 = distinct !DISubprogram(name: "getTestClass", linkageName: "_Z12getTestClassv", scope: !3, file: !3, line: 22, type: !4, isLocal: false, isDefinition: true, scopeLine: 22, flags: DIFlagPrototyped, isOptimized: true, unit: !10, variables: !11) | |
!46 = !DILocation(line: 11, column: 1, scope: !2, inlinedAt: !47) | |
!47 = distinct !DILocation(line: 23, column: 12, scope: !45) | |
!48 = !{!"branch_weights", i32 1, i32 1048575} | |
!49 = !DILocation(line: 23, column: 5, scope: !45) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment