blob: 71700893a3e8e6fa52a389147e7ec9fde4d29cda [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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"
17#include "llvm/Type.h"
Chris Lattner1fefaac2008-08-23 22:23:09 +000018#include "llvm/Support/raw_ostream.h"
Jim Grosbach3fe420b2009-08-11 15:26:27 +000019#include <cstdlib>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020using namespace llvm;
21
22ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
Jim Grosbach5e0257f2009-09-01 01:57:56 +000023 ARMCP::ARMCPKind K,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000024 unsigned char PCAdj,
25 const char *Modif,
26 bool AddCA)
27 : MachineConstantPoolValue((const Type*)gv->getType()),
Jim Grosbach5e0257f2009-09-01 01:57:56 +000028 GV(gv), S(NULL), LabelId(id), Kind(K), PCAdjust(PCAdj),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000029 Modifier(Modif), AddCurrentAddress(AddCA) {}
30
Owen Anderson35b47072009-08-13 21:58:54 +000031ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
32 const char *s, unsigned id,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033 unsigned char PCAdj,
34 const char *Modif,
35 bool AddCA)
Owen Anderson35b47072009-08-13 21:58:54 +000036 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
Jim Grosbach5e0257f2009-09-01 01:57:56 +000037 GV(NULL), S(strdup(s)), LabelId(id), Kind(ARMCP::CPValue), PCAdjust(PCAdj),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038 Modifier(Modif), AddCurrentAddress(AddCA) {}
39
Evan Chengc2999142009-08-28 23:18:09 +000040ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, const char *Modif)
Owen Anderson35b47072009-08-13 21:58:54 +000041 : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
Jim Grosbach4b673ee2009-09-01 02:05:03 +000042 GV(gv), S(NULL), LabelId(0), Kind(ARMCP::CPValue), PCAdjust(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000043 Modifier(Modif) {}
44
45int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
46 unsigned Alignment) {
Evan Cheng68c18682009-03-13 07:51:59 +000047 unsigned AlignMask = Alignment - 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000048 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
49 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
50 if (Constants[i].isMachineConstantPoolEntry() &&
Evan Cheng68c18682009-03-13 07:51:59 +000051 (Constants[i].getAlignment() & AlignMask) == 0) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 ARMConstantPoolValue *CPV =
53 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
54 if (CPV->GV == GV &&
55 CPV->S == S &&
56 CPV->LabelId == LabelId &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057 CPV->PCAdjust == PCAdjust)
58 return i;
59 }
60 }
61
62 return -1;
63}
64
Benjamin Kramer909610a2009-08-11 16:03:08 +000065ARMConstantPoolValue::~ARMConstantPoolValue() {
Jim Grosbach3fe420b2009-08-11 15:26:27 +000066 free((void*)S);
67}
68
Dan Gohmanf17a25c2007-07-18 16:29:46 +000069void
70ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
71 ID.AddPointer(GV);
72 ID.AddPointer(S);
73 ID.AddInteger(LabelId);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000074 ID.AddInteger(PCAdjust);
75}
76
Evan Chengf3aaeed2008-10-29 23:55:17 +000077void ARMConstantPoolValue::dump() const {
Chris Lattnerd71b0b02009-08-23 03:41:05 +000078 errs() << " " << *this;
Evan Chengf3aaeed2008-10-29 23:55:17 +000079}
80
Evan Chengf3aaeed2008-10-29 23:55:17 +000081
Chris Lattner1fefaac2008-08-23 22:23:09 +000082void ARMConstantPoolValue::print(raw_ostream &O) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000083 if (GV)
84 O << GV->getName();
85 else
86 O << S;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087 if (Modifier) O << "(" << Modifier << ")";
88 if (PCAdjust != 0) {
Evan Cheng5a033a62008-11-04 00:50:32 +000089 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
90 if (AddCurrentAddress) O << "-.";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000091 O << ")";
92 }
93}