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

Registering a pass with pass manager


Until now, a new pass was a dynamic object that was run independently. The opt tool consists of a pipeline of such passes that are registered with the pass manager, and a part of LLVM. Let's see how to register our pass with the Pass Manager.

Getting ready

The PassManager class takes a list of passes, ensures that their prerequisites are set up correctly, and then schedules the passes to run efficiently. The Pass Manager does two main tasks to try to reduce the execution time of a series of passes:

  • Shares the analysis results to avoid recomputing analysis results as much as possible

  • Pipelines the execution of passes to the program to get better cache and memory usage behavior out of a series of passes by pipelining the passes together

How to do it…

Follow the given steps to register a pass with Pass Manager:

  1. Define a DEBUG_TYPE macro, specifying the debugging name in the FuncBlockCount.cpp file:

    #define DEBUG_TYPE "func-block-count"
  2. In the FuncBlockCount struct...