1 //===- PIC16ConstantPoolValue.cpp - PIC16 constantpool value --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the PIC16 specific constantpool value class.
12 //===----------------------------------------------------------------------===//
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"
21 PIC16ConstantPoolValue::PIC16ConstantPoolValue(GlobalValue *gv, unsigned id,
22 PIC16CP::PIC16CPKind k,
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) {}
29 PIC16ConstantPoolValue::PIC16ConstantPoolValue(const char *s, unsigned id,
30 PIC16CP::PIC16CPKind k,
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) {}
37 PIC16ConstantPoolValue::PIC16ConstantPoolValue(GlobalValue *gv,
38 PIC16CP::PIC16CPKind k,
40 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
41 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
44 int PIC16ConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
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;
55 CPV->LabelId == LabelId &&
57 CPV->PCAdjust == PCAdjust)
66 PIC16ConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
69 ID.AddInteger(LabelId);
70 ID.AddInteger((unsigned)Kind);
71 ID.AddInteger(PCAdjust);
74 void PIC16ConstantPoolValue::print(raw_ostream &O) const {
79 if (isNonLazyPointer()) O << "$non_lazy_ptr";
80 else if (isStub()) O << "$stub";
81 if (Modifier) O << "(" << Modifier << ")";
83 O << "-(LPIC" << LabelId << "+"
84 << (unsigned)PCAdjust;
85 if (AddCurrentAddress)