blob: 6c8c39f6fafdf184dbf83643b4e0406281b60c64 [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"
Jim Grosbachf1287872009-08-11 15:26:27 +000019#include <cstdlib>
Evan Chenga8e29892007-01-19 07:51:42 +000020using namespace llvm;
21
22ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
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()),
Evan Chenge4e4ed32009-08-28 23:18:09 +000027 GV(gv), S(NULL), LabelId(id), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000028 Modifier(Modif), AddCurrentAddress(AddCA) {}
Evan Chengc60e76d2007-01-30 20:37:08 +000029
Owen Anderson1d0be152009-08-13 21:58:54 +000030ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
31 const char *s, unsigned id,
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)
Owen Anderson1d0be152009-08-13 21:58:54 +000035 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
Evan Chenge4e4ed32009-08-28 23:18:09 +000036 GV(NULL), S(strdup(s)), LabelId(id), PCAdjust(PCAdj),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000037 Modifier(Modif), AddCurrentAddress(AddCA) {}
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000038
Evan Chenge4e4ed32009-08-28 23:18:09 +000039ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, const char *Modif)
Owen Anderson1d0be152009-08-13 21:58:54 +000040 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
Evan Chenge4e4ed32009-08-28 23:18:09 +000041 GV(gv), S(NULL), LabelId(0), PCAdjust(0),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000042 Modifier(Modif) {}
Evan Chenga8e29892007-01-19 07:51:42 +000043
44int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
45 unsigned Alignment) {
Evan Cheng1606e8e2009-03-13 07:51:59 +000046 unsigned AlignMask = Alignment - 1;
Evan Chenga8e29892007-01-19 07:51:42 +000047 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
48 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
49 if (Constants[i].isMachineConstantPoolEntry() &&
Evan Cheng1606e8e2009-03-13 07:51:59 +000050 (Constants[i].getAlignment() & AlignMask) == 0) {
Evan Chenga8e29892007-01-19 07:51:42 +000051 ARMConstantPoolValue *CPV =
52 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
Evan Chengc60e76d2007-01-30 20:37:08 +000053 if (CPV->GV == GV &&
54 CPV->S == S &&
55 CPV->LabelId == LabelId &&
Evan Chengc60e76d2007-01-30 20:37:08 +000056 CPV->PCAdjust == PCAdjust)
Evan Chenga8e29892007-01-19 07:51:42 +000057 return i;
58 }
59 }
60
61 return -1;
62}
63
Benjamin Kramer327365e2009-08-11 16:03:08 +000064ARMConstantPoolValue::~ARMConstantPoolValue() {
Jim Grosbachf1287872009-08-11 15:26:27 +000065 free((void*)S);
66}
67
Evan Chenga8e29892007-01-19 07:51:42 +000068void
69ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
70 ID.AddPointer(GV);
Evan Chengc60e76d2007-01-30 20:37:08 +000071 ID.AddPointer(S);
Evan Chenga8e29892007-01-19 07:51:42 +000072 ID.AddInteger(LabelId);
Evan Chenga8e29892007-01-19 07:51:42 +000073 ID.AddInteger(PCAdjust);
74}
75
Evan Cheng5be59ea2008-10-29 23:55:17 +000076void ARMConstantPoolValue::dump() const {
Chris Lattner705e07f2009-08-23 03:41:05 +000077 errs() << " " << *this;
Evan Cheng5be59ea2008-10-29 23:55:17 +000078}
79
Evan Cheng5be59ea2008-10-29 23:55:17 +000080
Chris Lattner944fac72008-08-23 22:23:09 +000081void ARMConstantPoolValue::print(raw_ostream &O) const {
Evan Chengc60e76d2007-01-30 20:37:08 +000082 if (GV)
83 O << GV->getName();
84 else
85 O << S;
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000086 if (Modifier) O << "(" << Modifier << ")";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000087 if (PCAdjust != 0) {
Evan Cheng25e04782008-11-04 00:50:32 +000088 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
89 if (AddCurrentAddress) O << "-.";
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000090 O << ")";
91 }
Evan Chenga8e29892007-01-19 07:51:42 +000092}