15f613dfdSUlrich Weigand //===-- SystemZConstantPoolValue.cpp - SystemZ constant-pool value --------===//
25f613dfdSUlrich Weigand //
3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65f613dfdSUlrich Weigand //
75f613dfdSUlrich Weigand //===----------------------------------------------------------------------===//
85f613dfdSUlrich Weigand 
95f613dfdSUlrich Weigand #include "SystemZConstantPoolValue.h"
105f613dfdSUlrich Weigand #include "llvm/ADT/FoldingSet.h"
115f613dfdSUlrich Weigand #include "llvm/IR/DerivedTypes.h"
125f613dfdSUlrich Weigand #include "llvm/IR/GlobalValue.h"
135f613dfdSUlrich Weigand #include "llvm/Support/raw_ostream.h"
145f613dfdSUlrich Weigand 
155f613dfdSUlrich Weigand using namespace llvm;
165f613dfdSUlrich Weigand 
175f613dfdSUlrich Weigand SystemZConstantPoolValue::
185f613dfdSUlrich Weigand SystemZConstantPoolValue(const GlobalValue *gv,
195f613dfdSUlrich Weigand                          SystemZCP::SystemZCPModifier modifier)
205f613dfdSUlrich Weigand   : MachineConstantPoolValue(gv->getType()), GV(gv), Modifier(modifier) {}
215f613dfdSUlrich Weigand 
225f613dfdSUlrich Weigand SystemZConstantPoolValue *
235f613dfdSUlrich Weigand SystemZConstantPoolValue::Create(const GlobalValue *GV,
245f613dfdSUlrich Weigand                                  SystemZCP::SystemZCPModifier Modifier) {
255f613dfdSUlrich Weigand   return new SystemZConstantPoolValue(GV, Modifier);
265f613dfdSUlrich Weigand }
275f613dfdSUlrich Weigand 
285f613dfdSUlrich Weigand int SystemZConstantPoolValue::
295f613dfdSUlrich Weigand getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) {
305f613dfdSUlrich Weigand   unsigned AlignMask = Alignment - 1;
317d605268SBenjamin Kramer   const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
325f613dfdSUlrich Weigand   for (unsigned I = 0, E = Constants.size(); I != E; ++I) {
335f613dfdSUlrich Weigand     if (Constants[I].isMachineConstantPoolEntry() &&
345f613dfdSUlrich Weigand         (Constants[I].getAlignment() & AlignMask) == 0) {
3521f5d68aSRichard Sandiford       auto *ZCPV =
365f613dfdSUlrich Weigand         static_cast<SystemZConstantPoolValue *>(Constants[I].Val.MachineCPVal);
375f613dfdSUlrich Weigand       if (ZCPV->GV == GV && ZCPV->Modifier == Modifier)
385f613dfdSUlrich Weigand         return I;
395f613dfdSUlrich Weigand     }
405f613dfdSUlrich Weigand   }
415f613dfdSUlrich Weigand   return -1;
425f613dfdSUlrich Weigand }
435f613dfdSUlrich Weigand 
445f613dfdSUlrich Weigand void SystemZConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
455f613dfdSUlrich Weigand   ID.AddPointer(GV);
465f613dfdSUlrich Weigand   ID.AddInteger(Modifier);
475f613dfdSUlrich Weigand }
485f613dfdSUlrich Weigand 
495f613dfdSUlrich Weigand void SystemZConstantPoolValue::print(raw_ostream &O) const {
505f613dfdSUlrich Weigand   O << GV << "@" << int(Modifier);
515f613dfdSUlrich Weigand }
52