Switch the asmprinter (.ll) and all the stuff it requires over to
[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 using namespace llvm;
20
21 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
22                                            ARMCP::ARMCPKind k,
23                                            unsigned char PCAdj,
24                                            const char *Modif,
25                                            bool AddCA)
26   : MachineConstantPoolValue((const Type*)gv->getType()),
27     GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
28     Modifier(Modif), AddCurrentAddress(AddCA) {}
29
30 ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
31                                            ARMCP::ARMCPKind k,
32                                            unsigned char PCAdj,
33                                            const char *Modif,
34                                            bool AddCA)
35   : MachineConstantPoolValue((const Type*)Type::Int32Ty),
36     GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj),
37     Modifier(Modif), AddCurrentAddress(AddCA) {}
38
39 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
40                                            ARMCP::ARMCPKind k,
41                                            const char *Modif)
42   : MachineConstantPoolValue((const Type*)Type::Int32Ty),
43     GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
44     Modifier(Modif) {}
45
46 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
47                                                     unsigned Alignment) {
48   unsigned AlignMask = (1 << Alignment)-1;
49   const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
50   for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
51     if (Constants[i].isMachineConstantPoolEntry() &&
52         (Constants[i].Offset & AlignMask) == 0) {
53       ARMConstantPoolValue *CPV =
54         (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
55       if (CPV->GV == GV &&
56           CPV->S == S &&
57           CPV->LabelId == LabelId &&
58           CPV->Kind == Kind &&
59           CPV->PCAdjust == PCAdjust)
60         return i;
61     }
62   }
63
64   return -1;
65 }
66
67 void
68 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
69   ID.AddPointer(GV);
70   ID.AddPointer(S);
71   ID.AddInteger(LabelId);
72   ID.AddInteger((unsigned)Kind);
73   ID.AddInteger(PCAdjust);
74 }
75
76 void ARMConstantPoolValue::print(raw_ostream &O) const {
77   if (GV)
78     O << GV->getName();
79   else
80     O << S;
81   if (isNonLazyPointer()) O << "$non_lazy_ptr";
82   else if (isStub()) O << "$stub";
83   if (Modifier) O << "(" << Modifier << ")";
84   if (PCAdjust != 0) {
85     O << "-(LPIC" << LabelId << "+"
86       << (unsigned)PCAdjust;
87     if (AddCurrentAddress)
88       O << "-.";
89     O << ")";
90   }
91 }