blob: 002ebf109f7835626baa06d6cae77b957e8dca16 [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"
Evan Chengf3aaeed2008-10-29 23:55:17 +000020#include <ostream>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021using namespace llvm;
22
23ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
24 ARMCP::ARMCPKind k,
25 unsigned char PCAdj,
26 const char *Modif,
27 bool AddCA)
28 : MachineConstantPoolValue((const Type*)gv->getType()),
29 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
30 Modifier(Modif), AddCurrentAddress(AddCA) {}
31
32ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
33 ARMCP::ARMCPKind k,
34 unsigned char PCAdj,
35 const char *Modif,
36 bool AddCA)
37 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
38 GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj),
39 Modifier(Modif), AddCurrentAddress(AddCA) {}
40
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) {}
47
48int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
49 unsigned Alignment) {
50 unsigned AlignMask = (1 << Alignment)-1;
51 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
52 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
53 if (Constants[i].isMachineConstantPoolEntry() &&
54 (Constants[i].Offset & AlignMask) == 0) {
55 ARMConstantPoolValue *CPV =
56 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
57 if (CPV->GV == GV &&
58 CPV->S == S &&
59 CPV->LabelId == LabelId &&
60 CPV->Kind == Kind &&
61 CPV->PCAdjust == PCAdjust)
62 return i;
63 }
64 }
65
66 return -1;
67}
68
69void
70ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
71 ID.AddPointer(GV);
72 ID.AddPointer(S);
73 ID.AddInteger(LabelId);
74 ID.AddInteger((unsigned)Kind);
75 ID.AddInteger(PCAdjust);
76}
77
Evan Chengf3aaeed2008-10-29 23:55:17 +000078void ARMConstantPoolValue::dump() const {
79 cerr << " " << *this;
80}
81
82void ARMConstantPoolValue::print(std::ostream &O) const {
83 raw_os_ostream RawOS(O);
84 print(RawOS);
85}
86
Chris Lattner1fefaac2008-08-23 22:23:09 +000087void ARMConstantPoolValue::print(raw_ostream &O) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000088 if (GV)
89 O << GV->getName();
90 else
91 O << S;
92 if (isNonLazyPointer()) O << "$non_lazy_ptr";
93 else if (isStub()) O << "$stub";
94 if (Modifier) O << "(" << Modifier << ")";
95 if (PCAdjust != 0) {
96 O << "-(LPIC" << LabelId << "+"
97 << (unsigned)PCAdjust;
98 if (AddCurrentAddress)
99 O << "-.";
100 O << ")";
101 }
102}