LCOV - code coverage report
Current view: top level - lib/Target/ARM - ARMConstantPoolValue.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 25 28 89.3 %
Date: 2017-09-14 15:23:50 Functions: 10 13 76.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- ARMConstantPoolValue.h - ARM constantpool value ---------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements the ARM specific constantpool value class.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #ifndef LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H
      15             : #define LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H
      16             : 
      17             : #include "llvm/ADT/StringRef.h"
      18             : #include "llvm/ADT/SmallPtrSet.h"
      19             : #include "llvm/CodeGen/MachineConstantPool.h"
      20             : #include "llvm/Support/Casting.h"
      21             : #include <string>
      22             : #include <vector>
      23             : 
      24             : namespace llvm {
      25             : 
      26             : class BlockAddress;
      27             : class Constant;
      28             : class GlobalValue;
      29             : class GlobalVariable;
      30             : class LLVMContext;
      31             : class MachineBasicBlock;
      32             : 
      33             : namespace ARMCP {
      34             : 
      35             :   enum ARMCPKind {
      36             :     CPValue,
      37             :     CPExtSymbol,
      38             :     CPBlockAddress,
      39             :     CPLSDA,
      40             :     CPMachineBasicBlock,
      41             :     CPPromotedGlobal
      42             :   };
      43             : 
      44             :   enum ARMCPModifier {
      45             :     no_modifier, /// None
      46             :     TLSGD,       /// Thread Local Storage (General Dynamic Mode)
      47             :     GOT_PREL,    /// Global Offset Table, PC Relative
      48             :     GOTTPOFF,    /// Global Offset Table, Thread Pointer Offset
      49             :     TPOFF,       /// Thread Pointer Offset
      50             :     SECREL,      /// Section Relative (Windows TLS)
      51             :     SBREL,       /// Static Base Relative (RWPI)
      52             :   };
      53             : 
      54             : } // end namespace ARMCP
      55             : 
      56             : /// ARMConstantPoolValue - ARM specific constantpool value. This is used to
      57             : /// represent PC-relative displacement between the address of the load
      58             : /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
      59         635 : class ARMConstantPoolValue : public MachineConstantPoolValue {
      60             :   unsigned LabelId;        // Label id of the load.
      61             :   ARMCP::ARMCPKind Kind;   // Kind of constant.
      62             :   unsigned char PCAdjust;  // Extra adjustment if constantpool is pc-relative.
      63             :                            // 8 for ARM, 4 for Thumb.
      64             :   ARMCP::ARMCPModifier Modifier;   // GV modifier i.e. (&GV(modifier)-(LPIC+8))
      65             :   bool AddCurrentAddress;
      66             : 
      67             : protected:
      68             :   ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind,
      69             :                        unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
      70             :                        bool AddCurrentAddress);
      71             : 
      72             :   ARMConstantPoolValue(LLVMContext &C, unsigned id, ARMCP::ARMCPKind Kind,
      73             :                        unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
      74             :                        bool AddCurrentAddress);
      75             : 
      76             :   template <typename Derived>
      77         639 :   int getExistingMachineCPValueImpl(MachineConstantPool *CP,
      78             :                                     unsigned Alignment) {
      79         639 :     unsigned AlignMask = Alignment - 1;
      80         639 :     const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
      81        1671 :     for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
      82        1465 :       if (Constants[i].isMachineConstantPoolEntry() &&
      83         506 :           (Constants[i].getAlignment() & AlignMask) == 0) {
      84         253 :         auto *CPV =
      85         253 :           static_cast<ARMConstantPoolValue*>(Constants[i].Val.MachineCPVal);
      86         204 :         if (Derived *APC = dyn_cast<Derived>(CPV))
      87         215 :           if (cast<Derived>(this)->equals(APC))
      88          11 :             return i;
      89             :       }
      90             :     }
      91             : 
      92             :     return -1;
      93             :   }
      94             : 
      95             : public:
      96             :   ~ARMConstantPoolValue() override;
      97             : 
      98             :   ARMCP::ARMCPModifier getModifier() const { return Modifier; }
      99             :   StringRef getModifierText() const;
     100             :   bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
     101             : 
     102             :   bool mustAddCurrentAddress() const { return AddCurrentAddress; }
     103             : 
     104             :   unsigned getLabelId() const { return LabelId; }
     105             :   unsigned char getPCAdjustment() const { return PCAdjust; }
     106             : 
     107             :   bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
     108             :   bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
     109             :   bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
     110             :   bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
     111             :   bool isMachineBasicBlock() const{ return Kind == ARMCP::CPMachineBasicBlock; }
     112             :   bool isPromotedGlobal() const{ return Kind == ARMCP::CPPromotedGlobal; }
     113             :   
     114             :   int getExistingMachineCPValue(MachineConstantPool *CP,
     115             :                                 unsigned Alignment) override;
     116             : 
     117             :   void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
     118             : 
     119             :   /// hasSameValue - Return true if this ARM constpool value can share the same
     120             :   /// constantpool entry as another ARM constpool value.
     121             :   virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
     122             : 
     123             :   bool equals(const ARMConstantPoolValue *A) const {
     124          42 :     return this->LabelId == A->LabelId &&
     125          42 :       this->PCAdjust == A->PCAdjust &&
     126             :       this->Modifier == A->Modifier;
     127             :   }
     128             : 
     129             :   void print(raw_ostream &O) const override;
     130             :   void print(raw_ostream *O) const { if (O) print(*O); }
     131             :   void dump() const;
     132             : };
     133             : 
     134             : inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
     135             :   V.print(O);
     136             :   return O;
     137             : }
     138             : 
     139             : /// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
     140             : /// Functions, and BlockAddresses.
     141        1716 : class ARMConstantPoolConstant : public ARMConstantPoolValue {
     142             :   const Constant *CVal;         // Constant being loaded.
     143             :   SmallPtrSet<const GlobalVariable*, 1> GVars;
     144             : 
     145             :   ARMConstantPoolConstant(const Constant *C,
     146             :                           unsigned ID,
     147             :                           ARMCP::ARMCPKind Kind,
     148             :                           unsigned char PCAdj,
     149             :                           ARMCP::ARMCPModifier Modifier,
     150             :                           bool AddCurrentAddress);
     151             :   ARMConstantPoolConstant(Type *Ty, const Constant *C,
     152             :                           unsigned ID,
     153             :                           ARMCP::ARMCPKind Kind,
     154             :                           unsigned char PCAdj,
     155             :                           ARMCP::ARMCPModifier Modifier,
     156             :                           bool AddCurrentAddress);
     157             :   ARMConstantPoolConstant(const GlobalVariable *GV, const Constant *Init);
     158             : 
     159             : public:
     160             :   static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
     161             :   static ARMConstantPoolConstant *Create(const GlobalValue *GV,
     162             :                                          ARMCP::ARMCPModifier Modifier);
     163             :   static ARMConstantPoolConstant *Create(const GlobalVariable *GV,
     164             :                                          const Constant *Initializer);
     165             :   static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
     166             :                                          ARMCP::ARMCPKind Kind,
     167             :                                          unsigned char PCAdj);
     168             :   static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
     169             :                                          ARMCP::ARMCPKind Kind,
     170             :                                          unsigned char PCAdj,
     171             :                                          ARMCP::ARMCPModifier Modifier,
     172             :                                          bool AddCurrentAddress);
     173             : 
     174             :   const GlobalValue *getGV() const;
     175             :   const BlockAddress *getBlockAddress() const;
     176             : 
     177             :   typedef SmallPtrSet<const GlobalVariable *, 1>::iterator promoted_iterator;
     178          93 :   iterator_range<promoted_iterator> promotedGlobals() {
     179         186 :     return iterator_range<promoted_iterator>(GVars.begin(), GVars.end());
     180             :   }
     181             : 
     182             :   const Constant *getPromotedGlobalInit() const {
     183             :     return CVal;
     184             :   }
     185             : 
     186             :   int getExistingMachineCPValue(MachineConstantPool *CP,
     187             :                                 unsigned Alignment) override;
     188             : 
     189             :   /// hasSameValue - Return true if this ARM constpool value can share the same
     190             :   /// constantpool entry as another ARM constpool value.
     191             :   bool hasSameValue(ARMConstantPoolValue *ACPV) override;
     192             : 
     193             :   void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
     194             : 
     195             :   void print(raw_ostream &O) const override;
     196             : 
     197             :   static bool classof(const ARMConstantPoolValue *APV) {
     198         248 :     return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA() ||
     199          24 :            APV->isPromotedGlobal();
     200             :   }
     201             : 
     202             :   bool equals(const ARMConstantPoolConstant *A) const {
     203         204 :     return CVal == A->CVal && ARMConstantPoolValue::equals(A);
     204             :   }
     205             : };
     206             : 
     207             : /// ARMConstantPoolSymbol - ARM-specific constantpool values for external
     208             : /// symbols.
     209         105 : class ARMConstantPoolSymbol : public ARMConstantPoolValue {
     210             :   const std::string S;          // ExtSymbol being loaded.
     211             : 
     212             :   ARMConstantPoolSymbol(LLVMContext &C, StringRef s, unsigned id,
     213             :                         unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
     214             :                         bool AddCurrentAddress);
     215             : 
     216             : public:
     217             :   static ARMConstantPoolSymbol *Create(LLVMContext &C, StringRef s, unsigned ID,
     218             :                                        unsigned char PCAdj);
     219             : 
     220          70 :   StringRef getSymbol() const { return S; }
     221             : 
     222             :   int getExistingMachineCPValue(MachineConstantPool *CP,
     223             :                                 unsigned Alignment) override;
     224             : 
     225             :   void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
     226             : 
     227             :   /// hasSameValue - Return true if this ARM constpool value can share the same
     228             :   /// constantpool entry as another ARM constpool value.
     229             :   bool hasSameValue(ARMConstantPoolValue *ACPV) override;
     230             : 
     231             :   void print(raw_ostream &O) const override;
     232             : 
     233             :   static bool classof(const ARMConstantPoolValue *ACPV) {
     234           2 :     return ACPV->isExtSymbol();
     235             :   }
     236             : 
     237           0 :   bool equals(const ARMConstantPoolSymbol *A) const {
     238           0 :     return S == A->S && ARMConstantPoolValue::equals(A);
     239             :   }
     240             : };
     241             : 
     242             : /// ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic
     243             : /// block.
     244          28 : class ARMConstantPoolMBB : public ARMConstantPoolValue {
     245             :   const MachineBasicBlock *MBB; // Machine basic block.
     246             : 
     247             :   ARMConstantPoolMBB(LLVMContext &C, const MachineBasicBlock *mbb, unsigned id,
     248             :                      unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
     249             :                      bool AddCurrentAddress);
     250             : 
     251             : public:
     252             :   static ARMConstantPoolMBB *Create(LLVMContext &C,
     253             :                                     const MachineBasicBlock *mbb,
     254             :                                     unsigned ID, unsigned char PCAdj);
     255             : 
     256             :   const MachineBasicBlock *getMBB() const { return MBB; }
     257             : 
     258             :   int getExistingMachineCPValue(MachineConstantPool *CP,
     259             :                                 unsigned Alignment) override;
     260             : 
     261             :   void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
     262             : 
     263             :   /// hasSameValue - Return true if this ARM constpool value can share the same
     264             :   /// constantpool entry as another ARM constpool value.
     265             :   bool hasSameValue(ARMConstantPoolValue *ACPV) override;
     266             : 
     267             :   void print(raw_ostream &O) const override;
     268             : 
     269             :   static bool classof(const ARMConstantPoolValue *ACPV) {
     270          28 :     return ACPV->isMachineBasicBlock();
     271             :   }
     272             : 
     273             :   bool equals(const ARMConstantPoolMBB *A) const {
     274           0 :     return MBB == A->MBB && ARMConstantPoolValue::equals(A);
     275             :   }
     276             : };
     277             : 
     278             : } // end namespace llvm
     279             : 
     280             : #endif // LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H

Generated by: LCOV version 1.13