[InstCombine] Signed saturation tests. NFC
[llvm-complete.git] / lib / CodeGen / PseudoSourceValue.cpp
blob74e721dbd138865f0d21eb20a55757441e3a3edc
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.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/CodeGen/PseudoSourceValue.h"
14 #include "llvm/ADT/STLExtras.h"
15 #include "llvm/CodeGen/MachineFrameInfo.h"
16 #include "llvm/CodeGen/TargetInstrInfo.h"
17 #include "llvm/IR/DerivedTypes.h"
18 #include "llvm/IR/LLVMContext.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/raw_ostream.h"
21 using namespace llvm;
23 static const char *const PSVNames[] = {
24 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
25 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
27 PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII)
28 : Kind(Kind) {
29 AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind);
33 PseudoSourceValue::~PseudoSourceValue() {}
35 void PseudoSourceValue::printCustom(raw_ostream &O) const {
36 if (Kind < TargetCustom)
37 O << PSVNames[Kind];
38 else
39 O << "TargetCustom" << Kind;
42 bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
43 if (isStack())
44 return false;
45 if (isGOT() || isConstantPool() || isJumpTable())
46 return true;
47 llvm_unreachable("Unknown PseudoSourceValue!");
50 bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
51 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
52 return false;
53 llvm_unreachable("Unknown PseudoSourceValue!");
56 bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
57 return !(isGOT() || isConstantPool() || isJumpTable());
60 bool FixedStackPseudoSourceValue::isConstant(
61 const MachineFrameInfo *MFI) const {
62 return MFI && MFI->isImmutableObjectIndex(FI);
65 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
66 if (!MFI)
67 return true;
68 return MFI->isAliasedObjectIndex(FI);
71 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
72 if (!MFI)
73 return true;
74 // Spill slots will not alias any LLVM IR value.
75 return !MFI->isSpillSlotObjectIndex(FI);
78 void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
79 OS << "FixedStack" << FI;
82 CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(
83 unsigned Kind, const TargetInstrInfo &TII)
84 : PseudoSourceValue(Kind, TII) {}
86 bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
87 return false;
90 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
91 return false;
94 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
95 return false;
98 GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
99 const GlobalValue *GV,
100 const TargetInstrInfo &TII)
101 : CallEntryPseudoSourceValue(GlobalValueCallEntry, TII), GV(GV) {}
102 ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(
103 const char *ES, const TargetInstrInfo &TII)
104 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TII), ES(ES) {}
106 PseudoSourceValueManager::PseudoSourceValueManager(
107 const TargetInstrInfo &TIInfo)
108 : TII(TIInfo),
109 StackPSV(PseudoSourceValue::Stack, TII),
110 GOTPSV(PseudoSourceValue::GOT, TII),
111 JumpTablePSV(PseudoSourceValue::JumpTable, TII),
112 ConstantPoolPSV(PseudoSourceValue::ConstantPool, TII) {}
114 const PseudoSourceValue *PseudoSourceValueManager::getStack() {
115 return &StackPSV;
118 const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
120 const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
121 return &ConstantPoolPSV;
124 const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
125 return &JumpTablePSV;
128 const PseudoSourceValue *
129 PseudoSourceValueManager::getFixedStack(int FI) {
130 std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
131 if (!V)
132 V = std::make_unique<FixedStackPseudoSourceValue>(FI, TII);
133 return V.get();
136 const PseudoSourceValue *
137 PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
138 std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
139 GlobalCallEntries[GV];
140 if (!E)
141 E = std::make_unique<GlobalValuePseudoSourceValue>(GV, TII);
142 return E.get();
145 const PseudoSourceValue *
146 PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
147 std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
148 ExternalCallEntries[ES];
149 if (!E)
150 E = std::make_unique<ExternalSymbolPseudoSourceValue>(ES, TII);
151 return E.get();