LLVM API Documentation

PseudoSourceValue.cpp

Go to the documentation of this file.
00001 //===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- 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 PseudoSourceValue class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/CodeGen/MachineFrameInfo.h"
00015 #include "llvm/CodeGen/PseudoSourceValue.h"
00016 #include "llvm/DerivedTypes.h"
00017 #include "llvm/Support/Compiler.h"
00018 #include "llvm/Support/ManagedStatic.h"
00019 #include "llvm/Support/raw_ostream.h"
00020 #include <map>
00021 using namespace llvm;
00022 
00023 static ManagedStatic<PseudoSourceValue[4]> PSVs;
00024 
00025 const PseudoSourceValue *PseudoSourceValue::getStack()
00026 { return &(*PSVs)[0]; }
00027 const PseudoSourceValue *PseudoSourceValue::getGOT()
00028 { return &(*PSVs)[1]; }
00029 const PseudoSourceValue *PseudoSourceValue::getJumpTable()
00030 { return &(*PSVs)[2]; }
00031 const PseudoSourceValue *PseudoSourceValue::getConstantPool()
00032 { return &(*PSVs)[3]; }
00033 
00034 static const char *const PSVNames[] = {
00035   "Stack",
00036   "GOT",
00037   "JumpTable",
00038   "ConstantPool"
00039 };
00040 
00041 PseudoSourceValue::PseudoSourceValue() :
00042   Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {}
00043 
00044 void PseudoSourceValue::dump() const {
00045   print(errs()); errs() << '\n'; errs().flush();
00046 }
00047 
00048 void PseudoSourceValue::print(raw_ostream &OS) const {
00049   OS << PSVNames[this - *PSVs];
00050 }
00051 
00052 namespace {
00053   /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
00054   /// for holding FixedStack values, which must include a frame
00055   /// index.
00056   class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
00057     : public PseudoSourceValue {
00058     const int FI;
00059   public:
00060     explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
00061 
00062     virtual bool isConstant(const MachineFrameInfo *MFI) const;
00063 
00064     virtual void print(raw_ostream &OS) const {
00065       OS << "FixedStack" << FI;
00066     }
00067   };
00068 }
00069 
00070 static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
00071 
00072 const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
00073   const PseudoSourceValue *&V = (*FSValues)[FI];
00074   if (!V)
00075     V = new FixedStackPseudoSourceValue(FI);
00076   return V;
00077 }
00078 
00079 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
00080   if (this == getStack())
00081     return false;
00082   if (this == getGOT() ||
00083       this == getConstantPool() ||
00084       this == getJumpTable())
00085     return true;
00086   assert(0 && "Unknown PseudoSourceValue!");
00087   return false;
00088 }
00089 
00090 bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
00091   return MFI && MFI->isImmutableObjectIndex(FI);
00092 }