blob: 8c9de810597dbd9ef8334aa093cb7f503f5db863 [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
Chris Lattneredfb72c2008-08-24 20:37:32 +000044void PseudoSourceValue::print(raw_ostream &OS) const {
45 OS << PSVNames[this - *PSVs];
46}
Dan Gohmana54cf172008-07-11 22:44:52 +000047
Chris Lattneredfb72c2008-08-24 20:37:32 +000048namespace {
Dan Gohmana54cf172008-07-11 22:44:52 +000049 /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
50 /// for holding FixedStack values, which must include a frame
51 /// index.
52 class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
53 : public PseudoSourceValue {
54 const int FI;
55 public:
56 explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
Dan Gohman6d69ba82008-07-25 00:02:30 +000057
58 virtual bool isConstant(const MachineFrameInfo *MFI) const;
59
Dan Gohmana54cf172008-07-11 22:44:52 +000060 virtual void print(std::ostream &OS) const {
61 OS << "FixedStack" << FI;
62 }
Evan Cheng40ab1642008-08-24 18:51:20 +000063 virtual void print(raw_ostream &OS) const {
64 OS << "FixedStack" << FI;
65 }
Dan Gohmana54cf172008-07-11 22:44:52 +000066 };
Chris Lattneredfb72c2008-08-24 20:37:32 +000067}
Dan Gohmana54cf172008-07-11 22:44:52 +000068
Chris Lattneredfb72c2008-08-24 20:37:32 +000069static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
Dan Gohmana54cf172008-07-11 22:44:52 +000070
Chris Lattneredfb72c2008-08-24 20:37:32 +000071const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
72 const PseudoSourceValue *&V = (*FSValues)[FI];
73 if (!V)
74 V = new FixedStackPseudoSourceValue(FI);
75 return V;
76}
Dan Gohman6d69ba82008-07-25 00:02:30 +000077
Chris Lattneredfb72c2008-08-24 20:37:32 +000078bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
79 if (this == getStack())
Dan Gohman6d69ba82008-07-25 00:02:30 +000080 return false;
Chris Lattneredfb72c2008-08-24 20:37:32 +000081 if (this == getGOT() ||
82 this == getConstantPool() ||
83 this == getJumpTable())
84 return true;
85 assert(0 && "Unknown PseudoSourceValue!");
86 return false;
87}
Dan Gohman6d69ba82008-07-25 00:02:30 +000088
Chris Lattneredfb72c2008-08-24 20:37:32 +000089bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
90 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman69de1932008-02-06 22:27:42 +000091}