blob: 55a6cf51c906220d38690e7dad20bb77a2708da2 [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"
Torok Edwinc25e7582009-07-11 20:10:48 +000018#include "llvm/Support/ErrorHandling.h"
Dan Gohman69de1932008-02-06 22:27:42 +000019#include "llvm/Support/ManagedStatic.h"
Evan Cheng40ab1642008-08-24 18:51:20 +000020#include "llvm/Support/raw_ostream.h"
Dan Gohmana54cf172008-07-11 22:44:52 +000021#include <map>
Chris Lattneredfb72c2008-08-24 20:37:32 +000022using namespace llvm;
Dan Gohman69de1932008-02-06 22:27:42 +000023
Chris Lattneredfb72c2008-08-24 20:37:32 +000024static ManagedStatic<PseudoSourceValue[4]> PSVs;
Dan Gohman69de1932008-02-06 22:27:42 +000025
Chris Lattneredfb72c2008-08-24 20:37:32 +000026const PseudoSourceValue *PseudoSourceValue::getStack()
27{ return &(*PSVs)[0]; }
28const PseudoSourceValue *PseudoSourceValue::getGOT()
29{ return &(*PSVs)[1]; }
30const PseudoSourceValue *PseudoSourceValue::getJumpTable()
31{ return &(*PSVs)[2]; }
32const PseudoSourceValue *PseudoSourceValue::getConstantPool()
33{ return &(*PSVs)[3]; }
Dan Gohman69de1932008-02-06 22:27:42 +000034
Chris Lattneredfb72c2008-08-24 20:37:32 +000035static const char *const PSVNames[] = {
36 "Stack",
37 "GOT",
38 "JumpTable",
39 "ConstantPool"
40};
Dan Gohman69de1932008-02-06 22:27:42 +000041
Chris Lattneredfb72c2008-08-24 20:37:32 +000042PseudoSourceValue::PseudoSourceValue() :
43 Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {}
Dan Gohman69de1932008-02-06 22:27:42 +000044
Dan Gohmand71703d2008-12-03 21:37:21 +000045void PseudoSourceValue::dump() const {
Dan Gohmanf871ccb2009-03-23 15:57:19 +000046 print(errs()); errs() << '\n';
Dan Gohmand71703d2008-12-03 21:37:21 +000047}
48
Chris Lattneredfb72c2008-08-24 20:37:32 +000049void PseudoSourceValue::print(raw_ostream &OS) const {
50 OS << PSVNames[this - *PSVs];
51}
Dan Gohmana54cf172008-07-11 22:44:52 +000052
Chris Lattneredfb72c2008-08-24 20:37:32 +000053namespace {
Dan Gohmana54cf172008-07-11 22:44:52 +000054 /// 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 Gohman6d69ba82008-07-25 00:02:30 +000062
63 virtual bool isConstant(const MachineFrameInfo *MFI) const;
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 };
Chris Lattneredfb72c2008-08-24 20:37:32 +000069}
Dan Gohmana54cf172008-07-11 22:44:52 +000070
Chris Lattneredfb72c2008-08-24 20:37:32 +000071static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
Dan Gohmana54cf172008-07-11 22:44:52 +000072
Chris Lattneredfb72c2008-08-24 20:37:32 +000073const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
74 const PseudoSourceValue *&V = (*FSValues)[FI];
75 if (!V)
76 V = new FixedStackPseudoSourceValue(FI);
77 return V;
78}
Dan Gohman6d69ba82008-07-25 00:02:30 +000079
Chris Lattneredfb72c2008-08-24 20:37:32 +000080bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
81 if (this == getStack())
Dan Gohman6d69ba82008-07-25 00:02:30 +000082 return false;
Chris Lattneredfb72c2008-08-24 20:37:32 +000083 if (this == getGOT() ||
84 this == getConstantPool() ||
85 this == getJumpTable())
86 return true;
Torok Edwinc25e7582009-07-11 20:10:48 +000087 LLVM_UNREACHABLE("Unknown PseudoSourceValue!");
Chris Lattneredfb72c2008-08-24 20:37:32 +000088 return false;
89}
Dan Gohman6d69ba82008-07-25 00:02:30 +000090
Chris Lattneredfb72c2008-08-24 20:37:32 +000091bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
92 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman69de1932008-02-06 22:27:42 +000093}