blob: 1fe66fb174bdd214a534621de493afa0f36a0c7b [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Evan Cheng and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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,
23 const char *Modif)
Evan Chenga8e29892007-01-19 07:51:42 +000024 : MachineConstantPoolValue((const Type*)gv->getType()),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000025 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
26 Modifier(Modif) {}
Evan Chengc60e76d2007-01-30 20:37:08 +000027
28ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
29 ARMCP::ARMCPKind k,
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000030 unsigned char PCAdj,
31 const char *Modif)
Evan Chengc60e76d2007-01-30 20:37:08 +000032 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000033 GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj),
34 Modifier(Modif) {}
35
36ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
37 ARMCP::ARMCPKind k,
38 const char *Modif)
39 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
40 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
41 Modifier(Modif) {}
Evan Chenga8e29892007-01-19 07:51:42 +000042
43int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
44 unsigned Alignment) {
45 unsigned AlignMask = (1 << Alignment)-1;
46 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
47 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
48 if (Constants[i].isMachineConstantPoolEntry() &&
49 (Constants[i].Offset & AlignMask) == 0) {
50 ARMConstantPoolValue *CPV =
51 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
Evan Chengc60e76d2007-01-30 20:37:08 +000052 if (CPV->GV == GV &&
53 CPV->S == S &&
54 CPV->LabelId == LabelId &&
55 CPV->Kind == Kind &&
56 CPV->PCAdjust == PCAdjust)
Evan Chenga8e29892007-01-19 07:51:42 +000057 return i;
58 }
59 }
60
61 return -1;
62}
63
64void
65ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
66 ID.AddPointer(GV);
Evan Chengc60e76d2007-01-30 20:37:08 +000067 ID.AddPointer(S);
Evan Chenga8e29892007-01-19 07:51:42 +000068 ID.AddInteger(LabelId);
Evan Chengc60e76d2007-01-30 20:37:08 +000069 ID.AddInteger((unsigned)Kind);
Evan Chenga8e29892007-01-19 07:51:42 +000070 ID.AddInteger(PCAdjust);
71}
72
73void ARMConstantPoolValue::print(std::ostream &O) const {
Evan Chengc60e76d2007-01-30 20:37:08 +000074 if (GV)
75 O << GV->getName();
76 else
77 O << S;
78 if (isNonLazyPointer()) O << "$non_lazy_ptr";
79 else if (isStub()) O << "$stub";
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000080 if (Modifier) O << "(" << Modifier << ")";
Evan Chenga8e29892007-01-19 07:51:42 +000081 if (PCAdjust != 0) O << "-(LPIC" << LabelId << "+"
82 << (unsigned)PCAdjust << ")";
83}