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 | |
| 14 | #include "llvm/CodeGen/PseudoSourceValue.h" |
| 15 | #include "llvm/DerivedTypes.h" |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Compiler.h" |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 17 | #include "llvm/Support/ManagedStatic.h" |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 18 | #include <map> |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 21 | static ManagedStatic<PseudoSourceValue[4]> PSVs; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 22 | |
Dan Gohman | debeeba | 2008-02-11 18:57:43 +0000 | [diff] [blame] | 23 | const PseudoSourceValue *PseudoSourceValue::getStack() |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 24 | { return &(*PSVs)[0]; } |
Dan Gohman | debeeba | 2008-02-11 18:57:43 +0000 | [diff] [blame] | 25 | const PseudoSourceValue *PseudoSourceValue::getGOT() |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 26 | { return &(*PSVs)[1]; } |
| 27 | const PseudoSourceValue *PseudoSourceValue::getJumpTable() |
Dan Gohman | debeeba | 2008-02-11 18:57:43 +0000 | [diff] [blame] | 28 | { return &(*PSVs)[2]; } |
| 29 | const PseudoSourceValue *PseudoSourceValue::getConstantPool() |
| 30 | { return &(*PSVs)[3]; } |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 31 | |
Dan Gohman | cfbb2f0 | 2008-03-25 21:45:14 +0000 | [diff] [blame] | 32 | static const char *const PSVNames[] = { |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 33 | "Stack", |
| 34 | "GOT", |
Dan Gohman | 2b06299 | 2008-07-14 17:45:47 +0000 | [diff] [blame^] | 35 | "JumpTable", |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 36 | "ConstantPool" |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | PseudoSourceValue::PseudoSourceValue() : |
| 40 | Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {} |
| 41 | |
| 42 | void PseudoSourceValue::print(std::ostream &OS) const { |
| 43 | OS << PSVNames[this - *PSVs]; |
| 44 | } |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 45 | |
| 46 | /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue |
| 47 | /// for holding FixedStack values, which must include a frame |
| 48 | /// index. |
| 49 | class VISIBILITY_HIDDEN FixedStackPseudoSourceValue |
| 50 | : public PseudoSourceValue { |
| 51 | const int FI; |
| 52 | public: |
| 53 | explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {} |
| 54 | virtual void print(std::ostream &OS) const { |
| 55 | OS << "FixedStack" << FI; |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues; |
| 60 | |
| 61 | const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) { |
| 62 | const PseudoSourceValue *&V = (*FSValues)[FI]; |
| 63 | if (!V) |
| 64 | V = new FixedStackPseudoSourceValue(FI); |
| 65 | return V; |
| 66 | } |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 67 | } |