1//===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the PseudoSourceValue class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/CodeGen/PseudoSourceValue.h"
14#include "llvm/CodeGen/MachineFrameInfo.h"
15#include "llvm/CodeGen/PseudoSourceValueManager.h"
16#include "llvm/Support/ErrorHandling.h"
17#include "llvm/Support/raw_ostream.h"
18#include "llvm/Target/TargetMachine.h"
19
20using namespace llvm;
21
22static const char *const PSVNames[] = {
23 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
24 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
25
26PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetMachine &TM)
27 : Kind(Kind) {
28 AddressSpace = TM.getAddressSpaceForPseudoSourceKind(Kind);
29}
30
31PseudoSourceValue::~PseudoSourceValue() = default;
32
33void PseudoSourceValue::printCustom(raw_ostream &O) const {
34 if (Kind < TargetCustom)
35 O << PSVNames[Kind];
36 else
37 O << "TargetCustom" << Kind;
38}
39
40bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
41 if (isStack())
42 return false;
43 if (isGOT() || isConstantPool() || isJumpTable())
44 return true;
45 llvm_unreachable("Unknown PseudoSourceValue!");
46}
47
48bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
49 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
50 return false;
51 llvm_unreachable("Unknown PseudoSourceValue!");
52}
53
54bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
55 return !(isGOT() || isConstantPool() || isJumpTable());
56}
57
58bool FixedStackPseudoSourceValue::isConstant(
59 const MachineFrameInfo *MFI) const {
60 return MFI && MFI->isImmutableObjectIndex(ObjectIdx: FI);
61}
62
63bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
64 if (!MFI)
65 return true;
66 return MFI->isAliasedObjectIndex(ObjectIdx: FI);
67}
68
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(ObjectIdx: FI);
74}
75
76void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
77 OS << "FixedStack" << FI;
78}
79
80CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(unsigned Kind,
81 const TargetMachine &TM)
82 : PseudoSourceValue(Kind, TM) {}
83
84bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
85 return false;
86}
87
88bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
89 return false;
90}
91
92bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
93 return false;
94}
95
96GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
97 const GlobalValue *GV, const TargetMachine &TM)
98 : CallEntryPseudoSourceValue(GlobalValueCallEntry, TM), GV(GV) {}
99ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(
100 const char *ES, const TargetMachine &TM)
101 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TM), ES(ES) {}
102
103PseudoSourceValueManager::PseudoSourceValueManager(const TargetMachine &TMInfo)
104 : TM(TMInfo), StackPSV(PseudoSourceValue::Stack, TM),
105 GOTPSV(PseudoSourceValue::GOT, TM),
106 JumpTablePSV(PseudoSourceValue::JumpTable, TM),
107 ConstantPoolPSV(PseudoSourceValue::ConstantPool, TM) {}
108
109const PseudoSourceValue *PseudoSourceValueManager::getStack() {
110 return &StackPSV;
111}
112
113const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
114
115const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
116 return &ConstantPoolPSV;
117}
118
119const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
120 return &JumpTablePSV;
121}
122
123const PseudoSourceValue *
124PseudoSourceValueManager::getFixedStack(int FI) {
125 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
126 if (!V)
127 V = std::make_unique<FixedStackPseudoSourceValue>(args&: FI, args: TM);
128 return V.get();
129}
130
131const PseudoSourceValue *
132PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
133 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
134 GlobalCallEntries[GV];
135 if (!E)
136 E = std::make_unique<GlobalValuePseudoSourceValue>(args&: GV, args: TM);
137 return E.get();
138}
139
140const PseudoSourceValue *
141PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
142 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
143 ExternalCallEntries[ES];
144 if (!E)
145 E = std::make_unique<ExternalSymbolPseudoSourceValue>(args&: ES, args: TM);
146 return E.get();
147}
148

source code of llvm/lib/CodeGen/PseudoSourceValue.cpp