Dan Gohman | 2d489b5 | 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 | |
Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/STLExtras.h" |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 17 | #include "llvm/IR/DerivedTypes.h" |
| 18 | #include "llvm/IR/LLVMContext.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 19 | #include "llvm/Support/ErrorHandling.h" |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 20 | #include "llvm/Support/ManagedStatic.h" |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Mutex.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Dan Gohman | 02c7c6c | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 23 | #include <map> |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 24 | using namespace llvm; |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 25 | |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 26 | static const char *const PSVNames[] = { |
Alex Lorenz | 5659a2f | 2015-08-11 23:23:17 +0000 | [diff] [blame^] | 27 | "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack", |
| 28 | "GlobalValueCallEntry", "ExternalSymbolCallEntry"}; |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 29 | |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 30 | PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {} |
Nick Lewycky | aad475b | 2014-04-15 07:22:52 +0000 | [diff] [blame] | 31 | |
| 32 | PseudoSourceValue::~PseudoSourceValue() {} |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 33 | |
Dan Gohman | c0353bf | 2009-09-23 01:33:16 +0000 | [diff] [blame] | 34 | void PseudoSourceValue::printCustom(raw_ostream &O) const { |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 35 | O << PSVNames[Kind]; |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 36 | } |
Dan Gohman | 02c7c6c | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 37 | |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 38 | bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 39 | if (isStack()) |
Dan Gohman | 09b0448 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 40 | return false; |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 41 | if (isGOT() || isConstantPool() || isJumpTable()) |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 42 | return true; |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 43 | llvm_unreachable("Unknown PseudoSourceValue!"); |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 44 | } |
Dan Gohman | 09b0448 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 45 | |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 46 | bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const { |
| 47 | if (isStack() || isGOT() || isConstantPool() || isJumpTable()) |
Evan Cheng | 0e9d9ca | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 48 | return false; |
| 49 | llvm_unreachable("Unknown PseudoSourceValue!"); |
Evan Cheng | 0e9d9ca | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 52 | bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const { |
| 53 | if (isGOT() || isConstantPool() || isJumpTable()) |
Evan Cheng | ea68c7c | 2009-11-01 23:50:04 +0000 | [diff] [blame] | 54 | return false; |
| 55 | return true; |
| 56 | } |
| 57 | |
Alex Lorenz | 4ae214d | 2015-08-11 22:17:22 +0000 | [diff] [blame] | 58 | bool FixedStackPseudoSourceValue::isConstant( |
| 59 | const MachineFrameInfo *MFI) const { |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 60 | return MFI && MFI->isImmutableObjectIndex(FI); |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 61 | } |
Evan Cheng | 0e9d9ca | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 62 | |
Evan Cheng | f0236e0 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 63 | bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { |
Evan Cheng | f0236e0 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 64 | if (!MFI) |
Hal Finkel | 0815a05 | 2014-08-16 00:17:02 +0000 | [diff] [blame] | 65 | return true; |
| 66 | return MFI->isAliasedObjectIndex(FI); |
Evan Cheng | 0e9d9ca | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 67 | } |
Evan Cheng | ea68c7c | 2009-11-01 23:50:04 +0000 | [diff] [blame] | 68 | |
| 69 | bool 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(FI); |
| 74 | } |
David Greene | 033d655 | 2009-11-12 21:49:55 +0000 | [diff] [blame] | 75 | |
| 76 | void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const { |
| 77 | OS << "FixedStack" << FI; |
| 78 | } |
Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 79 | |
Alex Lorenz | 5659a2f | 2015-08-11 23:23:17 +0000 | [diff] [blame^] | 80 | CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(PSVKind Kind) |
| 81 | : PseudoSourceValue(Kind) {} |
| 82 | |
| 83 | bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const { |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue( |
| 96 | const GlobalValue *GV) |
| 97 | : CallEntryPseudoSourceValue(GlobalValueCallEntry), GV(GV) {} |
| 98 | |
| 99 | ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(const char *ES) |
| 100 | : CallEntryPseudoSourceValue(ExternalSymbolCallEntry), ES(ES) {} |
| 101 | |
Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 102 | PseudoSourceValueManager::PseudoSourceValueManager() |
| 103 | : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT), |
| 104 | JumpTablePSV(PseudoSourceValue::JumpTable), |
| 105 | ConstantPoolPSV(PseudoSourceValue::ConstantPool) {} |
| 106 | |
| 107 | const PseudoSourceValue *PseudoSourceValueManager::getStack() { |
| 108 | return &StackPSV; |
| 109 | } |
| 110 | |
| 111 | const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; } |
| 112 | |
| 113 | const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() { |
| 114 | return &ConstantPoolPSV; |
| 115 | } |
| 116 | |
| 117 | const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() { |
| 118 | return &JumpTablePSV; |
| 119 | } |
| 120 | |
| 121 | const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) { |
| 122 | std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI]; |
| 123 | if (!V) |
| 124 | V = llvm::make_unique<FixedStackPseudoSourceValue>(FI); |
| 125 | return V.get(); |
| 126 | } |
Alex Lorenz | 5659a2f | 2015-08-11 23:23:17 +0000 | [diff] [blame^] | 127 | |
| 128 | const PseudoSourceValue * |
| 129 | PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) { |
| 130 | std::unique_ptr<const GlobalValuePseudoSourceValue> &E = |
| 131 | GlobalCallEntries[GV]; |
| 132 | if (!E) |
| 133 | E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV); |
| 134 | return E.get(); |
| 135 | } |
| 136 | |
| 137 | const PseudoSourceValue * |
| 138 | PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) { |
| 139 | std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E = |
| 140 | ExternalCallEntries[ES]; |
| 141 | if (!E) |
| 142 | E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES); |
| 143 | return E.get(); |
| 144 | } |