2003-01-13 01:01:31 +00:00
|
|
|
//===-- CodeGen/MachineConstantPool.h - Abstract Constant Pool --*- C++ -*-===//
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2009-03-03 02:55:14 +00:00
|
|
|
/// @file
|
|
|
|
/// This file declares the MachineConstantPool class which is an abstract
|
2006-05-15 16:12:01 +00:00
|
|
|
/// constant pool to keep track of constants referenced by a function.
|
2003-01-13 01:01:31 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H
|
|
|
|
#define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
|
|
|
|
|
2011-02-22 08:54:30 +00:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2008-07-11 20:38:31 +00:00
|
|
|
#include <cassert>
|
2009-04-01 18:45:54 +00:00
|
|
|
#include <climits>
|
2003-01-13 01:01:31 +00:00
|
|
|
#include <vector>
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2003-01-13 01:01:31 +00:00
|
|
|
class Constant;
|
2008-12-03 01:53:18 +00:00
|
|
|
class FoldingSetNodeID;
|
2006-02-09 04:44:32 +00:00
|
|
|
class TargetData;
|
2006-09-12 21:00:35 +00:00
|
|
|
class TargetMachine;
|
2008-07-11 20:38:31 +00:00
|
|
|
class Type;
|
2006-09-12 21:00:35 +00:00
|
|
|
class MachineConstantPool;
|
2008-08-23 22:23:09 +00:00
|
|
|
class raw_ostream;
|
2006-09-12 21:00:35 +00:00
|
|
|
|
|
|
|
/// Abstract base class for all machine specific constantpool value subclasses.
|
|
|
|
///
|
|
|
|
class MachineConstantPoolValue {
|
|
|
|
const Type *Ty;
|
|
|
|
|
|
|
|
public:
|
2007-03-23 18:44:11 +00:00
|
|
|
explicit MachineConstantPoolValue(const Type *ty) : Ty(ty) {}
|
2007-08-27 14:50:10 +00:00
|
|
|
virtual ~MachineConstantPoolValue() {}
|
2006-09-12 21:00:35 +00:00
|
|
|
|
|
|
|
/// getType - get type of this MachineConstantPoolValue.
|
|
|
|
///
|
2009-07-21 23:34:23 +00:00
|
|
|
const Type *getType() const { return Ty; }
|
2006-09-12 21:00:35 +00:00
|
|
|
|
2009-07-21 23:34:23 +00:00
|
|
|
|
2009-07-21 23:36:01 +00:00
|
|
|
/// getRelocationInfo - This method classifies the entry according to
|
2009-07-21 23:34:23 +00:00
|
|
|
/// whether or not it may generate a relocation entry. This must be
|
|
|
|
/// conservative, so if it might codegen to a relocatable entry, it should say
|
2009-07-24 03:27:21 +00:00
|
|
|
/// so. The return values are the same as Constant::getRelocationInfo().
|
2009-07-21 23:36:01 +00:00
|
|
|
virtual unsigned getRelocationInfo() const = 0;
|
2009-07-21 23:34:23 +00:00
|
|
|
|
2006-09-12 21:00:35 +00:00
|
|
|
virtual int getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) = 0;
|
|
|
|
|
2006-10-27 23:46:08 +00:00
|
|
|
virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID) = 0;
|
2006-09-12 21:00:35 +00:00
|
|
|
|
2008-08-23 22:53:13 +00:00
|
|
|
/// print - Implement operator<<
|
2008-08-23 22:23:09 +00:00
|
|
|
virtual void print(raw_ostream &O) const = 0;
|
2006-09-12 21:00:35 +00:00
|
|
|
};
|
|
|
|
|
2008-08-23 22:23:09 +00:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS,
|
|
|
|
const MachineConstantPoolValue &V) {
|
|
|
|
V.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2003-01-13 01:01:31 +00:00
|
|
|
|
2006-05-15 16:12:01 +00:00
|
|
|
/// This class is a data container for one entry in a MachineConstantPool.
|
|
|
|
/// It contains a pointer to the value and an offset from the start of
|
|
|
|
/// the constant pool.
|
|
|
|
/// @brief An entry in a MachineConstantPool
|
2006-11-05 19:31:28 +00:00
|
|
|
class MachineConstantPoolEntry {
|
|
|
|
public:
|
2006-09-12 21:00:35 +00:00
|
|
|
/// The constant itself.
|
|
|
|
union {
|
2010-04-15 01:51:59 +00:00
|
|
|
const Constant *ConstVal;
|
2006-09-12 21:00:35 +00:00
|
|
|
MachineConstantPoolValue *MachineCPVal;
|
|
|
|
} Val;
|
|
|
|
|
2009-03-13 07:51:59 +00:00
|
|
|
/// The required alignment for this entry. The top bit is set when Val is
|
|
|
|
/// a MachineConstantPoolValue.
|
|
|
|
unsigned Alignment;
|
2006-09-12 21:00:35 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
MachineConstantPoolEntry(const Constant *V, unsigned A)
|
2009-03-13 07:51:59 +00:00
|
|
|
: Alignment(A) {
|
2006-09-12 21:00:35 +00:00
|
|
|
Val.ConstVal = V;
|
|
|
|
}
|
2009-03-13 07:51:59 +00:00
|
|
|
MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned A)
|
|
|
|
: Alignment(A) {
|
2006-09-12 21:00:35 +00:00
|
|
|
Val.MachineCPVal = V;
|
2009-09-06 12:56:52 +00:00
|
|
|
Alignment |= 1U << (sizeof(unsigned)*CHAR_BIT-1);
|
2006-09-12 21:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isMachineConstantPoolEntry() const {
|
2009-03-13 07:51:59 +00:00
|
|
|
return (int)Alignment < 0;
|
2006-09-12 21:00:35 +00:00
|
|
|
}
|
2006-09-14 05:48:39 +00:00
|
|
|
|
2009-03-13 07:51:59 +00:00
|
|
|
int getAlignment() const {
|
2009-04-01 18:45:54 +00:00
|
|
|
return Alignment & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
|
2006-09-14 07:32:32 +00:00
|
|
|
}
|
|
|
|
|
2006-09-14 05:48:39 +00:00
|
|
|
const Type *getType() const;
|
2009-07-21 23:34:23 +00:00
|
|
|
|
2009-07-21 23:36:01 +00:00
|
|
|
/// getRelocationInfo - This method classifies the entry according to
|
2009-07-21 23:34:23 +00:00
|
|
|
/// whether or not it may generate a relocation entry. This must be
|
|
|
|
/// conservative, so if it might codegen to a relocatable entry, it should say
|
|
|
|
/// so. The return values are:
|
|
|
|
///
|
|
|
|
/// 0: This constant pool entry is guaranteed to never have a relocation
|
|
|
|
/// applied to it (because it holds a simple constant like '4').
|
|
|
|
/// 1: This entry has relocations, but the entries are guaranteed to be
|
|
|
|
/// resolvable by the static linker, so the dynamic linker will never see
|
|
|
|
/// them.
|
|
|
|
/// 2: This entry may have arbitrary relocations.
|
2009-07-21 23:36:01 +00:00
|
|
|
unsigned getRelocationInfo() const;
|
2006-02-09 04:21:49 +00:00
|
|
|
};
|
|
|
|
|
2006-05-15 16:12:01 +00:00
|
|
|
/// The MachineConstantPool class keeps track of constants referenced by a
|
|
|
|
/// function which must be spilled to memory. This is used for constants which
|
|
|
|
/// are unable to be used directly as operands to instructions, which typically
|
|
|
|
/// include floating point and large integer constants.
|
|
|
|
///
|
|
|
|
/// Instructions reference the address of these constant pool constants through
|
|
|
|
/// the use of MO_ConstantPoolIndex values. When emitting assembly or machine
|
|
|
|
/// code, these virtual address references are converted to refer to the
|
|
|
|
/// address of the function constant pool values.
|
|
|
|
/// @brief The machine constant pool.
|
2003-01-13 01:01:31 +00:00
|
|
|
class MachineConstantPool {
|
2006-05-15 16:12:01 +00:00
|
|
|
const TargetData *TD; ///< The machine's TargetData.
|
|
|
|
unsigned PoolAlignment; ///< The alignment for the pool.
|
|
|
|
std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants.
|
2011-02-22 08:54:30 +00:00
|
|
|
/// MachineConstantPoolValues that use an existing MachineConstantPoolEntry.
|
|
|
|
DenseSet<MachineConstantPoolValue*> MachineCPVsSharingEntries;
|
2003-01-13 01:01:31 +00:00
|
|
|
public:
|
2006-05-15 16:12:01 +00:00
|
|
|
/// @brief The only constructor.
|
2007-08-01 15:32:29 +00:00
|
|
|
explicit MachineConstantPool(const TargetData *td)
|
|
|
|
: TD(td), PoolAlignment(1) {}
|
2006-09-12 21:00:35 +00:00
|
|
|
~MachineConstantPool();
|
2006-02-09 04:44:32 +00:00
|
|
|
|
2010-02-10 16:03:48 +00:00
|
|
|
/// getConstantPoolAlignment - Return the alignment required by
|
2006-02-09 04:44:32 +00:00
|
|
|
/// the whole constant pool, of which the first element must be aligned.
|
|
|
|
unsigned getConstantPoolAlignment() const { return PoolAlignment; }
|
|
|
|
|
2003-01-13 01:01:31 +00:00
|
|
|
/// getConstantPoolIndex - Create a new entry in the constant pool or return
|
2009-03-13 07:51:59 +00:00
|
|
|
/// an existing one. User must specify the minimum required alignment for
|
|
|
|
/// the object.
|
2010-04-15 01:51:59 +00:00
|
|
|
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment);
|
2006-09-12 21:00:35 +00:00
|
|
|
unsigned getConstantPoolIndex(MachineConstantPoolValue *V,unsigned Alignment);
|
2006-02-09 04:44:32 +00:00
|
|
|
|
2005-07-11 04:49:33 +00:00
|
|
|
/// isEmpty - Return true if this constant pool contains no constants.
|
|
|
|
bool isEmpty() const { return Constants.empty(); }
|
|
|
|
|
2006-02-09 04:21:49 +00:00
|
|
|
const std::vector<MachineConstantPoolEntry> &getConstants() const {
|
2006-01-31 22:23:14 +00:00
|
|
|
return Constants;
|
|
|
|
}
|
2003-01-13 01:01:31 +00:00
|
|
|
|
|
|
|
/// print - Used by the MachineFunction printer to print information about
|
2006-04-18 16:03:18 +00:00
|
|
|
/// constant pool objects. Implemented in MachineFunction.cpp
|
2003-01-13 01:01:31 +00:00
|
|
|
///
|
2008-08-23 22:53:13 +00:00
|
|
|
void print(raw_ostream &OS) const;
|
2003-01-13 01:01:31 +00:00
|
|
|
|
2008-08-23 22:53:13 +00:00
|
|
|
/// dump - Call print(cerr) to be called from the debugger.
|
2003-01-13 01:01:31 +00:00
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-01-13 01:01:31 +00:00
|
|
|
#endif
|