1284c1978SDimitry Andric //===-- SystemZConstantPoolValue.cpp - SystemZ constant-pool value --------===//
2284c1978SDimitry Andric //
3284c1978SDimitry Andric //                     The LLVM Compiler Infrastructure
4284c1978SDimitry Andric //
5284c1978SDimitry Andric // This file is distributed under the University of Illinois Open Source
6284c1978SDimitry Andric // License. See LICENSE.TXT for details.
7284c1978SDimitry Andric //
8284c1978SDimitry Andric //===----------------------------------------------------------------------===//
9284c1978SDimitry Andric 
10284c1978SDimitry Andric #include "SystemZConstantPoolValue.h"
11284c1978SDimitry Andric #include "llvm/ADT/FoldingSet.h"
12284c1978SDimitry Andric #include "llvm/IR/DerivedTypes.h"
13284c1978SDimitry Andric #include "llvm/IR/GlobalValue.h"
14284c1978SDimitry Andric #include "llvm/Support/raw_ostream.h"
15284c1978SDimitry Andric 
16284c1978SDimitry Andric using namespace llvm;
17284c1978SDimitry Andric 
18284c1978SDimitry Andric SystemZConstantPoolValue::
SystemZConstantPoolValue(const GlobalValue * gv,SystemZCP::SystemZCPModifier modifier)19284c1978SDimitry Andric SystemZConstantPoolValue(const GlobalValue *gv,
20284c1978SDimitry Andric                          SystemZCP::SystemZCPModifier modifier)
21284c1978SDimitry Andric   : MachineConstantPoolValue(gv->getType()), GV(gv), Modifier(modifier) {}
22284c1978SDimitry Andric 
23284c1978SDimitry Andric SystemZConstantPoolValue *
Create(const GlobalValue * GV,SystemZCP::SystemZCPModifier Modifier)24284c1978SDimitry Andric SystemZConstantPoolValue::Create(const GlobalValue *GV,
25284c1978SDimitry Andric                                  SystemZCP::SystemZCPModifier Modifier) {
26284c1978SDimitry Andric   return new SystemZConstantPoolValue(GV, Modifier);
27284c1978SDimitry Andric }
28284c1978SDimitry Andric 
29284c1978SDimitry Andric int SystemZConstantPoolValue::
getExistingMachineCPValue(MachineConstantPool * CP,unsigned Alignment)30284c1978SDimitry Andric getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) {
31284c1978SDimitry Andric   unsigned AlignMask = Alignment - 1;
32f785676fSDimitry Andric   const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
33284c1978SDimitry Andric   for (unsigned I = 0, E = Constants.size(); I != E; ++I) {
34284c1978SDimitry Andric     if (Constants[I].isMachineConstantPoolEntry() &&
35284c1978SDimitry Andric         (Constants[I].getAlignment() & AlignMask) == 0) {
36*91bc56edSDimitry Andric       auto *ZCPV =
37284c1978SDimitry Andric         static_cast<SystemZConstantPoolValue *>(Constants[I].Val.MachineCPVal);
38284c1978SDimitry Andric       if (ZCPV->GV == GV && ZCPV->Modifier == Modifier)
39284c1978SDimitry Andric         return I;
40284c1978SDimitry Andric     }
41284c1978SDimitry Andric   }
42284c1978SDimitry Andric   return -1;
43284c1978SDimitry Andric }
44284c1978SDimitry Andric 
addSelectionDAGCSEId(FoldingSetNodeID & ID)45284c1978SDimitry Andric void SystemZConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
46284c1978SDimitry Andric   ID.AddPointer(GV);
47284c1978SDimitry Andric   ID.AddInteger(Modifier);
48284c1978SDimitry Andric }
49284c1978SDimitry Andric 
print(raw_ostream & O) const50284c1978SDimitry Andric void SystemZConstantPoolValue::print(raw_ostream &O) const {
51284c1978SDimitry Andric   O << GV << "@" << int(Modifier);
52284c1978SDimitry Andric }
53