2010-12-10 19:36:02 +01:00
|
|
|
//===-- llvm/CodeGen/AllocationOrder.h - Allocation Order -*- C++ -*-------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements an allocation order for virtual registers.
|
|
|
|
//
|
|
|
|
// The preferred allocation order for a virtual register depends on allocation
|
|
|
|
// hints and target hooks. The AllocationOrder class encapsulates all of that.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 18:26:38 +02:00
|
|
|
#ifndef LLVM_LIB_CODEGEN_ALLOCATIONORDER_H
|
|
|
|
#define LLVM_LIB_CODEGEN_ALLOCATIONORDER_H
|
2010-12-10 19:36:02 +01:00
|
|
|
|
2012-12-03 23:51:04 +01:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2016-08-12 00:21:41 +02:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2012-12-04 08:12:27 +01:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2012-11-29 04:34:17 +01:00
|
|
|
|
2010-12-10 19:36:02 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2011-06-03 22:34:53 +02:00
|
|
|
class RegisterClassInfo;
|
2010-12-10 19:36:02 +01:00
|
|
|
class VirtRegMap;
|
2015-07-16 00:16:00 +02:00
|
|
|
class LiveRegMatrix;
|
2010-12-10 19:36:02 +01:00
|
|
|
|
2015-07-01 16:47:39 +02:00
|
|
|
class LLVM_LIBRARY_VISIBILITY AllocationOrder {
|
2012-12-03 23:51:04 +01:00
|
|
|
SmallVector<MCPhysReg, 16> Hints;
|
|
|
|
ArrayRef<MCPhysReg> Order;
|
2012-12-04 23:25:16 +01:00
|
|
|
int Pos;
|
2010-12-10 19:36:02 +01:00
|
|
|
|
2017-11-10 09:46:26 +01:00
|
|
|
// If HardHints is true, *only* Hints will be returned.
|
|
|
|
bool HardHints;
|
|
|
|
|
2012-12-03 23:51:04 +01:00
|
|
|
public:
|
2017-11-10 09:46:26 +01:00
|
|
|
|
2012-12-03 23:51:04 +01:00
|
|
|
/// Create a new AllocationOrder for VirtReg.
|
2010-12-10 19:36:02 +01:00
|
|
|
/// @param VirtReg Virtual register to allocate for.
|
|
|
|
/// @param VRM Virtual register map for function.
|
2012-01-24 19:09:18 +01:00
|
|
|
/// @param RegClassInfo Information about reserved and allocatable registers.
|
2010-12-10 19:36:02 +01:00
|
|
|
AllocationOrder(unsigned VirtReg,
|
|
|
|
const VirtRegMap &VRM,
|
2015-07-16 00:16:00 +02:00
|
|
|
const RegisterClassInfo &RegClassInfo,
|
|
|
|
const LiveRegMatrix *Matrix);
|
2010-12-10 19:36:02 +01:00
|
|
|
|
2013-01-12 01:57:44 +01:00
|
|
|
/// Get the allocation order without reordered hints.
|
|
|
|
ArrayRef<MCPhysReg> getOrder() const { return Order; }
|
|
|
|
|
2012-12-03 23:51:04 +01:00
|
|
|
/// Return the next physical register in the allocation order, or 0.
|
|
|
|
/// It is safe to call next() again after it returned 0, it will keep
|
|
|
|
/// returning 0 until rewind() is called.
|
2013-12-05 22:18:40 +01:00
|
|
|
unsigned next(unsigned Limit = 0) {
|
2012-12-04 23:25:16 +01:00
|
|
|
if (Pos < 0)
|
|
|
|
return Hints.end()[Pos++];
|
2017-11-10 09:46:26 +01:00
|
|
|
if (HardHints)
|
|
|
|
return 0;
|
2013-12-05 22:18:40 +01:00
|
|
|
if (!Limit)
|
|
|
|
Limit = Order.size();
|
|
|
|
while (Pos < int(Limit)) {
|
2012-12-04 23:25:16 +01:00
|
|
|
unsigned Reg = Order[Pos++];
|
|
|
|
if (!isHint(Reg))
|
|
|
|
return Reg;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-06-06 23:02:04 +02:00
|
|
|
|
2013-01-12 01:57:44 +01:00
|
|
|
/// As next(), but allow duplicates to be returned, and stop before the
|
|
|
|
/// Limit'th register in the RegisterClassInfo allocation order.
|
|
|
|
///
|
|
|
|
/// This can produce more than Limit registers if there are hints.
|
|
|
|
unsigned nextWithDups(unsigned Limit) {
|
|
|
|
if (Pos < 0)
|
|
|
|
return Hints.end()[Pos++];
|
2017-11-10 09:46:26 +01:00
|
|
|
if (HardHints)
|
|
|
|
return 0;
|
2013-01-12 01:57:44 +01:00
|
|
|
if (Pos < int(Limit))
|
|
|
|
return Order[Pos++];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-03 23:51:04 +01:00
|
|
|
/// Start over from the beginning.
|
2012-12-04 23:25:16 +01:00
|
|
|
void rewind() { Pos = -int(Hints.size()); }
|
2010-12-10 19:36:02 +01:00
|
|
|
|
2012-12-03 23:51:04 +01:00
|
|
|
/// Return true if the last register returned from next() was a preferred register.
|
2012-12-04 23:25:16 +01:00
|
|
|
bool isHint() const { return Pos <= 0; }
|
2012-12-03 23:51:04 +01:00
|
|
|
|
|
|
|
/// Return true if PhysReg is a preferred register.
|
2016-08-12 00:21:41 +02:00
|
|
|
bool isHint(unsigned PhysReg) const { return is_contained(Hints, PhysReg); }
|
2010-12-10 19:36:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|