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