Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [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 | |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/PseudoSourceValue.h" |
| 16 | #include "llvm/DerivedTypes.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 17 | #include "llvm/Support/ErrorHandling.h" |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 18 | #include "llvm/Support/ManagedStatic.h" |
Evan Cheng | 40ab164 | 2008-08-24 18:51:20 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 20 | #include <map> |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 21 | using namespace llvm; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 22 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 23 | static ManagedStatic<PseudoSourceValue[4]> PSVs; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 24 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 25 | const PseudoSourceValue *PseudoSourceValue::getStack() |
| 26 | { return &(*PSVs)[0]; } |
| 27 | const PseudoSourceValue *PseudoSourceValue::getGOT() |
| 28 | { return &(*PSVs)[1]; } |
| 29 | const PseudoSourceValue *PseudoSourceValue::getJumpTable() |
| 30 | { return &(*PSVs)[2]; } |
| 31 | const PseudoSourceValue *PseudoSourceValue::getConstantPool() |
| 32 | { return &(*PSVs)[3]; } |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 33 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 34 | static const char *const PSVNames[] = { |
| 35 | "Stack", |
| 36 | "GOT", |
| 37 | "JumpTable", |
| 38 | "ConstantPool" |
| 39 | }; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 40 | |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 41 | // FIXME: THIS IS A HACK!!!! |
| 42 | // Eventually these should be uniqued on LLVMContext rather than in a managed |
| 43 | // static. For now, we can safely use the global context for the time being to |
| 44 | // squeak by. |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 45 | PseudoSourceValue::PseudoSourceValue() : |
Duncan Sands | ac53a0b | 2009-10-06 15:40:36 +0000 | [diff] [blame] | 46 | Value(Type::getInt8PtrTy(getGlobalContext()), |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 47 | PseudoSourceValueVal) {} |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 48 | |
Dan Gohman | cd26ec5 | 2009-09-23 01:33:16 +0000 | [diff] [blame] | 49 | void PseudoSourceValue::printCustom(raw_ostream &O) const { |
| 50 | O << PSVNames[this - *PSVs]; |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 51 | } |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 52 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 53 | namespace { |
Evan Cheng | 6553155 | 2009-10-17 07:53:04 +0000 | [diff] [blame] | 54 | /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue |
| 55 | /// for holding FixedStack values, which must include a frame |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 56 | /// index. |
Nick Lewycky | 6726b6d | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 57 | class FixedStackPseudoSourceValue : public PseudoSourceValue { |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 58 | const int FI; |
| 59 | public: |
Evan Cheng | 6553155 | 2009-10-17 07:53:04 +0000 | [diff] [blame] | 60 | explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {} |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 61 | |
| 62 | virtual bool isConstant(const MachineFrameInfo *MFI) const; |
| 63 | |
Evan Cheng | 38bdfc6 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 64 | virtual bool isAliased(const MachineFrameInfo *MFI) const; |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 65 | |
Dan Gohman | cd26ec5 | 2009-09-23 01:33:16 +0000 | [diff] [blame] | 66 | virtual void printCustom(raw_ostream &OS) const { |
Evan Cheng | 6553155 | 2009-10-17 07:53:04 +0000 | [diff] [blame] | 67 | OS << "FixedStack" << FI; |
Evan Cheng | 40ab164 | 2008-08-24 18:51:20 +0000 | [diff] [blame] | 68 | } |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 69 | }; |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 70 | } |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 71 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 72 | static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues; |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 73 | |
Evan Cheng | 6553155 | 2009-10-17 07:53:04 +0000 | [diff] [blame] | 74 | const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) { |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 75 | const PseudoSourceValue *&V = (*FSValues)[FI]; |
| 76 | if (!V) |
Evan Cheng | 6553155 | 2009-10-17 07:53:04 +0000 | [diff] [blame] | 77 | V = new FixedStackPseudoSourceValue(FI); |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 78 | return V; |
| 79 | } |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 80 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 81 | bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { |
| 82 | if (this == getStack()) |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 83 | return false; |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 84 | if (this == getGOT() || |
| 85 | this == getConstantPool() || |
| 86 | this == getJumpTable()) |
| 87 | return true; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 88 | llvm_unreachable("Unknown PseudoSourceValue!"); |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 89 | return false; |
| 90 | } |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 91 | |
Evan Cheng | 38bdfc6 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 92 | bool PseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 93 | if (this == getStack() || |
| 94 | this == getGOT() || |
| 95 | this == getConstantPool() || |
| 96 | this == getJumpTable()) |
| 97 | return false; |
| 98 | llvm_unreachable("Unknown PseudoSourceValue!"); |
| 99 | return true; |
| 100 | } |
| 101 | |
Evan Cheng | 6553155 | 2009-10-17 07:53:04 +0000 | [diff] [blame] | 102 | bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{ |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 103 | return MFI && MFI->isImmutableObjectIndex(FI); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 104 | } |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 105 | |
Evan Cheng | 38bdfc6 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 106 | bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 107 | // Negative frame indices are used for special things that don't |
| 108 | // appear in LLVM IR. Non-negative indices may be used for things |
| 109 | // like static allocas. |
Evan Cheng | 38bdfc6 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 110 | if (!MFI) |
| 111 | return FI >= 0; |
| 112 | // Spill slots should not alias others. |
| 113 | return !MFI->isFixedObjectIndex(FI) && !MFI->isSpillSlotObjectIndex(FI); |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 114 | } |