blob: ac41609d39a78266aedd2bfe375220789703f2fc [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"
Evan Cheng40ab1642008-08-24 18:51:20 +000019#include "llvm/Support/raw_ostream.h"
Dan Gohmana54cf172008-07-11 22:44:52 +000020#include <map>
Dan Gohman69de1932008-02-06 22:27:42 +000021
22namespace llvm {
Dan Gohmana54cf172008-07-11 22:44:52 +000023 static ManagedStatic<PseudoSourceValue[4]> PSVs;
Dan Gohman69de1932008-02-06 22:27:42 +000024
Dan Gohmandebeeba2008-02-11 18:57:43 +000025 const PseudoSourceValue *PseudoSourceValue::getStack()
Dan Gohmana54cf172008-07-11 22:44:52 +000026 { return &(*PSVs)[0]; }
Dan Gohmandebeeba2008-02-11 18:57:43 +000027 const PseudoSourceValue *PseudoSourceValue::getGOT()
Dan Gohmana54cf172008-07-11 22:44:52 +000028 { return &(*PSVs)[1]; }
29 const PseudoSourceValue *PseudoSourceValue::getJumpTable()
Dan Gohmandebeeba2008-02-11 18:57:43 +000030 { return &(*PSVs)[2]; }
31 const PseudoSourceValue *PseudoSourceValue::getConstantPool()
32 { return &(*PSVs)[3]; }
Dan Gohman69de1932008-02-06 22:27:42 +000033
Dan Gohmancfbb2f02008-03-25 21:45:14 +000034 static const char *const PSVNames[] = {
Dan Gohman69de1932008-02-06 22:27:42 +000035 "Stack",
36 "GOT",
Dan Gohman2b062992008-07-14 17:45:47 +000037 "JumpTable",
Dan Gohmana54cf172008-07-11 22:44:52 +000038 "ConstantPool"
Dan Gohman69de1932008-02-06 22:27:42 +000039 };
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 Cheng40ab1642008-08-24 18:51:20 +000047 void PseudoSourceValue::print(raw_ostream &OS) const {
48 OS << PSVNames[this - *PSVs];
49 }
Dan Gohmana54cf172008-07-11 22:44:52 +000050
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 Gohman6d69ba82008-07-25 00:02:30 +000059
60 virtual bool isConstant(const MachineFrameInfo *MFI) const;
61
Dan Gohmana54cf172008-07-11 22:44:52 +000062 virtual void print(std::ostream &OS) const {
63 OS << "FixedStack" << FI;
64 }
Evan Cheng40ab1642008-08-24 18:51:20 +000065 virtual void print(raw_ostream &OS) const {
66 OS << "FixedStack" << FI;
67 }
Dan Gohmana54cf172008-07-11 22:44:52 +000068 };
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 Gohman6d69ba82008-07-25 00:02:30 +000078
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 Gohman69de1932008-02-06 22:27:42 +000094}