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/raw_ostream.h"
22 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
26 : MachineConstantPoolValue((const Type*)gv->getType()),
27 GV(gv), S(NULL), LabelId(id), PCAdjust(PCAdj),
28 Modifier(Modif), AddCurrentAddress(AddCA) {}
30 ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
31 const char *s, unsigned id,
35 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
36 GV(NULL), S(strdup(s)), LabelId(id), PCAdjust(PCAdj),
37 Modifier(Modif), AddCurrentAddress(AddCA) {}
39 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, const char *Modif)
40 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
41 GV(gv), S(NULL), LabelId(0), PCAdjust(0),
44 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
46 unsigned AlignMask = Alignment - 1;
47 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
48 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
49 if (Constants[i].isMachineConstantPoolEntry() &&
50 (Constants[i].getAlignment() & AlignMask) == 0) {
51 ARMConstantPoolValue *CPV =
52 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
55 CPV->LabelId == LabelId &&
56 CPV->PCAdjust == PCAdjust)
64 ARMConstantPoolValue::~ARMConstantPoolValue() {
69 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
72 ID.AddInteger(LabelId);
73 ID.AddInteger(PCAdjust);
76 void ARMConstantPoolValue::dump() const {
77 errs() << " " << *this;
81 void ARMConstantPoolValue::print(raw_ostream &O) const {
86 if (Modifier) O << "(" << Modifier << ")";
88 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
89 if (AddCurrentAddress) O << "-.";