blob: b4c20e6bfd311c377b6567c5cfe46fece91479f1 [file] [log] [blame]
Dan Gohman2d489b52008-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 Gohman09b04482008-07-25 00:02:30 +000014#include "llvm/CodeGen/MachineFrameInfo.h"
Dan Gohman2d489b52008-02-06 22:27:42 +000015#include "llvm/CodeGen/PseudoSourceValue.h"
16#include "llvm/DerivedTypes.h"
Dan Gohman02c7c6c2008-07-11 22:44:52 +000017#include "llvm/Support/Compiler.h"
Dan Gohman2d489b52008-02-06 22:27:42 +000018#include "llvm/Support/ManagedStatic.h"
Evan Cheng72e7d912008-08-24 18:51:20 +000019#include "llvm/Support/raw_ostream.h"
Dan Gohman02c7c6c2008-07-11 22:44:52 +000020#include <map>
Chris Lattnera078d832008-08-24 20:37:32 +000021using namespace llvm;
Dan Gohman2d489b52008-02-06 22:27:42 +000022
Chris Lattnera078d832008-08-24 20:37:32 +000023static ManagedStatic<PseudoSourceValue[4]> PSVs;
Dan Gohman2d489b52008-02-06 22:27:42 +000024
Chris Lattnera078d832008-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 Gohman2d489b52008-02-06 22:27:42 +000033
Chris Lattnera078d832008-08-24 20:37:32 +000034static const char *const PSVNames[] = {
35 "Stack",
36 "GOT",
37 "JumpTable",
38 "ConstantPool"
39};
Dan Gohman2d489b52008-02-06 22:27:42 +000040
Chris Lattnera078d832008-08-24 20:37:32 +000041PseudoSourceValue::PseudoSourceValue() :
42 Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {}
Dan Gohman2d489b52008-02-06 22:27:42 +000043
Dan Gohmanee1cd172008-12-03 21:37:21 +000044void PseudoSourceValue::dump() const {
Dan Gohman4f2fea12009-03-23 15:57:19 +000045 print(errs()); errs() << '\n';
Dan Gohmanee1cd172008-12-03 21:37:21 +000046}
47
Chris Lattnera078d832008-08-24 20:37:32 +000048void PseudoSourceValue::print(raw_ostream &OS) const {
49 OS << PSVNames[this - *PSVs];
50}
Dan Gohman02c7c6c2008-07-11 22:44:52 +000051
Chris Lattnera078d832008-08-24 20:37:32 +000052namespace {
Dan Gohman02c7c6c2008-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 Gohman09b04482008-07-25 00:02:30 +000061
62 virtual bool isConstant(const MachineFrameInfo *MFI) const;
63
Evan Cheng72e7d912008-08-24 18:51:20 +000064 virtual void print(raw_ostream &OS) const {
65 OS << "FixedStack" << FI;
66 }
Dan Gohman02c7c6c2008-07-11 22:44:52 +000067 };
Chris Lattnera078d832008-08-24 20:37:32 +000068}
Dan Gohman02c7c6c2008-07-11 22:44:52 +000069
Chris Lattnera078d832008-08-24 20:37:32 +000070static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
Dan Gohman02c7c6c2008-07-11 22:44:52 +000071
Chris Lattnera078d832008-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 Gohman09b04482008-07-25 00:02:30 +000078
Chris Lattnera078d832008-08-24 20:37:32 +000079bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
80 if (this == getStack())
Dan Gohman09b04482008-07-25 00:02:30 +000081 return false;
Chris Lattnera078d832008-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 Gohman09b04482008-07-25 00:02:30 +000089
Chris Lattnera078d832008-08-24 20:37:32 +000090bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
91 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman2d489b52008-02-06 22:27:42 +000092}