2012-02-18 20:03:15 +08:00
|
|
|
//===-- ARMConstantPoolValue.h - ARM constantpool value ---------*- C++ -*-===//
|
2007-01-19 15:51:42 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-01-19 15:51:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the ARM specific constantpool value class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H
|
|
|
|
#define LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H
|
2007-01-19 15:51:42 +08:00
|
|
|
|
2017-01-28 07:58:02 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2007-01-19 15:51:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2013-09-16 18:17:31 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
2017-01-28 07:58:02 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2007-01-19 15:51:42 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2009-11-03 00:59:06 +08:00
|
|
|
class BlockAddress;
|
2011-09-30 07:48:44 +08:00
|
|
|
class Constant;
|
2008-07-12 04:38:31 +08:00
|
|
|
class GlobalValue;
|
2016-09-26 15:26:24 +08:00
|
|
|
class GlobalVariable;
|
2009-08-14 05:58:54 +08:00
|
|
|
class LLVMContext;
|
2011-09-30 07:48:44 +08:00
|
|
|
class MachineBasicBlock;
|
2008-07-12 04:38:31 +08:00
|
|
|
|
2009-09-01 09:57:56 +08:00
|
|
|
namespace ARMCP {
|
2017-01-28 07:58:02 +08:00
|
|
|
|
2009-09-01 09:57:56 +08:00
|
|
|
enum ARMCPKind {
|
|
|
|
CPValue,
|
2009-11-03 00:59:06 +08:00
|
|
|
CPExtSymbol,
|
|
|
|
CPBlockAddress,
|
2011-09-30 07:48:44 +08:00
|
|
|
CPLSDA,
|
2016-09-26 15:26:24 +08:00
|
|
|
CPMachineBasicBlock,
|
|
|
|
CPPromotedGlobal
|
2009-09-01 09:57:56 +08:00
|
|
|
};
|
2010-11-10 05:36:17 +08:00
|
|
|
|
|
|
|
enum ARMCPModifier {
|
2016-06-07 11:15:01 +08:00
|
|
|
no_modifier, /// None
|
|
|
|
TLSGD, /// Thread Local Storage (General Dynamic Mode)
|
|
|
|
GOT_PREL, /// Global Offset Table, PC Relative
|
|
|
|
GOTTPOFF, /// Global Offset Table, Thread Pointer Offset
|
|
|
|
TPOFF, /// Thread Pointer Offset
|
2016-06-07 11:15:07 +08:00
|
|
|
SECREL, /// Section Relative (Windows TLS)
|
2016-08-08 23:28:31 +08:00
|
|
|
SBREL, /// Static Base Relative (RWPI)
|
2010-11-10 05:36:17 +08:00
|
|
|
};
|
2017-01-28 07:58:02 +08:00
|
|
|
|
|
|
|
} // end namespace ARMCP
|
2009-09-01 09:57:56 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
|
2009-11-03 01:10:37 +08:00
|
|
|
/// represent PC-relative displacement between the address of the load
|
2009-11-03 00:59:06 +08:00
|
|
|
/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
|
2007-01-19 15:51:42 +08:00
|
|
|
class ARMConstantPoolValue : public MachineConstantPoolValue {
|
|
|
|
unsigned LabelId; // Label id of the load.
|
2009-11-03 00:59:06 +08:00
|
|
|
ARMCP::ARMCPKind Kind; // Kind of constant.
|
2009-11-03 01:10:37 +08:00
|
|
|
unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
|
2007-01-19 15:51:42 +08:00
|
|
|
// 8 for ARM, 4 for Thumb.
|
2010-11-10 05:36:17 +08:00
|
|
|
ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
|
2007-04-27 21:54:47 +08:00
|
|
|
bool AddCurrentAddress;
|
2007-01-19 15:51:42 +08:00
|
|
|
|
2011-10-01 14:40:33 +08:00
|
|
|
protected:
|
|
|
|
ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind,
|
|
|
|
unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
|
|
|
|
bool AddCurrentAddress);
|
|
|
|
|
2011-10-01 16:36:59 +08:00
|
|
|
ARMConstantPoolValue(LLVMContext &C, unsigned id, ARMCP::ARMCPKind Kind,
|
|
|
|
unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
|
|
|
|
bool AddCurrentAddress);
|
2013-09-16 18:17:31 +08:00
|
|
|
|
|
|
|
template <typename Derived>
|
|
|
|
int getExistingMachineCPValueImpl(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;
|
|
|
|
if (Derived *APC = dyn_cast<Derived>(CPV))
|
|
|
|
if (cast<Derived>(this)->equals(APC))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
public:
|
2015-04-11 10:11:45 +08:00
|
|
|
~ARMConstantPoolValue() override;
|
2007-04-22 08:04:12 +08:00
|
|
|
|
2010-11-10 05:36:17 +08:00
|
|
|
ARMCP::ARMCPModifier getModifier() const { return Modifier; }
|
2016-10-05 09:41:06 +08:00
|
|
|
StringRef getModifierText() const;
|
2010-11-10 05:36:17 +08:00
|
|
|
bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
|
2011-10-01 02:42:06 +08:00
|
|
|
|
2007-04-27 21:54:47 +08:00
|
|
|
bool mustAddCurrentAddress() const { return AddCurrentAddress; }
|
2011-10-01 02:42:06 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
unsigned getLabelId() const { return LabelId; }
|
|
|
|
unsigned char getPCAdjustment() const { return PCAdjust; }
|
2011-10-01 02:42:06 +08:00
|
|
|
|
2009-11-03 00:59:06 +08:00
|
|
|
bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
|
|
|
|
bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
|
2011-10-01 14:40:33 +08:00
|
|
|
bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
|
2011-10-01 02:42:06 +08:00
|
|
|
bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
|
2011-10-01 17:19:10 +08:00
|
|
|
bool isMachineBasicBlock() const{ return Kind == ARMCP::CPMachineBasicBlock; }
|
2016-09-26 15:26:24 +08:00
|
|
|
bool isPromotedGlobal() const{ return Kind == ARMCP::CPPromotedGlobal; }
|
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
int getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) override;
|
2007-01-19 15:51:42 +08:00
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
|
2007-01-19 15:51:42 +08:00
|
|
|
|
2011-10-01 14:40:33 +08:00
|
|
|
/// hasSameValue - Return true if this ARM constpool value can share the same
|
|
|
|
/// constantpool entry as another ARM constpool value.
|
|
|
|
virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
|
2009-11-07 11:52:02 +08:00
|
|
|
|
2011-10-01 20:44:28 +08:00
|
|
|
bool equals(const ARMConstantPoolValue *A) const {
|
|
|
|
return this->LabelId == A->LabelId &&
|
|
|
|
this->PCAdjust == A->PCAdjust &&
|
|
|
|
this->Modifier == A->Modifier;
|
|
|
|
}
|
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
void print(raw_ostream &O) const override;
|
2008-10-30 07:55:17 +08:00
|
|
|
void print(raw_ostream *O) const { if (O) print(*O); }
|
|
|
|
void dump() const;
|
2007-01-19 15:51:42 +08:00
|
|
|
};
|
2008-10-30 07:55:17 +08:00
|
|
|
|
|
|
|
inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
|
|
|
|
V.print(O);
|
|
|
|
return O;
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
|
|
|
|
2011-10-01 14:40:33 +08:00
|
|
|
/// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
|
|
|
|
/// Functions, and BlockAddresses.
|
|
|
|
class ARMConstantPoolConstant : public ARMConstantPoolValue {
|
|
|
|
const Constant *CVal; // Constant being loaded.
|
2016-09-26 15:26:24 +08:00
|
|
|
const GlobalVariable *GVar = nullptr;
|
2011-10-01 14:40:33 +08:00
|
|
|
|
|
|
|
ARMConstantPoolConstant(const Constant *C,
|
|
|
|
unsigned ID,
|
|
|
|
ARMCP::ARMCPKind Kind,
|
|
|
|
unsigned char PCAdj,
|
|
|
|
ARMCP::ARMCPModifier Modifier,
|
|
|
|
bool AddCurrentAddress);
|
2011-10-01 15:52:37 +08:00
|
|
|
ARMConstantPoolConstant(Type *Ty, const Constant *C,
|
|
|
|
unsigned ID,
|
|
|
|
ARMCP::ARMCPKind Kind,
|
|
|
|
unsigned char PCAdj,
|
|
|
|
ARMCP::ARMCPModifier Modifier,
|
|
|
|
bool AddCurrentAddress);
|
2016-09-26 15:26:24 +08:00
|
|
|
ARMConstantPoolConstant(const GlobalVariable *GV, const Constant *Init);
|
2011-10-01 15:52:37 +08:00
|
|
|
|
2011-10-01 14:40:33 +08:00
|
|
|
public:
|
|
|
|
static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
|
2011-10-01 15:52:37 +08:00
|
|
|
static ARMConstantPoolConstant *Create(const GlobalValue *GV,
|
|
|
|
ARMCP::ARMCPModifier Modifier);
|
2016-09-26 15:26:24 +08:00
|
|
|
static ARMConstantPoolConstant *Create(const GlobalVariable *GV,
|
|
|
|
const Constant *Initializer);
|
2011-10-01 14:44:24 +08:00
|
|
|
static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
|
|
|
|
ARMCP::ARMCPKind Kind,
|
|
|
|
unsigned char PCAdj);
|
2011-10-01 15:52:37 +08:00
|
|
|
static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
|
|
|
|
ARMCP::ARMCPKind Kind,
|
|
|
|
unsigned char PCAdj,
|
|
|
|
ARMCP::ARMCPModifier Modifier,
|
|
|
|
bool AddCurrentAddress);
|
2011-10-01 14:40:33 +08:00
|
|
|
|
|
|
|
const GlobalValue *getGV() const;
|
2011-10-01 15:52:37 +08:00
|
|
|
const BlockAddress *getBlockAddress() const;
|
2017-01-28 07:58:02 +08:00
|
|
|
|
2016-09-26 15:26:24 +08:00
|
|
|
const GlobalVariable *getPromotedGlobal() const {
|
|
|
|
return dyn_cast_or_null<GlobalVariable>(GVar);
|
|
|
|
}
|
2017-01-28 07:58:02 +08:00
|
|
|
|
2016-09-26 15:26:24 +08:00
|
|
|
const Constant *getPromotedGlobalInit() const {
|
|
|
|
return CVal;
|
|
|
|
}
|
2011-10-01 15:52:37 +08:00
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
int getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) override;
|
2011-10-01 14:40:33 +08:00
|
|
|
|
|
|
|
/// hasSameValue - Return true if this ARM constpool value can share the same
|
|
|
|
/// constantpool entry as another ARM constpool value.
|
2014-03-10 10:09:33 +08:00
|
|
|
bool hasSameValue(ARMConstantPoolValue *ACPV) override;
|
2011-10-01 14:40:33 +08:00
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
|
2011-10-01 14:40:33 +08:00
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
void print(raw_ostream &O) const override;
|
2017-01-28 07:58:02 +08:00
|
|
|
|
2011-10-01 14:40:33 +08:00
|
|
|
static bool classof(const ARMConstantPoolValue *APV) {
|
2016-09-26 15:26:24 +08:00
|
|
|
return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA() ||
|
|
|
|
APV->isPromotedGlobal();
|
2011-10-01 14:40:33 +08:00
|
|
|
}
|
2013-09-16 18:17:31 +08:00
|
|
|
|
|
|
|
bool equals(const ARMConstantPoolConstant *A) const {
|
|
|
|
return CVal == A->CVal && ARMConstantPoolValue::equals(A);
|
|
|
|
}
|
2011-10-01 14:40:33 +08:00
|
|
|
};
|
|
|
|
|
2011-10-01 16:36:59 +08:00
|
|
|
/// ARMConstantPoolSymbol - ARM-specific constantpool values for external
|
|
|
|
/// symbols.
|
|
|
|
class ARMConstantPoolSymbol : public ARMConstantPoolValue {
|
2012-12-25 03:23:30 +08:00
|
|
|
const std::string S; // ExtSymbol being loaded.
|
2011-10-01 16:36:59 +08:00
|
|
|
|
2016-10-05 09:41:06 +08:00
|
|
|
ARMConstantPoolSymbol(LLVMContext &C, StringRef s, unsigned id,
|
2011-10-01 16:36:59 +08:00
|
|
|
unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
|
|
|
|
bool AddCurrentAddress);
|
|
|
|
|
|
|
|
public:
|
2016-10-05 09:41:06 +08:00
|
|
|
static ARMConstantPoolSymbol *Create(LLVMContext &C, StringRef s, unsigned ID,
|
|
|
|
unsigned char PCAdj);
|
2011-10-01 16:58:29 +08:00
|
|
|
|
2016-10-05 09:41:06 +08:00
|
|
|
StringRef getSymbol() const { return S; }
|
2011-10-01 16:36:59 +08:00
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
int getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) override;
|
2011-10-01 16:36:59 +08:00
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
|
2011-10-01 16:36:59 +08:00
|
|
|
|
|
|
|
/// hasSameValue - Return true if this ARM constpool value can share the same
|
|
|
|
/// constantpool entry as another ARM constpool value.
|
2014-03-10 10:09:33 +08:00
|
|
|
bool hasSameValue(ARMConstantPoolValue *ACPV) override;
|
2011-10-01 16:36:59 +08:00
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
void print(raw_ostream &O) const override;
|
2011-10-01 16:36:59 +08:00
|
|
|
|
|
|
|
static bool classof(const ARMConstantPoolValue *ACPV) {
|
|
|
|
return ACPV->isExtSymbol();
|
|
|
|
}
|
2013-09-16 18:17:31 +08:00
|
|
|
|
|
|
|
bool equals(const ARMConstantPoolSymbol *A) const {
|
|
|
|
return S == A->S && ARMConstantPoolValue::equals(A);
|
|
|
|
}
|
2011-10-01 16:36:59 +08:00
|
|
|
};
|
|
|
|
|
2011-10-01 17:19:10 +08:00
|
|
|
/// ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic
|
|
|
|
/// block.
|
|
|
|
class ARMConstantPoolMBB : public ARMConstantPoolValue {
|
2011-10-01 17:30:42 +08:00
|
|
|
const MachineBasicBlock *MBB; // Machine basic block.
|
2011-10-01 17:19:10 +08:00
|
|
|
|
2011-10-01 17:30:42 +08:00
|
|
|
ARMConstantPoolMBB(LLVMContext &C, const MachineBasicBlock *mbb, unsigned id,
|
2011-10-01 17:19:10 +08:00
|
|
|
unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
|
|
|
|
bool AddCurrentAddress);
|
|
|
|
|
|
|
|
public:
|
2011-10-01 17:30:42 +08:00
|
|
|
static ARMConstantPoolMBB *Create(LLVMContext &C,
|
|
|
|
const MachineBasicBlock *mbb,
|
2011-10-01 17:19:10 +08:00
|
|
|
unsigned ID, unsigned char PCAdj);
|
|
|
|
|
|
|
|
const MachineBasicBlock *getMBB() const { return MBB; }
|
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
int getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) override;
|
2011-10-01 17:19:10 +08:00
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
|
2011-10-01 17:19:10 +08:00
|
|
|
|
|
|
|
/// hasSameValue - Return true if this ARM constpool value can share the same
|
|
|
|
/// constantpool entry as another ARM constpool value.
|
2014-03-10 10:09:33 +08:00
|
|
|
bool hasSameValue(ARMConstantPoolValue *ACPV) override;
|
2011-10-01 17:19:10 +08:00
|
|
|
|
2014-03-10 10:09:33 +08:00
|
|
|
void print(raw_ostream &O) const override;
|
2011-10-01 17:19:10 +08:00
|
|
|
|
|
|
|
static bool classof(const ARMConstantPoolValue *ACPV) {
|
|
|
|
return ACPV->isMachineBasicBlock();
|
|
|
|
}
|
2013-09-16 18:17:31 +08:00
|
|
|
|
|
|
|
bool equals(const ARMConstantPoolMBB *A) const {
|
|
|
|
return MBB == A->MBB && ARMConstantPoolValue::equals(A);
|
|
|
|
}
|
2011-10-01 17:19:10 +08:00
|
|
|
};
|
|
|
|
|
2017-01-28 07:58:02 +08:00
|
|
|
} // end namespace llvm
|
2008-10-30 07:55:17 +08:00
|
|
|
|
2017-01-28 07:58:02 +08:00
|
|
|
#endif // LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H
|