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[] = { |
| 27 | "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack", "MipsCallEntry"}; |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 28 | |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 29 | PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {} |
Nick Lewycky | aad475b | 2014-04-15 07:22:52 +0000 | [diff] [blame] | 30 | |
| 31 | PseudoSourceValue::~PseudoSourceValue() {} |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 32 | |
Dan Gohman | c0353bf | 2009-09-23 01:33:16 +0000 | [diff] [blame] | 33 | void PseudoSourceValue::printCustom(raw_ostream &O) const { |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 34 | O << PSVNames[Kind]; |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 35 | } |
Dan Gohman | 02c7c6c | 2008-07-11 22:44:52 +0000 | [diff] [blame] | 36 | |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 37 | bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 38 | if (isStack()) |
Dan Gohman | 09b0448 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 39 | return false; |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 40 | if (isGOT() || isConstantPool() || isJumpTable()) |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 41 | return true; |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 42 | llvm_unreachable("Unknown PseudoSourceValue!"); |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 43 | } |
Dan Gohman | 09b0448 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 44 | |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 45 | bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const { |
| 46 | if (isStack() || isGOT() || isConstantPool() || isJumpTable()) |
Evan Cheng | 0e9d9ca | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 47 | return false; |
| 48 | llvm_unreachable("Unknown PseudoSourceValue!"); |
Evan Cheng | 0e9d9ca | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Alex Lorenz | c49e4fe | 2015-08-11 22:32:00 +0000 | [diff] [blame] | 51 | bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const { |
| 52 | if (isGOT() || isConstantPool() || isJumpTable()) |
Evan Cheng | ea68c7c | 2009-11-01 23:50:04 +0000 | [diff] [blame] | 53 | return false; |
| 54 | return true; |
| 55 | } |
| 56 | |
Alex Lorenz | 4ae214d | 2015-08-11 22:17:22 +0000 | [diff] [blame] | 57 | bool FixedStackPseudoSourceValue::isConstant( |
| 58 | const MachineFrameInfo *MFI) const { |
Chris Lattner | a078d83 | 2008-08-24 20:37:32 +0000 | [diff] [blame] | 59 | return MFI && MFI->isImmutableObjectIndex(FI); |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 60 | } |
Evan Cheng | 0e9d9ca | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 61 | |
Evan Cheng | f0236e0 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 62 | bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const { |
Evan Cheng | f0236e0 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 63 | if (!MFI) |
Hal Finkel | 0815a05 | 2014-08-16 00:17:02 +0000 | [diff] [blame] | 64 | return true; |
| 65 | return MFI->isAliasedObjectIndex(FI); |
Evan Cheng | 0e9d9ca | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 66 | } |
Evan Cheng | ea68c7c | 2009-11-01 23:50:04 +0000 | [diff] [blame] | 67 | |
| 68 | bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const { |
| 69 | if (!MFI) |
| 70 | return true; |
| 71 | // Spill slots will not alias any LLVM IR value. |
| 72 | return !MFI->isSpillSlotObjectIndex(FI); |
| 73 | } |
David Greene | 033d655 | 2009-11-12 21:49:55 +0000 | [diff] [blame] | 74 | |
| 75 | void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const { |
| 76 | OS << "FixedStack" << FI; |
| 77 | } |
Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame^] | 78 | |
| 79 | PseudoSourceValueManager::PseudoSourceValueManager() |
| 80 | : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT), |
| 81 | JumpTablePSV(PseudoSourceValue::JumpTable), |
| 82 | ConstantPoolPSV(PseudoSourceValue::ConstantPool) {} |
| 83 | |
| 84 | const PseudoSourceValue *PseudoSourceValueManager::getStack() { |
| 85 | return &StackPSV; |
| 86 | } |
| 87 | |
| 88 | const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; } |
| 89 | |
| 90 | const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() { |
| 91 | return &ConstantPoolPSV; |
| 92 | } |
| 93 | |
| 94 | const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() { |
| 95 | return &JumpTablePSV; |
| 96 | } |
| 97 | |
| 98 | const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) { |
| 99 | std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI]; |
| 100 | if (!V) |
| 101 | V = llvm::make_unique<FixedStackPseudoSourceValue>(FI); |
| 102 | return V.get(); |
| 103 | } |