blob: 9697422c6dc2ec0a061d4e77f42a9be6672b55f4 [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"
Jim Grosbach3fe420b2009-08-11 15:26:27 +000020#include <cstdlib>
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
Owen Anderson35b47072009-08-13 21:58:54 +000032ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
33 const char *s, unsigned id,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000034 ARMCP::ARMCPKind k,
35 unsigned char PCAdj,
36 const char *Modif,
37 bool AddCA)
Owen Anderson35b47072009-08-13 21:58:54 +000038 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
Jim Grosbach29feb6a2009-08-11 00:09:57 +000039 GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040 Modifier(Modif), AddCurrentAddress(AddCA) {}
41
42ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
43 ARMCP::ARMCPKind k,
44 const char *Modif)
Owen Anderson35b47072009-08-13 21:58:54 +000045 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
47 Modifier(Modif) {}
48
49int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
50 unsigned Alignment) {
Evan Cheng68c18682009-03-13 07:51:59 +000051 unsigned AlignMask = Alignment - 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
53 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
54 if (Constants[i].isMachineConstantPoolEntry() &&
Evan Cheng68c18682009-03-13 07:51:59 +000055 (Constants[i].getAlignment() & AlignMask) == 0) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056 ARMConstantPoolValue *CPV =
57 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
58 if (CPV->GV == GV &&
59 CPV->S == S &&
60 CPV->LabelId == LabelId &&
61 CPV->Kind == Kind &&
62 CPV->PCAdjust == PCAdjust)
63 return i;
64 }
65 }
66
67 return -1;
68}
69
Benjamin Kramer909610a2009-08-11 16:03:08 +000070ARMConstantPoolValue::~ARMConstantPoolValue() {
Jim Grosbach3fe420b2009-08-11 15:26:27 +000071 free((void*)S);
72}
73
Dan Gohmanf17a25c2007-07-18 16:29:46 +000074void
75ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
76 ID.AddPointer(GV);
77 ID.AddPointer(S);
78 ID.AddInteger(LabelId);
79 ID.AddInteger((unsigned)Kind);
80 ID.AddInteger(PCAdjust);
81}
82
Evan Chengf3aaeed2008-10-29 23:55:17 +000083void ARMConstantPoolValue::dump() const {
84 cerr << " " << *this;
85}
86
87void ARMConstantPoolValue::print(std::ostream &O) const {
88 raw_os_ostream RawOS(O);
89 print(RawOS);
90}
91
Chris Lattner1fefaac2008-08-23 22:23:09 +000092void ARMConstantPoolValue::print(raw_ostream &O) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000093 if (GV)
94 O << GV->getName();
95 else
96 O << S;
97 if (isNonLazyPointer()) O << "$non_lazy_ptr";
98 else if (isStub()) O << "$stub";
99 if (Modifier) O << "(" << Modifier << ")";
100 if (PCAdjust != 0) {
Evan Cheng5a033a62008-11-04 00:50:32 +0000101 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
102 if (AddCurrentAddress) O << "-.";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000103 O << ")";
104 }
105}