2012-02-18 20:03:15 +08:00
|
|
|
//===-- ARMConstantPoolValue.cpp - ARM constantpool value -----------------===//
|
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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMConstantPoolValue.h"
|
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2017-01-28 07:58:02 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constant.h"
|
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/GlobalValue.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2017-01-28 07:58:02 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2008-08-24 06:23:09 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-01-28 07:58:02 +08:00
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2011-10-01 14:40:33 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ARMConstantPoolValue
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
ARMConstantPoolValue::ARMConstantPoolValue(Type *Ty, unsigned id,
|
|
|
|
ARMCP::ARMCPKind kind,
|
|
|
|
unsigned char PCAdj,
|
|
|
|
ARMCP::ARMCPModifier modifier,
|
|
|
|
bool addCurrentAddress)
|
2011-10-01 17:30:42 +08:00
|
|
|
: MachineConstantPoolValue(Ty), LabelId(id), Kind(kind),
|
2011-10-01 15:52:37 +08:00
|
|
|
PCAdjust(PCAdj), Modifier(modifier),
|
|
|
|
AddCurrentAddress(addCurrentAddress) {}
|
2011-10-01 14:40:33 +08:00
|
|
|
|
2011-10-01 16:36:59 +08:00
|
|
|
ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C, unsigned id,
|
|
|
|
ARMCP::ARMCPKind kind,
|
|
|
|
unsigned char PCAdj,
|
|
|
|
ARMCP::ARMCPModifier modifier,
|
|
|
|
bool addCurrentAddress)
|
|
|
|
: MachineConstantPoolValue((Type*)Type::getInt32Ty(C)),
|
2011-10-01 17:04:18 +08:00
|
|
|
LabelId(id), Kind(kind), PCAdjust(PCAdj), Modifier(modifier),
|
2011-10-01 16:36:59 +08:00
|
|
|
AddCurrentAddress(addCurrentAddress) {}
|
|
|
|
|
2017-01-28 07:58:02 +08:00
|
|
|
ARMConstantPoolValue::~ARMConstantPoolValue() = default;
|
2011-10-01 16:36:59 +08:00
|
|
|
|
2016-10-05 09:41:06 +08:00
|
|
|
StringRef ARMConstantPoolValue::getModifierText() const {
|
2011-10-01 02:42:06 +08:00
|
|
|
switch (Modifier) {
|
|
|
|
// FIXME: Are these case sensitive? It'd be nice to lower-case all the
|
|
|
|
// strings if that's legal.
|
2016-06-07 11:15:01 +08:00
|
|
|
case ARMCP::no_modifier:
|
|
|
|
return "none";
|
|
|
|
case ARMCP::TLSGD:
|
|
|
|
return "tlsgd";
|
|
|
|
case ARMCP::GOT_PREL:
|
|
|
|
return "GOT_PREL";
|
|
|
|
case ARMCP::GOTTPOFF:
|
|
|
|
return "gottpoff";
|
|
|
|
case ARMCP::TPOFF:
|
|
|
|
return "tpoff";
|
2016-08-08 23:28:31 +08:00
|
|
|
case ARMCP::SBREL:
|
|
|
|
return "SBREL";
|
2016-06-07 11:15:07 +08:00
|
|
|
case ARMCP::SECREL:
|
|
|
|
return "secrel32";
|
2011-10-01 02:42:06 +08:00
|
|
|
}
|
2012-01-17 07:24:27 +08:00
|
|
|
llvm_unreachable("Unknown modifier!");
|
2011-10-01 02:42:06 +08:00
|
|
|
}
|
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) {
|
2012-02-07 10:50:20 +08:00
|
|
|
llvm_unreachable("Shouldn't be calling this directly!");
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 04:59:33 +08:00
|
|
|
ARMConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
|
2007-01-19 15:51:42 +08:00
|
|
|
ID.AddInteger(LabelId);
|
|
|
|
ID.AddInteger(PCAdjust);
|
|
|
|
}
|
|
|
|
|
2009-11-07 11:52:02 +08:00
|
|
|
bool
|
|
|
|
ARMConstantPoolValue::hasSameValue(ARMConstantPoolValue *ACPV) {
|
|
|
|
if (ACPV->Kind == Kind &&
|
|
|
|
ACPV->PCAdjust == PCAdjust &&
|
2016-05-06 02:38:53 +08:00
|
|
|
ACPV->Modifier == Modifier &&
|
|
|
|
ACPV->LabelId == LabelId &&
|
|
|
|
ACPV->AddCurrentAddress == AddCurrentAddress) {
|
2009-11-07 11:52:02 +08:00
|
|
|
// Two PC relative constpool entries containing the same GV address or
|
|
|
|
// external symbols. FIXME: What about blockaddress?
|
|
|
|
if (Kind == ARMCP::CPValue || Kind == ARMCP::CPExtSymbol)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-28 10:02:38 +08:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2016-01-30 04:50:44 +08:00
|
|
|
LLVM_DUMP_METHOD void ARMConstantPoolValue::dump() const {
|
2009-08-23 11:41:05 +08:00
|
|
|
errs() << " " << *this;
|
2008-10-30 07:55:17 +08:00
|
|
|
}
|
2017-01-28 10:02:38 +08:00
|
|
|
#endif
|
2008-10-30 07:55:17 +08:00
|
|
|
|
2008-08-24 06:23:09 +08:00
|
|
|
void ARMConstantPoolValue::print(raw_ostream &O) const {
|
2010-11-10 05:36:17 +08:00
|
|
|
if (Modifier) O << "(" << getModifierText() << ")";
|
2007-04-27 21:54:47 +08:00
|
|
|
if (PCAdjust != 0) {
|
2008-11-04 08:50:32 +08:00
|
|
|
O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
|
|
|
|
if (AddCurrentAddress) O << "-.";
|
2007-04-27 21:54:47 +08:00
|
|
|
O << ")";
|
|
|
|
}
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
2011-10-01 14:40:33 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ARMConstantPoolConstant
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-10-01 15:52:37 +08:00
|
|
|
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) {}
|
|
|
|
|
2011-10-01 14:40:33 +08:00
|
|
|
ARMConstantPoolConstant::ARMConstantPoolConstant(const Constant *C,
|
|
|
|
unsigned ID,
|
|
|
|
ARMCP::ARMCPKind Kind,
|
|
|
|
unsigned char PCAdj,
|
|
|
|
ARMCP::ARMCPModifier Modifier,
|
|
|
|
bool AddCurrentAddress)
|
|
|
|
: ARMConstantPoolValue((Type*)C->getType(), ID, Kind, PCAdj, Modifier,
|
|
|
|
AddCurrentAddress),
|
|
|
|
CVal(C) {}
|
|
|
|
|
2016-09-26 15:26:24 +08:00
|
|
|
ARMConstantPoolConstant::ARMConstantPoolConstant(const GlobalVariable *GV,
|
|
|
|
const Constant *C)
|
|
|
|
: ARMConstantPoolValue((Type *)C->getType(), 0, ARMCP::CPPromotedGlobal, 0,
|
2017-09-07 12:00:13 +08:00
|
|
|
ARMCP::no_modifier, false), CVal(C) {
|
|
|
|
GVars.insert(GV);
|
|
|
|
}
|
2016-09-26 15:26:24 +08:00
|
|
|
|
2011-10-01 14:40:33 +08:00
|
|
|
ARMConstantPoolConstant *
|
|
|
|
ARMConstantPoolConstant::Create(const Constant *C, unsigned ID) {
|
|
|
|
return new ARMConstantPoolConstant(C, ID, ARMCP::CPValue, 0,
|
|
|
|
ARMCP::no_modifier, false);
|
|
|
|
}
|
|
|
|
|
2016-09-26 15:26:24 +08:00
|
|
|
ARMConstantPoolConstant *
|
|
|
|
ARMConstantPoolConstant::Create(const GlobalVariable *GVar,
|
|
|
|
const Constant *Initializer) {
|
|
|
|
return new ARMConstantPoolConstant(GVar, Initializer);
|
|
|
|
}
|
|
|
|
|
2011-10-01 15:52:37 +08:00
|
|
|
ARMConstantPoolConstant *
|
|
|
|
ARMConstantPoolConstant::Create(const GlobalValue *GV,
|
|
|
|
ARMCP::ARMCPModifier Modifier) {
|
|
|
|
return new ARMConstantPoolConstant((Type*)Type::getInt32Ty(GV->getContext()),
|
|
|
|
GV, 0, ARMCP::CPValue, 0,
|
|
|
|
Modifier, false);
|
|
|
|
}
|
|
|
|
|
2011-10-01 14:44:24 +08:00
|
|
|
ARMConstantPoolConstant *
|
|
|
|
ARMConstantPoolConstant::Create(const Constant *C, unsigned ID,
|
|
|
|
ARMCP::ARMCPKind Kind, unsigned char PCAdj) {
|
|
|
|
return new ARMConstantPoolConstant(C, ID, Kind, PCAdj,
|
|
|
|
ARMCP::no_modifier, false);
|
|
|
|
}
|
|
|
|
|
2011-10-01 15:52:37 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-10-01 14:40:33 +08:00
|
|
|
const GlobalValue *ARMConstantPoolConstant::getGV() const {
|
2011-10-01 15:52:37 +08:00
|
|
|
return dyn_cast_or_null<GlobalValue>(CVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
const BlockAddress *ARMConstantPoolConstant::getBlockAddress() const {
|
|
|
|
return dyn_cast_or_null<BlockAddress>(CVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ARMConstantPoolConstant::getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) {
|
2017-09-07 12:00:13 +08:00
|
|
|
int index =
|
|
|
|
getExistingMachineCPValueImpl<ARMConstantPoolConstant>(CP, Alignment);
|
|
|
|
if (index != -1) {
|
|
|
|
auto *CPV = static_cast<ARMConstantPoolValue*>(
|
|
|
|
CP->getConstants()[index].Val.MachineCPVal);
|
|
|
|
auto *Constant = cast<ARMConstantPoolConstant>(CPV);
|
|
|
|
Constant->GVars.insert(GVars.begin(), GVars.end());
|
|
|
|
}
|
|
|
|
return index;
|
2011-10-01 14:40:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ARMConstantPoolConstant::hasSameValue(ARMConstantPoolValue *ACPV) {
|
|
|
|
const ARMConstantPoolConstant *ACPC = dyn_cast<ARMConstantPoolConstant>(ACPV);
|
2011-10-01 15:52:37 +08:00
|
|
|
return ACPC && ACPC->CVal == CVal && ARMConstantPoolValue::hasSameValue(ACPV);
|
2011-10-01 14:40:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARMConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
|
|
|
|
ID.AddPointer(CVal);
|
2017-09-07 12:00:13 +08:00
|
|
|
for (const auto *GV : GVars)
|
|
|
|
ID.AddPointer(GV);
|
2011-10-01 14:40:33 +08:00
|
|
|
ARMConstantPoolValue::addSelectionDAGCSEId(ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARMConstantPoolConstant::print(raw_ostream &O) const {
|
|
|
|
O << CVal->getName();
|
|
|
|
ARMConstantPoolValue::print(O);
|
|
|
|
}
|
2011-10-01 16:36:59 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ARMConstantPoolSymbol
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-10-05 09:41:06 +08:00
|
|
|
ARMConstantPoolSymbol::ARMConstantPoolSymbol(LLVMContext &C, StringRef s,
|
|
|
|
unsigned id, unsigned char PCAdj,
|
2011-10-01 16:36:59 +08:00
|
|
|
ARMCP::ARMCPModifier Modifier,
|
|
|
|
bool AddCurrentAddress)
|
2016-10-05 09:41:06 +08:00
|
|
|
: ARMConstantPoolValue(C, id, ARMCP::CPExtSymbol, PCAdj, Modifier,
|
|
|
|
AddCurrentAddress),
|
|
|
|
S(s) {}
|
2011-10-01 16:36:59 +08:00
|
|
|
|
2016-10-05 09:41:06 +08:00
|
|
|
ARMConstantPoolSymbol *ARMConstantPoolSymbol::Create(LLVMContext &C,
|
|
|
|
StringRef s, unsigned ID,
|
|
|
|
unsigned char PCAdj) {
|
2011-10-01 16:58:29 +08:00
|
|
|
return new ARMConstantPoolSymbol(C, s, ID, PCAdj, ARMCP::no_modifier, false);
|
|
|
|
}
|
|
|
|
|
2011-10-01 16:36:59 +08:00
|
|
|
int ARMConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) {
|
2013-09-16 18:17:31 +08:00
|
|
|
return getExistingMachineCPValueImpl<ARMConstantPoolSymbol>(CP, Alignment);
|
2011-10-01 16:36:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ARMConstantPoolSymbol::hasSameValue(ARMConstantPoolValue *ACPV) {
|
|
|
|
const ARMConstantPoolSymbol *ACPS = dyn_cast<ARMConstantPoolSymbol>(ACPV);
|
2012-12-25 03:23:30 +08:00
|
|
|
return ACPS && ACPS->S == S && ARMConstantPoolValue::hasSameValue(ACPV);
|
2011-10-01 16:36:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARMConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
|
2012-12-25 03:23:30 +08:00
|
|
|
ID.AddString(S);
|
2011-10-01 16:36:59 +08:00
|
|
|
ARMConstantPoolValue::addSelectionDAGCSEId(ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARMConstantPoolSymbol::print(raw_ostream &O) const {
|
|
|
|
O << S;
|
|
|
|
ARMConstantPoolValue::print(O);
|
|
|
|
}
|
2011-10-01 17:19:10 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ARMConstantPoolMBB
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-10-01 17:30:42 +08:00
|
|
|
ARMConstantPoolMBB::ARMConstantPoolMBB(LLVMContext &C,
|
|
|
|
const MachineBasicBlock *mbb,
|
2011-10-01 17:19:10 +08:00
|
|
|
unsigned id, unsigned char PCAdj,
|
|
|
|
ARMCP::ARMCPModifier Modifier,
|
|
|
|
bool AddCurrentAddress)
|
2011-10-01 17:30:42 +08:00
|
|
|
: ARMConstantPoolValue(C, id, ARMCP::CPMachineBasicBlock, PCAdj,
|
2011-10-01 17:19:10 +08:00
|
|
|
Modifier, AddCurrentAddress),
|
|
|
|
MBB(mbb) {}
|
|
|
|
|
|
|
|
ARMConstantPoolMBB *ARMConstantPoolMBB::Create(LLVMContext &C,
|
2011-10-01 17:30:42 +08:00
|
|
|
const MachineBasicBlock *mbb,
|
2011-10-01 17:19:10 +08:00
|
|
|
unsigned ID,
|
|
|
|
unsigned char PCAdj) {
|
|
|
|
return new ARMConstantPoolMBB(C, mbb, ID, PCAdj, ARMCP::no_modifier, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ARMConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) {
|
2013-09-16 18:17:31 +08:00
|
|
|
return getExistingMachineCPValueImpl<ARMConstantPoolMBB>(CP, Alignment);
|
2011-10-01 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ARMConstantPoolMBB::hasSameValue(ARMConstantPoolValue *ACPV) {
|
|
|
|
const ARMConstantPoolMBB *ACPMBB = dyn_cast<ARMConstantPoolMBB>(ACPV);
|
|
|
|
return ACPMBB && ACPMBB->MBB == MBB &&
|
|
|
|
ARMConstantPoolValue::hasSameValue(ACPV);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARMConstantPoolMBB::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
|
|
|
|
ID.AddPointer(MBB);
|
|
|
|
ARMConstantPoolValue::addSelectionDAGCSEId(ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARMConstantPoolMBB::print(raw_ostream &O) const {
|
2011-10-25 07:01:03 +08:00
|
|
|
O << "BB#" << MBB->getNumber();
|
2011-10-01 17:19:10 +08:00
|
|
|
ARMConstantPoolValue::print(O);
|
|
|
|
}
|