blob: 27995547c60db306592d955904d1df93e645eb55 [file] [log] [blame]
Dan Gohman69de1932008-02-06 22:27:42 +00001//===-- 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 Gohmana54cf172008-07-11 22:44:52 +000016#include "llvm/Support/Compiler.h"
Dan Gohman69de1932008-02-06 22:27:42 +000017#include "llvm/Support/ManagedStatic.h"
Dan Gohmana54cf172008-07-11 22:44:52 +000018#include <map>
Dan Gohman69de1932008-02-06 22:27:42 +000019
20namespace llvm {
Dan Gohmana54cf172008-07-11 22:44:52 +000021 static ManagedStatic<PseudoSourceValue[4]> PSVs;
Dan Gohman69de1932008-02-06 22:27:42 +000022
Dan Gohmandebeeba2008-02-11 18:57:43 +000023 const PseudoSourceValue *PseudoSourceValue::getStack()
Dan Gohmana54cf172008-07-11 22:44:52 +000024 { return &(*PSVs)[0]; }
Dan Gohmandebeeba2008-02-11 18:57:43 +000025 const PseudoSourceValue *PseudoSourceValue::getGOT()
Dan Gohmana54cf172008-07-11 22:44:52 +000026 { return &(*PSVs)[1]; }
27 const PseudoSourceValue *PseudoSourceValue::getJumpTable()
Dan Gohmandebeeba2008-02-11 18:57:43 +000028 { return &(*PSVs)[2]; }
29 const PseudoSourceValue *PseudoSourceValue::getConstantPool()
30 { return &(*PSVs)[3]; }
Dan Gohman69de1932008-02-06 22:27:42 +000031
Dan Gohmancfbb2f02008-03-25 21:45:14 +000032 static const char *const PSVNames[] = {
Dan Gohman69de1932008-02-06 22:27:42 +000033 "Stack",
34 "GOT",
Dan Gohman2b062992008-07-14 17:45:47 +000035 "JumpTable",
Dan Gohmana54cf172008-07-11 22:44:52 +000036 "ConstantPool"
Dan Gohman69de1932008-02-06 22:27:42 +000037 };
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 Gohmana54cf172008-07-11 22:44:52 +000045
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 Gohman69de1932008-02-06 22:27:42 +000067}