Shih-wei Liao | e264f62 | 2010-02-10 11:10:31 -0800 | [diff] [blame^] | 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/LLVMContext.h" |
| 18 | #include "llvm/Support/ErrorHandling.h" |
| 19 | #include "llvm/Support/ManagedStatic.h" |
| 20 | #include "llvm/Support/raw_ostream.h" |
| 21 | #include <map> |
| 22 | using namespace llvm; |
| 23 | |
| 24 | static ManagedStatic<PseudoSourceValue[4]> PSVs; |
| 25 | |
| 26 | const PseudoSourceValue *PseudoSourceValue::getStack() |
| 27 | { return &(*PSVs)[0]; } |
| 28 | const PseudoSourceValue *PseudoSourceValue::getGOT() |
| 29 | { return &(*PSVs)[1]; } |
| 30 | const PseudoSourceValue *PseudoSourceValue::getJumpTable() |
| 31 | { return &(*PSVs)[2]; } |
| 32 | const PseudoSourceValue *PseudoSourceValue::getConstantPool() |
| 33 | { return &(*PSVs)[3]; } |
| 34 | |
| 35 | static 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. |
| 46 | PseudoSourceValue::PseudoSourceValue(enum ValueTy Subclass) : |
| 47 | Value(Type::getInt8PtrTy(getGlobalContext()), |
| 48 | Subclass) {} |
| 49 | |
| 50 | void PseudoSourceValue::printCustom(raw_ostream &O) const { |
| 51 | O << PSVNames[this - *PSVs]; |
| 52 | } |
| 53 | |
| 54 | static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues; |
| 55 | |
| 56 | const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) { |
| 57 | const PseudoSourceValue *&V = (*FSValues)[FI]; |
| 58 | if (!V) |
| 59 | V = new FixedStackPseudoSourceValue(FI); |
| 60 | return V; |
| 61 | } |
| 62 | |
| 63 | bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { |
| 64 | if (this == getStack()) |
| 65 | return false; |
| 66 | if (this == getGOT() || |
| 67 | this == getConstantPool() || |
| 68 | this == getJumpTable()) |
| 69 | return true; |
| 70 | llvm_unreachable("Unknown PseudoSourceValue!"); |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | bool PseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { |
| 75 | if (this == getStack() || |
| 76 | this == getGOT() || |
| 77 | this == getConstantPool() || |
| 78 | this == getJumpTable()) |
| 79 | return false; |
| 80 | llvm_unreachable("Unknown PseudoSourceValue!"); |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | bool PseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const { |
| 85 | if (this == getGOT() || |
| 86 | this == getConstantPool() || |
| 87 | this == getJumpTable()) |
| 88 | return false; |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{ |
| 93 | return MFI && MFI->isImmutableObjectIndex(FI); |
| 94 | } |
| 95 | |
| 96 | bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { |
| 97 | // Negative frame indices are used for special things that don't |
| 98 | // appear in LLVM IR. Non-negative indices may be used for things |
| 99 | // like static allocas. |
| 100 | if (!MFI) |
| 101 | return FI >= 0; |
| 102 | // Spill slots should not alias others. |
| 103 | return !MFI->isFixedObjectIndex(FI) && !MFI->isSpillSlotObjectIndex(FI); |
| 104 | } |
| 105 | |
| 106 | bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const { |
| 107 | if (!MFI) |
| 108 | return true; |
| 109 | // Spill slots will not alias any LLVM IR value. |
| 110 | return !MFI->isSpillSlotObjectIndex(FI); |
| 111 | } |
| 112 | |
| 113 | void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const { |
| 114 | OS << "FixedStack" << FI; |
| 115 | } |