1 //===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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"
20 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
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,
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,
41 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
42 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
45 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
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;
56 CPV->LabelId == LabelId &&
58 CPV->PCAdjust == PCAdjust)
67 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
70 ID.AddInteger(LabelId);
71 ID.AddInteger((unsigned)Kind);
72 ID.AddInteger(PCAdjust);
75 void ARMConstantPoolValue::print(std::ostream &O) const {
80 if (isNonLazyPointer()) O << "$non_lazy_ptr";
81 else if (isStub()) O << "$stub";
82 if (Modifier) O << "(" << Modifier << ")";
84 O << "-(LPIC" << LabelId << "+"
85 << (unsigned)PCAdjust;
86 if (AddCurrentAddress)