2007-01-19 08:51:42 +01:00
|
|
|
//===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-01-19 08:51:42 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the ARM specific constantpool value class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMConstantPoolValue.h"
|
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2009-11-02 17:59:06 +01:00
|
|
|
#include "llvm/Constant.h"
|
|
|
|
#include "llvm/Constants.h"
|
2007-01-19 08:51:42 +01:00
|
|
|
#include "llvm/GlobalValue.h"
|
2007-01-30 21:37:08 +01:00
|
|
|
#include "llvm/Type.h"
|
2008-08-24 00:23:09 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-08-11 17:26:27 +02:00
|
|
|
#include <cstdlib>
|
2007-01-19 08:51:42 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2010-04-15 03:51:59 +02:00
|
|
|
ARMConstantPoolValue::ARMConstantPoolValue(const Constant *cval, unsigned id,
|
2009-09-01 03:57:56 +02:00
|
|
|
ARMCP::ARMCPKind K,
|
2007-04-22 02:04:12 +02:00
|
|
|
unsigned char PCAdj,
|
2010-11-09 22:36:17 +01:00
|
|
|
ARMCP::ARMCPModifier Modif,
|
2007-04-27 15:54:47 +02:00
|
|
|
bool AddCA)
|
2009-11-02 17:59:06 +01:00
|
|
|
: MachineConstantPoolValue((const Type*)cval->getType()),
|
|
|
|
CVal(cval), S(NULL), LabelId(id), Kind(K), PCAdjust(PCAdj),
|
2007-04-27 15:54:47 +02:00
|
|
|
Modifier(Modif), AddCurrentAddress(AddCA) {}
|
2007-01-30 21:37:08 +01:00
|
|
|
|
2009-08-13 23:58:54 +02:00
|
|
|
ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
|
|
|
|
const char *s, unsigned id,
|
2007-04-22 02:04:12 +02:00
|
|
|
unsigned char PCAdj,
|
2010-11-09 22:36:17 +01:00
|
|
|
ARMCP::ARMCPModifier Modif,
|
2007-04-27 15:54:47 +02:00
|
|
|
bool AddCA)
|
2009-08-13 23:58:54 +02:00
|
|
|
: MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
|
2009-11-02 17:59:06 +01:00
|
|
|
CVal(NULL), S(strdup(s)), LabelId(id), Kind(ARMCP::CPExtSymbol),
|
|
|
|
PCAdjust(PCAdj), Modifier(Modif), AddCurrentAddress(AddCA) {}
|
2007-04-22 02:04:12 +02:00
|
|
|
|
2010-04-15 03:51:59 +02:00
|
|
|
ARMConstantPoolValue::ARMConstantPoolValue(const GlobalValue *gv,
|
2010-11-09 22:36:17 +01:00
|
|
|
ARMCP::ARMCPModifier Modif)
|
2009-08-13 23:58:54 +02:00
|
|
|
: MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
|
2009-11-02 17:59:06 +01:00
|
|
|
CVal(gv), S(NULL), LabelId(0), Kind(ARMCP::CPValue), PCAdjust(0),
|
2010-12-01 02:38:58 +01:00
|
|
|
Modifier(Modif), AddCurrentAddress(false) {}
|
2007-01-19 08:51:42 +01:00
|
|
|
|
2010-04-15 03:51:59 +02:00
|
|
|
const GlobalValue *ARMConstantPoolValue::getGV() const {
|
2009-11-02 17:59:06 +01:00
|
|
|
return dyn_cast_or_null<GlobalValue>(CVal);
|
|
|
|
}
|
|
|
|
|
2010-04-15 03:51:59 +02:00
|
|
|
const BlockAddress *ARMConstantPoolValue::getBlockAddress() const {
|
2009-11-02 17:59:06 +01:00
|
|
|
return dyn_cast_or_null<BlockAddress>(CVal);
|
|
|
|
}
|
|
|
|
|
2010-09-24 07:18:35 +02:00
|
|
|
static bool CPV_streq(const char *S1, const char *S2) {
|
|
|
|
if (S1 == S2)
|
|
|
|
return true;
|
|
|
|
if (S1 && S2 && strcmp(S1, S2) == 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-01-19 08:51:42 +01:00
|
|
|
int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
|
|
|
|
unsigned Alignment) {
|
2009-03-13 08:51:59 +01:00
|
|
|
unsigned AlignMask = Alignment - 1;
|
2007-01-19 08:51:42 +01:00
|
|
|
const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
|
|
|
|
for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
|
|
|
|
if (Constants[i].isMachineConstantPoolEntry() &&
|
2009-03-13 08:51:59 +01:00
|
|
|
(Constants[i].getAlignment() & AlignMask) == 0) {
|
2007-01-19 08:51:42 +01:00
|
|
|
ARMConstantPoolValue *CPV =
|
|
|
|
(ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
|
2009-11-02 17:59:06 +01:00
|
|
|
if (CPV->CVal == CVal &&
|
2007-01-30 21:37:08 +01:00
|
|
|
CPV->LabelId == LabelId &&
|
2009-11-07 04:52:02 +01:00
|
|
|
CPV->PCAdjust == PCAdjust &&
|
2010-09-24 07:18:35 +02:00
|
|
|
CPV_streq(CPV->S, S) &&
|
2010-11-09 22:36:17 +01:00
|
|
|
CPV->Modifier == Modifier)
|
2007-01-19 08:51:42 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-08-11 18:03:08 +02:00
|
|
|
ARMConstantPoolValue::~ARMConstantPoolValue() {
|
2009-08-11 17:26:27 +02:00
|
|
|
free((void*)S);
|
|
|
|
}
|
|
|
|
|
2007-01-19 08:51:42 +01:00
|
|
|
void
|
|
|
|
ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
|
2009-11-02 17:59:06 +01:00
|
|
|
ID.AddPointer(CVal);
|
2007-01-30 21:37:08 +01:00
|
|
|
ID.AddPointer(S);
|
2007-01-19 08:51:42 +01:00
|
|
|
ID.AddInteger(LabelId);
|
|
|
|
ID.AddInteger(PCAdjust);
|
|
|
|
}
|
|
|
|
|
2009-11-07 04:52:02 +01:00
|
|
|
bool
|
|
|
|
ARMConstantPoolValue::hasSameValue(ARMConstantPoolValue *ACPV) {
|
|
|
|
if (ACPV->Kind == Kind &&
|
|
|
|
ACPV->CVal == CVal &&
|
|
|
|
ACPV->PCAdjust == PCAdjust &&
|
2010-09-24 07:18:35 +02:00
|
|
|
CPV_streq(ACPV->S, S) &&
|
2010-11-09 22:36:17 +01:00
|
|
|
ACPV->Modifier == Modifier) {
|
2009-11-07 04:52:02 +01: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 00:55:17 +01:00
|
|
|
void ARMConstantPoolValue::dump() const {
|
2009-08-23 05:41:05 +02:00
|
|
|
errs() << " " << *this;
|
2008-10-30 00:55:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-24 00:23:09 +02:00
|
|
|
void ARMConstantPoolValue::print(raw_ostream &O) const {
|
2009-11-02 17:59:06 +01:00
|
|
|
if (CVal)
|
|
|
|
O << CVal->getName();
|
2007-01-30 21:37:08 +01:00
|
|
|
else
|
|
|
|
O << S;
|
2010-11-09 22:36:17 +01:00
|
|
|
if (Modifier) O << "(" << getModifierText() << ")";
|
2007-04-27 15:54:47 +02:00
|
|
|
if (PCAdjust != 0) {
|
2008-11-04 01:50:32 +01:00
|
|
|
O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
|
|
|
|
if (AddCurrentAddress) O << "-.";
|
2007-04-27 15:54:47 +02:00
|
|
|
O << ")";
|
|
|
|
}
|
2007-01-19 08:51:42 +01:00
|
|
|
}
|