erect abstraction boundaries for accessing SDValue members, rename Val -> Node to...
[oota-llvm.git] / lib / Target / PIC16 / PIC16ConstantPoolValue.cpp
1 //===- PIC16ConstantPoolValue.cpp - PIC16 constantpool value --------------===//
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 PIC16 specific constantpool value class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PIC16ConstantPoolValue.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 PIC16ConstantPoolValue::PIC16ConstantPoolValue(GlobalValue *gv, unsigned id,
22                                                PIC16CP::PIC16CPKind k,
23                                                unsigned char PCAdj,
24                                                const char *Modif, bool AddCA)
25   : MachineConstantPoolValue((const Type*)gv->getType()),
26     GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
27     Modifier(Modif), AddCurrentAddress(AddCA) {}
28
29 PIC16ConstantPoolValue::PIC16ConstantPoolValue(const char *s, unsigned id,
30                                                PIC16CP::PIC16CPKind k,
31                                                unsigned char PCAdj,
32                                                const char *Modif, bool AddCA)
33   : MachineConstantPoolValue((const Type*)Type::Int32Ty),
34     GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj),
35     Modifier(Modif), AddCurrentAddress(AddCA) {}
36
37 PIC16ConstantPoolValue::PIC16ConstantPoolValue(GlobalValue *gv,
38                                                PIC16CP::PIC16CPKind k,
39                                                const char *Modif)
40   : MachineConstantPoolValue((const Type*)Type::Int32Ty),
41     GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
42     Modifier(Modif) {}
43
44 int PIC16ConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
45                                                       unsigned Alignment) {
46   unsigned AlignMask = (1 << 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].Offset & AlignMask) == 0) {
51       PIC16ConstantPoolValue *CPV =
52         (PIC16ConstantPoolValue *)Constants[i].Val.MachineCPVal;
53       if (CPV->GV == GV &&
54           CPV->S == S &&
55           CPV->LabelId == LabelId &&
56           CPV->Kind == Kind &&
57           CPV->PCAdjust == PCAdjust)
58         return i;
59     }
60   }
61
62   return -1;
63 }
64
65 void
66 PIC16ConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
67   ID.AddPointer(GV);
68   ID.AddPointer(S);
69   ID.AddInteger(LabelId);
70   ID.AddInteger((unsigned)Kind);
71   ID.AddInteger(PCAdjust);
72 }
73
74 void PIC16ConstantPoolValue::print(raw_ostream &O) const {
75   if (GV)
76     O << GV->getName();
77   else
78     O << S;
79   if (isNonLazyPointer()) O << "$non_lazy_ptr";
80   else if (isStub()) O << "$stub";
81   if (Modifier) O << "(" << Modifier << ")";
82   if (PCAdjust != 0) {
83     O << "-(LPIC" << LabelId << "+"
84       << (unsigned)PCAdjust;
85     if (AddCurrentAddress)
86       O << "-.";
87     O << ")";
88   }
89 }