blob: 9697422c6dc2ec0a061d4e77f42a9be6672b55f4 [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 Cheng5be59ea2008-10-29 23:55:17 +000018#include "llvm/Support/Streams.h"
Chris Lattner944fac72008-08-23 22:23:09 +000019#include "llvm/Support/raw_ostream.h"
Jim Grosbachf1287872009-08-11 15:26:27 +000020#include <cstdlib>
Evan Chenga8e29892007-01-19 07:51:42 +000021using namespace llvm;
22
23ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
Evan Chengc60e76d2007-01-30 20:37:08 +000024 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000025 unsigned char PCAdj,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000026 const char *Modif,
27 bool AddCA)
Evan Chenga8e29892007-01-19 07:51:42 +000028 : MachineConstantPoolValue((const Type*)gv->getType()),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000029 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000030 Modifier(Modif), AddCurrentAddress(AddCA) {}
Evan Chengc60e76d2007-01-30 20:37:08 +000031
Owen Anderson1d0be152009-08-13 21:58:54 +000032ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
33 const char *s, unsigned id,
Evan Chengc60e76d2007-01-30 20:37:08 +000034 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000035 unsigned char PCAdj,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000036 const char *Modif,
37 bool AddCA)
Owen Anderson1d0be152009-08-13 21:58:54 +000038 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
Jim Grosbach1b747ad2009-08-11 00:09:57 +000039 GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000040 Modifier(Modif), AddCurrentAddress(AddCA) {}
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000041
42ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
43 ARMCP::ARMCPKind k,
44 const char *Modif)
Owen Anderson1d0be152009-08-13 21:58:54 +000045 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000046 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
47 Modifier(Modif) {}
Evan Chenga8e29892007-01-19 07:51:42 +000048
49int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
50 unsigned Alignment) {
Evan Cheng1606e8e2009-03-13 07:51:59 +000051 unsigned AlignMask = Alignment - 1;
Evan Chenga8e29892007-01-19 07:51:42 +000052 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
53 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
54 if (Constants[i].isMachineConstantPoolEntry() &&
Evan Cheng1606e8e2009-03-13 07:51:59 +000055 (Constants[i].getAlignment() & AlignMask) == 0) {
Evan Chenga8e29892007-01-19 07:51:42 +000056 ARMConstantPoolValue *CPV =
57 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
Evan Chengc60e76d2007-01-30 20:37:08 +000058 if (CPV->GV == GV &&
59 CPV->S == S &&
60 CPV->LabelId == LabelId &&
61 CPV->Kind == Kind &&
62 CPV->PCAdjust == PCAdjust)
Evan Chenga8e29892007-01-19 07:51:42 +000063 return i;
64 }
65 }
66
67 return -1;
68}
69
Benjamin Kramer327365e2009-08-11 16:03:08 +000070ARMConstantPoolValue::~ARMConstantPoolValue() {
Jim Grosbachf1287872009-08-11 15:26:27 +000071 free((void*)S);
72}
73
Evan Chenga8e29892007-01-19 07:51:42 +000074void
75ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
76 ID.AddPointer(GV);
Evan Chengc60e76d2007-01-30 20:37:08 +000077 ID.AddPointer(S);
Evan Chenga8e29892007-01-19 07:51:42 +000078 ID.AddInteger(LabelId);
Evan Chengc60e76d2007-01-30 20:37:08 +000079 ID.AddInteger((unsigned)Kind);
Evan Chenga8e29892007-01-19 07:51:42 +000080 ID.AddInteger(PCAdjust);
81}
82
Evan Cheng5be59ea2008-10-29 23:55:17 +000083void ARMConstantPoolValue::dump() const {
84 cerr << " " << *this;
85}
86
87void ARMConstantPoolValue::print(std::ostream &O) const {
88 raw_os_ostream RawOS(O);
89 print(RawOS);
90}
91
Chris Lattner944fac72008-08-23 22:23:09 +000092void ARMConstantPoolValue::print(raw_ostream &O) const {
Evan Chengc60e76d2007-01-30 20:37:08 +000093 if (GV)
94 O << GV->getName();
95 else
96 O << S;
97 if (isNonLazyPointer()) O << "$non_lazy_ptr";
98 else if (isStub()) O << "$stub";
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000099 if (Modifier) O << "(" << Modifier << ")";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000100 if (PCAdjust != 0) {
Evan Cheng25e04782008-11-04 00:50:32 +0000101 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
102 if (AddCurrentAddress) O << "-.";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000103 O << ")";
104 }
Evan Chenga8e29892007-01-19 07:51:42 +0000105}