2003-09-30 20:37:50 +02:00
|
|
|
//===- llvm/Analysis/Interval.h - Interval Class Declaration ----*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-20 21:26:12 +02:00
|
|
|
//
|
2002-04-28 18:19:42 +02:00
|
|
|
// This file contains the declaration of the Interval class, which
|
2001-06-24 06:05:09 +02:00
|
|
|
// represents a set of CFG nodes and is a portion of an interval partition.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2001-06-24 06:05:09 +02:00
|
|
|
// Intervals have some interesting and useful properties, including the
|
|
|
|
// following:
|
|
|
|
// 1. The header node of an interval dominates all of the elements of the
|
|
|
|
// interval
|
2001-06-22 04:23:27 +02:00
|
|
|
//
|
2001-06-20 21:26:12 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2001-06-24 06:05:09 +02:00
|
|
|
#ifndef LLVM_INTERVAL_H
|
|
|
|
#define LLVM_INTERVAL_H
|
2001-06-20 21:26:12 +02:00
|
|
|
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/ADT/GraphTraits.h"
|
2001-06-20 21:26:12 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2001-06-20 21:26:12 +02:00
|
|
|
class BasicBlock;
|
2009-08-23 08:03:38 +02:00
|
|
|
class raw_ostream;
|
2001-06-20 21:26:12 +02:00
|
|
|
|
2001-06-22 04:23:27 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2005-04-21 18:04:49 +02:00
|
|
|
/// Interval Class - An Interval is a set of nodes defined such that every node
|
|
|
|
/// in the interval has all of its predecessors in the interval (except for the
|
|
|
|
/// header)
|
|
|
|
///
|
2001-06-20 21:26:12 +02:00
|
|
|
class Interval {
|
2005-04-21 18:04:49 +02:00
|
|
|
/// HeaderNode - The header BasicBlock, which dominates all BasicBlocks in this
|
|
|
|
/// interval. Also, any loops in this interval must go through the HeaderNode.
|
|
|
|
///
|
2001-06-20 21:26:12 +02:00
|
|
|
BasicBlock *HeaderNode;
|
2001-06-22 04:23:27 +02:00
|
|
|
public:
|
2002-01-20 23:54:45 +01:00
|
|
|
typedef std::vector<BasicBlock*>::iterator succ_iterator;
|
|
|
|
typedef std::vector<BasicBlock*>::iterator pred_iterator;
|
|
|
|
typedef std::vector<BasicBlock*>::iterator node_iterator;
|
2001-06-22 04:23:27 +02:00
|
|
|
|
2001-06-24 06:05:09 +02:00
|
|
|
inline Interval(BasicBlock *Header) : HeaderNode(Header) {
|
|
|
|
Nodes.push_back(Header);
|
|
|
|
}
|
|
|
|
|
2001-06-25 05:54:14 +02:00
|
|
|
inline Interval(const Interval &I) // copy ctor
|
|
|
|
: HeaderNode(I.HeaderNode), Nodes(I.Nodes), Successors(I.Successors) {}
|
|
|
|
|
2001-06-22 04:23:27 +02:00
|
|
|
inline BasicBlock *getHeaderNode() const { return HeaderNode; }
|
2001-06-20 21:26:12 +02:00
|
|
|
|
2005-04-21 18:04:49 +02:00
|
|
|
/// Nodes - The basic blocks in this interval.
|
|
|
|
///
|
2002-01-20 23:54:45 +01:00
|
|
|
std::vector<BasicBlock*> Nodes;
|
2001-06-20 21:26:12 +02:00
|
|
|
|
2005-04-21 18:04:49 +02:00
|
|
|
/// Successors - List of BasicBlocks that are reachable directly from nodes in
|
|
|
|
/// this interval, but are not in the interval themselves.
|
|
|
|
/// These nodes necessarily must be header nodes for other intervals.
|
|
|
|
///
|
2002-01-20 23:54:45 +01:00
|
|
|
std::vector<BasicBlock*> Successors;
|
2001-06-20 21:26:12 +02:00
|
|
|
|
2005-04-21 18:04:49 +02:00
|
|
|
/// Predecessors - List of BasicBlocks that have this Interval's header block
|
|
|
|
/// as one of their successors.
|
|
|
|
///
|
2002-01-20 23:54:45 +01:00
|
|
|
std::vector<BasicBlock*> Predecessors;
|
2001-06-20 21:26:12 +02:00
|
|
|
|
2005-04-21 18:04:49 +02:00
|
|
|
/// contains - Find out if a basic block is in this interval
|
2001-06-21 07:24:46 +02:00
|
|
|
inline bool contains(BasicBlock *BB) const {
|
2001-06-24 06:05:09 +02:00
|
|
|
for (unsigned i = 0; i < Nodes.size(); ++i)
|
|
|
|
if (Nodes[i] == BB) return true;
|
|
|
|
return false;
|
|
|
|
// I don't want the dependency on <algorithm>
|
|
|
|
//return find(Nodes.begin(), Nodes.end(), BB) != Nodes.end();
|
2001-06-20 21:26:12 +02:00
|
|
|
}
|
|
|
|
|
2005-04-21 18:04:49 +02:00
|
|
|
/// isSuccessor - find out if a basic block is a successor of this Interval
|
2001-06-21 07:24:46 +02:00
|
|
|
inline bool isSuccessor(BasicBlock *BB) const {
|
2001-06-24 06:05:09 +02:00
|
|
|
for (unsigned i = 0; i < Successors.size(); ++i)
|
|
|
|
if (Successors[i] == BB) return true;
|
|
|
|
return false;
|
|
|
|
// I don't want the dependency on <algorithm>
|
|
|
|
//return find(Successors.begin(), Successors.end(), BB) != Successors.end();
|
2001-06-20 21:26:12 +02:00
|
|
|
}
|
|
|
|
|
2005-04-21 22:19:05 +02:00
|
|
|
/// Equality operator. It is only valid to compare two intervals from the
|
|
|
|
/// same partition, because of this, all we have to check is the header node
|
|
|
|
/// for equality.
|
2005-04-21 18:04:49 +02:00
|
|
|
///
|
2001-06-25 05:54:14 +02:00
|
|
|
inline bool operator==(const Interval &I) const {
|
|
|
|
return HeaderNode == I.HeaderNode;
|
|
|
|
}
|
|
|
|
|
2005-04-21 18:04:49 +02:00
|
|
|
/// isLoop - Find out if there is a back edge in this interval...
|
2001-06-21 07:24:46 +02:00
|
|
|
bool isLoop() const;
|
2002-07-27 03:12:15 +02:00
|
|
|
|
2005-04-21 18:04:49 +02:00
|
|
|
/// print - Show contents in human readable format...
|
2009-08-23 08:03:38 +02:00
|
|
|
void print(raw_ostream &O) const;
|
2002-02-12 23:35:27 +01:00
|
|
|
};
|
2001-06-20 21:26:12 +02:00
|
|
|
|
2005-04-21 18:04:49 +02:00
|
|
|
/// succ_begin/succ_end - define methods so that Intervals may be used
|
|
|
|
/// just like BasicBlocks can with the succ_* functions, and *::succ_iterator.
|
|
|
|
///
|
2002-04-28 18:19:42 +02:00
|
|
|
inline Interval::succ_iterator succ_begin(Interval *I) {
|
2002-02-12 23:35:27 +01:00
|
|
|
return I->Successors.begin();
|
|
|
|
}
|
2002-04-28 18:19:42 +02:00
|
|
|
inline Interval::succ_iterator succ_end(Interval *I) {
|
2002-02-12 23:35:27 +01:00
|
|
|
return I->Successors.end();
|
|
|
|
}
|
2005-07-27 07:53:44 +02:00
|
|
|
|
2005-04-21 18:04:49 +02:00
|
|
|
/// pred_begin/pred_end - define methods so that Intervals may be used
|
|
|
|
/// just like BasicBlocks can with the pred_* functions, and *::pred_iterator.
|
|
|
|
///
|
2002-04-28 18:19:42 +02:00
|
|
|
inline Interval::pred_iterator pred_begin(Interval *I) {
|
2002-02-12 23:35:27 +01:00
|
|
|
return I->Predecessors.begin();
|
|
|
|
}
|
2002-04-28 18:19:42 +02:00
|
|
|
inline Interval::pred_iterator pred_end(Interval *I) {
|
2002-02-12 23:35:27 +01:00
|
|
|
return I->Predecessors.end();
|
|
|
|
}
|
2001-06-21 00:44:32 +02:00
|
|
|
|
2003-10-02 00:27:36 +02:00
|
|
|
template <> struct GraphTraits<Interval*> {
|
|
|
|
typedef Interval NodeType;
|
|
|
|
typedef Interval::succ_iterator ChildIteratorType;
|
|
|
|
|
|
|
|
static NodeType *getEntryNode(Interval *I) { return I; }
|
|
|
|
|
2005-04-21 18:04:49 +02:00
|
|
|
/// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
|
2005-07-27 07:53:44 +02:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2003-10-02 00:27:36 +02:00
|
|
|
return succ_begin(N);
|
|
|
|
}
|
2005-04-21 22:19:05 +02:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2003-10-02 00:27:36 +02:00
|
|
|
return succ_end(N);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct GraphTraits<Inverse<Interval*> > {
|
|
|
|
typedef Interval NodeType;
|
|
|
|
typedef Interval::pred_iterator ChildIteratorType;
|
|
|
|
static NodeType *getEntryNode(Inverse<Interval *> G) { return G.Graph; }
|
2005-04-21 22:19:05 +02:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2003-10-02 00:27:36 +02:00
|
|
|
return pred_begin(N);
|
|
|
|
}
|
2005-04-21 22:19:05 +02:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2003-10-02 00:27:36 +02:00
|
|
|
return pred_end(N);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-06-20 21:26:12 +02:00
|
|
|
#endif
|