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