PseudoSourceValue.cpp revision 218893
11849Swollman//===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===// 21849Swollman// 31849Swollman// The LLVM Compiler Infrastructure 41849Swollman// 51849Swollman// This file is distributed under the University of Illinois Open Source 61849Swollman// License. See LICENSE.TXT for details. 71849Swollman// 81849Swollman//===----------------------------------------------------------------------===// 91849Swollman// 101849Swollman// This file implements the PseudoSourceValue class. 111849Swollman// 121849Swollman//===----------------------------------------------------------------------===// 131849Swollman 141849Swollman#include "llvm/CodeGen/MachineFrameInfo.h" 151849Swollman#include "llvm/CodeGen/PseudoSourceValue.h" 161849Swollman#include "llvm/DerivedTypes.h" 171849Swollman#include "llvm/LLVMContext.h" 181849Swollman#include "llvm/Support/ErrorHandling.h" 191849Swollman#include "llvm/Support/ManagedStatic.h" 201849Swollman#include "llvm/Support/raw_ostream.h" 211849Swollman#include "llvm/Support/Mutex.h" 221849Swollman#include <map> 231849Swollmanusing namespace llvm; 241849Swollman 251849Swollmannamespace { 261849Swollmanstruct PSVGlobalsTy { 271849Swollman // PseudoSourceValues are immutable so don't need locking. 281849Swollman const PseudoSourceValue PSVs[4]; 291849Swollman sys::Mutex Lock; // Guards FSValues, but not the values inside it. 301849Swollman std::map<int, const PseudoSourceValue *> FSValues; 311849Swollman 321849Swollman PSVGlobalsTy() : PSVs() {} 3392999Sobrien ~PSVGlobalsTy() { 3492999Sobrien for (std::map<int, const PseudoSourceValue *>::iterator 3592999Sobrien I = FSValues.begin(), E = FSValues.end(); I != E; ++I) { 3692999Sobrien delete I->second; 3792999Sobrien } 381849Swollman } 391849Swollman}; 401849Swollman 4171579Sdeischenstatic ManagedStatic<PSVGlobalsTy> PSVGlobals; 4271579Sdeischen 4371579Sdeischen} // anonymous namespace 4471579Sdeischen 4571579Sdeischenconst PseudoSourceValue *PseudoSourceValue::getStack() 461849Swollman{ return &PSVGlobals->PSVs[0]; } 4787006Sjhbconst PseudoSourceValue *PseudoSourceValue::getGOT() 4815634Speter{ return &PSVGlobals->PSVs[1]; } 4986325Sjhbconst PseudoSourceValue *PseudoSourceValue::getJumpTable() 5069332Sjhb{ return &PSVGlobals->PSVs[2]; } 5186325Sjhbconst PseudoSourceValue *PseudoSourceValue::getConstantPool() 5239455Sluoqi{ return &PSVGlobals->PSVs[3]; } 53240152Sjilles 54184548Speterstatic const char *const PSVNames[] = { 55217106Skib "Stack", 56217106Skib "GOT", 57 "JumpTable", 58 "ConstantPool" 59}; 60 61// FIXME: THIS IS A HACK!!!! 62// Eventually these should be uniqued on LLVMContext rather than in a managed 63// static. For now, we can safely use the global context for the time being to 64// squeak by. 65PseudoSourceValue::PseudoSourceValue(enum ValueTy Subclass) : 66 Value(Type::getInt8PtrTy(getGlobalContext()), 67 Subclass) {} 68 69void PseudoSourceValue::printCustom(raw_ostream &O) const { 70 O << PSVNames[this - PSVGlobals->PSVs]; 71} 72 73const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) { 74 PSVGlobalsTy &PG = *PSVGlobals; 75 sys::ScopedLock locked(PG.Lock); 76 const PseudoSourceValue *&V = PG.FSValues[FI]; 77 if (!V) 78 V = new FixedStackPseudoSourceValue(FI); 79 return V; 80} 81 82bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { 83 if (this == getStack()) 84 return false; 85 if (this == getGOT() || 86 this == getConstantPool() || 87 this == getJumpTable()) 88 return true; 89 llvm_unreachable("Unknown PseudoSourceValue!"); 90 return false; 91} 92 93bool PseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { 94 if (this == getStack() || 95 this == getGOT() || 96 this == getConstantPool() || 97 this == getJumpTable()) 98 return false; 99 llvm_unreachable("Unknown PseudoSourceValue!"); 100 return true; 101} 102 103bool PseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const { 104 if (this == getGOT() || 105 this == getConstantPool() || 106 this == getJumpTable()) 107 return false; 108 return true; 109} 110 111bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{ 112 return MFI && MFI->isImmutableObjectIndex(FI); 113} 114 115bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { 116 // Negative frame indices are used for special things that don't 117 // appear in LLVM IR. Non-negative indices may be used for things 118 // like static allocas. 119 if (!MFI) 120 return FI >= 0; 121 // Spill slots should not alias others. 122 return !MFI->isFixedObjectIndex(FI) && !MFI->isSpillSlotObjectIndex(FI); 123} 124 125bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const { 126 if (!MFI) 127 return true; 128 // Spill slots will not alias any LLVM IR value. 129 return !MFI->isSpillSlotObjectIndex(FI); 130} 131 132void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const { 133 OS << "FixedStack" << FI; 134} 135