Fix bugs section.
[llvm-complete.git] / lib / Target / ARM / ARMConstantPoolValue.cpp
blob6add3c38d377b017e5ae48fc4950b491d5ad25ea
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.
12 //===----------------------------------------------------------------------===//
14 #include "ARMConstantPoolValue.h"
15 #include "llvm/ADT/FoldingSet.h"
16 #include "llvm/GlobalValue.h"
17 #include "llvm/Type.h"
18 using namespace llvm;
20 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
21 ARMCP::ARMCPKind k,
22 unsigned char PCAdj,
23 const char *Modif,
24 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 ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
30 ARMCP::ARMCPKind k,
31 unsigned char PCAdj,
32 const char *Modif,
33 bool AddCA)
34 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
35 GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj),
36 Modifier(Modif), AddCurrentAddress(AddCA) {}
38 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
39 ARMCP::ARMCPKind k,
40 const char *Modif)
41 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
42 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
43 Modifier(Modif) {}
45 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
46 unsigned Alignment) {
47 unsigned AlignMask = (1 << Alignment)-1;
48 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
49 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
50 if (Constants[i].isMachineConstantPoolEntry() &&
51 (Constants[i].Offset & AlignMask) == 0) {
52 ARMConstantPoolValue *CPV =
53 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
54 if (CPV->GV == GV &&
55 CPV->S == S &&
56 CPV->LabelId == LabelId &&
57 CPV->Kind == Kind &&
58 CPV->PCAdjust == PCAdjust)
59 return i;
63 return -1;
66 void
67 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
68 ID.AddPointer(GV);
69 ID.AddPointer(S);
70 ID.AddInteger(LabelId);
71 ID.AddInteger((unsigned)Kind);
72 ID.AddInteger(PCAdjust);
75 void ARMConstantPoolValue::print(std::ostream &O) const {
76 if (GV)
77 O << GV->getName();
78 else
79 O << S;
80 if (isNonLazyPointer()) O << "$non_lazy_ptr";
81 else if (isStub()) O << "$stub";
82 if (Modifier) O << "(" << Modifier << ")";
83 if (PCAdjust != 0) {
84 O << "-(LPIC" << LabelId << "+"
85 << (unsigned)PCAdjust;
86 if (AddCurrentAddress)
87 O << "-.";
88 O << ")";