1*5f613dfdSUlrich Weigand //===-- SystemZConstantPoolValue.cpp - SystemZ constant-pool value --------===// 2*5f613dfdSUlrich Weigand // 3*5f613dfdSUlrich Weigand // The LLVM Compiler Infrastructure 4*5f613dfdSUlrich Weigand // 5*5f613dfdSUlrich Weigand // This file is distributed under the University of Illinois Open Source 6*5f613dfdSUlrich Weigand // License. See LICENSE.TXT for details. 7*5f613dfdSUlrich Weigand // 8*5f613dfdSUlrich Weigand //===----------------------------------------------------------------------===// 9*5f613dfdSUlrich Weigand 10*5f613dfdSUlrich Weigand #include "SystemZConstantPoolValue.h" 11*5f613dfdSUlrich Weigand #include "llvm/ADT/FoldingSet.h" 12*5f613dfdSUlrich Weigand #include "llvm/IR/DerivedTypes.h" 13*5f613dfdSUlrich Weigand #include "llvm/IR/GlobalValue.h" 14*5f613dfdSUlrich Weigand #include "llvm/Support/raw_ostream.h" 15*5f613dfdSUlrich Weigand 16*5f613dfdSUlrich Weigand using namespace llvm; 17*5f613dfdSUlrich Weigand 18*5f613dfdSUlrich Weigand SystemZConstantPoolValue:: 19*5f613dfdSUlrich Weigand SystemZConstantPoolValue(const GlobalValue *gv, 20*5f613dfdSUlrich Weigand SystemZCP::SystemZCPModifier modifier) 21*5f613dfdSUlrich Weigand : MachineConstantPoolValue(gv->getType()), GV(gv), Modifier(modifier) {} 22*5f613dfdSUlrich Weigand 23*5f613dfdSUlrich Weigand SystemZConstantPoolValue * 24*5f613dfdSUlrich Weigand SystemZConstantPoolValue::Create(const GlobalValue *GV, 25*5f613dfdSUlrich Weigand SystemZCP::SystemZCPModifier Modifier) { 26*5f613dfdSUlrich Weigand return new SystemZConstantPoolValue(GV, Modifier); 27*5f613dfdSUlrich Weigand } 28*5f613dfdSUlrich Weigand 29*5f613dfdSUlrich Weigand unsigned SystemZConstantPoolValue::getRelocationInfo() const { 30*5f613dfdSUlrich Weigand switch (Modifier) { 31*5f613dfdSUlrich Weigand case SystemZCP::NTPOFF: 32*5f613dfdSUlrich Weigand // May require a relocation, but the relocations are always resolved 33*5f613dfdSUlrich Weigand // by the static linker. 34*5f613dfdSUlrich Weigand return 1; 35*5f613dfdSUlrich Weigand } 36*5f613dfdSUlrich Weigand llvm_unreachable("Unknown modifier"); 37*5f613dfdSUlrich Weigand } 38*5f613dfdSUlrich Weigand 39*5f613dfdSUlrich Weigand int SystemZConstantPoolValue:: 40*5f613dfdSUlrich Weigand getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) { 41*5f613dfdSUlrich Weigand unsigned AlignMask = Alignment - 1; 42*5f613dfdSUlrich Weigand const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants(); 43*5f613dfdSUlrich Weigand for (unsigned I = 0, E = Constants.size(); I != E; ++I) { 44*5f613dfdSUlrich Weigand if (Constants[I].isMachineConstantPoolEntry() && 45*5f613dfdSUlrich Weigand (Constants[I].getAlignment() & AlignMask) == 0) { 46*5f613dfdSUlrich Weigand SystemZConstantPoolValue *ZCPV = 47*5f613dfdSUlrich Weigand static_cast<SystemZConstantPoolValue *>(Constants[I].Val.MachineCPVal); 48*5f613dfdSUlrich Weigand if (ZCPV->GV == GV && ZCPV->Modifier == Modifier) 49*5f613dfdSUlrich Weigand return I; 50*5f613dfdSUlrich Weigand } 51*5f613dfdSUlrich Weigand } 52*5f613dfdSUlrich Weigand return -1; 53*5f613dfdSUlrich Weigand } 54*5f613dfdSUlrich Weigand 55*5f613dfdSUlrich Weigand void SystemZConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) { 56*5f613dfdSUlrich Weigand ID.AddPointer(GV); 57*5f613dfdSUlrich Weigand ID.AddInteger(Modifier); 58*5f613dfdSUlrich Weigand } 59*5f613dfdSUlrich Weigand 60*5f613dfdSUlrich Weigand void SystemZConstantPoolValue::print(raw_ostream &O) const { 61*5f613dfdSUlrich Weigand O << GV << "@" << int(Modifier); 62*5f613dfdSUlrich Weigand } 63