mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-24 09:29:42 +00:00
This patch improves how the different costs (register, interference, spill and coalescing) relates together. The assumption is now that: - coalescing (or any other "side effect" of reg alloc) is negative, and instead of being derived from a spill cost, they use the block frequency info. - spill costs are in the [MinSpillCost:+inf( range - register or interference costs are in [0.0:MinSpillCost( or +inf The current MinSpillCost is set to 10.0, which is a random value high enough that the current constraint builders do not need to worry about when settings costs. It would however be worth adding a normalization step for register and interference costs as the last step in the constraint builder chain to ensure they are not greater than SpillMinCost (unless this has some sense for some architectures). This would work well with the current builder pipeline, where all costs are tweaked relatively to each others, but could grow above MinSpillCost if the pipeline is deep enough. The current heuristic is tuned to depend rather on the number of uses of a live interval rather than a density of uses, as used by the greedy allocator. This heuristic provides a few percent improvement on a number of benchmarks (eembc, spec, ...) and will definitely need to change once spill placement is implemented: the current spill placement is really ineficient, so making the cost proportionnal to the number of use is a clear win. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221292 91177308-0d34-0410-b5e6-96231b3b80d8
80 lines
2.9 KiB
C++
80 lines
2.9 KiB
C++
//===---------------- 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
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
#include "llvm/CodeGen/SlotIndexes.h"
|
|
|
|
namespace llvm {
|
|
|
|
class LiveInterval;
|
|
class LiveIntervals;
|
|
class MachineBlockFrequencyInfo;
|
|
class MachineLoopInfo;
|
|
|
|
/// \brief Normalize the spill weight of a live interval
|
|
///
|
|
/// 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()
|
|
/// @param NumInstr Number of instructions using this live interval
|
|
///
|
|
static inline float normalizeSpillWeight(float UseDefFreq, unsigned Size,
|
|
unsigned NumInstr) {
|
|
// 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);
|
|
}
|
|
|
|
/// \brief Calculate auxiliary information for a virtual register such as its
|
|
/// spill weight and allocation hint.
|
|
class VirtRegAuxInfo {
|
|
public:
|
|
typedef float (*NormalizingFn)(float, unsigned, unsigned);
|
|
|
|
private:
|
|
MachineFunction &MF;
|
|
LiveIntervals &LIS;
|
|
const MachineLoopInfo &Loops;
|
|
const MachineBlockFrequencyInfo &MBFI;
|
|
DenseMap<unsigned, float> Hint;
|
|
NormalizingFn normalize;
|
|
|
|
public:
|
|
VirtRegAuxInfo(MachineFunction &mf, LiveIntervals &lis,
|
|
const MachineLoopInfo &loops,
|
|
const MachineBlockFrequencyInfo &mbfi,
|
|
NormalizingFn norm = normalizeSpillWeight)
|
|
: MF(mf), LIS(lis), Loops(loops), MBFI(mbfi), normalize(norm) {}
|
|
|
|
/// \brief (re)compute li's spill weight and allocation hint.
|
|
void calculateSpillWeightAndHint(LiveInterval &li);
|
|
};
|
|
|
|
/// \brief Compute spill weights and allocation hints for all virtual register
|
|
/// live intervals.
|
|
void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF,
|
|
const MachineLoopInfo &MLI,
|
|
const MachineBlockFrequencyInfo &MBFI,
|
|
VirtRegAuxInfo::NormalizingFn norm =
|
|
normalizeSpillWeight);
|
|
}
|
|
|
|
#endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H
|