blob: a219c352ba5714a7bbc703509d4dee33ccc579f1 [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,
22 unsigned char PCAdj)
Evan Chenga8e29892007-01-19 07:51:42 +000023 : MachineConstantPoolValue((const Type*)gv->getType()),
Evan Chengc60e76d2007-01-30 20:37:08 +000024 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj) {}
25
26ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id,
27 ARMCP::ARMCPKind k,
28 unsigned char PCAdj)
29 : MachineConstantPoolValue((const Type*)Type::Int32Ty),
30 GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj) {}
Evan Chenga8e29892007-01-19 07:51:42 +000031
32int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
33 unsigned Alignment) {
34 unsigned AlignMask = (1 << Alignment)-1;
35 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
36 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
37 if (Constants[i].isMachineConstantPoolEntry() &&
38 (Constants[i].Offset & AlignMask) == 0) {
39 ARMConstantPoolValue *CPV =
40 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
Evan Chengc60e76d2007-01-30 20:37:08 +000041 if (CPV->GV == GV &&
42 CPV->S == S &&
43 CPV->LabelId == LabelId &&
44 CPV->Kind == Kind &&
45 CPV->PCAdjust == PCAdjust)
Evan Chenga8e29892007-01-19 07:51:42 +000046 return i;
47 }
48 }
49
50 return -1;
51}
52
53void
54ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
55 ID.AddPointer(GV);
Evan Chengc60e76d2007-01-30 20:37:08 +000056 ID.AddPointer(S);
Evan Chenga8e29892007-01-19 07:51:42 +000057 ID.AddInteger(LabelId);
Evan Chengc60e76d2007-01-30 20:37:08 +000058 ID.AddInteger((unsigned)Kind);
Evan Chenga8e29892007-01-19 07:51:42 +000059 ID.AddInteger(PCAdjust);
60}
61
62void ARMConstantPoolValue::print(std::ostream &O) const {
Evan Chengc60e76d2007-01-30 20:37:08 +000063 if (GV)
64 O << GV->getName();
65 else
66 O << S;
67 if (isNonLazyPointer()) O << "$non_lazy_ptr";
68 else if (isStub()) O << "$stub";
Evan Chenga8e29892007-01-19 07:51:42 +000069 if (PCAdjust != 0) O << "-(LPIC" << LabelId << "+"
70 << (unsigned)PCAdjust << ")";
71}