blob: 1f46417e61e7f8a93c68a9bcce64507e4d6a2ea2 [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
Alex Lorenze40c8a22015-08-11 23:09:45 +000014#include "llvm/ADT/STLExtras.h"
Dan Gohman2d489b52008-02-06 22:27:42 +000015#include "llvm/CodeGen/PseudoSourceValue.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000017#include "llvm/IR/DerivedTypes.h"
18#include "llvm/IR/LLVMContext.h"
Torok Edwin56d06592009-07-11 20:10:48 +000019#include "llvm/Support/ErrorHandling.h"
Dan Gohman2d489b52008-02-06 22:27:42 +000020#include "llvm/Support/ManagedStatic.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000021#include "llvm/Support/Mutex.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/Support/raw_ostream.h"
Dan Gohman02c7c6c2008-07-11 22:44:52 +000023#include <map>
Chris Lattnera078d832008-08-24 20:37:32 +000024using namespace llvm;
Dan Gohman2d489b52008-02-06 22:27:42 +000025
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000026static const char *const PSVNames[] = {
Alex Lorenz5659a2f2015-08-11 23:23:17 +000027 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
28 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
Dan Gohman2d489b52008-02-06 22:27:42 +000029
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000030PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {}
Nick Lewyckyaad475b2014-04-15 07:22:52 +000031
32PseudoSourceValue::~PseudoSourceValue() {}
Dan Gohman2d489b52008-02-06 22:27:42 +000033
Dan Gohmanc0353bf2009-09-23 01:33:16 +000034void PseudoSourceValue::printCustom(raw_ostream &O) const {
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000035 O << PSVNames[Kind];
Chris Lattnera078d832008-08-24 20:37:32 +000036}
Dan Gohman02c7c6c2008-07-11 22:44:52 +000037
Chris Lattnera078d832008-08-24 20:37:32 +000038bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000039 if (isStack())
Dan Gohman09b04482008-07-25 00:02:30 +000040 return false;
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000041 if (isGOT() || isConstantPool() || isJumpTable())
Chris Lattnera078d832008-08-24 20:37:32 +000042 return true;
Torok Edwinfbcc6632009-07-14 16:55:14 +000043 llvm_unreachable("Unknown PseudoSourceValue!");
Chris Lattnera078d832008-08-24 20:37:32 +000044}
Dan Gohman09b04482008-07-25 00:02:30 +000045
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000046bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
47 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000048 return false;
49 llvm_unreachable("Unknown PseudoSourceValue!");
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000050}
51
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000052bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
Rafael Espindola84921b92015-10-24 23:11:13 +000053 return !(isGOT() || isConstantPool() || isJumpTable());
Evan Chengea68c7c2009-11-01 23:50:04 +000054}
55
Alex Lorenz4ae214d2015-08-11 22:17:22 +000056bool FixedStackPseudoSourceValue::isConstant(
57 const MachineFrameInfo *MFI) const {
Chris Lattnera078d832008-08-24 20:37:32 +000058 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman2d489b52008-02-06 22:27:42 +000059}
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000060
Evan Chengf0236e02009-10-18 19:58:47 +000061bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
Evan Chengf0236e02009-10-18 19:58:47 +000062 if (!MFI)
Hal Finkel0815a052014-08-16 00:17:02 +000063 return true;
64 return MFI->isAliasedObjectIndex(FI);
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000065}
Evan Chengea68c7c2009-11-01 23:50:04 +000066
67bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
68 if (!MFI)
69 return true;
70 // Spill slots will not alias any LLVM IR value.
71 return !MFI->isSpillSlotObjectIndex(FI);
72}
David Greene033d6552009-11-12 21:49:55 +000073
74void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
75 OS << "FixedStack" << FI;
76}
Alex Lorenze40c8a22015-08-11 23:09:45 +000077
Alex Lorenz5659a2f2015-08-11 23:23:17 +000078CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(PSVKind Kind)
79 : PseudoSourceValue(Kind) {}
80
81bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
82 return false;
83}
84
85bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
86 return false;
87}
88
89bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
90 return false;
91}
92
93GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
94 const GlobalValue *GV)
95 : CallEntryPseudoSourceValue(GlobalValueCallEntry), GV(GV) {}
96
97ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(const char *ES)
98 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry), ES(ES) {}
99
Alex Lorenze40c8a22015-08-11 23:09:45 +0000100PseudoSourceValueManager::PseudoSourceValueManager()
101 : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
102 JumpTablePSV(PseudoSourceValue::JumpTable),
103 ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
104
105const PseudoSourceValue *PseudoSourceValueManager::getStack() {
106 return &StackPSV;
107}
108
109const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
110
111const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
112 return &ConstantPoolPSV;
113}
114
115const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
116 return &JumpTablePSV;
117}
118
119const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) {
120 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
121 if (!V)
122 V = llvm::make_unique<FixedStackPseudoSourceValue>(FI);
123 return V.get();
124}
Alex Lorenz5659a2f2015-08-11 23:23:17 +0000125
126const PseudoSourceValue *
127PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
128 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
129 GlobalCallEntries[GV];
130 if (!E)
131 E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV);
132 return E.get();
133}
134
135const PseudoSourceValue *
136PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
137 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
138 ExternalCallEntries[ES];
139 if (!E)
140 E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES);
141 return E.get();
142}