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

Adding a machine code descriptor


The LLVM IR has functions, which have basic blocks. Basic blocks in turn have instructions. The next logical step is to convert those IR abstract blocks into machine-specific blocks. LLVM code is translated into a machine-specific representation formed from the MachineFunction, MachineBasicBlock, and MachineInstr instances. This representation contains instructions in their most abstract form—that is, having an opcode and a series of operands.

How it's done…

Now the LLVM IR instruction has to be represented in the machine instruction. Machine instructions are instances of the MachineInstr class. This class is an extremely abstract way of representing machine instructions. In particular, it only keeps track of an opcode number and a set of operands. The opcode number is a simple unsigned integer that has a meaning only for a specific backend.

Let's look at some important functions defined in the MachineInstr.cpp file:

The MachineInstr constructor:

MachineInstr...