blob: 79b09ee990ece089a25a86aeba5ee62acfebefd7 [file] [log] [blame]
Dan Gohman2d489b52008-02-06 22:27:42 +00001//===-- 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 Lorenze40c8a22015-08-11 23:09:45 +000014#include "llvm/ADT/STLExtras.h"
Dan Gohman2d489b52008-02-06 22:27:42 +000015#include "llvm/CodeGen/PseudoSourceValue.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000017#include "llvm/IR/DerivedTypes.h"
18#include "llvm/IR/LLVMContext.h"
Torok Edwin56d06592009-07-11 20:10:48 +000019#include "llvm/Support/ErrorHandling.h"
Dan Gohman2d489b52008-02-06 22:27:42 +000020#include "llvm/Support/ManagedStatic.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000021#include "llvm/Support/Mutex.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/Support/raw_ostream.h"
Dan Gohman02c7c6c2008-07-11 22:44:52 +000023#include <map>
Chris Lattnera078d832008-08-24 20:37:32 +000024using namespace llvm;
Dan Gohman2d489b52008-02-06 22:27:42 +000025
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000026static const char *const PSVNames[] = {
27 "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack", "MipsCallEntry"};
Dan Gohman2d489b52008-02-06 22:27:42 +000028
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000029PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(Kind) {}
Nick Lewyckyaad475b2014-04-15 07:22:52 +000030
31PseudoSourceValue::~PseudoSourceValue() {}
Dan Gohman2d489b52008-02-06 22:27:42 +000032
Dan Gohmanc0353bf2009-09-23 01:33:16 +000033void PseudoSourceValue::printCustom(raw_ostream &O) const {
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000034 O << PSVNames[Kind];
Chris Lattnera078d832008-08-24 20:37:32 +000035}
Dan Gohman02c7c6c2008-07-11 22:44:52 +000036
Chris Lattnera078d832008-08-24 20:37:32 +000037bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000038 if (isStack())
Dan Gohman09b04482008-07-25 00:02:30 +000039 return false;
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000040 if (isGOT() || isConstantPool() || isJumpTable())
Chris Lattnera078d832008-08-24 20:37:32 +000041 return true;
Torok Edwinfbcc6632009-07-14 16:55:14 +000042 llvm_unreachable("Unknown PseudoSourceValue!");
Chris Lattnera078d832008-08-24 20:37:32 +000043}
Dan Gohman09b04482008-07-25 00:02:30 +000044
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000045bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
46 if (isStack() || isGOT() || isConstantPool() || isJumpTable())
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000047 return false;
48 llvm_unreachable("Unknown PseudoSourceValue!");
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000049}
50
Alex Lorenzc49e4fe2015-08-11 22:32:00 +000051bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
52 if (isGOT() || isConstantPool() || isJumpTable())
Evan Chengea68c7c2009-11-01 23:50:04 +000053 return false;
54 return true;
55}
56
Alex Lorenz4ae214d2015-08-11 22:17:22 +000057bool FixedStackPseudoSourceValue::isConstant(
58 const MachineFrameInfo *MFI) const {
Chris Lattnera078d832008-08-24 20:37:32 +000059 return MFI && MFI->isImmutableObjectIndex(FI);
Dan Gohman2d489b52008-02-06 22:27:42 +000060}
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000061
Evan Chengf0236e02009-10-18 19:58:47 +000062bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
Evan Chengf0236e02009-10-18 19:58:47 +000063 if (!MFI)
Hal Finkel0815a052014-08-16 00:17:02 +000064 return true;
65 return MFI->isAliasedObjectIndex(FI);
Evan Cheng0e9d9ca2009-10-18 18:16:27 +000066}
Evan Chengea68c7c2009-11-01 23:50:04 +000067
68bool 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 Greene033d6552009-11-12 21:49:55 +000074
75void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
76 OS << "FixedStack" << FI;
77}
Alex Lorenze40c8a22015-08-11 23:09:45 +000078
79PseudoSourceValueManager::PseudoSourceValueManager()
80 : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
81 JumpTablePSV(PseudoSourceValue::JumpTable),
82 ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
83
84const PseudoSourceValue *PseudoSourceValueManager::getStack() {
85 return &StackPSV;
86}
87
88const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
89
90const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
91 return &ConstantPoolPSV;
92}
93
94const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
95 return &JumpTablePSV;
96}
97
98const 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}