blob: 7fb3e6e6d2d287aac9d2aa68f6339861c0ac5deb [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"
Chris Lattner09979912009-10-27 17:02:08 +000017#include "llvm/LLVMContext.h"
Torok Edwin56d06592009-07-11 20:10:48 +000018#include "llvm/Support/ErrorHandling.h"
Dan Gohman2d489b52008-02-06 22:27:42 +000019#include "llvm/Support/ManagedStatic.h"
Evan Cheng72e7d912008-08-24 18:51:20 +000020#include "llvm/Support/raw_ostream.h"
Dan Gohman02c7c6c2008-07-11 22:44:52 +000021#include <map>
Chris Lattnera078d832008-08-24 20:37:32 +000022using namespace llvm;
Dan Gohman2d489b52008-02-06 22:27:42 +000023
Chris Lattnera078d832008-08-24 20:37:32 +000024static ManagedStatic<PseudoSourceValue[4]> PSVs;
Dan Gohman2d489b52008-02-06 22:27:42 +000025
Chris Lattnera078d832008-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 Gohman2d489b52008-02-06 22:27:42 +000034
Chris Lattnera078d832008-08-24 20:37:32 +000035static const char *const PSVNames[] = {
36 "Stack",
37 "GOT",
38 "JumpTable",
39 "ConstantPool"
40};
Dan Gohman2d489b52008-02-06 22:27:42 +000041
Owen Anderson55f1c092009-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 Greene81eb42d2009-11-12 20:25:07 +000046PseudoSourceValue::PseudoSourceValue(enum ValueTy Subclass) :
Duncan Sands9ed7b162009-10-06 15:40:36 +000047 Value(Type::getInt8PtrTy(getGlobalContext()),
David Greene81eb42d2009-11-12 20:25:07 +000048 Subclass) {}
Dan Gohman2d489b52008-02-06 22:27:42 +000049
Dan Gohmanc0353bf2009-09-23 01:33:16 +000050void PseudoSourceValue::printCustom(raw_ostream &O) const {
51 O << PSVNames[this - *PSVs];
Chris Lattnera078d832008-08-24 20:37:32 +000052}
Dan Gohman02c7c6c2008-07-11 22:44:52 +000053
Chris Lattnera078d832008-08-24 20:37:32 +000054static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
Dan Gohman02c7c6c2008-07-11 22:44:52 +000055
Evan Cheng87595852009-10-17 07:53:04 +000056const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
Chris Lattnera078d832008-08-24 20:37:32 +000057 const PseudoSourceValue *&V = (*FSValues)[FI];
58 if (!V)
Evan Cheng87595852009-10-17 07:53:04 +000059 V = new FixedStackPseudoSourceValue(FI);
Chris Lattnera078d832008-08-24 20:37:32 +000060 return V;
61}
Dan Gohman09b04482008-07-25 00:02:30 +000062
Chris Lattnera078d832008-08-24 20:37:32 +000063bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
64 if (this == getStack())
Dan Gohman09b04482008-07-25 00:02:30 +000065 return false;
Chris Lattnera078d832008-08-24 20:37:32 +000066 if (this == getGOT() ||
67 this == getConstantPool() ||
68 this == getJumpTable())
69 return true;
Torok Edwinfbcc6632009-07-14 16:55:14 +000070 llvm_unreachable("Unknown PseudoSourceValue!");
Chris Lattnera078d832008-08-24 20:37:32 +000071 return false;
72}
Dan Gohman09b04482008-07-25 00:02:30 +000073
Evan Chengf0236e02009-10-18 19:58:47 +000074bool PseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
Evan Cheng0e9d9ca2009-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 Chengea68c7c2009-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 Cheng87595852009-10-17 07:53:04 +000092bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
Chris Lattnera078d832008-08-24 20:37:32 +000093 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman2d489b52008-02-06 22:27:42 +000094}
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000095
Evan Chengf0236e02009-10-18 19:58:47 +000096bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
Evan Cheng0e9d9ca2009-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 Chengf0236e02009-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 Cheng0e9d9ca2009-10-18 18:16:27 +0000104}
Evan Chengea68c7c2009-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}
David Greene033d6552009-11-12 21:49:55 +0000112
113void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
114 OS << "FixedStack" << FI;
115}