1 //===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
23 static const char *const PSVNames
[] = {
24 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
25 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
27 PseudoSourceValue::PseudoSourceValue(unsigned Kind
, const TargetInstrInfo
&TII
)
29 AddressSpace
= TII
.getAddressSpaceForPseudoSourceKind(Kind
);
33 PseudoSourceValue::~PseudoSourceValue() {}
35 void PseudoSourceValue::printCustom(raw_ostream
&O
) const {
36 if (Kind
< TargetCustom
)
39 O
<< "TargetCustom" << Kind
;
42 bool PseudoSourceValue::isConstant(const MachineFrameInfo
*) const {
45 if (isGOT() || isConstantPool() || isJumpTable())
47 llvm_unreachable("Unknown PseudoSourceValue!");
50 bool PseudoSourceValue::isAliased(const MachineFrameInfo
*) const {
51 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
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 {
68 return MFI
->isAliasedObjectIndex(FI
);
71 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo
*MFI
) const {
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 {
90 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo
*) const {
94 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo
*) const {
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
)
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() {
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
];
132 V
= std::make_unique
<FixedStackPseudoSourceValue
>(FI
, TII
);
136 const PseudoSourceValue
*
137 PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue
*GV
) {
138 std::unique_ptr
<const GlobalValuePseudoSourceValue
> &E
=
139 GlobalCallEntries
[GV
];
141 E
= std::make_unique
<GlobalValuePseudoSourceValue
>(GV
, TII
);
145 const PseudoSourceValue
*
146 PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES
) {
147 std::unique_ptr
<const ExternalSymbolPseudoSourceValue
> &E
=
148 ExternalCallEntries
[ES
];
150 E
= std::make_unique
<ExternalSymbolPseudoSourceValue
>(ES
, TII
);