LLVM API Documentation
00001 //===- ARMConstantPoolValue.cpp - ARM constantpool value --------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the ARM specific constantpool value class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "ARMConstantPoolValue.h" 00015 #include "llvm/ADT/FoldingSet.h" 00016 #include "llvm/GlobalValue.h" 00017 #include "llvm/Type.h" 00018 #include "llvm/Support/Streams.h" 00019 #include "llvm/Support/raw_ostream.h" 00020 #include <ostream> 00021 using namespace llvm; 00022 00023 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id, 00024 ARMCP::ARMCPKind k, 00025 unsigned char PCAdj, 00026 const char *Modif, 00027 bool AddCA) 00028 : MachineConstantPoolValue((const Type*)gv->getType()), 00029 GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj), 00030 Modifier(Modif), AddCurrentAddress(AddCA) {} 00031 00032 ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id, 00033 ARMCP::ARMCPKind k, 00034 unsigned char PCAdj, 00035 const char *Modif, 00036 bool AddCA) 00037 : MachineConstantPoolValue((const Type*)Type::Int32Ty), 00038 GV(NULL), S(s), LabelId(id), Kind(k), PCAdjust(PCAdj), 00039 Modifier(Modif), AddCurrentAddress(AddCA) {} 00040 00041 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, 00042 ARMCP::ARMCPKind k, 00043 const char *Modif) 00044 : MachineConstantPoolValue((const Type*)Type::Int32Ty), 00045 GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0), 00046 Modifier(Modif) {} 00047 00048 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP, 00049 unsigned Alignment) { 00050 unsigned AlignMask = (1 << Alignment)-1; 00051 const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants(); 00052 for (unsigned i = 0, e = Constants.size(); i != e; ++i) { 00053 if (Constants[i].isMachineConstantPoolEntry() && 00054 (Constants[i].Offset & AlignMask) == 0) { 00055 ARMConstantPoolValue *CPV = 00056 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal; 00057 if (CPV->GV == GV && 00058 CPV->S == S && 00059 CPV->LabelId == LabelId && 00060 CPV->Kind == Kind && 00061 CPV->PCAdjust == PCAdjust) 00062 return i; 00063 } 00064 } 00065 00066 return -1; 00067 } 00068 00069 void 00070 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) { 00071 ID.AddPointer(GV); 00072 ID.AddPointer(S); 00073 ID.AddInteger(LabelId); 00074 ID.AddInteger((unsigned)Kind); 00075 ID.AddInteger(PCAdjust); 00076 } 00077 00078 void ARMConstantPoolValue::dump() const { 00079 cerr << " " << *this; 00080 } 00081 00082 void ARMConstantPoolValue::print(std::ostream &O) const { 00083 raw_os_ostream RawOS(O); 00084 print(RawOS); 00085 } 00086 00087 void ARMConstantPoolValue::print(raw_ostream &O) const { 00088 if (GV) 00089 O << GV->getName(); 00090 else 00091 O << S; 00092 if (isNonLazyPointer()) O << "$non_lazy_ptr"; 00093 else if (isStub()) O << "$stub"; 00094 if (Modifier) O << "(" << Modifier << ")"; 00095 if (PCAdjust != 0) { 00096 O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust; 00097 if (AddCurrentAddress) O << "-."; 00098 O << ")"; 00099 } 00100 }