blob: e95f017fc39694387af1841b491928a99ff3e744 [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"
Chris Lattner75c478a2009-10-27 17:02:08 +000017#include "llvm/LLVMContext.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
Owen Anderson1d0be152009-08-13 21:58:54 +000042// FIXME: THIS IS A HACK!!!!
43// Eventually these should be uniqued on LLVMContext rather than in a managed
44// static. For now, we can safely use the global context for the time being to
45// squeak by.
David Greenecf626322009-11-12 20:25:07 +000046PseudoSourceValue::PseudoSourceValue(enum ValueTy Subclass) :
Duncan Sandsac53a0b2009-10-06 15:40:36 +000047 Value(Type::getInt8PtrTy(getGlobalContext()),
David Greenecf626322009-11-12 20:25:07 +000048 Subclass) {}
Dan Gohman69de1932008-02-06 22:27:42 +000049
Dan Gohmancd26ec52009-09-23 01:33:16 +000050void PseudoSourceValue::printCustom(raw_ostream &O) const {
51 O << PSVNames[this - *PSVs];
Chris Lattneredfb72c2008-08-24 20:37:32 +000052}
Dan Gohmana54cf172008-07-11 22:44:52 +000053
Chris Lattneredfb72c2008-08-24 20:37:32 +000054static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
Dan Gohmana54cf172008-07-11 22:44:52 +000055
Evan Cheng65531552009-10-17 07:53:04 +000056const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
Chris Lattneredfb72c2008-08-24 20:37:32 +000057 const PseudoSourceValue *&V = (*FSValues)[FI];
58 if (!V)
Evan Cheng65531552009-10-17 07:53:04 +000059 V = new FixedStackPseudoSourceValue(FI);
Chris Lattneredfb72c2008-08-24 20:37:32 +000060 return V;
61}
Dan Gohman6d69ba82008-07-25 00:02:30 +000062
Chris Lattneredfb72c2008-08-24 20:37:32 +000063bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
64 if (this == getStack())
Dan Gohman6d69ba82008-07-25 00:02:30 +000065 return false;
Chris Lattneredfb72c2008-08-24 20:37:32 +000066 if (this == getGOT() ||
67 this == getConstantPool() ||
68 this == getJumpTable())
69 return true;
Torok Edwinc23197a2009-07-14 16:55:14 +000070 llvm_unreachable("Unknown PseudoSourceValue!");
Chris Lattneredfb72c2008-08-24 20:37:32 +000071 return false;
72}
Dan Gohman6d69ba82008-07-25 00:02:30 +000073
Evan Cheng38bdfc62009-10-18 19:58:47 +000074bool PseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
Evan Chengff89dcb2009-10-18 18:16:27 +000075 if (this == getStack() ||
76 this == getGOT() ||
77 this == getConstantPool() ||
78 this == getJumpTable())
79 return false;
80 llvm_unreachable("Unknown PseudoSourceValue!");
81 return true;
82}
83
Evan Chengf57b1ba2009-11-01 23:50:04 +000084bool PseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
85 if (this == getGOT() ||
86 this == getConstantPool() ||
87 this == getJumpTable())
88 return false;
89 return true;
90}
91
Evan Cheng65531552009-10-17 07:53:04 +000092bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
Chris Lattneredfb72c2008-08-24 20:37:32 +000093 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman69de1932008-02-06 22:27:42 +000094}
Evan Chengff89dcb2009-10-18 18:16:27 +000095
Evan Cheng38bdfc62009-10-18 19:58:47 +000096bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
Evan Chengff89dcb2009-10-18 18:16:27 +000097 // Negative frame indices are used for special things that don't
98 // appear in LLVM IR. Non-negative indices may be used for things
99 // like static allocas.
Evan Cheng38bdfc62009-10-18 19:58:47 +0000100 if (!MFI)
101 return FI >= 0;
102 // Spill slots should not alias others.
103 return !MFI->isFixedObjectIndex(FI) && !MFI->isSpillSlotObjectIndex(FI);
Evan Chengff89dcb2009-10-18 18:16:27 +0000104}
Evan Chengf57b1ba2009-11-01 23:50:04 +0000105
106bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
107 if (!MFI)
108 return true;
109 // Spill slots will not alias any LLVM IR value.
110 return !MFI->isSpillSlotObjectIndex(FI);
111}