LLVM API Documentation

ARMConstantPoolValue.cpp

Go to the documentation of this file.
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 <cstdlib>
00021 using namespace llvm;
00022 
00023 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
00024                                            unsigned char PCAdj,
00025                                            const char *Modif,
00026                                            bool AddCA)
00027   : MachineConstantPoolValue((const Type*)gv->getType()),
00028     GV(gv), S(NULL), LabelId(id), PCAdjust(PCAdj),
00029     Modifier(Modif), AddCurrentAddress(AddCA) {}
00030 
00031 ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
00032                                            const char *s, unsigned id,
00033                                            unsigned char PCAdj,
00034                                            const char *Modif,
00035                                            bool AddCA)
00036   : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
00037     GV(NULL), S(strdup(s)), LabelId(id), PCAdjust(PCAdj),
00038     Modifier(Modif), AddCurrentAddress(AddCA) {}
00039 
00040 ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, const char *Modif)
00041   : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
00042     GV(gv), S(NULL), LabelId(0), PCAdjust(0),
00043     Modifier(Modif) {}
00044 
00045 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
00046                                                     unsigned Alignment) {
00047   unsigned AlignMask = Alignment - 1;
00048   const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants();
00049   for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
00050     if (Constants[i].isMachineConstantPoolEntry() &&
00051         (Constants[i].getAlignment() & AlignMask) == 0) {
00052       ARMConstantPoolValue *CPV =
00053         (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
00054       if (CPV->GV == GV &&
00055           CPV->S == S &&
00056           CPV->LabelId == LabelId &&
00057           CPV->PCAdjust == PCAdjust)
00058         return i;
00059     }
00060   }
00061 
00062   return -1;
00063 }
00064 
00065 ARMConstantPoolValue::~ARMConstantPoolValue() {
00066   free((void*)S);
00067 }
00068 
00069 void
00070 ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
00071   ID.AddPointer(GV);
00072   ID.AddPointer(S);
00073   ID.AddInteger(LabelId);
00074   ID.AddInteger(PCAdjust);
00075 }
00076 
00077 void ARMConstantPoolValue::dump() const {
00078   cerr << "  " << *this;
00079 }
00080 
00081 void ARMConstantPoolValue::print(std::ostream &O) const {
00082   raw_os_ostream RawOS(O);
00083   print(RawOS);
00084 }
00085 
00086 void ARMConstantPoolValue::print(raw_ostream &O) const {
00087   if (GV)
00088     O << GV->getName();
00089   else
00090     O << S;
00091   if (Modifier) O << "(" << Modifier << ")";
00092   if (PCAdjust != 0) {
00093     O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
00094     if (AddCurrentAddress) O << "-.";
00095     O << ")";
00096   }
00097 }