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