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

Optimizing SelectionDAG


A SelectionDAG representation shows data and instructions in the form of nodes. Similar to the InstCombine pass in the LLVM IR, these nodes can be combined and optimized to form a minimized SelectionDAG. But, it's not just a DAGCombine operation that optimizes the SelectionDAG. A DAGLegalize phase may generate some unnecessary DAG nodes, which are cleaned up by subsequent runs of the DAG optimization pass. This finally represents the SelectionDAG in a more simple and elegant way.

How to do it…

There are lots and lots of function members (most of them are named like this: visit**()) provided in the DAGCombiner class to perform optimizations by folding, reordering, combining, and modifying SDNode nodes. Note that, from the DAGCombiner constructor, we can guess that some optimizations require alias analysis information:

class DAGCombiner {
SelectionDAG &DAG;
const TargetLowering &TLI;
CombineLevel Level;
CodeGenOpt::Level OptLevel;
bool LegalOperations;
bool LegalTypes...