1 //===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the PseudoSourceValue class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/PseudoSourceValue.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/CodeGen/MachineFrameInfo.h"
17 #include "llvm/CodeGen/TargetInstrInfo.h"
18 #include "llvm/IR/DerivedTypes.h"
19 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/raw_ostream.h"
24 static const char *const PSVNames
[] = {
25 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
26 "GlobalValueCallEntry", "ExternalSymbolCallEntry"};
28 PseudoSourceValue::PseudoSourceValue(unsigned Kind
, const TargetInstrInfo
&TII
)
30 AddressSpace
= TII
.getAddressSpaceForPseudoSourceKind(Kind
);
34 PseudoSourceValue::~PseudoSourceValue() {}
36 void PseudoSourceValue::printCustom(raw_ostream
&O
) const {
37 if (Kind
< TargetCustom
)
40 O
<< "TargetCustom" << Kind
;
43 bool PseudoSourceValue::isConstant(const MachineFrameInfo
*) const {
46 if (isGOT() || isConstantPool() || isJumpTable())
48 llvm_unreachable("Unknown PseudoSourceValue!");
51 bool PseudoSourceValue::isAliased(const MachineFrameInfo
*) const {
52 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
54 llvm_unreachable("Unknown PseudoSourceValue!");
57 bool PseudoSourceValue::mayAlias(const MachineFrameInfo
*) const {
58 return !(isGOT() || isConstantPool() || isJumpTable());
61 bool FixedStackPseudoSourceValue::isConstant(
62 const MachineFrameInfo
*MFI
) const {
63 return MFI
&& MFI
->isImmutableObjectIndex(FI
);
66 bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo
*MFI
) const {
69 return MFI
->isAliasedObjectIndex(FI
);
72 bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo
*MFI
) const {
75 // Spill slots will not alias any LLVM IR value.
76 return !MFI
->isSpillSlotObjectIndex(FI
);
79 void FixedStackPseudoSourceValue::printCustom(raw_ostream
&OS
) const {
80 OS
<< "FixedStack" << FI
;
83 CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(
84 unsigned Kind
, const TargetInstrInfo
&TII
)
85 : PseudoSourceValue(Kind
, TII
) {}
87 bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo
*) const {
91 bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo
*) const {
95 bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo
*) const {
99 GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
100 const GlobalValue
*GV
,
101 const TargetInstrInfo
&TII
)
102 : CallEntryPseudoSourceValue(GlobalValueCallEntry
, TII
), GV(GV
) {}
103 ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(
104 const char *ES
, const TargetInstrInfo
&TII
)
105 : CallEntryPseudoSourceValue(ExternalSymbolCallEntry
, TII
), ES(ES
) {}
107 PseudoSourceValueManager::PseudoSourceValueManager(
108 const TargetInstrInfo
&TIInfo
)
110 StackPSV(PseudoSourceValue::Stack
, TII
),
111 GOTPSV(PseudoSourceValue::GOT
, TII
),
112 JumpTablePSV(PseudoSourceValue::JumpTable
, TII
),
113 ConstantPoolPSV(PseudoSourceValue::ConstantPool
, TII
) {}
115 const PseudoSourceValue
*PseudoSourceValueManager::getStack() {
119 const PseudoSourceValue
*PseudoSourceValueManager::getGOT() { return &GOTPSV
; }
121 const PseudoSourceValue
*PseudoSourceValueManager::getConstantPool() {
122 return &ConstantPoolPSV
;
125 const PseudoSourceValue
*PseudoSourceValueManager::getJumpTable() {
126 return &JumpTablePSV
;
129 const PseudoSourceValue
*
130 PseudoSourceValueManager::getFixedStack(int FI
) {
131 std::unique_ptr
<FixedStackPseudoSourceValue
> &V
= FSValues
[FI
];
133 V
= llvm::make_unique
<FixedStackPseudoSourceValue
>(FI
, TII
);
137 const PseudoSourceValue
*
138 PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue
*GV
) {
139 std::unique_ptr
<const GlobalValuePseudoSourceValue
> &E
=
140 GlobalCallEntries
[GV
];
142 E
= llvm::make_unique
<GlobalValuePseudoSourceValue
>(GV
, TII
);
146 const PseudoSourceValue
*
147 PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES
) {
148 std::unique_ptr
<const ExternalSymbolPseudoSourceValue
> &E
=
149 ExternalCallEntries
[ES
];
151 E
= llvm::make_unique
<ExternalSymbolPseudoSourceValue
>(ES
, TII
);