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"
20 PIC16ConstantPoolValue::PIC16ConstantPoolValue(GlobalValue *gv, unsigned id,
21 PIC16CP::PIC16CPKind k,
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) {}
28 PIC16ConstantPoolValue::PIC16ConstantPoolValue(const char *s, unsigned id,
29 PIC16CP::PIC16CPKind k,
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) {}
36 PIC16ConstantPoolValue::PIC16ConstantPoolValue(GlobalValue *gv,
37 PIC16CP::PIC16CPKind k,
39 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
40 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
43 int PIC16ConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
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;
54 CPV->LabelId == LabelId &&
56 CPV->PCAdjust == PCAdjust)
65 PIC16ConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
68 ID.AddInteger(LabelId);
69 ID.AddInteger((unsigned)Kind);
70 ID.AddInteger(PCAdjust);
73 void PIC16ConstantPoolValue::print(std::ostream &O) const {
78 if (isNonLazyPointer()) O << "$non_lazy_ptr";
79 else if (isStub()) O << "$stub";
80 if (Modifier) O << "(" << Modifier << ")";
82 O << "-(LPIC" << LabelId << "+"
83 << (unsigned)PCAdjust;
84 if (AddCurrentAddress)