1 //===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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"
18 #include "llvm/Support/Streams.h"
19 #include "llvm/Support/raw_ostream.h"
23 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
28 : MachineConstantPoolValue((const Type*)gv->getType()),
29 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
30 Modifier(Modif), AddCurrentAddress(AddCA) {}
32 ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
33 const char *s, unsigned id,
38 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
39 GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
40 Modifier(Modif), AddCurrentAddress(AddCA) {}
42 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
45 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
46 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
49 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
51 unsigned AlignMask = Alignment - 1;
52 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
53 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
54 if (Constants[i].isMachineConstantPoolEntry() &&
55 (Constants[i].getAlignment() & AlignMask) == 0) {
56 ARMConstantPoolValue *CPV =
57 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
60 CPV->LabelId == LabelId &&
62 CPV->PCAdjust == PCAdjust)
70 ARMConstantPoolValue::~ARMConstantPoolValue() {
75 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
78 ID.AddInteger(LabelId);
79 ID.AddInteger((unsigned)Kind);
80 ID.AddInteger(PCAdjust);
83 void ARMConstantPoolValue::dump() const {
87 void ARMConstantPoolValue::print(std::ostream &O) const {
88 raw_os_ostream RawOS(O);
92 void ARMConstantPoolValue::print(raw_ostream &O) const {
97 if (isNonLazyPointer()) O << "$non_lazy_ptr";
98 else if (isStub()) O << "$stub";
99 if (Modifier) O << "(" << Modifier << ")";
101 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
102 if (AddCurrentAddress) O << "-.";