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/ErrorHandling.h"
00019 #include "llvm/Support/ManagedStatic.h"
00020 #include "llvm/Support/raw_ostream.h"
00021 #include <map>
00022 using namespace llvm;
00023 
00024 static ManagedStatic<PseudoSourceValue[4]> PSVs;
00025 
00026 const PseudoSourceValue *PseudoSourceValue::getStack()
00027 { return &(*PSVs)[0]; }
00028 const PseudoSourceValue *PseudoSourceValue::getGOT()
00029 { return &(*PSVs)[1]; }
00030 const PseudoSourceValue *PseudoSourceValue::getJumpTable()
00031 { return &(*PSVs)[2]; }
00032 const PseudoSourceValue *PseudoSourceValue::getConstantPool()
00033 { return &(*PSVs)[3]; }
00034 
00035 static const char *const PSVNames[] = {
00036   "Stack",
00037   "GOT",
00038   "JumpTable",
00039   "ConstantPool"
00040 };
00041 
00042 // FIXME: THIS IS A HACK!!!!
00043 // Eventually these should be uniqued on LLVMContext rather than in a managed
00044 // static.  For now, we can safely use the global context for the time being to
00045 // squeak by.
00046 PseudoSourceValue::PseudoSourceValue() :
00047   Value(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext())),
00048         PseudoSourceValueVal) {}
00049 
00050 void PseudoSourceValue::dump() const {
00051   print(errs()); errs() << '\n';
00052 }
00053 
00054 void PseudoSourceValue::print(raw_ostream &OS) const {
00055   OS << PSVNames[this - *PSVs];
00056 }
00057 
00058 namespace {
00059   /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
00060   /// for holding FixedStack values, which must include a frame
00061   /// index.
00062   class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
00063     : public PseudoSourceValue {
00064     const int FI;
00065   public:
00066     explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
00067 
00068     virtual bool isConstant(const MachineFrameInfo *MFI) const;
00069 
00070     virtual void print(raw_ostream &OS) const {
00071       OS << "FixedStack" << FI;
00072     }
00073   };
00074 }
00075 
00076 static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
00077 
00078 const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
00079   const PseudoSourceValue *&V = (*FSValues)[FI];
00080   if (!V)
00081     V = new FixedStackPseudoSourceValue(FI);
00082   return V;
00083 }
00084 
00085 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
00086   if (this == getStack())
00087     return false;
00088   if (this == getGOT() ||
00089       this == getConstantPool() ||
00090       this == getJumpTable())
00091     return true;
00092   llvm_unreachable("Unknown PseudoSourceValue!");
00093   return false;
00094 }
00095 
00096 bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
00097   return MFI && MFI->isImmutableObjectIndex(FI);
00098 }