blob: 804a4c3dad6698afcb39dc5433b90f002e4e55c0 [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
14#include "llvm/CodeGen/PseudoSourceValue.h"
Mehdi Aminib550cb12016-04-18 09:17:29 +000015#include "llvm/ADT/STLExtras.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"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/Support/raw_ostream.h"
Chris Lattnera078d832008-08-24 20:37:32 +000021using namespace llvm;
Dan Gohman2d489b52008-02-06 22:27:42 +000022
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000023static const char *const PSVNames[] = {
Alex Lorenz5659a2f2015-08-11 23:23:17 +000024 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
25 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
Dan Gohman2d489b52008-02-06 22:27:42 +000026
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000027PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {}
Nick Lewyckyaad475b2014-04-15 07:22:52 +000028
29PseudoSourceValue::~PseudoSourceValue() {}
Dan Gohman2d489b52008-02-06 22:27:42 +000030
Dan Gohmanc0353bf2009-09-23 01:33:16 +000031void PseudoSourceValue::printCustom(raw_ostream &O) const {
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000032 O << PSVNames[Kind];
Chris Lattnera078d832008-08-24 20:37:32 +000033}
Dan Gohman02c7c6c2008-07-11 22:44:52 +000034
Chris Lattnera078d832008-08-24 20:37:32 +000035bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000036 if (isStack())
Dan Gohman09b04482008-07-25 00:02:30 +000037 return false;
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000038 if (isGOT() || isConstantPool() || isJumpTable())
Chris Lattnera078d832008-08-24 20:37:32 +000039 return true;
Torok Edwinfbcc6632009-07-14 16:55:14 +000040 llvm_unreachable("Unknown PseudoSourceValue!");
Chris Lattnera078d832008-08-24 20:37:32 +000041}
Dan Gohman09b04482008-07-25 00:02:30 +000042
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000043bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
44 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000045 return false;
46 llvm_unreachable("Unknown PseudoSourceValue!");
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000047}
48
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000049bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
Rafael Espindola84921b92015-10-24 23:11:13 +000050 return !(isGOT() || isConstantPool() || isJumpTable());
Evan Chengea68c7c2009-11-01 23:50:04 +000051}
52
Alex Lorenz4ae214d2015-08-11 22:17:22 +000053bool FixedStackPseudoSourceValue::isConstant(
54 const MachineFrameInfo *MFI) const {
Chris Lattnera078d832008-08-24 20:37:32 +000055 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman2d489b52008-02-06 22:27:42 +000056}
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000057
Evan Chengf0236e02009-10-18 19:58:47 +000058bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
Evan Chengf0236e02009-10-18 19:58:47 +000059 if (!MFI)
Hal Finkel0815a052014-08-16 00:17:02 +000060 return true;
61 return MFI->isAliasedObjectIndex(FI);
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000062}
Evan Chengea68c7c2009-11-01 23:50:04 +000063
64bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
65 if (!MFI)
66 return true;
67 // Spill slots will not alias any LLVM IR value.
68 return !MFI->isSpillSlotObjectIndex(FI);
69}
David Greene033d6552009-11-12 21:49:55 +000070
71void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
72 OS << "FixedStack" << FI;
73}
Alex Lorenze40c8a22015-08-11 23:09:45 +000074
Alex Lorenz5659a2f2015-08-11 23:23:17 +000075CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(PSVKind Kind)
76 : PseudoSourceValue(Kind) {}
77
78bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
79 return false;
80}
81
82bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
83 return false;
84}
85
86bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
87 return false;
88}
89
90GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
91 const GlobalValue *GV)
92 : CallEntryPseudoSourceValue(GlobalValueCallEntry), GV(GV) {}
93
94ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(const char *ES)
95 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry), ES(ES) {}
96
Alex Lorenze40c8a22015-08-11 23:09:45 +000097PseudoSourceValueManager::PseudoSourceValueManager()
98 : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
99 JumpTablePSV(PseudoSourceValue::JumpTable),
100 ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
101
102const PseudoSourceValue *PseudoSourceValueManager::getStack() {
103 return &StackPSV;
104}
105
106const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
107
108const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
109 return &ConstantPoolPSV;
110}
111
112const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
113 return &JumpTablePSV;
114}
115
116const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) {
117 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
118 if (!V)
119 V = llvm::make_unique<FixedStackPseudoSourceValue>(FI);
120 return V.get();
121}
Alex Lorenz5659a2f2015-08-11 23:23:17 +0000122
123const PseudoSourceValue *
124PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
125 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
126 GlobalCallEntries[GV];
127 if (!E)
128 E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV);
129 return E.get();
130}
131
132const PseudoSourceValue *
133PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
134 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
135 ExternalCallEntries[ES];
136 if (!E)
137 E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES);
138 return E.get();
139}