15f613dfdSUlrich Weigand //===-- SystemZConstantPoolValue.cpp - SystemZ constant-pool value --------===//
25f613dfdSUlrich Weigand //
35f613dfdSUlrich Weigand //                     The LLVM Compiler Infrastructure
45f613dfdSUlrich Weigand //
55f613dfdSUlrich Weigand // This file is distributed under the University of Illinois Open Source
65f613dfdSUlrich Weigand // License. See LICENSE.TXT for details.
75f613dfdSUlrich Weigand //
85f613dfdSUlrich Weigand //===----------------------------------------------------------------------===//
95f613dfdSUlrich Weigand 
105f613dfdSUlrich Weigand #include "SystemZConstantPoolValue.h"
115f613dfdSUlrich Weigand #include "llvm/ADT/FoldingSet.h"
125f613dfdSUlrich Weigand #include "llvm/IR/DerivedTypes.h"
135f613dfdSUlrich Weigand #include "llvm/IR/GlobalValue.h"
145f613dfdSUlrich Weigand #include "llvm/Support/raw_ostream.h"
155f613dfdSUlrich Weigand 
165f613dfdSUlrich Weigand using namespace llvm;
175f613dfdSUlrich Weigand 
185f613dfdSUlrich Weigand SystemZConstantPoolValue::
195f613dfdSUlrich Weigand SystemZConstantPoolValue(const GlobalValue *gv,
205f613dfdSUlrich Weigand                          SystemZCP::SystemZCPModifier modifier)
215f613dfdSUlrich Weigand   : MachineConstantPoolValue(gv->getType()), GV(gv), Modifier(modifier) {}
225f613dfdSUlrich Weigand 
235f613dfdSUlrich Weigand SystemZConstantPoolValue *
245f613dfdSUlrich Weigand SystemZConstantPoolValue::Create(const GlobalValue *GV,
255f613dfdSUlrich Weigand                                  SystemZCP::SystemZCPModifier Modifier) {
265f613dfdSUlrich Weigand   return new SystemZConstantPoolValue(GV, Modifier);
275f613dfdSUlrich Weigand }
285f613dfdSUlrich Weigand 
295f613dfdSUlrich Weigand unsigned SystemZConstantPoolValue::getRelocationInfo() const {
305f613dfdSUlrich Weigand   switch (Modifier) {
315f613dfdSUlrich Weigand   case SystemZCP::NTPOFF:
325f613dfdSUlrich Weigand     // May require a relocation, but the relocations are always resolved
335f613dfdSUlrich Weigand     // by the static linker.
345f613dfdSUlrich Weigand     return 1;
355f613dfdSUlrich Weigand   }
365f613dfdSUlrich Weigand   llvm_unreachable("Unknown modifier");
375f613dfdSUlrich Weigand }
385f613dfdSUlrich Weigand 
395f613dfdSUlrich Weigand int SystemZConstantPoolValue::
405f613dfdSUlrich Weigand getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) {
415f613dfdSUlrich Weigand   unsigned AlignMask = Alignment - 1;
42*7d605268SBenjamin Kramer   const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
435f613dfdSUlrich Weigand   for (unsigned I = 0, E = Constants.size(); I != E; ++I) {
445f613dfdSUlrich Weigand     if (Constants[I].isMachineConstantPoolEntry() &&
455f613dfdSUlrich Weigand         (Constants[I].getAlignment() & AlignMask) == 0) {
465f613dfdSUlrich Weigand       SystemZConstantPoolValue *ZCPV =
475f613dfdSUlrich Weigand         static_cast<SystemZConstantPoolValue *>(Constants[I].Val.MachineCPVal);
485f613dfdSUlrich Weigand       if (ZCPV->GV == GV && ZCPV->Modifier == Modifier)
495f613dfdSUlrich Weigand         return I;
505f613dfdSUlrich Weigand     }
515f613dfdSUlrich Weigand   }
525f613dfdSUlrich Weigand   return -1;
535f613dfdSUlrich Weigand }
545f613dfdSUlrich Weigand 
555f613dfdSUlrich Weigand void SystemZConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
565f613dfdSUlrich Weigand   ID.AddPointer(GV);
575f613dfdSUlrich Weigand   ID.AddInteger(Modifier);
585f613dfdSUlrich Weigand }
595f613dfdSUlrich Weigand 
605f613dfdSUlrich Weigand void SystemZConstantPoolValue::print(raw_ostream &O) const {
615f613dfdSUlrich Weigand   O << GV << "@" << int(Modifier);
625f613dfdSUlrich Weigand }
63