blob: da54c69e36c616bff9685d71086b3d3f58e192e0 [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 {
53 if (isGOT() || isConstantPool() || isJumpTable())
Evan Chengea68c7c2009-11-01 23:50:04 +000054 return false;
55 return true;
56}
57
Alex Lorenz4ae214d2015-08-11 22:17:22 +000058bool FixedStackPseudoSourceValue::isConstant(
59 const MachineFrameInfo *MFI) const {
Chris Lattnera078d832008-08-24 20:37:32 +000060 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman2d489b52008-02-06 22:27:42 +000061}
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000062
Evan Chengf0236e02009-10-18 19:58:47 +000063bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
Evan Chengf0236e02009-10-18 19:58:47 +000064 if (!MFI)
Hal Finkel0815a052014-08-16 00:17:02 +000065 return true;
66 return MFI->isAliasedObjectIndex(FI);
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000067}
Evan Chengea68c7c2009-11-01 23:50:04 +000068
69bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
70 if (!MFI)
71 return true;
72 // Spill slots will not alias any LLVM IR value.
73 return !MFI->isSpillSlotObjectIndex(FI);
74}
David Greene033d6552009-11-12 21:49:55 +000075
76void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
77 OS << "FixedStack" << FI;
78}
Alex Lorenze40c8a22015-08-11 23:09:45 +000079
Alex Lorenz5659a2f2015-08-11 23:23:17 +000080CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(PSVKind Kind)
81 : PseudoSourceValue(Kind) {}
82
83bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
84 return false;
85}
86
87bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
88 return false;
89}
90
91bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
92 return false;
93}
94
95GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
96 const GlobalValue *GV)
97 : CallEntryPseudoSourceValue(GlobalValueCallEntry), GV(GV) {}
98
99ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(const char *ES)
100 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry), ES(ES) {}
101
Alex Lorenze40c8a22015-08-11 23:09:45 +0000102PseudoSourceValueManager::PseudoSourceValueManager()
103 : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
104 JumpTablePSV(PseudoSourceValue::JumpTable),
105 ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
106
107const PseudoSourceValue *PseudoSourceValueManager::getStack() {
108 return &StackPSV;
109}
110
111const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
112
113const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
114 return &ConstantPoolPSV;
115}
116
117const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
118 return &JumpTablePSV;
119}
120
121const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) {
122 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
123 if (!V)
124 V = llvm::make_unique<FixedStackPseudoSourceValue>(FI);
125 return V.get();
126}
Alex Lorenz5659a2f2015-08-11 23:23:17 +0000127
128const PseudoSourceValue *
129PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
130 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
131 GlobalCallEntries[GV];
132 if (!E)
133 E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV);
134 return E.get();
135}
136
137const PseudoSourceValue *
138PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
139 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
140 ExternalCallEntries[ES];
141 if (!E)
142 E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES);
143 return E.get();
144}