From d6594ae54cfde4db4d30272192645c0a45fb9902 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Tue, 12 Sep 2006 21:00:35 +0000 Subject: 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 --- lib/CodeGen/MachineFunction.cpp | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'lib/CodeGen/MachineFunction.cpp') diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 64ab572648..e07832435b 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -351,6 +351,12 @@ void MachineJumpTableInfo::dump() const { print(std::cerr); } // MachineConstantPool implementation //===----------------------------------------------------------------------===// +MachineConstantPool::~MachineConstantPool() { + for (unsigned i = 0, e = Constants.size(); i != e; ++i) + if (Constants[i].isMachineConstantPoolEntry()) + delete Constants[i].Val.MachineCPVal; +} + /// getConstantPoolIndex - Create a new entry in the constant pool or return /// an existing one. User must specify an alignment in bytes for the object. /// @@ -364,13 +370,13 @@ unsigned MachineConstantPool::getConstantPoolIndex(Constant *C, // FIXME, this could be made much more efficient for large constant pools. unsigned AlignMask = (1 << Alignment)-1; for (unsigned i = 0, e = Constants.size(); i != e; ++i) - if (Constants[i].Val == C && (Constants[i].Offset & AlignMask) == 0) + if (Constants[i].Val.ConstVal == C && (Constants[i].Offset & AlignMask)== 0) return i; unsigned Offset = 0; if (!Constants.empty()) { Offset = Constants.back().Offset; - Offset += TD->getTypeSize(Constants.back().Val->getType()); + Offset += TD->getTypeSize(Constants.back().Val.ConstVal->getType()); Offset = (Offset+AlignMask)&~AlignMask; } @@ -378,10 +384,38 @@ unsigned MachineConstantPool::getConstantPoolIndex(Constant *C, return Constants.size()-1; } +unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V, + unsigned Alignment) { + assert(Alignment && "Alignment must be specified!"); + if (Alignment > PoolAlignment) PoolAlignment = Alignment; + + // Check to see if we already have this constant. + // + // FIXME, this could be made much more efficient for large constant pools. + unsigned AlignMask = (1 << Alignment)-1; + int Idx = V->getExistingMachineCPValue(this, Alignment); + if (Idx != -1) + return (unsigned)Idx; + + unsigned Offset = 0; + if (!Constants.empty()) { + Offset = Constants.back().Offset; + Offset += TD->getTypeSize(Constants.back().Val.MachineCPVal->getType()); + Offset = (Offset+AlignMask)&~AlignMask; + } + + Constants.push_back(MachineConstantPoolEntry(V, Offset)); + return Constants.size()-1; +} + void MachineConstantPool::print(std::ostream &OS) const { for (unsigned i = 0, e = Constants.size(); i != e; ++i) { - OS << " is" << *(Value*)Constants[i].Val; + OS << " is"; + if (Constants[i].isMachineConstantPoolEntry()) + Constants[i].Val.MachineCPVal->print(OS); + else + OS << *(Value*)Constants[i].Val.ConstVal; OS << " , offset=" << Constants[i].Offset; OS << "\n"; } -- cgit v1.2.3-18-g5258