Added support for machine specific constantpool values. These are useful for

representing expressions that can only be resolved at link time, etc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30278 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng
2006-09-12 21:00:35 +00:00
parent cd5731d98b
commit d6594ae54c
11 changed files with 275 additions and 61 deletions

View File

@@ -24,6 +24,7 @@ namespace llvm {
class ConstantArray;
class GlobalVariable;
class MachineConstantPoolEntry;
class MachineConstantPoolValue;
class Mangler;
class TargetAsmInfo;
@@ -174,6 +175,8 @@ namespace llvm {
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
///
void EmitGlobalConstant(const Constant* CV);
virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV);
/// printInlineAsm - This method formats and prints the specified machine
/// instruction that is an inline asm.
@@ -188,7 +191,11 @@ namespace llvm {
/// printSetLabel - This method prints a set label for the specified
/// MachineBasicBlock
void printSetLabel(unsigned uid, const MachineBasicBlock *MBB) const;
/// printDataDirective - This method prints the asm directive for the
/// specified type.
void printDataDirective(const Type *type);
private:
void EmitXXStructorList(Constant *List);
void EmitConstantPool(unsigned Alignment, const char *Section,

View File

@@ -15,22 +15,77 @@
#ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H
#define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
#include "llvm/CodeGen/SelectionDAGCSEMap.h"
#include <vector>
#include <iosfwd>
namespace llvm {
class AsmPrinter;
class Constant;
class TargetData;
class TargetMachine;
class MachineConstantPool;
/// Abstract base class for all machine specific constantpool value subclasses.
///
class MachineConstantPoolValue {
const Type *Ty;
public:
MachineConstantPoolValue(const Type *ty) : Ty(ty) {}
virtual ~MachineConstantPoolValue() {};
/// getType - get type of this MachineConstantPoolValue.
///
inline const Type *getType() const { return Ty; }
virtual int getExistingMachineCPValue(MachineConstantPool *CP,
unsigned Alignment) = 0;
virtual void AddSelectionDAGCSEId(SelectionDAGCSEMap::NodeID *Id) = 0;
/// print - Implement operator<<...
///
virtual void print(std::ostream &O) const = 0;
};
inline std::ostream &operator<<(std::ostream &OS,
const MachineConstantPoolValue &V) {
V.print(OS);
return OS;
}
/// 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
struct MachineConstantPoolEntry {
Constant *Val; ///< The constant itself.
unsigned Offset; ///< The offset of the constant from the start of the pool.
MachineConstantPoolEntry(Constant *V, unsigned O) : Val(V), Offset(O) {}
/// The constant itself.
union {
Constant *ConstVal;
MachineConstantPoolValue *MachineCPVal;
} Val;
/// The offset of the constant from the start of the pool. It's really
/// 31-bit only. The top bit is set when Val is a MachineConstantPoolValue.
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;
}
};
/// The MachineConstantPool class keeps track of constants referenced by a
@@ -50,6 +105,7 @@ class MachineConstantPool {
public:
/// @brief The only constructor.
MachineConstantPool(const TargetData *td) : TD(td), PoolAlignment(1) {}
~MachineConstantPool();
/// getConstantPoolAlignment - Return the log2 of the alignment required by
/// the whole constant pool, of which the first element must be aligned.
@@ -58,6 +114,7 @@ public:
/// getConstantPoolIndex - Create a new entry in the constant pool or return
/// an existing one. User must specify an alignment in bytes for the object.
unsigned getConstantPoolIndex(Constant *C, unsigned Alignment);
unsigned getConstantPoolIndex(MachineConstantPoolValue *V,unsigned Alignment);
/// isEmpty - Return true if this constant pool contains no constants.
bool isEmpty() const { return Constants.empty(); }

View File

@@ -15,7 +15,6 @@
#ifndef LLVM_CODEGEN_SELECTIONDAG_H
#define LLVM_CODEGEN_SELECTIONDAG_H
#include "llvm/CodeGen/SelectionDAGNodes.h"
#include "llvm/CodeGen/SelectionDAGCSEMap.h"
#include "llvm/ADT/ilist"
@@ -30,6 +29,7 @@ namespace llvm {
class TargetMachine;
class MachineDebugInfo;
class MachineFunction;
class MachineConstantPoolValue;
/// SelectionDAG class - This is used to represent a portion of an LLVM function
/// in a low-level Data Dependence DAG representation suitable for instruction
@@ -167,6 +167,13 @@ public:
unsigned Align = 0, int Offset = 0) {
return getConstantPool(C, VT, Align, Offset, true);
}
SDOperand getConstantPool(MachineConstantPoolValue *C, MVT::ValueType VT,
unsigned Align = 0, int Offs = 0, bool isT=false);
SDOperand getTargetConstantPool(MachineConstantPoolValue *C,
MVT::ValueType VT, unsigned Align = 0,
int Offset = 0) {
return getConstantPool(C, VT, Align, Offset, true);
}
SDOperand getBasicBlock(MachineBasicBlock *MBB);
SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT);
SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT);

View File

@@ -16,6 +16,7 @@
#define LLVM_CODEGEN_SELECTIONDAGCSEMAP_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/SelectionDAGNodes.h"
namespace llvm {
class SDNode;

View File

@@ -19,11 +19,11 @@
#ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
#define LLVM_CODEGEN_SELECTIONDAGNODES_H
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/Value.h"
#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/iterator"
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/Support/DataTypes.h"
#include <cassert>
@@ -32,6 +32,7 @@ namespace llvm {
class SelectionDAG;
class GlobalValue;
class MachineBasicBlock;
class MachineConstantPoolValue;
class SDNode;
template <typename T> struct simplify_type;
template <typename T> struct ilist_traits;
@@ -1145,7 +1146,10 @@ public:
};
class ConstantPoolSDNode : public SDNode {
Constant *C;
union {
Constant *ConstVal;
MachineConstantPoolValue *MachineCPVal;
} Val;
int Offset;
unsigned Alignment;
protected:
@@ -1153,20 +1157,57 @@ protected:
ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
int o=0)
: SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
C(c), Offset(o), Alignment(0) {}
Offset(o), Alignment(0) {
assert((int)Offset >= 0 && "Offset is too large");
Val.ConstVal = c;
}
ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
unsigned Align)
: SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
C(c), Offset(o), Alignment(Align) {}
Offset(o), Alignment(Align) {
assert((int)Offset >= 0 && "Offset is too large");
Val.ConstVal = c;
}
ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
MVT::ValueType VT, int o=0)
: SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
Offset(o), Alignment(0) {
assert((int)Offset >= 0 && "Offset is too large");
Val.MachineCPVal = v;
Offset |= 1 << (sizeof(unsigned)*8-1);
}
ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
MVT::ValueType VT, int o, unsigned Align)
: SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
Offset(o), Alignment(Align) {
assert((int)Offset >= 0 && "Offset is too large");
Val.MachineCPVal = v;
Offset |= 1 << (sizeof(unsigned)*8-1);
}
public:
Constant *get() const { return C; }
bool isMachineConstantPoolEntry() const {
return (int)Offset < 0;
}
Constant *getConstVal() const {
assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
return Val.ConstVal;
}
MachineConstantPoolValue *getMachineCPVal() const {
assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
return Val.MachineCPVal;
}
int getOffset() const { return Offset; }
// Return the alignment of this constant pool object, which is either 0 (for
// default alignment) or log2 of the desired value.
unsigned getAlignment() const { return Alignment; }
const Type *getType() const;
static bool classof(const ConstantPoolSDNode *) { return true; }
static bool classof(const SDNode *N) {
return N->getOpcode() == ISD::ConstantPool ||