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" |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Compiler.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> |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 23 | static ManagedStatic<PseudoSourceValue[4]> PSVs; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 24 | |
Dan Gohman | debeeba | 2008-02-11 18:57:43 +0000 | [diff] [blame] | 25 | const PseudoSourceValue *PseudoSourceValue::getStack() |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 26 | { return &(*PSVs)[0]; } |
Dan Gohman | debeeba | 2008-02-11 18:57:43 +0000 | [diff] [blame] | 27 | const PseudoSourceValue *PseudoSourceValue::getGOT() |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 28 | { return &(*PSVs)[1]; } |
| 29 | const PseudoSourceValue *PseudoSourceValue::getJumpTable() |
Dan Gohman | debeeba | 2008-02-11 18:57:43 +0000 | [diff] [blame] | 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 | |
Dan Gohman | cfbb2f0 | 2008-03-25 21:45:14 +0000 | [diff] [blame] | 34 | static const char *const PSVNames[] = { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 35 | "Stack", |
| 36 | "GOT", |
Dan Gohman | 2b06299 | 2008-07-14 17:45:47 +0000 | [diff] [blame] | 37 | "JumpTable", |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 38 | "ConstantPool" |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | PseudoSourceValue::PseudoSourceValue() : |
| 42 | Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {} |
| 43 | |
| 44 | void PseudoSourceValue::print(std::ostream &OS) const { |
| 45 | OS << PSVNames[this - *PSVs]; |
| 46 | } |
Evan Cheng | 40ab164 | 2008-08-24 18:51:20 +0000 | [diff] [blame^] | 47 | void PseudoSourceValue::print(raw_ostream &OS) const { |
| 48 | OS << PSVNames[this - *PSVs]; |
| 49 | } |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 50 | |
| 51 | /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue |
| 52 | /// for holding FixedStack values, which must include a frame |
| 53 | /// index. |
| 54 | class VISIBILITY_HIDDEN FixedStackPseudoSourceValue |
| 55 | : public PseudoSourceValue { |
| 56 | const int FI; |
| 57 | public: |
| 58 | explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {} |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 59 | |
| 60 | virtual bool isConstant(const MachineFrameInfo *MFI) const; |
| 61 | |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 62 | virtual void print(std::ostream &OS) const { |
| 63 | OS << "FixedStack" << FI; |
| 64 | } |
Evan Cheng | 40ab164 | 2008-08-24 18:51:20 +0000 | [diff] [blame^] | 65 | virtual void print(raw_ostream &OS) const { |
| 66 | OS << "FixedStack" << FI; |
| 67 | } |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues; |
| 71 | |
| 72 | const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) { |
| 73 | const PseudoSourceValue *&V = (*FSValues)[FI]; |
| 74 | if (!V) |
| 75 | V = new FixedStackPseudoSourceValue(FI); |
| 76 | return V; |
| 77 | } |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 78 | |
| 79 | bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { |
| 80 | if (this == getStack()) |
| 81 | return false; |
| 82 | if (this == getGOT() || |
| 83 | this == getConstantPool() || |
| 84 | this == getJumpTable()) |
| 85 | return true; |
| 86 | assert(0 && "Unknown PseudoSourceValue!"); |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | bool |
| 91 | FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const { |
| 92 | return MFI && MFI->isImmutableObjectIndex(FI); |
| 93 | } |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 94 | } |