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,
23 : MachineConstantPoolValue((const Type*)gv->getType()),
24 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj) {}
26 ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
29 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
30 GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj) {}
32 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
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;
43 CPV->LabelId == LabelId &&
45 CPV->PCAdjust == PCAdjust)
54 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
57 ID.AddInteger(LabelId);
58 ID.AddInteger((unsigned)Kind);
59 ID.AddInteger(PCAdjust);
62 void ARMConstantPoolValue::print(std::ostream &O) const {
67 if (isNonLazyPointer()) O << "$non_lazy_ptr";
68 else if (isStub()) O << "$stub";
69 if (PCAdjust != 0) O << "-(LPIC" << LabelId << "+"
70 << (unsigned)PCAdjust << ")";