pass machinemoduleinfo down into getSymbolForDwarfGlobalReference,
[llvm/avr.git] / lib / Target / ARM / ARMConstantPoolValue.cpp
blob71700893a3e8e6fa52a389147e7ec9fde4d29cda
1 //===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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"
19 #include <cstdlib>
20 using namespace llvm;
22 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
23 ARMCP::ARMCPKind K,
24 unsigned char PCAdj,
25 const char *Modif,
26 bool AddCA)
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,
33 unsigned char PCAdj,
34 const char *Modif,
35 bool AddCA)
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),
43 Modifier(Modif) {}
45 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
46 unsigned Alignment) {
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;
54 if (CPV->GV == GV &&
55 CPV->S == S &&
56 CPV->LabelId == LabelId &&
57 CPV->PCAdjust == PCAdjust)
58 return i;
62 return -1;
65 ARMConstantPoolValue::~ARMConstantPoolValue() {
66 free((void*)S);
69 void
70 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
71 ID.AddPointer(GV);
72 ID.AddPointer(S);
73 ID.AddInteger(LabelId);
74 ID.AddInteger(PCAdjust);
77 void ARMConstantPoolValue::dump() const {
78 errs() << " " << *this;
82 void ARMConstantPoolValue::print(raw_ostream &O) const {
83 if (GV)
84 O << GV->getName();
85 else
86 O << S;
87 if (Modifier) O << "(" << Modifier << ")";
88 if (PCAdjust != 0) {
89 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
90 if (AddCurrentAddress) O << "-.";
91 O << ")";