PseudoSourceValue.cpp revision 77e61b46fce5e165ecfedb5666c43b3d2c1dc971
1//===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements the PseudoSourceValue class. 11// 12//===----------------------------------------------------------------------===// 13 14#include "llvm/CodeGen/MachineFrameInfo.h" 15#include "llvm/CodeGen/PseudoSourceValue.h" 16#include "llvm/DerivedTypes.h" 17#include "llvm/Support/Compiler.h" 18#include "llvm/Support/ErrorHandling.h" 19#include "llvm/Support/ManagedStatic.h" 20#include "llvm/Support/raw_ostream.h" 21#include <map> 22using namespace llvm; 23 24static ManagedStatic<PseudoSourceValue[4]> PSVs; 25 26const PseudoSourceValue *PseudoSourceValue::getStack() 27{ return &(*PSVs)[0]; } 28const PseudoSourceValue *PseudoSourceValue::getGOT() 29{ return &(*PSVs)[1]; } 30const PseudoSourceValue *PseudoSourceValue::getJumpTable() 31{ return &(*PSVs)[2]; } 32const PseudoSourceValue *PseudoSourceValue::getConstantPool() 33{ return &(*PSVs)[3]; } 34 35static const char *const PSVNames[] = { 36 "Stack", 37 "GOT", 38 "JumpTable", 39 "ConstantPool" 40}; 41 42// FIXME: THIS IS A HACK!!!! 43// Eventually these should be uniqued on LLVMContext rather than in a managed 44// static. For now, we can safely use the global context for the time being to 45// squeak by. 46PseudoSourceValue::PseudoSourceValue() : 47 Value(Type::getInt8PtrTy(getGlobalContext()), 48 PseudoSourceValueVal) {} 49 50void PseudoSourceValue::printCustom(raw_ostream &O) const { 51 O << PSVNames[this - *PSVs]; 52} 53 54namespace { 55 /// StackObjectPseudoSourceValue - A specialized PseudoSourceValue 56 /// for holding StackObject values, which must include a frame 57 /// index. 58 class VISIBILITY_HIDDEN StackObjectPseudoSourceValue 59 : public PseudoSourceValue { 60 const int FI; 61 public: 62 explicit StackObjectPseudoSourceValue(int fi) : FI(fi) {} 63 64 virtual bool isConstant(const MachineFrameInfo *MFI) const; 65 66 virtual void printCustom(raw_ostream &OS) const { 67 if (FI < 0) 68 OS << "Fixed"; 69 OS << "StackObject" << FI; 70 } 71 }; 72} 73 74static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues; 75 76const PseudoSourceValue *PseudoSourceValue::getStackObject(int FI) { 77 const PseudoSourceValue *&V = (*FSValues)[FI]; 78 if (!V) 79 V = new StackObjectPseudoSourceValue(FI); 80 return V; 81} 82 83bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { 84 if (this == getStack()) 85 return false; 86 if (this == getGOT() || 87 this == getConstantPool() || 88 this == getJumpTable()) 89 return true; 90 llvm_unreachable("Unknown PseudoSourceValue!"); 91 return false; 92} 93 94bool 95StackObjectPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const { 96 return MFI && MFI->isImmutableObjectIndex(FI); 97} 98