Let Darwin linker auto-synthesize stubs and lazy-pointers. This deletes a bunch of...
[oota-llvm.git] / lib / Target / ARM / ARMConstantPoolValue.cpp
1 //===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
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"
18 #include "llvm/Support/raw_ostream.h"
19 #include <cstdlib>
20 using namespace llvm;
21
22 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
23                                            unsigned char PCAdj,
24                                            const char *Modif,
25                                            bool AddCA)
26   : MachineConstantPoolValue((const Type*)gv->getType()),
27     GV(gv), S(NULL), LabelId(id), PCAdjust(PCAdj),
28     Modifier(Modif), AddCurrentAddress(AddCA) {}
29
30 ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
31                                            const char *s, unsigned id,
32                                            unsigned char PCAdj,
33                                            const char *Modif,
34                                            bool AddCA)
35   : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
36     GV(NULL), S(strdup(s)), LabelId(id), PCAdjust(PCAdj),
37     Modifier(Modif), AddCurrentAddress(AddCA) {}
38
39 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, const char *Modif)
40   : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
41     GV(gv), S(NULL), LabelId(0), PCAdjust(0),
42     Modifier(Modif) {}
43
44 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
45                                                     unsigned Alignment) {
46   unsigned AlignMask = Alignment - 1;
47   const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
48   for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
49     if (Constants[i].isMachineConstantPoolEntry() &&
50         (Constants[i].getAlignment() & AlignMask) == 0) {
51       ARMConstantPoolValue *CPV =
52         (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
53       if (CPV->GV == GV &&
54           CPV->S == S &&
55           CPV->LabelId == LabelId &&
56           CPV->PCAdjust == PCAdjust)
57         return i;
58     }
59   }
60
61   return -1;
62 }
63
64 ARMConstantPoolValue::~ARMConstantPoolValue() {
65   free((void*)S);
66 }
67
68 void
69 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
70   ID.AddPointer(GV);
71   ID.AddPointer(S);
72   ID.AddInteger(LabelId);
73   ID.AddInteger(PCAdjust);
74 }
75
76 void ARMConstantPoolValue::dump() const {
77   errs() << "  " << *this;
78 }
79
80
81 void ARMConstantPoolValue::print(raw_ostream &O) const {
82   if (GV)
83     O << GV->getName();
84   else
85     O << S;
86   if (Modifier) O << "(" << Modifier << ")";
87   if (PCAdjust != 0) {
88     O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
89     if (AddCurrentAddress) O << "-.";
90     O << ")";
91   }
92 }