blob: a598af4f228d43a794a32f224e4e0437f4fd245c [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Chenga8e29892007-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"
16#include "llvm/GlobalValue.h"
Evan Chengc60e76d2007-01-30 20:37:08 +000017#include "llvm/Type.h"
Evan Cheng5be59ea2008-10-29 23:55:17 +000018#include "llvm/Support/Streams.h"
Chris Lattner944fac72008-08-23 22:23:09 +000019#include "llvm/Support/raw_ostream.h"
Jim Grosbachf1287872009-08-11 15:26:27 +000020#include <cstdlib>
Evan Chenga8e29892007-01-19 07:51:42 +000021using namespace llvm;
22
23ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
Evan Chengc60e76d2007-01-30 20:37:08 +000024 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000025 unsigned char PCAdj,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000026 const char *Modif,
27 bool AddCA)
Evan Chenga8e29892007-01-19 07:51:42 +000028 : MachineConstantPoolValue((const Type*)gv->getType()),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000029 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000030 Modifier(Modif), AddCurrentAddress(AddCA) {}
Evan Chengc60e76d2007-01-30 20:37:08 +000031
32ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
33 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000034 unsigned char PCAdj,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000035 const char *Modif,
36 bool AddCA)
Evan Chengc60e76d2007-01-30 20:37:08 +000037 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
Jim Grosbach1b747ad2009-08-11 00:09:57 +000038 GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000039 Modifier(Modif), AddCurrentAddress(AddCA) {}
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000040
41ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
42 ARMCP::ARMCPKind k,
43 const char *Modif)
44 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
45 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
46 Modifier(Modif) {}
Evan Chenga8e29892007-01-19 07:51:42 +000047
48int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
49 unsigned Alignment) {
Evan Cheng1606e8e2009-03-13 07:51:59 +000050 unsigned AlignMask = Alignment - 1;
Evan Chenga8e29892007-01-19 07:51:42 +000051 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
52 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
53 if (Constants[i].isMachineConstantPoolEntry() &&
Evan Cheng1606e8e2009-03-13 07:51:59 +000054 (Constants[i].getAlignment() & AlignMask) == 0) {
Evan Chenga8e29892007-01-19 07:51:42 +000055 ARMConstantPoolValue *CPV =
56 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
Evan Chengc60e76d2007-01-30 20:37:08 +000057 if (CPV->GV == GV &&
58 CPV->S == S &&
59 CPV->LabelId == LabelId &&
60 CPV->Kind == Kind &&
61 CPV->PCAdjust == PCAdjust)
Evan Chenga8e29892007-01-19 07:51:42 +000062 return i;
63 }
64 }
65
66 return -1;
67}
68
Jim Grosbachf1287872009-08-11 15:26:27 +000069ARMConstantPoolValue::~ARMConstantPoolValue(void) {
70 free((void*)S);
71}
72
Evan Chenga8e29892007-01-19 07:51:42 +000073void
74ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
75 ID.AddPointer(GV);
Evan Chengc60e76d2007-01-30 20:37:08 +000076 ID.AddPointer(S);
Evan Chenga8e29892007-01-19 07:51:42 +000077 ID.AddInteger(LabelId);
Evan Chengc60e76d2007-01-30 20:37:08 +000078 ID.AddInteger((unsigned)Kind);
Evan Chenga8e29892007-01-19 07:51:42 +000079 ID.AddInteger(PCAdjust);
80}
81
Evan Cheng5be59ea2008-10-29 23:55:17 +000082void ARMConstantPoolValue::dump() const {
83 cerr << " " << *this;
84}
85
86void ARMConstantPoolValue::print(std::ostream &O) const {
87 raw_os_ostream RawOS(O);
88 print(RawOS);
89}
90
Chris Lattner944fac72008-08-23 22:23:09 +000091void ARMConstantPoolValue::print(raw_ostream &O) const {
Evan Chengc60e76d2007-01-30 20:37:08 +000092 if (GV)
93 O << GV->getName();
94 else
95 O << S;
96 if (isNonLazyPointer()) O << "$non_lazy_ptr";
97 else if (isStub()) O << "$stub";
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000098 if (Modifier) O << "(" << Modifier << ")";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000099 if (PCAdjust != 0) {
Evan Cheng25e04782008-11-04 00:50:32 +0000100 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
101 if (AddCurrentAddress) O << "-.";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000102 O << ")";
103 }
Evan Chenga8e29892007-01-19 07:51:42 +0000104}