blob: efa941a677c9c4e31522fb3a239d0a250bd6dd3c [file] [log] [blame]
Evan Cheng10043e22007-01-19 07:51:42 +00001//===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Cheng10043e22007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the ARM specific constantpool value class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARMConstantPoolValue.h"
15#include "llvm/ADT/FoldingSet.h"
Bob Wilson433ab092009-11-02 16:59:06 +000016#include "llvm/Constant.h"
17#include "llvm/Constants.h"
Evan Cheng10043e22007-01-19 07:51:42 +000018#include "llvm/GlobalValue.h"
Evan Cheng83f35172007-01-30 20:37:08 +000019#include "llvm/Type.h"
Chris Lattner0c19df42008-08-23 22:23:09 +000020#include "llvm/Support/raw_ostream.h"
Jim Grosbach74eb9e72009-08-11 15:26:27 +000021#include <cstdlib>
Evan Cheng10043e22007-01-19 07:51:42 +000022using namespace llvm;
23
Bob Wilson433ab092009-11-02 16:59:06 +000024ARMConstantPoolValue::ARMConstantPoolValue(Constant *cval, unsigned id,
Jim Grosbach20eac922009-09-01 01:57:56 +000025 ARMCP::ARMCPKind K,
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000026 unsigned char PCAdj,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000027 const char *Modif,
28 bool AddCA)
Bob Wilson433ab092009-11-02 16:59:06 +000029 : MachineConstantPoolValue((const Type*)cval->getType()),
30 CVal(cval), S(NULL), LabelId(id), Kind(K), PCAdjust(PCAdj),
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000031 Modifier(Modif), AddCurrentAddress(AddCA) {}
Evan Cheng83f35172007-01-30 20:37:08 +000032
Owen Anderson55f1c092009-08-13 21:58:54 +000033ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
34 const char *s, unsigned id,
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000035 unsigned char PCAdj,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000036 const char *Modif,
37 bool AddCA)
Owen Anderson55f1c092009-08-13 21:58:54 +000038 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
Bob Wilson433ab092009-11-02 16:59:06 +000039 CVal(NULL), S(strdup(s)), LabelId(id), Kind(ARMCP::CPExtSymbol),
40 PCAdjust(PCAdj), Modifier(Modif), AddCurrentAddress(AddCA) {}
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000041
Evan Cheng43b9ca62009-08-28 23:18:09 +000042ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, const char *Modif)
Owen Anderson55f1c092009-08-13 21:58:54 +000043 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
Bob Wilson433ab092009-11-02 16:59:06 +000044 CVal(gv), S(NULL), LabelId(0), Kind(ARMCP::CPValue), PCAdjust(0),
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000045 Modifier(Modif) {}
Evan Cheng10043e22007-01-19 07:51:42 +000046
Bob Wilson433ab092009-11-02 16:59:06 +000047GlobalValue *ARMConstantPoolValue::getGV() const {
48 return dyn_cast_or_null<GlobalValue>(CVal);
49}
50
51BlockAddress *ARMConstantPoolValue::getBlockAddress() const {
52 return dyn_cast_or_null<BlockAddress>(CVal);
53}
54
Evan Cheng10043e22007-01-19 07:51:42 +000055int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
56 unsigned Alignment) {
Evan Cheng1fb8aed2009-03-13 07:51:59 +000057 unsigned AlignMask = Alignment - 1;
Evan Cheng10043e22007-01-19 07:51:42 +000058 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
59 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
60 if (Constants[i].isMachineConstantPoolEntry() &&
Evan Cheng1fb8aed2009-03-13 07:51:59 +000061 (Constants[i].getAlignment() & AlignMask) == 0) {
Evan Cheng10043e22007-01-19 07:51:42 +000062 ARMConstantPoolValue *CPV =
63 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
Bob Wilson433ab092009-11-02 16:59:06 +000064 if (CPV->CVal == CVal &&
Evan Cheng83f35172007-01-30 20:37:08 +000065 CPV->S == S &&
66 CPV->LabelId == LabelId &&
Evan Cheng83f35172007-01-30 20:37:08 +000067 CPV->PCAdjust == PCAdjust)
Evan Cheng10043e22007-01-19 07:51:42 +000068 return i;
69 }
70 }
71
72 return -1;
73}
74
Benjamin Kramereda08012009-08-11 16:03:08 +000075ARMConstantPoolValue::~ARMConstantPoolValue() {
Jim Grosbach74eb9e72009-08-11 15:26:27 +000076 free((void*)S);
77}
78
Evan Cheng10043e22007-01-19 07:51:42 +000079void
80ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
Bob Wilson433ab092009-11-02 16:59:06 +000081 ID.AddPointer(CVal);
Evan Cheng83f35172007-01-30 20:37:08 +000082 ID.AddPointer(S);
Evan Cheng10043e22007-01-19 07:51:42 +000083 ID.AddInteger(LabelId);
Evan Cheng10043e22007-01-19 07:51:42 +000084 ID.AddInteger(PCAdjust);
85}
86
Evan Chengde9dbc52008-10-29 23:55:17 +000087void ARMConstantPoolValue::dump() const {
Chris Lattnera6f074f2009-08-23 03:41:05 +000088 errs() << " " << *this;
Evan Chengde9dbc52008-10-29 23:55:17 +000089}
90
Evan Chengde9dbc52008-10-29 23:55:17 +000091
Chris Lattner0c19df42008-08-23 22:23:09 +000092void ARMConstantPoolValue::print(raw_ostream &O) const {
Bob Wilson433ab092009-11-02 16:59:06 +000093 if (CVal)
94 O << CVal->getName();
Evan Cheng83f35172007-01-30 20:37:08 +000095 else
96 O << S;
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000097 if (Modifier) O << "(" << Modifier << ")";
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000098 if (PCAdjust != 0) {
Evan Cheng6dd08b62008-11-04 00:50:32 +000099 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
100 if (AddCurrentAddress) O << "-.";
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +0000101 O << ")";
102 }
Evan Cheng10043e22007-01-19 07:51:42 +0000103}