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
|
|
|
//
|
2006-05-15 16:12:01 +00:00
|
|
|
/// @file This file declares the MachineConstantPool class which is an abstract
|
|
|
|
/// 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
|
|
|
|
|
2006-10-27 23:46:08 +00:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAGNodes.h"
|
2006-11-28 22:21:29 +00:00
|
|
|
#include "llvm/Support/Streams.h"
|
2003-01-13 01:01:31 +00:00
|
|
|
#include <vector>
|
2005-12-28 06:47:33 +00:00
|
|
|
#include <iosfwd>
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2006-09-12 21:00:35 +00:00
|
|
|
class AsmPrinter;
|
2003-01-13 01:01:31 +00:00
|
|
|
class Constant;
|
2006-02-09 04:44:32 +00:00
|
|
|
class TargetData;
|
2006-09-12 21:00:35 +00:00
|
|
|
class TargetMachine;
|
|
|
|
class MachineConstantPool;
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
inline const Type *getType() const { return Ty; }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/// print - Implement operator<<...
|
|
|
|
///
|
|
|
|
virtual void print(std::ostream &O) const = 0;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *O) const { if (O) print(*O); }
|
2006-09-12 21:00:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline std::ostream &operator<<(std::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 {
|
|
|
|
Constant *ConstVal;
|
|
|
|
MachineConstantPoolValue *MachineCPVal;
|
|
|
|
} Val;
|
|
|
|
|
2006-09-14 07:32:32 +00:00
|
|
|
/// The offset of the constant from the start of the pool. The top bit is set
|
|
|
|
/// when Val is a MachineConstantPoolValue.
|
2006-09-12 21:00:35 +00:00
|
|
|
unsigned Offset;
|
|
|
|
|
|
|
|
MachineConstantPoolEntry(Constant *V, unsigned O)
|
|
|
|
: Offset(O) {
|
|
|
|
assert((int)Offset >= 0 && "Offset is too large");
|
|
|
|
Val.ConstVal = V;
|
|
|
|
}
|
|
|
|
MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned O)
|
|
|
|
: Offset(O){
|
|
|
|
assert((int)Offset >= 0 && "Offset is too large");
|
|
|
|
Val.MachineCPVal = V;
|
|
|
|
Offset |= 1 << (sizeof(unsigned)*8-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isMachineConstantPoolEntry() const {
|
|
|
|
return (int)Offset < 0;
|
|
|
|
}
|
2006-09-14 05:48:39 +00:00
|
|
|
|
2006-09-14 07:32:32 +00:00
|
|
|
int getOffset() const {
|
|
|
|
return Offset & ~(1 << (sizeof(unsigned)*8-1));
|
|
|
|
}
|
|
|
|
|
2006-09-14 05:48:39 +00:00
|
|
|
const Type *getType() 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.
|
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
|
|
|
|
|
|
|
/// getConstantPoolAlignment - Return the log2 of the alignment required by
|
|
|
|
/// 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
|
2006-02-09 02:24:25 +00:00
|
|
|
/// an existing one. User must specify an alignment in bytes for the object.
|
2006-02-09 04:44:32 +00:00
|
|
|
unsigned getConstantPoolIndex(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
|
|
|
///
|
|
|
|
void print(std::ostream &OS) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
2003-01-13 01:01:31 +00:00
|
|
|
|
|
|
|
/// dump - Call print(std::cerr) to be called from the debugger.
|
2006-02-09 04:44:32 +00:00
|
|
|
///
|
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
|