remove various std::ostream version of printing methods from
[oota-llvm.git] / lib / Target / ARM / ARMConstantPoolValue.cpp
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.
11 //
12 //===----------------------------------------------------------------------===//
13
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;
21
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) {}
30
31 ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
32                                            const char *s, unsigned id,
33                                            ARMCP::ARMCPKind k,
34                                            unsigned char PCAdj,
35                                            const char *Modif,
36                                            bool AddCA)
37   : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
38     GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
39     Modifier(Modif), AddCurrentAddress(AddCA) {}
40
41 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
42                                            ARMCP::ARMCPKind k,
43                                            const char *Modif)
44   : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
45     GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
46     Modifier(Modif) {}
47
48 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
49                                                     unsigned Alignment) {
50   unsigned AlignMask = Alignment - 1;
51   const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
52   for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
53     if (Constants[i].isMachineConstantPoolEntry() &&
54         (Constants[i].getAlignment() & AlignMask) == 0) {
55       ARMConstantPoolValue *CPV =
56         (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
57       if (CPV->GV == GV &&
58           CPV->S == S &&
59           CPV->LabelId == LabelId &&
60           CPV->Kind == Kind &&
61           CPV->PCAdjust == PCAdjust)
62         return i;
63     }
64   }
65
66   return -1;
67 }
68
69 ARMConstantPoolValue::~ARMConstantPoolValue() {
70   free((void*)S);
71 }
72
73 void
74 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
75   ID.AddPointer(GV);
76   ID.AddPointer(S);
77   ID.AddInteger(LabelId);
78   ID.AddInteger((unsigned)Kind);
79   ID.AddInteger(PCAdjust);
80 }
81
82 void ARMConstantPoolValue::dump() const {
83   errs() << "  " << *this;
84 }
85
86
87 void ARMConstantPoolValue::print(raw_ostream &O) const {
88   if (GV)
89     O << GV->getName();
90   else
91     O << S;
92   if (isNonLazyPointer()) O << "$non_lazy_ptr";
93   else if (isStub()) O << "$stub";
94   if (Modifier) O << "(" << Modifier << ")";
95   if (PCAdjust != 0) {
96     O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
97     if (AddCurrentAddress) O << "-.";
98     O << ")";
99   }
100 }