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,
24 : MachineConstantPoolValue((const Type*)gv->getType()),
25 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
28 ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
32 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
33 GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj),
36 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
39 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
40 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
43 int ARMConstantPoolValue::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 ARMConstantPoolValue *CPV =
51 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
54 CPV->LabelId == LabelId &&
56 CPV->PCAdjust == PCAdjust)
65 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
68 ID.AddInteger(LabelId);
69 ID.AddInteger((unsigned)Kind);
70 ID.AddInteger(PCAdjust);
73 void ARMConstantPoolValue::print(std::ostream &O) const {
78 if (isNonLazyPointer()) O << "$non_lazy_ptr";
79 else if (isStub()) O << "$stub";
80 if (Modifier) O << "(" << Modifier << ")";
81 if (PCAdjust != 0) O << "-(LPIC" << LabelId << "+"
82 << (unsigned)PCAdjust << ")";