blob: 6ca8d86e3f8e12d6875189fce124139ced1d1633 [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
14#include "llvm/CodeGen/PseudoSourceValue.h"
Mehdi Aminif6071e12016-04-18 09:17:29 +000015#include "llvm/ADT/STLExtras.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000016#include "llvm/CodeGen/MachineFrameInfo.h"
David Blaikie48319232017-11-08 01:01:31 +000017#include "llvm/CodeGen/TargetInstrInfo.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000018#include "llvm/IR/DerivedTypes.h"
19#include "llvm/IR/LLVMContext.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000020#include "llvm/Support/ErrorHandling.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000021#include "llvm/Support/raw_ostream.h"
Chris Lattneredfb72c2008-08-24 20:37:32 +000022using namespace llvm;
Dan Gohman69de1932008-02-06 22:27:42 +000023
Alex Lorenzc18bd9d2015-08-11 22:32:00 +000024static const char *const PSVNames[] = {
Alex Lorenzc1661a32015-08-11 23:23:17 +000025 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
26 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
Dan Gohman69de1932008-02-06 22:27:42 +000027
Marcello Maggionib0ab6f72018-08-20 19:23:45 +000028PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII)
Jan Sjodin028255f2017-09-14 20:53:51 +000029 : Kind(Kind) {
30 AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind);
31}
32
Nick Lewyckyd63390c2014-04-15 07:22:52 +000033
34PseudoSourceValue::~PseudoSourceValue() {}
Dan Gohman69de1932008-02-06 22:27:42 +000035
Dan Gohmancd26ec52009-09-23 01:33:16 +000036void PseudoSourceValue::printCustom(raw_ostream &O) const {
Matt Arsenault98ede9e2017-03-28 20:33:12 +000037 if (Kind < TargetCustom)
38 O << PSVNames[Kind];
39 else
40 O << "TargetCustom" << Kind;
Chris Lattneredfb72c2008-08-24 20:37:32 +000041}
Dan Gohmana54cf172008-07-11 22:44:52 +000042
Chris Lattneredfb72c2008-08-24 20:37:32 +000043bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
Alex Lorenzc18bd9d2015-08-11 22:32:00 +000044 if (isStack())
Dan Gohman6d69ba82008-07-25 00:02:30 +000045 return false;
Alex Lorenzc18bd9d2015-08-11 22:32:00 +000046 if (isGOT() || isConstantPool() || isJumpTable())
Chris Lattneredfb72c2008-08-24 20:37:32 +000047 return true;
Torok Edwinc23197a2009-07-14 16:55:14 +000048 llvm_unreachable("Unknown PseudoSourceValue!");
Chris Lattneredfb72c2008-08-24 20:37:32 +000049}
Dan Gohman6d69ba82008-07-25 00:02:30 +000050
Alex Lorenzc18bd9d2015-08-11 22:32:00 +000051bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
52 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
Evan Chengff89dcb2009-10-18 18:16:27 +000053 return false;
54 llvm_unreachable("Unknown PseudoSourceValue!");
Evan Chengff89dcb2009-10-18 18:16:27 +000055}
56
Alex Lorenzc18bd9d2015-08-11 22:32:00 +000057bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
Rafael Espindola2fe94b62015-10-24 23:11:13 +000058 return !(isGOT() || isConstantPool() || isJumpTable());
Evan Chengf57b1ba2009-11-01 23:50:04 +000059}
60
Alex Lorenz60ae8c82015-08-11 22:17:22 +000061bool FixedStackPseudoSourceValue::isConstant(
62 const MachineFrameInfo *MFI) const {
Chris Lattneredfb72c2008-08-24 20:37:32 +000063 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman69de1932008-02-06 22:27:42 +000064}
Evan Chengff89dcb2009-10-18 18:16:27 +000065
Evan Cheng38bdfc62009-10-18 19:58:47 +000066bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
Evan Cheng38bdfc62009-10-18 19:58:47 +000067 if (!MFI)
Hal Finkel227df4b2014-08-16 00:17:02 +000068 return true;
69 return MFI->isAliasedObjectIndex(FI);
Evan Chengff89dcb2009-10-18 18:16:27 +000070}
Evan Chengf57b1ba2009-11-01 23:50:04 +000071
72bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
73 if (!MFI)
74 return true;
75 // Spill slots will not alias any LLVM IR value.
76 return !MFI->isSpillSlotObjectIndex(FI);
77}
David Greeneb3bc1152009-11-12 21:49:55 +000078
79void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
80 OS << "FixedStack" << FI;
81}
Alex Lorenzde0129a2015-08-11 23:09:45 +000082
Jan Sjodin028255f2017-09-14 20:53:51 +000083CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(
Marcello Maggionib0ab6f72018-08-20 19:23:45 +000084 unsigned Kind, const TargetInstrInfo &TII)
Jan Sjodin028255f2017-09-14 20:53:51 +000085 : PseudoSourceValue(Kind, TII) {}
Alex Lorenzc1661a32015-08-11 23:23:17 +000086
87bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
88 return false;
89}
90
91bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
92 return false;
93}
94
95bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
96 return false;
97}
98
99GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
Jan Sjodin028255f2017-09-14 20:53:51 +0000100 const GlobalValue *GV,
101 const TargetInstrInfo &TII)
102 : CallEntryPseudoSourceValue(GlobalValueCallEntry, TII), GV(GV) {}
103ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(
104 const char *ES, const TargetInstrInfo &TII)
105 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TII), ES(ES) {}
Alex Lorenzc1661a32015-08-11 23:23:17 +0000106
Jan Sjodin028255f2017-09-14 20:53:51 +0000107PseudoSourceValueManager::PseudoSourceValueManager(
108 const TargetInstrInfo &TIInfo)
109 : TII(TIInfo),
110 StackPSV(PseudoSourceValue::Stack, TII),
111 GOTPSV(PseudoSourceValue::GOT, TII),
112 JumpTablePSV(PseudoSourceValue::JumpTable, TII),
113 ConstantPoolPSV(PseudoSourceValue::ConstantPool, TII) {}
Alex Lorenzde0129a2015-08-11 23:09:45 +0000114
115const PseudoSourceValue *PseudoSourceValueManager::getStack() {
116 return &StackPSV;
117}
118
119const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
120
121const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
122 return &ConstantPoolPSV;
123}
124
125const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
126 return &JumpTablePSV;
127}
128
Jan Sjodin028255f2017-09-14 20:53:51 +0000129const PseudoSourceValue *
130PseudoSourceValueManager::getFixedStack(int FI) {
Alex Lorenzde0129a2015-08-11 23:09:45 +0000131 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
132 if (!V)
Jan Sjodin028255f2017-09-14 20:53:51 +0000133 V = llvm::make_unique<FixedStackPseudoSourceValue>(FI, TII);
Alex Lorenzde0129a2015-08-11 23:09:45 +0000134 return V.get();
135}
Alex Lorenzc1661a32015-08-11 23:23:17 +0000136
137const PseudoSourceValue *
138PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
139 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
140 GlobalCallEntries[GV];
141 if (!E)
Jan Sjodin028255f2017-09-14 20:53:51 +0000142 E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV, TII);
Alex Lorenzc1661a32015-08-11 23:23:17 +0000143 return E.get();
144}
145
146const PseudoSourceValue *
147PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
148 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
149 ExternalCallEntries[ES];
150 if (!E)
Jan Sjodin028255f2017-09-14 20:53:51 +0000151 E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES, TII);
Alex Lorenzc1661a32015-08-11 23:23:17 +0000152 return E.get();
153}