From ff4a8023ecf328047c8f98c7f42bf5e8b46b2f11 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 1 Oct 2011 08:36:59 +0000 Subject: [PATCH] Add an ARMConstantPool class for external symbols. This will split out the support for external symbols from the base class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140938 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMConstantPoolValue.cpp | 82 +++++++++++++++++++++++-- lib/Target/ARM/ARMConstantPoolValue.h | 41 ++++++++++++- 2 files changed, 118 insertions(+), 5 deletions(-) diff --git a/lib/Target/ARM/ARMConstantPoolValue.cpp b/lib/Target/ARM/ARMConstantPoolValue.cpp index 1061c6a0b23..2d2ab885fd3 100644 --- a/lib/Target/ARM/ARMConstantPoolValue.cpp +++ b/lib/Target/ARM/ARMConstantPoolValue.cpp @@ -35,6 +35,15 @@ ARMConstantPoolValue::ARMConstantPoolValue(Type *Ty, unsigned id, PCAdjust(PCAdj), Modifier(modifier), AddCurrentAddress(addCurrentAddress) {} +ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C, unsigned id, + ARMCP::ARMCPKind kind, + unsigned char PCAdj, + ARMCP::ARMCPModifier modifier, + bool addCurrentAddress) + : MachineConstantPoolValue((Type*)Type::getInt32Ty(C)), + LabelId(id), Kind(kind), PCAdjust(PCAdj), Modifier(modifier), + AddCurrentAddress(addCurrentAddress) {} + ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C, const MachineBasicBlock *mbb, unsigned id, @@ -55,6 +64,10 @@ ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C, S(strdup(s)), LabelId(id), Kind(ARMCP::CPExtSymbol), PCAdjust(PCAdj), Modifier(Modif), AddCurrentAddress(AddCA) {} +ARMConstantPoolValue::~ARMConstantPoolValue() { + free((void*)S); +} + const MachineBasicBlock *ARMConstantPoolValue::getMBB() const { return MBB; } @@ -101,10 +114,6 @@ int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP, return -1; } -ARMConstantPoolValue::~ARMConstantPoolValue() { - free((void*)S); -} - void ARMConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) { ID.AddPointer(S); @@ -245,3 +254,68 @@ void ARMConstantPoolConstant::print(raw_ostream &O) const { O << CVal->getName(); ARMConstantPoolValue::print(O); } + +//===----------------------------------------------------------------------===// +// ARMConstantPoolSymbol +//===----------------------------------------------------------------------===// + +ARMConstantPoolSymbol::ARMConstantPoolSymbol(LLVMContext &C, const char *s, + unsigned id, + unsigned char PCAdj, + ARMCP::ARMCPModifier Modifier, + bool AddCurrentAddress) + : ARMConstantPoolValue(C, id, ARMCP::CPExtSymbol, PCAdj, Modifier, + AddCurrentAddress), + S(strdup(s)) {} + +ARMConstantPoolSymbol::~ARMConstantPoolSymbol() { + free((void*)S); +} + +ARMConstantPoolSymbol * +ARMConstantPoolSymbol::Create(LLVMContext &C, const char *s, + unsigned ID, unsigned char PCAdj, + ARMCP::ARMCPModifier Modifier, + bool AddCurrentAddress) { + return new ARMConstantPoolSymbol(C, s, ID, PCAdj, Modifier, + AddCurrentAddress); +} + +int ARMConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP, + unsigned Alignment) { + unsigned AlignMask = Alignment - 1; + const std::vector Constants = CP->getConstants(); + for (unsigned i = 0, e = Constants.size(); i != e; ++i) { + if (Constants[i].isMachineConstantPoolEntry() && + (Constants[i].getAlignment() & AlignMask) == 0) { + ARMConstantPoolValue *CPV = + (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal; + ARMConstantPoolSymbol *APS = dyn_cast(CPV); + if (!APS) continue; + + if (APS->getLabelId() == this->getLabelId() && + APS->getPCAdjustment() == this->getPCAdjustment() && + CPV_streq(APS->getSymbol(), this->getSymbol()) && + APS->getModifier() == this->getModifier()) + return i; + } + } + + return -1; +} + +bool ARMConstantPoolSymbol::hasSameValue(ARMConstantPoolValue *ACPV) { + const ARMConstantPoolSymbol *ACPS = dyn_cast(ACPV); + return ACPS && CPV_streq(ACPS->S, S) && + ARMConstantPoolValue::hasSameValue(ACPV); +} + +void ARMConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) { + ID.AddPointer(S); + ARMConstantPoolValue::addSelectionDAGCSEId(ID); +} + +void ARMConstantPoolSymbol::print(raw_ostream &O) const { + O << S; + ARMConstantPoolValue::print(O); +} diff --git a/lib/Target/ARM/ARMConstantPoolValue.h b/lib/Target/ARM/ARMConstantPoolValue.h index fea43790c0e..4ced33ab2c3 100644 --- a/lib/Target/ARM/ARMConstantPoolValue.h +++ b/lib/Target/ARM/ARMConstantPoolValue.h @@ -63,6 +63,9 @@ protected: unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, bool AddCurrentAddress); + ARMConstantPoolValue(LLVMContext &C, unsigned id, ARMCP::ARMCPKind Kind, + unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, + bool AddCurrentAddress); public: ARMConstantPoolValue(LLVMContext &C, const MachineBasicBlock *mbb,unsigned id, ARMCP::ARMCPKind Kind = ARMCP::CPValue, @@ -73,7 +76,7 @@ public: unsigned char PCAdj = 0, ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier, bool AddCurrentAddress = false); - ~ARMConstantPoolValue(); + virtual ~ARMConstantPoolValue(); const char *getSymbol() const { return S; } const MachineBasicBlock *getMBB() const; @@ -166,6 +169,42 @@ public: static bool classof(const ARMConstantPoolConstant *) { return true; } }; +/// ARMConstantPoolSymbol - ARM-specific constantpool values for external +/// symbols. +class ARMConstantPoolSymbol : public ARMConstantPoolValue { + const char *S; // ExtSymbol being loaded. + + ARMConstantPoolSymbol(LLVMContext &C, const char *s, unsigned id, + unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, + bool AddCurrentAddress); + +public: + ~ARMConstantPoolSymbol(); + + static ARMConstantPoolSymbol *Create(LLVMContext &C, const char *s, + unsigned ID, unsigned char PCAdj, + ARMCP::ARMCPModifier Modifier, + bool AddCurrentAddress); + + const char *getSymbol() const { return S; } + + virtual int getExistingMachineCPValue(MachineConstantPool *CP, + unsigned Alignment); + + virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID); + + /// hasSameValue - Return true if this ARM constpool value can share the same + /// constantpool entry as another ARM constpool value. + virtual bool hasSameValue(ARMConstantPoolValue *ACPV); + + virtual void print(raw_ostream &O) const; + + static bool classof(const ARMConstantPoolValue *ACPV) { + return ACPV->isExtSymbol(); + } + static bool classof(const ARMConstantPoolSymbol *) { return true; } +}; + } // End llvm namespace #endif