Fix part 1 of pr4682. PICADD is a 16-bit instruction even in thumb2 mode.
[llvm/avr.git] / lib / Target / ARM / ARMConstantPoolValue.cpp
bloba75ed3bd53396f1fc26a19080609c000a5e6801c
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/Streams.h"
19 #include "llvm/Support/raw_ostream.h"
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(const char *s, unsigned id,
32 ARMCP::ARMCPKind k,
33 unsigned char PCAdj,
34 const char *Modif,
35 bool AddCA)
36 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
37 GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj),
38 Modifier(Modif), AddCurrentAddress(AddCA) {}
40 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
41 ARMCP::ARMCPKind k,
42 const char *Modif)
43 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
44 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
45 Modifier(Modif) {}
47 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
48 unsigned Alignment) {
49 unsigned AlignMask = Alignment - 1;
50 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
51 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
52 if (Constants[i].isMachineConstantPoolEntry() &&
53 (Constants[i].getAlignment() & AlignMask) == 0) {
54 ARMConstantPoolValue *CPV =
55 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
56 if (CPV->GV == GV &&
57 CPV->S == S &&
58 CPV->LabelId == LabelId &&
59 CPV->Kind == Kind &&
60 CPV->PCAdjust == PCAdjust)
61 return i;
65 return -1;
68 void
69 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
70 ID.AddPointer(GV);
71 ID.AddPointer(S);
72 ID.AddInteger(LabelId);
73 ID.AddInteger((unsigned)Kind);
74 ID.AddInteger(PCAdjust);
77 void ARMConstantPoolValue::dump() const {
78 cerr << " " << *this;
81 void ARMConstantPoolValue::print(std::ostream &O) const {
82 raw_os_ostream RawOS(O);
83 print(RawOS);
86 void ARMConstantPoolValue::print(raw_ostream &O) const {
87 if (GV)
88 O << GV->getName();
89 else
90 O << S;
91 if (isNonLazyPointer()) O << "$non_lazy_ptr";
92 else if (isStub()) O << "$stub";
93 if (Modifier) O << "(" << Modifier << ")";
94 if (PCAdjust != 0) {
95 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
96 if (AddCurrentAddress) O << "-.";
97 O << ")";