LLVM  3.7.0
IteratedDominanceFrontier.h
Go to the documentation of this file.
1 //===- IteratedDominanceFrontier.h - Calculate IDF --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \brief Compute iterated dominance frontiers using a linear time algorithm.
11 ///
12 /// The algorithm used here is based on:
13 ///
14 /// Sreedhar and Gao. A linear time algorithm for placing phi-nodes.
15 /// In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of
16 /// Programming Languages
17 /// POPL '95. ACM, New York, NY, 62-73.
18 ///
19 /// It has been modified to not explicitly use the DJ graph data structure and
20 /// to directly compute pruned SSA using per-variable liveness information.
21 //
22 //===----------------------------------------------------------------------===//
23 
24 #ifndef LLVM_ANALYSIS_IDF_H
25 #define LLVM_ANALYSIS_IDF_H
26 
27 #include "llvm/ADT/ArrayRef.h"
28 #include "llvm/ADT/DenseMap.h"
29 #include "llvm/ADT/SmallPtrSet.h"
30 #include "llvm/ADT/SmallVector.h"
31 
32 namespace llvm {
33 
34 class BasicBlock;
35 template <class T> class DomTreeNodeBase;
37 class DominatorTree;
38 
39 /// \brief Determine the iterated dominance frontier, given a set of defining
40 /// blocks, and optionally, a set of live-in blocks.
41 ///
42 /// In turn, the results can be used to place phi nodes.
43 ///
44 /// This algorithm is a linear time computation of Iterated Dominance Frontiers,
45 /// pruned using the live-in set.
46 /// By default, liveness is not used to prune the IDF computation.
48 
49 public:
50  IDFCalculator(DominatorTree &DT) : DT(DT), useLiveIn(false) {}
51 
52  /// \brief Give the IDF calculator the set of blocks in which the value is
53  /// defined. This is equivalent to the set of starting blocks it should be
54  /// calculating the IDF for (though later gets pruned based on liveness).
55  ///
56  /// Note: This set *must* live for the entire lifetime of the IDF calculator.
58  DefBlocks = &Blocks;
59  }
60 
61  /// \brief Give the IDF calculator the set of blocks in which the value is
62  /// live on entry to the block. This is used to prune the IDF calculation to
63  /// not include blocks where any phi insertion would be dead.
64  ///
65  /// Note: This set *must* live for the entire lifetime of the IDF calculator.
66 
68  LiveInBlocks = &Blocks;
69  useLiveIn = true;
70  }
71 
72  /// \brief Reset the live-in block set to be empty, and tell the IDF
73  /// calculator to not use liveness anymore.
75  LiveInBlocks = nullptr;
76  useLiveIn = false;
77  }
78 
79  /// \brief Calculate iterated dominance frontiers
80  ///
81  /// This uses the linear-time phi algorithm based on DJ-graphs mentioned in
82  /// the file-level comment. It performs DF->IDF pruning using the live-in
83  /// set, to avoid computing the IDF for blocks where an inserted PHI node
84  /// would be dead.
86 
87 private:
88  DominatorTree &DT;
89  bool useLiveIn;
91  const SmallPtrSetImpl<BasicBlock *> *LiveInBlocks;
92  const SmallPtrSetImpl<BasicBlock *> *DefBlocks;
94 };
95 }
96 #endif
Various leaf nodes.
Definition: ISDOpcodes.h:60
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:242
void calculate(SmallVectorImpl< BasicBlock * > &IDFBlocks)
Calculate iterated dominance frontiers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APInt.h:33
#define false
Definition: ConvertUTF.c:65
Base class for the actual dominator tree node.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:67
void setLiveInBlocks(const SmallPtrSetImpl< BasicBlock * > &Blocks)
Give the IDF calculator the set of blocks in which the value is live on entry to the block...
IDFCalculator(DominatorTree &DT)
void resetLiveInBlocks()
Reset the live-in block set to be empty, and tell the IDF calculator to not use liveness anymore...
void setDefiningBlocks(const SmallPtrSetImpl< BasicBlock * > &Blocks)
Give the IDF calculator the set of blocks in which the value is defined.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
Determine the iterated dominance frontier, given a set of defining blocks, and optionally, a set of live-in blocks.
DomTreeNodeBase< BasicBlock > DomTreeNode