diff options
| author | Bill Wendling <isanbard@gmail.com> | 2011-10-01 08:36:59 +0000 | 
|---|---|---|
| committer | Bill Wendling <isanbard@gmail.com> | 2011-10-01 08:36:59 +0000 | 
| commit | d7fa0167209e629ae8536424888f6865d975dd62 (patch) | |
| tree | 537c03ce5fab62d7aa51727b4a0cdfa041acb649 /llvm/lib/Target/ARM | |
| parent | d115c4d300049e44fb2b87b3236a715fa1dcb63a (diff) | |
| download | bcm5719-llvm-d7fa0167209e629ae8536424888f6865d975dd62.tar.gz bcm5719-llvm-d7fa0167209e629ae8536424888f6865d975dd62.zip  | |
Add an ARMConstantPool class for external symbols. This will split out the support for external symbols from the base class.
llvm-svn: 140938
Diffstat (limited to 'llvm/lib/Target/ARM')
| -rw-r--r-- | llvm/lib/Target/ARM/ARMConstantPoolValue.cpp | 82 | ||||
| -rw-r--r-- | llvm/lib/Target/ARM/ARMConstantPoolValue.h | 41 | 
2 files changed, 118 insertions, 5 deletions
diff --git a/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp b/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp index 1061c6a0b23..2d2ab885fd3 100644 --- a/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp +++ b/llvm/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<MachineConstantPoolEntry> 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<ARMConstantPoolSymbol>(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<ARMConstantPoolSymbol>(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/llvm/lib/Target/ARM/ARMConstantPoolValue.h b/llvm/lib/Target/ARM/ARMConstantPoolValue.h index fea43790c0e..4ced33ab2c3 100644 --- a/llvm/lib/Target/ARM/ARMConstantPoolValue.h +++ b/llvm/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  | 

