1 //===-- SystemZConstantPoolValue.cpp - SystemZ constant-pool value --------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "SystemZConstantPoolValue.h"
11 #include "llvm/ADT/FoldingSet.h"
12 #include "llvm/IR/DerivedTypes.h"
13 #include "llvm/IR/GlobalValue.h"
14 #include "llvm/Support/raw_ostream.h"
15
16 using namespace llvm;
17
18 SystemZConstantPoolValue::
SystemZConstantPoolValue(const GlobalValue * gv,SystemZCP::SystemZCPModifier modifier)19 SystemZConstantPoolValue(const GlobalValue *gv,
20 SystemZCP::SystemZCPModifier modifier)
21 : MachineConstantPoolValue(gv->getType()), GV(gv), Modifier(modifier) {}
22
23 SystemZConstantPoolValue *
Create(const GlobalValue * GV,SystemZCP::SystemZCPModifier Modifier)24 SystemZConstantPoolValue::Create(const GlobalValue *GV,
25 SystemZCP::SystemZCPModifier Modifier) {
26 return new SystemZConstantPoolValue(GV, Modifier);
27 }
28
getRelocationInfo() const29 unsigned SystemZConstantPoolValue::getRelocationInfo() const {
30 switch (Modifier) {
31 case SystemZCP::NTPOFF:
32 // May require a relocation, but the relocations are always resolved
33 // by the static linker.
34 return 1;
35 }
36 llvm_unreachable("Unknown modifier");
37 }
38
39 int SystemZConstantPoolValue::
getExistingMachineCPValue(MachineConstantPool * CP,unsigned Alignment)40 getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) {
41 unsigned AlignMask = Alignment - 1;
42 const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
43 for (unsigned I = 0, E = Constants.size(); I != E; ++I) {
44 if (Constants[I].isMachineConstantPoolEntry() &&
45 (Constants[I].getAlignment() & AlignMask) == 0) {
46 auto *ZCPV =
47 static_cast<SystemZConstantPoolValue *>(Constants[I].Val.MachineCPVal);
48 if (ZCPV->GV == GV && ZCPV->Modifier == Modifier)
49 return I;
50 }
51 }
52 return -1;
53 }
54
addSelectionDAGCSEId(FoldingSetNodeID & ID)55 void SystemZConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
56 ID.AddPointer(GV);
57 ID.AddInteger(Modifier);
58 }
59
print(raw_ostream & O) const60 void SystemZConstantPoolValue::print(raw_ostream &O) const {
61 O << GV << "@" << int(Modifier);
62 }
63