2003-01-13 02:01:31 +01:00
|
|
|
//===-- CodeGen/MachineConstantPool.h - Abstract Constant Pool --*- C++ -*-===//
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2009-03-03 03:55:14 +01:00
|
|
|
/// @file
|
|
|
|
/// This file declares the MachineConstantPool class which is an abstract
|
2006-05-15 18:12:01 +02:00
|
|
|
/// constant pool to keep track of constants referenced by a function.
|
2003-01-13 02:01:31 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H
|
|
|
|
#define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
|
|
|
|
|
2008-07-11 22:38:31 +02:00
|
|
|
#include <cassert>
|
2009-04-01 20:45:54 +02:00
|
|
|
#include <climits>
|
2003-01-13 02:01:31 +01:00
|
|
|
#include <vector>
|
2003-11-11 23:41:34 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2003-01-13 02:01:31 +01:00
|
|
|
class Constant;
|
2008-12-03 02:53:18 +01:00
|
|
|
class FoldingSetNodeID;
|
2006-02-09 05:44:32 +01:00
|
|
|
class TargetData;
|
2006-09-12 23:00:35 +02:00
|
|
|
class TargetMachine;
|
2008-07-11 22:38:31 +02:00
|
|
|
class Type;
|
2006-09-12 23:00:35 +02:00
|
|
|
class MachineConstantPool;
|
2008-08-24 00:23:09 +02:00
|
|
|
class raw_ostream;
|
2006-09-12 23:00:35 +02:00
|
|
|
|
|
|
|
/// Abstract base class for all machine specific constantpool value subclasses.
|
|
|
|
///
|
|
|
|
class MachineConstantPoolValue {
|
|
|
|
const Type *Ty;
|
|
|
|
|
|
|
|
public:
|
2007-03-23 19:44:11 +01:00
|
|
|
explicit MachineConstantPoolValue(const Type *ty) : Ty(ty) {}
|
2007-08-27 16:50:10 +02:00
|
|
|
virtual ~MachineConstantPoolValue() {}
|
2006-09-12 23:00:35 +02:00
|
|
|
|
|
|
|
/// getType - get type of this MachineConstantPoolValue.
|
|
|
|
///
|
2009-07-22 01:34:23 +02:00
|
|
|
const Type *getType() const { return Ty; }
|
2006-09-12 23:00:35 +02:00
|
|
|
|
2009-07-22 01:34:23 +02:00
|
|
|
|
2009-07-22 01:36:01 +02:00
|
|
|
/// getRelocationInfo - This method classifies the entry according to
|
2009-07-22 01:34:23 +02: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 05:27:21 +02:00
|
|
|
/// so. The return values are the same as Constant::getRelocationInfo().
|
2009-07-22 01:36:01 +02:00
|
|
|
virtual unsigned getRelocationInfo() const = 0;
|
2009-07-22 01:34:23 +02:00
|
|
|
|
2006-09-12 23:00:35 +02:00
|
|
|
virtual int getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) = 0;
|
|
|
|
|
2006-10-28 01:46:08 +02:00
|
|
|
virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID) = 0;
|
2006-09-12 23:00:35 +02:00
|
|
|
|
2008-08-24 00:53:13 +02:00
|
|
|
/// print - Implement operator<<
|
2008-08-24 00:23:09 +02:00
|
|
|
virtual void print(raw_ostream &O) const = 0;
|
2006-09-12 23:00:35 +02:00
|
|
|
};
|
|
|
|
|
2008-08-24 00:23:09 +02:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS,
|
|
|
|
const MachineConstantPoolValue &V) {
|
|
|
|
V.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2003-01-13 02:01:31 +01:00
|
|
|
|
2006-05-15 18:12:01 +02: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 20:31:28 +01:00
|
|
|
class MachineConstantPoolEntry {
|
|
|
|
public:
|
2006-09-12 23:00:35 +02:00
|
|
|
/// The constant itself.
|
|
|
|
union {
|
2010-04-15 03:51:59 +02:00
|
|
|
const Constant *ConstVal;
|
2006-09-12 23:00:35 +02:00
|
|
|
MachineConstantPoolValue *MachineCPVal;
|
|
|
|
} Val;
|
|
|
|
|
2009-03-13 08:51:59 +01:00
|
|
|
/// The required alignment for this entry. The top bit is set when Val is
|
|
|
|
/// a MachineConstantPoolValue.
|
|
|
|
unsigned Alignment;
|
2006-09-12 23:00:35 +02:00
|
|
|
|
2010-04-15 03:51:59 +02:00
|
|
|
MachineConstantPoolEntry(const Constant *V, unsigned A)
|
2009-03-13 08:51:59 +01:00
|
|
|
: Alignment(A) {
|
2006-09-12 23:00:35 +02:00
|
|
|
Val.ConstVal = V;
|
|
|
|
}
|
2009-03-13 08:51:59 +01:00
|
|
|
MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned A)
|
|
|
|
: Alignment(A) {
|
2006-09-12 23:00:35 +02:00
|
|
|
Val.MachineCPVal = V;
|
2009-09-06 14:56:52 +02:00
|
|
|
Alignment |= 1U << (sizeof(unsigned)*CHAR_BIT-1);
|
2006-09-12 23:00:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isMachineConstantPoolEntry() const {
|
2009-03-13 08:51:59 +01:00
|
|
|
return (int)Alignment < 0;
|
2006-09-12 23:00:35 +02:00
|
|
|
}
|
2006-09-14 07:48:39 +02:00
|
|
|
|
2009-03-13 08:51:59 +01:00
|
|
|
int getAlignment() const {
|
2009-04-01 20:45:54 +02:00
|
|
|
return Alignment & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
|
2006-09-14 09:32:32 +02:00
|
|
|
}
|
|
|
|
|
2006-09-14 07:48:39 +02:00
|
|
|
const Type *getType() const;
|
2009-07-22 01:34:23 +02:00
|
|
|
|
2009-07-22 01:36:01 +02:00
|
|
|
/// getRelocationInfo - This method classifies the entry according to
|
2009-07-22 01:34:23 +02: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-22 01:36:01 +02:00
|
|
|
unsigned getRelocationInfo() const;
|
2006-02-09 05:21:49 +01:00
|
|
|
};
|
|
|
|
|
2006-05-15 18:12:01 +02: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 02:01:31 +01:00
|
|
|
class MachineConstantPool {
|
2006-05-15 18:12:01 +02:00
|
|
|
const TargetData *TD; ///< The machine's TargetData.
|
|
|
|
unsigned PoolAlignment; ///< The alignment for the pool.
|
|
|
|
std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants.
|
2003-01-13 02:01:31 +01:00
|
|
|
public:
|
2006-05-15 18:12:01 +02:00
|
|
|
/// @brief The only constructor.
|
2007-08-01 17:32:29 +02:00
|
|
|
explicit MachineConstantPool(const TargetData *td)
|
|
|
|
: TD(td), PoolAlignment(1) {}
|
2006-09-12 23:00:35 +02:00
|
|
|
~MachineConstantPool();
|
2006-02-09 05:44:32 +01:00
|
|
|
|
2010-02-10 17:03:48 +01:00
|
|
|
/// getConstantPoolAlignment - Return the alignment required by
|
2006-02-09 05:44:32 +01:00
|
|
|
/// the whole constant pool, of which the first element must be aligned.
|
|
|
|
unsigned getConstantPoolAlignment() const { return PoolAlignment; }
|
|
|
|
|
2003-01-13 02:01:31 +01:00
|
|
|
/// getConstantPoolIndex - Create a new entry in the constant pool or return
|
2009-03-13 08:51:59 +01:00
|
|
|
/// an existing one. User must specify the minimum required alignment for
|
|
|
|
/// the object.
|
2010-04-15 03:51:59 +02:00
|
|
|
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment);
|
2006-09-12 23:00:35 +02:00
|
|
|
unsigned getConstantPoolIndex(MachineConstantPoolValue *V,unsigned Alignment);
|
2006-02-09 05:44:32 +01:00
|
|
|
|
2005-07-11 06:49:33 +02:00
|
|
|
/// isEmpty - Return true if this constant pool contains no constants.
|
|
|
|
bool isEmpty() const { return Constants.empty(); }
|
|
|
|
|
2006-02-09 05:21:49 +01:00
|
|
|
const std::vector<MachineConstantPoolEntry> &getConstants() const {
|
2006-01-31 23:23:14 +01:00
|
|
|
return Constants;
|
|
|
|
}
|
2003-01-13 02:01:31 +01:00
|
|
|
|
|
|
|
/// print - Used by the MachineFunction printer to print information about
|
2006-04-18 18:03:18 +02:00
|
|
|
/// constant pool objects. Implemented in MachineFunction.cpp
|
2003-01-13 02:01:31 +01:00
|
|
|
///
|
2008-08-24 00:53:13 +02:00
|
|
|
void print(raw_ostream &OS) const;
|
2003-01-13 02:01:31 +01:00
|
|
|
|
2008-08-24 00:53:13 +02:00
|
|
|
/// dump - Call print(cerr) to be called from the debugger.
|
2003-01-13 02:01:31 +01:00
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-01-13 02:01:31 +01:00
|
|
|
#endif
|