New entry.
[oota-llvm.git] / lib / Target / ARM / ARMConstantPoolValue.cpp
1 //===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Evan Cheng and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the ARM specific constantpool value class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ARMConstantPoolValue.h"
15 #include "llvm/ADT/FoldingSet.h"
16 #include "llvm/GlobalValue.h"
17 #include "llvm/Type.h"
18 using namespace llvm;
19
20 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
21                                            ARMCP::ARMCPKind k,
22                                            unsigned char PCAdj)
23   : MachineConstantPoolValue((const Type*)gv->getType()),
24     GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj) {}
25
26 ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
27                                            ARMCP::ARMCPKind k,
28                                            unsigned char PCAdj)
29   : MachineConstantPoolValue((const Type*)Type::Int32Ty),
30     GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj) {}
31
32 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
33                                                     unsigned Alignment) {
34   unsigned AlignMask = (1 << Alignment)-1;
35   const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
36   for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
37     if (Constants[i].isMachineConstantPoolEntry() &&
38         (Constants[i].Offset & AlignMask) == 0) {
39       ARMConstantPoolValue *CPV =
40         (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
41       if (CPV->GV == GV &&
42           CPV->S == S &&
43           CPV->LabelId == LabelId &&
44           CPV->Kind == Kind &&
45           CPV->PCAdjust == PCAdjust)
46         return i;
47     }
48   }
49
50   return -1;
51 }
52
53 void
54 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
55   ID.AddPointer(GV);
56   ID.AddPointer(S);
57   ID.AddInteger(LabelId);
58   ID.AddInteger((unsigned)Kind);
59   ID.AddInteger(PCAdjust);
60 }
61
62 void ARMConstantPoolValue::print(std::ostream &O) const {
63   if (GV)
64     O << GV->getName();
65   else
66     O << S;
67   if (isNonLazyPointer()) O << "$non_lazy_ptr";
68   else if (isStub()) O << "$stub";
69   if (PCAdjust != 0) O << "-(LPIC" << LabelId << "+"
70                        << (unsigned)PCAdjust << ")";
71 }