SjLj based exception handling unwinding support. This patch is nasty, brutish
[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/Streams.h"
19 #include "llvm/Support/raw_ostream.h"
20 using namespace llvm;
21
22 ARMConstantPoolValue::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
31 ARMConstantPoolValue::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),
37     GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
38     Modifier(Modif), AddCurrentAddress(AddCA) {}
39
40 ARMConstantPoolValue::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
47 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
48                                                     unsigned Alignment) {
49   unsigned AlignMask = Alignment - 1;
50   const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
51   for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
52     if (Constants[i].isMachineConstantPoolEntry() &&
53         (Constants[i].getAlignment() & AlignMask) == 0) {
54       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
68 void
69 ARMConstantPoolValue::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
77 void ARMConstantPoolValue::dump() const {
78   cerr << "  " << *this;
79 }
80
81 void ARMConstantPoolValue::print(std::ostream &O) const {
82   raw_os_ostream RawOS(O);
83   print(RawOS);
84 }
85
86 void ARMConstantPoolValue::print(raw_ostream &O) const {
87   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) {
95     O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
96     if (AddCurrentAddress) O << "-.";
97     O << ")";
98   }
99 }