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,
27 : MachineConstantPoolValue((const Type*)gv->getType()),
28 GV(gv), S(NULL), LabelId(id), Kind(K), PCAdjust(PCAdj),
29 Modifier(Modif), AddCurrentAddress(AddCA) {}
31 ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
32 const char *s, unsigned id,
36 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
37 GV(NULL), S(strdup(s)), LabelId(id), Kind(ARMCP::CPValue), PCAdjust(PCAdj),
38 Modifier(Modif), AddCurrentAddress(AddCA) {}
40 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, const char *Modif)
41 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
42 GV(gv), S(NULL), LabelId(0), Kind(ARMCP::CPValue), PCAdjust(0),
45 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
47 unsigned AlignMask = 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].getAlignment() & AlignMask) == 0) {
52 ARMConstantPoolValue *CPV =
53 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
56 CPV->LabelId == LabelId &&
57 CPV->PCAdjust == PCAdjust)
65 ARMConstantPoolValue::~ARMConstantPoolValue() {
70 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
73 ID.AddInteger(LabelId);
74 ID.AddInteger(PCAdjust);
77 void ARMConstantPoolValue::dump() const {
78 errs() << " " << *this;
82 void ARMConstantPoolValue::print(raw_ostream &O) const {
87 if (Modifier) O << "(" << Modifier << ")";
89 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
90 if (AddCurrentAddress) O << "-.";