Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1 | //===-- SystemZConstantPoolValue.cpp - SystemZ constant-pool value --------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "SystemZConstantPoolValue.h" |
| 11 | #include "llvm/ADT/FoldingSet.h" |
| 12 | #include "llvm/IR/DerivedTypes.h" |
| 13 | #include "llvm/IR/GlobalValue.h" |
| 14 | #include "llvm/Support/raw_ostream.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | SystemZConstantPoolValue:: |
| 19 | SystemZConstantPoolValue(const GlobalValue *gv, |
| 20 | SystemZCP::SystemZCPModifier modifier) |
| 21 | : MachineConstantPoolValue(gv->getType()), GV(gv), Modifier(modifier) {} |
| 22 | |
| 23 | SystemZConstantPoolValue * |
| 24 | SystemZConstantPoolValue::Create(const GlobalValue *GV, |
| 25 | SystemZCP::SystemZCPModifier Modifier) { |
| 26 | return new SystemZConstantPoolValue(GV, Modifier); |
| 27 | } |
| 28 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 29 | int SystemZConstantPoolValue:: |
| 30 | getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) { |
| 31 | unsigned AlignMask = Alignment - 1; |
Benjamin Kramer | 7d60526 | 2013-09-15 22:04:42 +0000 | [diff] [blame] | 32 | const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 33 | for (unsigned I = 0, E = Constants.size(); I != E; ++I) { |
| 34 | if (Constants[I].isMachineConstantPoolEntry() && |
| 35 | (Constants[I].getAlignment() & AlignMask) == 0) { |
Richard Sandiford | 21f5d68 | 2014-03-06 11:22:58 +0000 | [diff] [blame] | 36 | auto *ZCPV = |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 37 | static_cast<SystemZConstantPoolValue *>(Constants[I].Val.MachineCPVal); |
| 38 | if (ZCPV->GV == GV && ZCPV->Modifier == Modifier) |
| 39 | return I; |
| 40 | } |
| 41 | } |
| 42 | return -1; |
| 43 | } |
| 44 | |
| 45 | void SystemZConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) { |
| 46 | ID.AddPointer(GV); |
| 47 | ID.AddInteger(Modifier); |
| 48 | } |
| 49 | |
| 50 | void SystemZConstantPoolValue::print(raw_ostream &O) const { |
| 51 | O << GV << "@" << int(Modifier); |
| 52 | } |