From 3e944e38ea2d7585d2ccbf1557746d6cf7132b23 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 1 Oct 2011 07:52:37 +0000 Subject: [PATCH] Some more refactoring. * Add a couple of Create methods to the ARMConstantPoolConstant class, * Add its own version of getExistingMachineCPValue, and * Modify hasSameValue to return false if the object isn't an ARMConstantPoolConstant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140935 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMConstantPoolValue.cpp | 66 ++++++++++++++++++++++--- lib/Target/ARM/ARMConstantPoolValue.h | 18 +++++++ 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/lib/Target/ARM/ARMConstantPoolValue.cpp b/lib/Target/ARM/ARMConstantPoolValue.cpp index bca165b36eb..8a4e555367e 100644 --- a/lib/Target/ARM/ARMConstantPoolValue.cpp +++ b/lib/Target/ARM/ARMConstantPoolValue.cpp @@ -31,8 +31,9 @@ ARMConstantPoolValue::ARMConstantPoolValue(Type *Ty, unsigned id, unsigned char PCAdj, ARMCP::ARMCPModifier modifier, bool addCurrentAddress) - : MachineConstantPoolValue(Ty), LabelId(id), Kind(kind), PCAdjust(PCAdj), - Modifier(modifier), AddCurrentAddress(addCurrentAddress) {} + : MachineConstantPoolValue(Ty), S(NULL), LabelId(id), Kind(kind), + PCAdjust(PCAdj), Modifier(modifier), + AddCurrentAddress(addCurrentAddress) {} ARMConstantPoolValue::ARMConstantPoolValue(const Constant *cval, unsigned id, ARMCP::ARMCPKind K, @@ -176,6 +177,16 @@ void ARMConstantPoolValue::print(raw_ostream &O) const { // ARMConstantPoolConstant //===----------------------------------------------------------------------===// +ARMConstantPoolConstant::ARMConstantPoolConstant(Type *Ty, + const Constant *C, + unsigned ID, + ARMCP::ARMCPKind Kind, + unsigned char PCAdj, + ARMCP::ARMCPModifier Modifier, + bool AddCurrentAddress) + : ARMConstantPoolValue(Ty, ID, Kind, PCAdj, Modifier, AddCurrentAddress), + CVal(C) {} + ARMConstantPoolConstant::ARMConstantPoolConstant(const Constant *C, unsigned ID, ARMCP::ARMCPKind Kind, @@ -192,6 +203,14 @@ ARMConstantPoolConstant::Create(const Constant *C, unsigned ID) { ARMCP::no_modifier, false); } +ARMConstantPoolConstant * +ARMConstantPoolConstant::Create(const GlobalValue *GV, + ARMCP::ARMCPModifier Modifier) { + return new ARMConstantPoolConstant((Type*)Type::getInt32Ty(GV->getContext()), + GV, 0, ARMCP::CPValue, 0, + Modifier, false); +} + ARMConstantPoolConstant * ARMConstantPoolConstant::Create(const Constant *C, unsigned ID, ARMCP::ARMCPKind Kind, unsigned char PCAdj) { @@ -199,15 +218,50 @@ ARMConstantPoolConstant::Create(const Constant *C, unsigned ID, ARMCP::no_modifier, false); } +ARMConstantPoolConstant * +ARMConstantPoolConstant::Create(const Constant *C, unsigned ID, + ARMCP::ARMCPKind Kind, unsigned char PCAdj, + ARMCP::ARMCPModifier Modifier, + bool AddCurrentAddress) { + return new ARMConstantPoolConstant(C, ID, Kind, PCAdj, Modifier, + AddCurrentAddress); +} + const GlobalValue *ARMConstantPoolConstant::getGV() const { - return dyn_cast(CVal); + return dyn_cast_or_null(CVal); +} + +const BlockAddress *ARMConstantPoolConstant::getBlockAddress() const { + return dyn_cast_or_null(CVal); +} + +int ARMConstantPoolConstant::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; + ARMConstantPoolConstant *APC = dyn_cast(CPV); + if (!APC) continue; + + if (APC->getGV() == this->CVal && + APC->getLabelId() == this->getLabelId() && + APC->getPCAdjustment() == this->getPCAdjustment() && + CPV_streq(APC->getSymbol(), this->getSymbol()) && + APC->getModifier() == this->getModifier()) + return i; + } + } + + return -1; } bool ARMConstantPoolConstant::hasSameValue(ARMConstantPoolValue *ACPV) { const ARMConstantPoolConstant *ACPC = dyn_cast(ACPV); - - return (ACPC ? ACPC->CVal == CVal : true) && - ARMConstantPoolValue::hasSameValue(ACPV); + return ACPC && ACPC->CVal == CVal && ARMConstantPoolValue::hasSameValue(ACPV); } void ARMConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) { diff --git a/lib/Target/ARM/ARMConstantPoolValue.h b/lib/Target/ARM/ARMConstantPoolValue.h index 8c74d25ffc9..acdd434d87e 100644 --- a/lib/Target/ARM/ARMConstantPoolValue.h +++ b/lib/Target/ARM/ARMConstantPoolValue.h @@ -137,13 +137,31 @@ class ARMConstantPoolConstant : public ARMConstantPoolValue { unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, bool AddCurrentAddress); + ARMConstantPoolConstant(Type *Ty, const Constant *C, + unsigned ID, + ARMCP::ARMCPKind Kind, + unsigned char PCAdj, + ARMCP::ARMCPModifier Modifier, + bool AddCurrentAddress); + public: static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID); + static ARMConstantPoolConstant *Create(const GlobalValue *GV, + ARMCP::ARMCPModifier Modifier); static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID, ARMCP::ARMCPKind Kind, unsigned char PCAdj); + static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID, + ARMCP::ARMCPKind Kind, + unsigned char PCAdj, + ARMCP::ARMCPModifier Modifier, + bool AddCurrentAddress); const GlobalValue *getGV() const; + const BlockAddress *getBlockAddress() const; + + virtual int getExistingMachineCPValue(MachineConstantPool *CP, + unsigned Alignment); /// hasSameValue - Return true if this ARM constpool value can share the same /// constantpool entry as another ARM constpool value.