blob: 04db1644f8c8c65da292379cbecbee907d5cf100 [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"
Chris Lattner944fac72008-08-23 22:23:09 +000018#include "llvm/Support/raw_ostream.h"
Evan Chenga8e29892007-01-19 07:51:42 +000019using namespace llvm;
20
21ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
Evan Chengc60e76d2007-01-30 20:37:08 +000022 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000023 unsigned char PCAdj,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000024 const char *Modif,
25 bool AddCA)
Evan Chenga8e29892007-01-19 07:51:42 +000026 : MachineConstantPoolValue((const Type*)gv->getType()),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000027 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000028 Modifier(Modif), AddCurrentAddress(AddCA) {}
Evan Chengc60e76d2007-01-30 20:37:08 +000029
30ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
31 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000032 unsigned char PCAdj,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000033 const char *Modif,
34 bool AddCA)
Evan Chengc60e76d2007-01-30 20:37:08 +000035 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000036 GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000037 Modifier(Modif), AddCurrentAddress(AddCA) {}
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000038
39ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
40 ARMCP::ARMCPKind k,
41 const char *Modif)
42 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
43 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
44 Modifier(Modif) {}
Evan Chenga8e29892007-01-19 07:51:42 +000045
46int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
47 unsigned Alignment) {
48 unsigned AlignMask = (1 << Alignment)-1;
49 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
50 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
51 if (Constants[i].isMachineConstantPoolEntry() &&
52 (Constants[i].Offset & AlignMask) == 0) {
53 ARMConstantPoolValue *CPV =
54 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
Evan Chengc60e76d2007-01-30 20:37:08 +000055 if (CPV->GV == GV &&
56 CPV->S == S &&
57 CPV->LabelId == LabelId &&
58 CPV->Kind == Kind &&
59 CPV->PCAdjust == PCAdjust)
Evan Chenga8e29892007-01-19 07:51:42 +000060 return i;
61 }
62 }
63
64 return -1;
65}
66
67void
68ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
69 ID.AddPointer(GV);
Evan Chengc60e76d2007-01-30 20:37:08 +000070 ID.AddPointer(S);
Evan Chenga8e29892007-01-19 07:51:42 +000071 ID.AddInteger(LabelId);
Evan Chengc60e76d2007-01-30 20:37:08 +000072 ID.AddInteger((unsigned)Kind);
Evan Chenga8e29892007-01-19 07:51:42 +000073 ID.AddInteger(PCAdjust);
74}
75
Chris Lattner944fac72008-08-23 22:23:09 +000076void ARMConstantPoolValue::print(raw_ostream &O) const {
Evan Chengc60e76d2007-01-30 20:37:08 +000077 if (GV)
78 O << GV->getName();
79 else
80 O << S;
81 if (isNonLazyPointer()) O << "$non_lazy_ptr";
82 else if (isStub()) O << "$stub";
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000083 if (Modifier) O << "(" << Modifier << ")";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000084 if (PCAdjust != 0) {
85 O << "-(LPIC" << LabelId << "+"
86 << (unsigned)PCAdjust;
87 if (AddCurrentAddress)
88 O << "-.";
89 O << ")";
90 }
Evan Chenga8e29892007-01-19 07:51:42 +000091}