xref: /freebsd/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZConstantPoolValue.cpp (revision e25152834cdf3b353892835a4f3b157e066a8ed4)
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/DerivedTypes.h"
12 #include "llvm/IR/GlobalValue.h"
13 #include "llvm/Support/raw_ostream.h"
14 
15 using namespace llvm;
16 
17 SystemZConstantPoolValue::
SystemZConstantPoolValue(const GlobalValue * gv,SystemZCP::SystemZCPModifier modifier)18 SystemZConstantPoolValue(const GlobalValue *gv,
19                          SystemZCP::SystemZCPModifier modifier)
20   : MachineConstantPoolValue(gv->getType()), GV(gv), Modifier(modifier) {}
21 
22 SystemZConstantPoolValue *
Create(const GlobalValue * GV,SystemZCP::SystemZCPModifier Modifier)23 SystemZConstantPoolValue::Create(const GlobalValue *GV,
24                                  SystemZCP::SystemZCPModifier Modifier) {
25   return new SystemZConstantPoolValue(GV, Modifier);
26 }
27 
getExistingMachineCPValue(MachineConstantPool * CP,Align Alignment)28 int SystemZConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
29                                                         Align Alignment) {
30   const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
31   for (unsigned I = 0, E = Constants.size(); I != E; ++I) {
32     if (Constants[I].isMachineConstantPoolEntry() &&
33         Constants[I].getAlign() >= Alignment) {
34       auto *ZCPV =
35         static_cast<SystemZConstantPoolValue *>(Constants[I].Val.MachineCPVal);
36       if (ZCPV->GV == GV && ZCPV->Modifier == Modifier)
37         return I;
38     }
39   }
40   return -1;
41 }
42 
addSelectionDAGCSEId(FoldingSetNodeID & ID)43 void SystemZConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
44   ID.AddPointer(GV);
45   ID.AddInteger(Modifier);
46 }
47 
print(raw_ostream & O) const48 void SystemZConstantPoolValue::print(raw_ostream &O) const {
49   O << GV << "@" << int(Modifier);
50 }
51