Writing your own machine pass

In this section, we will show how you can write a custom machine pass to count, just before code emission, how many machine instructions each function has. Differing from IR passes, you cannot run this pass with the opt tool, or load the pass and schedule it to happen via the command line. Machine passes are determined by the backend code. Therefore, we will modify an existing backend to run with our custom pass to see it in practice. We will choose SPARC for that end.

Recall from the Demonstrating the pluggable pass interface section in Chapter 3, Tools and Design, and from the white boxes in the first diagram of this chapter, that we have many options to decide where our pass should run. To use these methods, we ...

Get Getting Started with LLVM Core Libraries now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.