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