blob: adf03e04b81027d24471a6ff9186f71302023f18 [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"
Evan Chenga8e29892007-01-19 07:51:42 +000020using namespace llvm;
21
22ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
Evan Chengc60e76d2007-01-30 20:37:08 +000023 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000024 unsigned char PCAdj,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000025 const char *Modif,
26 bool AddCA)
Evan Chenga8e29892007-01-19 07:51:42 +000027 : MachineConstantPoolValue((const Type*)gv->getType()),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000028 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000029 Modifier(Modif), AddCurrentAddress(AddCA) {}
Evan Chengc60e76d2007-01-30 20:37:08 +000030
31ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
32 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000033 unsigned char PCAdj,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000034 const char *Modif,
35 bool AddCA)
Evan Chengc60e76d2007-01-30 20:37:08 +000036 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
Jim Grosbach1b747ad2009-08-11 00:09:57 +000037 GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000038 Modifier(Modif), AddCurrentAddress(AddCA) {}
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000039
40ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
41 ARMCP::ARMCPKind k,
42 const char *Modif)
43 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
44 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
45 Modifier(Modif) {}
Evan Chenga8e29892007-01-19 07:51:42 +000046
47int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
48 unsigned Alignment) {
Evan Cheng1606e8e2009-03-13 07:51:59 +000049 unsigned AlignMask = Alignment - 1;
Evan Chenga8e29892007-01-19 07:51:42 +000050 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
51 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
52 if (Constants[i].isMachineConstantPoolEntry() &&
Evan Cheng1606e8e2009-03-13 07:51:59 +000053 (Constants[i].getAlignment() & AlignMask) == 0) {
Evan Chenga8e29892007-01-19 07:51:42 +000054 ARMConstantPoolValue *CPV =
55 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
Evan Chengc60e76d2007-01-30 20:37:08 +000056 if (CPV->GV == GV &&
57 CPV->S == S &&
58 CPV->LabelId == LabelId &&
59 CPV->Kind == Kind &&
60 CPV->PCAdjust == PCAdjust)
Evan Chenga8e29892007-01-19 07:51:42 +000061 return i;
62 }
63 }
64
65 return -1;
66}
67
68void
69ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
70 ID.AddPointer(GV);
Evan Chengc60e76d2007-01-30 20:37:08 +000071 ID.AddPointer(S);
Evan Chenga8e29892007-01-19 07:51:42 +000072 ID.AddInteger(LabelId);
Evan Chengc60e76d2007-01-30 20:37:08 +000073 ID.AddInteger((unsigned)Kind);
Evan Chenga8e29892007-01-19 07:51:42 +000074 ID.AddInteger(PCAdjust);
75}
76
Evan Cheng5be59ea2008-10-29 23:55:17 +000077void ARMConstantPoolValue::dump() const {
78 cerr << " " << *this;
79}
80
81void ARMConstantPoolValue::print(std::ostream &O) const {
82 raw_os_ostream RawOS(O);
83 print(RawOS);
84}
85
Chris Lattner944fac72008-08-23 22:23:09 +000086void ARMConstantPoolValue::print(raw_ostream &O) const {
Evan Chengc60e76d2007-01-30 20:37:08 +000087 if (GV)
88 O << GV->getName();
89 else
90 O << S;
91 if (isNonLazyPointer()) O << "$non_lazy_ptr";
92 else if (isStub()) O << "$stub";
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000093 if (Modifier) O << "(" << Modifier << ")";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000094 if (PCAdjust != 0) {
Evan Cheng25e04782008-11-04 00:50:32 +000095 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
96 if (AddCurrentAddress) O << "-.";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000097 O << ")";
98 }
Evan Chenga8e29892007-01-19 07:51:42 +000099}