2003-09-30 20:37:50 +02:00
|
|
|
//===- IntervalPartition.h - Interval partition Calculation -----*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-24 06:07:37 +02:00
|
|
|
//
|
2002-04-28 18:19:42 +02:00
|
|
|
// This file contains the declaration of the IntervalPartition class, which
|
2002-04-27 08:56:12 +02:00
|
|
|
// calculates and represents the interval partition of a function, or a
|
2001-06-24 06:07:37 +02:00
|
|
|
// preexisting interval partition.
|
|
|
|
//
|
|
|
|
// In this way, the interval partition may be used to reduce a flow graph down
|
|
|
|
// to its degenerate single node interval partition (unless it is irreducible).
|
|
|
|
//
|
|
|
|
// TODO: The IntervalPartition class should take a bool parameter that tells
|
|
|
|
// whether it should add the "tails" of an interval to an interval itself or if
|
|
|
|
// they should be represented as distinct intervals.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 01:45:19 +01:00
|
|
|
#ifndef LLVM_ANALYSIS_INTERVALPARTITION_H
|
|
|
|
#define LLVM_ANALYSIS_INTERVALPARTITION_H
|
2001-06-24 06:07:37 +02:00
|
|
|
|
2002-01-31 00:27:55 +01:00
|
|
|
#include "llvm/Pass.h"
|
2008-03-22 00:51:57 +01:00
|
|
|
#include <map>
|
2017-07-25 01:16:33 +02:00
|
|
|
#include <vector>
|
2001-06-24 06:07:37 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2017-07-25 01:16:33 +02:00
|
|
|
class BasicBlock;
|
|
|
|
class Interval;
|
|
|
|
|
2001-06-24 06:07:37 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// IntervalPartition - This class builds and holds an "interval partition" for
|
2002-04-27 08:56:12 +02:00
|
|
|
// a function. This partition divides the control flow graph into a set of
|
2012-09-19 15:45:43 +02:00
|
|
|
// maximal intervals, as defined with the properties above. Intuitively, an
|
2013-12-05 06:44:44 +01:00
|
|
|
// interval is a (possibly nonexistent) loop with a "tail" of non-looping
|
2001-06-24 06:07:37 +02:00
|
|
|
// nodes following it.
|
|
|
|
//
|
2002-08-10 00:52:06 +02:00
|
|
|
class IntervalPartition : public FunctionPass {
|
2017-07-25 01:16:33 +02:00
|
|
|
using IntervalMapTy = std::map<BasicBlock *, Interval *>;
|
2001-06-24 06:07:37 +02:00
|
|
|
IntervalMapTy IntervalMap;
|
|
|
|
|
2017-07-25 01:16:33 +02:00
|
|
|
using IntervalListTy = std::vector<Interval *>;
|
|
|
|
Interval *RootInterval = nullptr;
|
|
|
|
std::vector<Interval *> Intervals;
|
2001-06-24 06:07:37 +02:00
|
|
|
|
|
|
|
public:
|
2007-05-06 15:37:16 +02:00
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2007-05-01 23:15:47 +02:00
|
|
|
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-13 22:15:01 +01:00
|
|
|
IntervalPartition();
|
2008-03-18 01:39:19 +01:00
|
|
|
|
2002-04-27 08:56:12 +02:00
|
|
|
// run - Calculate the interval partition for this function
|
2014-03-05 08:30:04 +01:00
|
|
|
bool runOnFunction(Function &F) override;
|
2001-06-24 06:07:37 +02:00
|
|
|
|
|
|
|
// IntervalPartition ctor - Build a reduced interval partition from an
|
|
|
|
// existing interval graph. This takes an additional boolean parameter to
|
|
|
|
// distinguish it from a copy constructor. Always pass in false for now.
|
|
|
|
IntervalPartition(IntervalPartition &I, bool);
|
|
|
|
|
2002-07-27 03:12:15 +02:00
|
|
|
// print - Show contents in human readable format...
|
2014-04-15 06:59:12 +02:00
|
|
|
void print(raw_ostream &O, const Module* = nullptr) const override;
|
2002-07-27 03:12:15 +02:00
|
|
|
|
2001-06-24 06:07:37 +02:00
|
|
|
// getRootInterval() - Return the root interval that contains the starting
|
2002-04-27 08:56:12 +02:00
|
|
|
// block of the function.
|
2001-06-24 06:07:37 +02:00
|
|
|
inline Interval *getRootInterval() { return RootInterval; }
|
|
|
|
|
|
|
|
// isDegeneratePartition() - Returns true if the interval partition contains
|
|
|
|
// a single interval, and thus cannot be simplified anymore.
|
2002-08-10 00:52:06 +02:00
|
|
|
bool isDegeneratePartition() { return Intervals.size() == 1; }
|
2001-06-24 06:07:37 +02:00
|
|
|
|
|
|
|
// TODO: isIrreducible - look for triangle graph.
|
|
|
|
|
|
|
|
// getBlockInterval - Return the interval that a basic block exists in.
|
|
|
|
inline Interval *getBlockInterval(BasicBlock *BB) {
|
|
|
|
IntervalMapTy::iterator I = IntervalMap.find(BB);
|
2014-04-15 06:59:12 +02:00
|
|
|
return I != IntervalMap.end() ? I->second : nullptr;
|
2001-06-24 06:07:37 +02:00
|
|
|
}
|
|
|
|
|
2002-04-27 08:56:12 +02:00
|
|
|
// getAnalysisUsage - Implement the Pass API
|
2014-03-05 08:30:04 +01:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2002-04-27 08:56:12 +02:00
|
|
|
AU.setPreservesAll();
|
2002-01-31 00:27:55 +01:00
|
|
|
}
|
|
|
|
|
2002-08-10 00:52:06 +02:00
|
|
|
// Interface to Intervals vector...
|
|
|
|
const std::vector<Interval*> &getIntervals() const { return Intervals; }
|
|
|
|
|
2008-08-29 00:56:53 +02:00
|
|
|
// releaseMemory - Reset state back to before function was analyzed
|
2014-03-05 08:30:04 +01:00
|
|
|
void releaseMemory() override;
|
2002-01-31 00:27:55 +01:00
|
|
|
|
2008-08-29 00:56:53 +02:00
|
|
|
private:
|
2001-06-25 05:54:14 +02:00
|
|
|
// addIntervalToPartition - Add an interval to the internal list of intervals,
|
|
|
|
// and then add mappings from all of the basic blocks in the interval to the
|
|
|
|
// interval itself (in the IntervalMap).
|
|
|
|
void addIntervalToPartition(Interval *I);
|
2001-06-24 06:07:37 +02:00
|
|
|
|
|
|
|
// updatePredecessors - Interval generation only sets the successor fields of
|
|
|
|
// the interval data structures. After interval generation is complete,
|
2002-10-29 23:55:11 +01:00
|
|
|
// run through all of the intervals and propagate successor info as
|
2001-06-24 06:07:37 +02:00
|
|
|
// predecessor info.
|
|
|
|
void updatePredecessors(Interval *Int);
|
|
|
|
};
|
|
|
|
|
2017-07-25 01:16:33 +02:00
|
|
|
} // end namespace llvm
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2017-07-25 01:16:33 +02:00
|
|
|
#endif // LLVM_ANALYSIS_INTERVALPARTITION_H
|