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

Selecting instruction from the DAG


After legalization and DAG combination, the SelectionDAG representation is in the optimized phase. However, the instructions represented are still target-independent and need to be mapped on target-specific instructions. The instruction selection phase takes the target-independent DAG nodes as the input, matches patterns in them, and gives the output DAG nodes, which are target-specific.

The TableGen DAG instruction selector generator reads the instruction patterns from the .td file, and automatically builds parts of the pattern matching code.

How to do it…

SelectionDAGISel is the common base class used for pattern-matching instruction selectors that are based on SelectionDAG. It inherits the MachineFunctionPass class. It has various functions used to determine the legality and profitability of operations such as folding. The basic skeleton of this class is as follows:

class SelectionDAGISel : public MachineFunctionPass {
public:
const TargetMachine &TM...