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" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 18 | #include "llvm/Support/ErrorHandling.h" |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 19 | #include "llvm/Support/ManagedStatic.h" |
Evan Cheng | 40ab164 | 2008-08-24 18:51:20 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 21 | #include <map> |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 22 | using namespace llvm; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 23 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 24 | static ManagedStatic<PseudoSourceValue[4]> PSVs; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 25 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 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]; } |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 34 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 35 | static const char *const PSVNames[] = { |
| 36 | "Stack", |
| 37 | "GOT", |
| 38 | "JumpTable", |
| 39 | "ConstantPool" |
| 40 | }; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 41 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 42 | PseudoSourceValue::PseudoSourceValue() : |
| 43 | Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {} |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 44 | |
Dan Gohman | d71703d | 2008-12-03 21:37:21 +0000 | [diff] [blame] | 45 | void PseudoSourceValue::dump() const { |
Dan Gohman | f871ccb | 2009-03-23 15:57:19 +0000 | [diff] [blame] | 46 | print(errs()); errs() << '\n'; |
Dan Gohman | d71703d | 2008-12-03 21:37:21 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 49 | void PseudoSourceValue::print(raw_ostream &OS) const { |
| 50 | OS << PSVNames[this - *PSVs]; |
| 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 { |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 54 | /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue |
| 55 | /// for holding FixedStack values, which must include a frame |
| 56 | /// index. |
| 57 | class VISIBILITY_HIDDEN FixedStackPseudoSourceValue |
| 58 | : public PseudoSourceValue { |
| 59 | const int FI; |
| 60 | public: |
| 61 | explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {} |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 62 | |
| 63 | virtual bool isConstant(const MachineFrameInfo *MFI) const; |
| 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 | }; |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 69 | } |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 70 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 71 | static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues; |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 72 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 73 | const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) { |
| 74 | const PseudoSourceValue *&V = (*FSValues)[FI]; |
| 75 | if (!V) |
| 76 | V = new FixedStackPseudoSourceValue(FI); |
| 77 | return V; |
| 78 | } |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 79 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 80 | bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { |
| 81 | if (this == getStack()) |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 82 | return false; |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 83 | if (this == getGOT() || |
| 84 | this == getConstantPool() || |
| 85 | this == getJumpTable()) |
| 86 | return true; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 87 | llvm_unreachable("Unknown PseudoSourceValue!"); |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 88 | return false; |
| 89 | } |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 90 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 91 | bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{ |
| 92 | return MFI && MFI->isImmutableObjectIndex(FI); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 93 | } |