blob: adf03e04b81027d24471a6ff9186f71302023f18 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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"
17#include "llvm/Type.h"
Evan Chengf3aaeed2008-10-29 23:55:17 +000018#include "llvm/Support/Streams.h"
Chris Lattner1fefaac2008-08-23 22:23:09 +000019#include "llvm/Support/raw_ostream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020using namespace llvm;
21
22ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
23 ARMCP::ARMCPKind k,
24 unsigned char PCAdj,
25 const char *Modif,
26 bool AddCA)
27 : MachineConstantPoolValue((const Type*)gv->getType()),
28 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
29 Modifier(Modif), AddCurrentAddress(AddCA) {}
30
31ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
32 ARMCP::ARMCPKind k,
33 unsigned char PCAdj,
34 const char *Modif,
35 bool AddCA)
36 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
Jim Grosbach29feb6a2009-08-11 00:09:57 +000037 GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038 Modifier(Modif), AddCurrentAddress(AddCA) {}
39
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) {}
46
47int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
48 unsigned Alignment) {
Evan Cheng68c18682009-03-13 07:51:59 +000049 unsigned AlignMask = Alignment - 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Cheng68c18682009-03-13 07:51:59 +000053 (Constants[i].getAlignment() & AlignMask) == 0) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054 ARMConstantPoolValue *CPV =
55 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
56 if (CPV->GV == GV &&
57 CPV->S == S &&
58 CPV->LabelId == LabelId &&
59 CPV->Kind == Kind &&
60 CPV->PCAdjust == PCAdjust)
61 return i;
62 }
63 }
64
65 return -1;
66}
67
68void
69ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
70 ID.AddPointer(GV);
71 ID.AddPointer(S);
72 ID.AddInteger(LabelId);
73 ID.AddInteger((unsigned)Kind);
74 ID.AddInteger(PCAdjust);
75}
76
Evan Chengf3aaeed2008-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 Lattner1fefaac2008-08-23 22:23:09 +000086void ARMConstantPoolValue::print(raw_ostream &O) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +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";
93 if (Modifier) O << "(" << Modifier << ")";
94 if (PCAdjust != 0) {
Evan Cheng5a033a62008-11-04 00:50:32 +000095 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
96 if (AddCurrentAddress) O << "-.";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000097 O << ")";
98 }
99}