blob: 6add3c38d377b017e5ae48fc4950b491d5ad25ea [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
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"
Evan Chengc60e76d2007-01-30 20:37:08 +000017#include "llvm/Type.h"
Evan Chenga8e29892007-01-19 07:51:42 +000018using namespace llvm;
19
20ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
Evan Chengc60e76d2007-01-30 20:37:08 +000021 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000022 unsigned char PCAdj,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000023 const char *Modif,
24 bool AddCA)
Evan Chenga8e29892007-01-19 07:51:42 +000025 : MachineConstantPoolValue((const Type*)gv->getType()),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000026 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000027 Modifier(Modif), AddCurrentAddress(AddCA) {}
Evan Chengc60e76d2007-01-30 20:37:08 +000028
29ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
30 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000031 unsigned char PCAdj,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000032 const char *Modif,
33 bool AddCA)
Evan Chengc60e76d2007-01-30 20:37:08 +000034 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000035 GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000036 Modifier(Modif), AddCurrentAddress(AddCA) {}
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000037
38ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
39 ARMCP::ARMCPKind k,
40 const char *Modif)
41 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
42 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
43 Modifier(Modif) {}
Evan Chenga8e29892007-01-19 07:51:42 +000044
45int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
46 unsigned Alignment) {
47 unsigned AlignMask = (1 << 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].Offset & AlignMask) == 0) {
52 ARMConstantPoolValue *CPV =
53 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
Evan Chengc60e76d2007-01-30 20:37:08 +000054 if (CPV->GV == GV &&
55 CPV->S == S &&
56 CPV->LabelId == LabelId &&
57 CPV->Kind == Kind &&
58 CPV->PCAdjust == PCAdjust)
Evan Chenga8e29892007-01-19 07:51:42 +000059 return i;
60 }
61 }
62
63 return -1;
64}
65
66void
67ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
68 ID.AddPointer(GV);
Evan Chengc60e76d2007-01-30 20:37:08 +000069 ID.AddPointer(S);
Evan Chenga8e29892007-01-19 07:51:42 +000070 ID.AddInteger(LabelId);
Evan Chengc60e76d2007-01-30 20:37:08 +000071 ID.AddInteger((unsigned)Kind);
Evan Chenga8e29892007-01-19 07:51:42 +000072 ID.AddInteger(PCAdjust);
73}
74
75void ARMConstantPoolValue::print(std::ostream &O) const {
Evan Chengc60e76d2007-01-30 20:37:08 +000076 if (GV)
77 O << GV->getName();
78 else
79 O << S;
80 if (isNonLazyPointer()) O << "$non_lazy_ptr";
81 else if (isStub()) O << "$stub";
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000082 if (Modifier) O << "(" << Modifier << ")";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000083 if (PCAdjust != 0) {
84 O << "-(LPIC" << LabelId << "+"
85 << (unsigned)PCAdjust;
86 if (AddCurrentAddress)
87 O << "-.";
88 O << ")";
89 }
Evan Chenga8e29892007-01-19 07:51:42 +000090}