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/PseudoSourceValue.h"
00015 #include "llvm/CodeGen/MachineFrameInfo.h"
00016 #include "llvm/IR/DerivedTypes.h"
00017 #include "llvm/IR/LLVMContext.h"
00018 #include "llvm/Support/ErrorHandling.h"
00019 #include "llvm/Support/ManagedStatic.h"
00020 #include "llvm/Support/Mutex.h"
00021 #include "llvm/Support/raw_ostream.h"
00022 #include <map>
00023 using namespace llvm;
00024 
00025 namespace {
00026 struct PSVGlobalsTy {
00027   // PseudoSourceValues are immutable so don't need locking.
00028   const PseudoSourceValue PSVs[4];
00029   sys::Mutex Lock;  // Guards FSValues, but not the values inside it.
00030   std::map<int, const PseudoSourceValue *> FSValues;
00031 
00032   PSVGlobalsTy() : PSVs() {}
00033   ~PSVGlobalsTy() {
00034     for (std::map<int, const PseudoSourceValue *>::iterator
00035            I = FSValues.begin(), E = FSValues.end(); I != E; ++I) {
00036       delete I->second;
00037     }
00038   }
00039 };
00040 
00041 static ManagedStatic<PSVGlobalsTy> PSVGlobals;
00042 
00043 }  // anonymous namespace
00044 
00045 const PseudoSourceValue *PseudoSourceValue::getStack()
00046 { return &PSVGlobals->PSVs[0]; }
00047 const PseudoSourceValue *PseudoSourceValue::getGOT()
00048 { return &PSVGlobals->PSVs[1]; }
00049 const PseudoSourceValue *PseudoSourceValue::getJumpTable()
00050 { return &PSVGlobals->PSVs[2]; }
00051 const PseudoSourceValue *PseudoSourceValue::getConstantPool()
00052 { return &PSVGlobals->PSVs[3]; }
00053 
00054 static const char *const PSVNames[] = {
00055   "Stack",
00056   "GOT",
00057   "JumpTable",
00058   "ConstantPool"
00059 };
00060 
00061 PseudoSourceValue::PseudoSourceValue(bool isFixed) : isFixed(isFixed) {}
00062 
00063 PseudoSourceValue::~PseudoSourceValue() {}
00064 
00065 void PseudoSourceValue::printCustom(raw_ostream &O) const {
00066   O << PSVNames[this - PSVGlobals->PSVs];
00067 }
00068 
00069 const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
00070   PSVGlobalsTy &PG = *PSVGlobals;
00071   sys::ScopedLock locked(PG.Lock);
00072   const PseudoSourceValue *&V = PG.FSValues[FI];
00073   if (!V)
00074     V = new FixedStackPseudoSourceValue(FI);
00075   return V;
00076 }
00077 
00078 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
00079   if (this == getStack())
00080     return false;
00081   if (this == getGOT() ||
00082       this == getConstantPool() ||
00083       this == getJumpTable())
00084     return true;
00085   llvm_unreachable("Unknown PseudoSourceValue!");
00086 }
00087 
00088 bool PseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
00089   if (this == getStack() ||
00090       this == getGOT() ||
00091       this == getConstantPool() ||
00092       this == getJumpTable())
00093     return false;
00094   llvm_unreachable("Unknown PseudoSourceValue!");
00095 }
00096 
00097 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
00098   if (this == getGOT() ||
00099       this == getConstantPool() ||
00100       this == getJumpTable())
00101     return false;
00102   return true;
00103 }
00104 
00105 bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
00106   return MFI && MFI->isImmutableObjectIndex(FI);
00107 }
00108 
00109 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
00110   if (!MFI)
00111     return true;
00112   return MFI->isAliasedObjectIndex(FI);
00113 }
00114 
00115 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
00116   if (!MFI)
00117     return true;
00118   // Spill slots will not alias any LLVM IR value.
00119   return !MFI->isSpillSlotObjectIndex(FI);
00120 }
00121 
00122 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
00123   OS << "FixedStack" << FI;
00124 }