blob: b28a295cb085354101da2a280d03fd566b463c37 [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"
Chris Lattner1fefaac2008-08-23 22:23:09 +000018#include "llvm/Support/raw_ostream.h"
Jim Grosbach3fe420b2009-08-11 15:26:27 +000019#include <cstdlib>
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
Owen Anderson35b47072009-08-13 21:58:54 +000031ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
32 const char *s, unsigned id,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033 ARMCP::ARMCPKind k,
34 unsigned char PCAdj,
35 const char *Modif,
36 bool AddCA)
Owen Anderson35b47072009-08-13 21:58:54 +000037 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
Jim Grosbach29feb6a2009-08-11 00:09:57 +000038 GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039 Modifier(Modif), AddCurrentAddress(AddCA) {}
40
41ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
42 ARMCP::ARMCPKind k,
43 const char *Modif)
Owen Anderson35b47072009-08-13 21:58:54 +000044 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
46 Modifier(Modif) {}
47
48int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
49 unsigned Alignment) {
Evan Cheng68c18682009-03-13 07:51:59 +000050 unsigned AlignMask = Alignment - 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Cheng68c18682009-03-13 07:51:59 +000054 (Constants[i].getAlignment() & AlignMask) == 0) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055 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
Benjamin Kramer909610a2009-08-11 16:03:08 +000069ARMConstantPoolValue::~ARMConstantPoolValue() {
Jim Grosbach3fe420b2009-08-11 15:26:27 +000070 free((void*)S);
71}
72
Dan Gohmanf17a25c2007-07-18 16:29:46 +000073void
74ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
75 ID.AddPointer(GV);
76 ID.AddPointer(S);
77 ID.AddInteger(LabelId);
78 ID.AddInteger((unsigned)Kind);
79 ID.AddInteger(PCAdjust);
80}
81
Evan Chengf3aaeed2008-10-29 23:55:17 +000082void ARMConstantPoolValue::dump() const {
Chris Lattnerd71b0b02009-08-23 03:41:05 +000083 errs() << " " << *this;
Evan Chengf3aaeed2008-10-29 23:55:17 +000084}
85
Evan Chengf3aaeed2008-10-29 23:55:17 +000086
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) {
Evan Cheng5a033a62008-11-04 00:50:32 +000096 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
97 if (AddCurrentAddress) O << "-.";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000098 O << ")";
99 }
100}