blob: 97cca07d33f0cfeb377bfc40fb2a5db84b932064 [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"
17using namespace llvm;
18
19ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
20 bool isNonLazy, unsigned char PCAdj)
21 : MachineConstantPoolValue((const Type*)gv->getType()),
22 GV(gv), LabelId(id), isNonLazyPtr(isNonLazy), PCAdjust(PCAdj) {}
23
24int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
25 unsigned Alignment) {
26 unsigned AlignMask = (1 << Alignment)-1;
27 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
28 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
29 if (Constants[i].isMachineConstantPoolEntry() &&
30 (Constants[i].Offset & AlignMask) == 0) {
31 ARMConstantPoolValue *CPV =
32 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
33 if (CPV->GV == GV && CPV->LabelId == LabelId &&
34 CPV->isNonLazyPtr == isNonLazyPtr)
35 return i;
36 }
37 }
38
39 return -1;
40}
41
42void
43ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
44 ID.AddPointer(GV);
45 ID.AddInteger(LabelId);
46 ID.AddInteger((unsigned)isNonLazyPtr);
47 ID.AddInteger(PCAdjust);
48}
49
50void ARMConstantPoolValue::print(std::ostream &O) const {
51 O << GV->getName();
52 if (isNonLazyPtr) O << "$non_lazy_ptr";
53 if (PCAdjust != 0) O << "-(LPIC" << LabelId << "+"
54 << (unsigned)PCAdjust << ")";
55}