Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Other optimization passes


In this recipe, we will look at some more transformational passes, which are more like of utility passes. We will look at the strip-debug-symbols pass and the prune-eh pass.

Getting ready…

The opt tool must be installed.

How to do it…

  1. Write a test case for checking the strip-debug pass, which strips off the debug symbols from the test code:

    $ cat teststripdebug.ll
    @x = common global i32 0                          ; <i32*> [#uses=0]
    
    define void @foo() nounwind readnone optsize ssp {
    entry:
      tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !5, metadata !{}), !dbg !10
      ret void, !dbg !11
    }
    
    declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnone
    
    !llvm.dbg.cu = !{!2}
    !llvm.module.flags = !{!13}
    !llvm.dbg.sp = !{!0}
    !llvm.dbg.lv.foo = !{!5}
    !llvm.dbg.gv = !{!8}
    
    !0 = !MDSubprogram(name: "foo", linkageName: "foo", line: 2, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: true, file: !12, scope: !1, type: ...