blob: bcf4ea8fb75da67d8171ab9c24daf4f7f24332a9 [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
Dan Gohman6d69ba82008-07-25 00:02:30 +000014#include "llvm/CodeGen/MachineFrameInfo.h"
Dan Gohman69de1932008-02-06 22:27:42 +000015#include "llvm/CodeGen/PseudoSourceValue.h"
16#include "llvm/DerivedTypes.h"
Dan Gohmana54cf172008-07-11 22:44:52 +000017#include "llvm/Support/Compiler.h"
Dan Gohman69de1932008-02-06 22:27:42 +000018#include "llvm/Support/ManagedStatic.h"
Dan Gohmana54cf172008-07-11 22:44:52 +000019#include <map>
Dan Gohman69de1932008-02-06 22:27:42 +000020
21namespace llvm {
Dan Gohmana54cf172008-07-11 22:44:52 +000022 static ManagedStatic<PseudoSourceValue[4]> PSVs;
Dan Gohman69de1932008-02-06 22:27:42 +000023
Dan Gohmandebeeba2008-02-11 18:57:43 +000024 const PseudoSourceValue *PseudoSourceValue::getStack()
Dan Gohmana54cf172008-07-11 22:44:52 +000025 { return &(*PSVs)[0]; }
Dan Gohmandebeeba2008-02-11 18:57:43 +000026 const PseudoSourceValue *PseudoSourceValue::getGOT()
Dan Gohmana54cf172008-07-11 22:44:52 +000027 { return &(*PSVs)[1]; }
28 const PseudoSourceValue *PseudoSourceValue::getJumpTable()
Dan Gohmandebeeba2008-02-11 18:57:43 +000029 { return &(*PSVs)[2]; }
30 const PseudoSourceValue *PseudoSourceValue::getConstantPool()
31 { return &(*PSVs)[3]; }
Dan Gohman69de1932008-02-06 22:27:42 +000032
Dan Gohmancfbb2f02008-03-25 21:45:14 +000033 static const char *const PSVNames[] = {
Dan Gohman69de1932008-02-06 22:27:42 +000034 "Stack",
35 "GOT",
Dan Gohman2b062992008-07-14 17:45:47 +000036 "JumpTable",
Dan Gohmana54cf172008-07-11 22:44:52 +000037 "ConstantPool"
Dan Gohman69de1932008-02-06 22:27:42 +000038 };
39
40 PseudoSourceValue::PseudoSourceValue() :
41 Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {}
42
43 void PseudoSourceValue::print(std::ostream &OS) const {
44 OS << PSVNames[this - *PSVs];
45 }
Dan Gohmana54cf172008-07-11 22:44:52 +000046
47 /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
48 /// for holding FixedStack values, which must include a frame
49 /// index.
50 class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
51 : public PseudoSourceValue {
52 const int FI;
53 public:
54 explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
Dan Gohman6d69ba82008-07-25 00:02:30 +000055
56 virtual bool isConstant(const MachineFrameInfo *MFI) const;
57
Dan Gohmana54cf172008-07-11 22:44:52 +000058 virtual void print(std::ostream &OS) const {
59 OS << "FixedStack" << FI;
60 }
61 };
62
63 static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
64
65 const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
66 const PseudoSourceValue *&V = (*FSValues)[FI];
67 if (!V)
68 V = new FixedStackPseudoSourceValue(FI);
69 return V;
70 }
Dan Gohman6d69ba82008-07-25 00:02:30 +000071
72 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
73 if (this == getStack())
74 return false;
75 if (this == getGOT() ||
76 this == getConstantPool() ||
77 this == getJumpTable())
78 return true;
79 assert(0 && "Unknown PseudoSourceValue!");
80 return false;
81 }
82
83 bool
84 FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const {
85 return MFI && MFI->isImmutableObjectIndex(FI);
86 }
Dan Gohman69de1932008-02-06 22:27:42 +000087}