Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1 | //===-- 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 Amini | f6071e1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineFrameInfo.h" |
David Blaikie | 4831923 | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/TargetInstrInfo.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/DerivedTypes.h" |
| 19 | #include "llvm/IR/LLVMContext.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 20 | #include "llvm/Support/ErrorHandling.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 22 | using namespace llvm; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 23 | |
Alex Lorenz | c18bd9d | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 24 | static const char *const PSVNames[] = { |
Alex Lorenz | c1661a3 | 2015-08-11 23:23:17 +0000 | [diff] [blame] | 25 | "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack", |
| 26 | "GlobalValueCallEntry", "ExternalSymbolCallEntry"}; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 27 | |
Marcello Maggioni | b0ab6f7 | 2018-08-20 19:23:45 +0000 | [diff] [blame] | 28 | PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII) |
Jan Sjodin | 028255f | 2017-09-14 20:53:51 +0000 | [diff] [blame] | 29 | : Kind(Kind) { |
| 30 | AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind); |
| 31 | } |
| 32 | |
Nick Lewycky | d63390c | 2014-04-15 07:22:52 +0000 | [diff] [blame] | 33 | |
| 34 | PseudoSourceValue::~PseudoSourceValue() {} |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 35 | |
Dan Gohman | cd26ec5 | 2009-09-23 01:33:16 +0000 | [diff] [blame] | 36 | void PseudoSourceValue::printCustom(raw_ostream &O) const { |
Matt Arsenault | 98ede9e | 2017-03-28 20:33:12 +0000 | [diff] [blame] | 37 | if (Kind < TargetCustom) |
| 38 | O << PSVNames[Kind]; |
| 39 | else |
| 40 | O << "TargetCustom" << Kind; |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 41 | } |
Dan Gohman | a54cf17 | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 42 | |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 43 | bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { |
Alex Lorenz | c18bd9d | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 44 | if (isStack()) |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 45 | return false; |
Alex Lorenz | c18bd9d | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 46 | if (isGOT() || isConstantPool() || isJumpTable()) |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 47 | return true; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 48 | llvm_unreachable("Unknown PseudoSourceValue!"); |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 49 | } |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 50 | |
Alex Lorenz | c18bd9d | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 51 | bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const { |
| 52 | if (isStack() || isGOT() || isConstantPool() || isJumpTable()) |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 53 | return false; |
| 54 | llvm_unreachable("Unknown PseudoSourceValue!"); |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Alex Lorenz | c18bd9d | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 57 | bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const { |
Rafael Espindola | 2fe94b6 | 2015-10-24 23:11:13 +0000 | [diff] [blame] | 58 | return !(isGOT() || isConstantPool() || isJumpTable()); |
Evan Cheng | f57b1ba | 2009-11-01 23:50:04 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Alex Lorenz | 60ae8c8 | 2015-08-11 22:17:22 +0000 | [diff] [blame] | 61 | bool FixedStackPseudoSourceValue::isConstant( |
| 62 | const MachineFrameInfo *MFI) const { |
Chris Lattner | edfb72c | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 63 | return MFI && MFI->isImmutableObjectIndex(FI); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 64 | } |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 65 | |
Evan Cheng | 38bdfc6 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 66 | bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { |
Evan Cheng | 38bdfc6 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 67 | if (!MFI) |
Hal Finkel | 227df4b | 2014-08-16 00:17:02 +0000 | [diff] [blame] | 68 | return true; |
| 69 | return MFI->isAliasedObjectIndex(FI); |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 70 | } |
Evan Cheng | f57b1ba | 2009-11-01 23:50:04 +0000 | [diff] [blame] | 71 | |
| 72 | bool 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 Greene | b3bc115 | 2009-11-12 21:49:55 +0000 | [diff] [blame] | 78 | |
| 79 | void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const { |
| 80 | OS << "FixedStack" << FI; |
| 81 | } |
Alex Lorenz | de0129a | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 82 | |
Jan Sjodin | 028255f | 2017-09-14 20:53:51 +0000 | [diff] [blame] | 83 | CallEntryPseudoSourceValue::CallEntryPseudoSourceValue( |
Marcello Maggioni | b0ab6f7 | 2018-08-20 19:23:45 +0000 | [diff] [blame] | 84 | unsigned Kind, const TargetInstrInfo &TII) |
Jan Sjodin | 028255f | 2017-09-14 20:53:51 +0000 | [diff] [blame] | 85 | : PseudoSourceValue(Kind, TII) {} |
Alex Lorenz | c1661a3 | 2015-08-11 23:23:17 +0000 | [diff] [blame] | 86 | |
| 87 | bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const { |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue( |
Jan Sjodin | 028255f | 2017-09-14 20:53:51 +0000 | [diff] [blame] | 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) {} |
Alex Lorenz | c1661a3 | 2015-08-11 23:23:17 +0000 | [diff] [blame] | 106 | |
Jan Sjodin | 028255f | 2017-09-14 20:53:51 +0000 | [diff] [blame] | 107 | PseudoSourceValueManager::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 Lorenz | de0129a | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 114 | |
| 115 | const PseudoSourceValue *PseudoSourceValueManager::getStack() { |
| 116 | return &StackPSV; |
| 117 | } |
| 118 | |
| 119 | const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; } |
| 120 | |
| 121 | const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() { |
| 122 | return &ConstantPoolPSV; |
| 123 | } |
| 124 | |
| 125 | const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() { |
| 126 | return &JumpTablePSV; |
| 127 | } |
| 128 | |
Jan Sjodin | 028255f | 2017-09-14 20:53:51 +0000 | [diff] [blame] | 129 | const PseudoSourceValue * |
| 130 | PseudoSourceValueManager::getFixedStack(int FI) { |
Alex Lorenz | de0129a | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 131 | std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI]; |
| 132 | if (!V) |
Jan Sjodin | 028255f | 2017-09-14 20:53:51 +0000 | [diff] [blame] | 133 | V = llvm::make_unique<FixedStackPseudoSourceValue>(FI, TII); |
Alex Lorenz | de0129a | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 134 | return V.get(); |
| 135 | } |
Alex Lorenz | c1661a3 | 2015-08-11 23:23:17 +0000 | [diff] [blame] | 136 | |
| 137 | const PseudoSourceValue * |
| 138 | PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) { |
| 139 | std::unique_ptr<const GlobalValuePseudoSourceValue> &E = |
| 140 | GlobalCallEntries[GV]; |
| 141 | if (!E) |
Jan Sjodin | 028255f | 2017-09-14 20:53:51 +0000 | [diff] [blame] | 142 | E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV, TII); |
Alex Lorenz | c1661a3 | 2015-08-11 23:23:17 +0000 | [diff] [blame] | 143 | return E.get(); |
| 144 | } |
| 145 | |
| 146 | const PseudoSourceValue * |
| 147 | PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) { |
| 148 | std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E = |
| 149 | ExternalCallEntries[ES]; |
| 150 | if (!E) |
Jan Sjodin | 028255f | 2017-09-14 20:53:51 +0000 | [diff] [blame] | 151 | E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES, TII); |
Alex Lorenz | c1661a3 | 2015-08-11 23:23:17 +0000 | [diff] [blame] | 152 | return E.get(); |
| 153 | } |