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

Introduction


The ultimate goal of a compiler is to produce a target code, or an assembly code that can be converted into object code and executed on the actual hardware. To generate the assembly code, the compiler needs to know the various aspects of the architecture of the target machine—the registers, instruction set, calling convention, pipeline, and so on. There are lots of optimizations that can be done in this phase as well.

LLVM has its own way of defining the target machine. It uses tablegen to specify the target registers, instructions, calling convention, and so on. The tablegen function eases the way we describe a large set of architecture properties in a programmatic way.

LLVM has a pipeline structure for the backend, where instructions travel through phases like this; from the LLVM IR to SelectionDAG, then to MachineDAG, then to MachineInstr, and finally to MCInst.

The IR is converted into SelectionDAG (DAG stands for Directed Acyclic Graph). Then SelectionDAG legalization occurs...