2009-12-14 06:49:42 +00:00
|
|
|
//===---------------- lib/CodeGen/CalcSpillWeights.h ------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_CALCSPILLWEIGHTS_H
|
|
|
|
#define LLVM_CODEGEN_CALCSPILLWEIGHTS_H
|
|
|
|
|
2011-03-04 18:36:51 +00:00
|
|
|
#include "llvm/CodeGen/SlotIndexes.h"
|
2010-08-10 00:02:26 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2009-12-14 06:49:42 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class LiveInterval;
|
2010-08-10 00:02:26 +00:00
|
|
|
class LiveIntervals;
|
|
|
|
class MachineLoopInfo;
|
|
|
|
|
2011-02-14 23:15:38 +00:00
|
|
|
/// normalizeSpillWeight - The spill weight of a live interval is computed as:
|
|
|
|
///
|
|
|
|
/// (sum(use freq) + sum(def freq)) / (K + size)
|
|
|
|
///
|
|
|
|
/// @param UseDefFreq Expected number of executed use and def instructions
|
|
|
|
/// per function call. Derived from block frequencies.
|
|
|
|
/// @param Size Size of live interval as returnexd by getSize()
|
|
|
|
///
|
|
|
|
static inline float normalizeSpillWeight(float UseDefFreq, unsigned Size) {
|
2011-03-04 18:36:51 +00:00
|
|
|
// The constant 25 instructions is added to avoid depending too much on
|
|
|
|
// accidental SlotIndex gaps for small intervals. The effect is that small
|
|
|
|
// intervals have a spill weight that is mostly proportional to the number
|
|
|
|
// of uses, while large intervals get a spill weight that is closer to a use
|
|
|
|
// density.
|
|
|
|
return UseDefFreq / (Size + 25*SlotIndex::InstrDist);
|
2011-02-14 23:15:38 +00:00
|
|
|
}
|
|
|
|
|
2010-08-10 00:02:26 +00:00
|
|
|
/// VirtRegAuxInfo - Calculate auxiliary information for a virtual
|
|
|
|
/// register such as its spill weight and allocation hint.
|
|
|
|
class VirtRegAuxInfo {
|
|
|
|
MachineFunction &mf_;
|
|
|
|
LiveIntervals &lis_;
|
2010-08-10 17:07:22 +00:00
|
|
|
const MachineLoopInfo &loops_;
|
2010-08-10 00:02:26 +00:00
|
|
|
DenseMap<unsigned, float> hint_;
|
|
|
|
public:
|
|
|
|
VirtRegAuxInfo(MachineFunction &mf, LiveIntervals &lis,
|
2010-08-10 17:07:22 +00:00
|
|
|
const MachineLoopInfo &loops) :
|
2010-08-10 00:02:26 +00:00
|
|
|
mf_(mf), lis_(lis), loops_(loops) {}
|
|
|
|
|
2010-08-10 18:37:40 +00:00
|
|
|
/// CalculateRegClass - recompute the register class for reg from its uses.
|
2010-08-10 00:02:26 +00:00
|
|
|
/// Since the register class can affect the allocation hint, this function
|
|
|
|
/// should be called before CalculateWeightAndHint if both are called.
|
2010-08-10 18:37:40 +00:00
|
|
|
void CalculateRegClass(unsigned reg);
|
2010-08-10 00:02:26 +00:00
|
|
|
|
|
|
|
/// CalculateWeightAndHint - (re)compute li's spill weight and allocation
|
|
|
|
/// hint.
|
|
|
|
void CalculateWeightAndHint(LiveInterval &li);
|
|
|
|
};
|
2009-12-14 06:49:42 +00:00
|
|
|
|
|
|
|
/// CalculateSpillWeights - Compute spill weights for all virtual register
|
|
|
|
/// live intervals.
|
|
|
|
class CalculateSpillWeights : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
2010-10-19 17:21:58 +00:00
|
|
|
CalculateSpillWeights() : MachineFunctionPass(ID) {
|
|
|
|
initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2009-12-14 06:49:42 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &au) const;
|
|
|
|
|
2010-08-10 00:02:26 +00:00
|
|
|
virtual bool runOnMachineFunction(MachineFunction &fn);
|
2009-12-14 06:49:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Returns true if the given live interval is zero length.
|
|
|
|
bool isZeroLengthInterval(LiveInterval *li) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H
|