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"
|
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"
|
2008-08-24 06:23:09 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-08-11 23:26:27 +08:00
|
|
|
#include <cstdlib>
|
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) {}
|
|
|
|
|
2011-10-01 17:04:18 +08:00
|
|
|
ARMConstantPoolValue::~ARMConstantPoolValue() {}
|
2011-10-01 16:36:59 +08:00
|
|
|
|
2011-10-01 02:42:06 +08:00
|
|
|
const char *ARMConstantPoolValue::getModifierText() const {
|
|
|
|
switch (Modifier) {
|
|
|
|
// FIXME: Are these case sensitive? It'd be nice to lower-case all the
|
|
|
|
// strings if that's legal.
|
|
|
|
case ARMCP::no_modifier: return "none";
|
|
|
|
case ARMCP::TLSGD: return "tlsgd";
|
|
|
|
case ARMCP::GOT: return "GOT";
|
|
|
|
case ARMCP::GOTOFF: return "GOTOFF";
|
|
|
|
case ARMCP::GOTTPOFF: return "gottpoff";
|
|
|
|
case ARMCP::TPOFF: return "tpoff";
|
|
|
|
}
|
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 &&
|
2010-11-10 05:36:17 +08:00
|
|
|
ACPV->Modifier == Modifier) {
|
2009-11-07 11:52:02 +08:00
|
|
|
if (ACPV->LabelId == LabelId)
|
|
|
|
return true;
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2008-10-30 07:55:17 +08:00
|
|
|
void ARMConstantPoolValue::dump() const {
|
2009-08-23 11:41:05 +08:00
|
|
|
errs() << " " << *this;
|
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) {}
|
|
|
|
|
|
|
|
ARMConstantPoolConstant *
|
|
|
|
ARMConstantPoolConstant::Create(const Constant *C, unsigned ID) {
|
|
|
|
return new ARMConstantPoolConstant(C, ID, ARMCP::CPValue, 0,
|
|
|
|
ARMCP::no_modifier, false);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
ARMConstantPoolConstant *APC = dyn_cast<ARMConstantPoolConstant>(CPV);
|
|
|
|
if (!APC) continue;
|
2011-10-01 20:44:28 +08:00
|
|
|
if (APC->CVal == CVal && equals(APC))
|
2011-10-01 15:52:37 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
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);
|
|
|
|
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
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
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),
|
2012-12-25 03:23:30 +08:00
|
|
|
S(s) {}
|
2011-10-01 16:36:59 +08:00
|
|
|
|
2011-10-01 16:58:29 +08:00
|
|
|
ARMConstantPoolSymbol *
|
|
|
|
ARMConstantPoolSymbol::Create(LLVMContext &C, const char *s,
|
|
|
|
unsigned ID, unsigned char PCAdj) {
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
|
2012-12-25 03:23:30 +08:00
|
|
|
if (APS->S == S && equals(APS))
|
2011-10-01 16:36:59 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
ARMConstantPoolMBB *APMBB = dyn_cast<ARMConstantPoolMBB>(CPV);
|
|
|
|
if (!APMBB) continue;
|
|
|
|
|
2011-10-01 20:44:28 +08:00
|
|
|
if (APMBB->MBB == MBB && equals(APMBB))
|
2011-10-01 17:19:10 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|