1 //===-- SystemZConstantPoolValue.cpp - SystemZ constant-pool value --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "SystemZConstantPoolValue.h"
10 #include "llvm/ADT/FoldingSet.h"
11 #include "llvm/IR/GlobalValue.h"
12 #include "llvm/Support/raw_ostream.h"
13
14 using namespace llvm;
15
16 SystemZConstantPoolValue::
SystemZConstantPoolValue(const GlobalValue * gv,SystemZCP::SystemZCPModifier modifier)17 SystemZConstantPoolValue(const GlobalValue *gv,
18 SystemZCP::SystemZCPModifier modifier)
19 : MachineConstantPoolValue(gv->getType()), GV(gv), Modifier(modifier) {}
20
21 SystemZConstantPoolValue *
Create(const GlobalValue * GV,SystemZCP::SystemZCPModifier Modifier)22 SystemZConstantPoolValue::Create(const GlobalValue *GV,
23 SystemZCP::SystemZCPModifier Modifier) {
24 return new SystemZConstantPoolValue(GV, Modifier);
25 }
26
getExistingMachineCPValue(MachineConstantPool * CP,Align Alignment)27 int SystemZConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
28 Align Alignment) {
29 const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
30 for (unsigned I = 0, E = Constants.size(); I != E; ++I) {
31 if (Constants[I].isMachineConstantPoolEntry() &&
32 Constants[I].getAlign() >= Alignment) {
33 auto *ZCPV =
34 static_cast<SystemZConstantPoolValue *>(Constants[I].Val.MachineCPVal);
35 if (ZCPV->GV == GV && ZCPV->Modifier == Modifier)
36 return I;
37 }
38 }
39 return -1;
40 }
41
addSelectionDAGCSEId(FoldingSetNodeID & ID)42 void SystemZConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
43 ID.AddPointer(GV);
44 ID.AddInteger(Modifier);
45 }
46
print(raw_ostream & O) const47 void SystemZConstantPoolValue::print(raw_ostream &O) const {
48 O << GV << "@" << int(Modifier);
49 }
50