blob: d0ea7069d4bbbe64d003a7b6d2e2553e6a23f738 [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>
Chris Lattneredfb72c2008-08-24 20:37:32 +000021using namespace llvm;
Dan Gohman69de1932008-02-06 22:27:42 +000022
Chris Lattneredfb72c2008-08-24 20:37:32 +000023static ManagedStatic<PseudoSourceValue[4]> PSVs;
Dan Gohman69de1932008-02-06 22:27:42 +000024
Chris Lattneredfb72c2008-08-24 20:37:32 +000025const PseudoSourceValue *PseudoSourceValue::getStack()
26{ return &(*PSVs)[0]; }
27const PseudoSourceValue *PseudoSourceValue::getGOT()
28{ return &(*PSVs)[1]; }
29const PseudoSourceValue *PseudoSourceValue::getJumpTable()
30{ return &(*PSVs)[2]; }
31const PseudoSourceValue *PseudoSourceValue::getConstantPool()
32{ return &(*PSVs)[3]; }
Dan Gohman69de1932008-02-06 22:27:42 +000033
Chris Lattneredfb72c2008-08-24 20:37:32 +000034static const char *const PSVNames[] = {
35 "Stack",
36 "GOT",
37 "JumpTable",
38 "ConstantPool"
39};
Dan Gohman69de1932008-02-06 22:27:42 +000040
Chris Lattneredfb72c2008-08-24 20:37:32 +000041PseudoSourceValue::PseudoSourceValue() :
42 Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {}
Dan Gohman69de1932008-02-06 22:27:42 +000043
Dan Gohmand71703d2008-12-03 21:37:21 +000044void PseudoSourceValue::dump() const {
45 print(errs()); errs() << '\n'; errs().flush();
46}
47
Chris Lattneredfb72c2008-08-24 20:37:32 +000048void PseudoSourceValue::print(raw_ostream &OS) const {
49 OS << PSVNames[this - *PSVs];
50}
Dan Gohmana54cf172008-07-11 22:44:52 +000051
Chris Lattneredfb72c2008-08-24 20:37:32 +000052namespace {
Dan Gohmana54cf172008-07-11 22:44:52 +000053 /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
54 /// for holding FixedStack values, which must include a frame
55 /// index.
56 class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
57 : public PseudoSourceValue {
58 const int FI;
59 public:
60 explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
Dan Gohman6d69ba82008-07-25 00:02:30 +000061
62 virtual bool isConstant(const MachineFrameInfo *MFI) const;
63
Evan Cheng40ab1642008-08-24 18:51:20 +000064 virtual void print(raw_ostream &OS) const {
65 OS << "FixedStack" << FI;
66 }
Dan Gohmana54cf172008-07-11 22:44:52 +000067 };
Chris Lattneredfb72c2008-08-24 20:37:32 +000068}
Dan Gohmana54cf172008-07-11 22:44:52 +000069
Chris Lattneredfb72c2008-08-24 20:37:32 +000070static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
Dan Gohmana54cf172008-07-11 22:44:52 +000071
Chris Lattneredfb72c2008-08-24 20:37:32 +000072const 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
Chris Lattneredfb72c2008-08-24 20:37:32 +000079bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
80 if (this == getStack())
Dan Gohman6d69ba82008-07-25 00:02:30 +000081 return false;
Chris Lattneredfb72c2008-08-24 20:37:32 +000082 if (this == getGOT() ||
83 this == getConstantPool() ||
84 this == getJumpTable())
85 return true;
86 assert(0 && "Unknown PseudoSourceValue!");
87 return false;
88}
Dan Gohman6d69ba82008-07-25 00:02:30 +000089
Chris Lattneredfb72c2008-08-24 20:37:32 +000090bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
91 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman69de1932008-02-06 22:27:42 +000092}