2008-02-06 23:27:42 +01:00
|
|
|
//===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2008-02-06 23:27:42 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the PseudoSourceValue class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2016-04-18 11:17:29 +02:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2017-11-08 02:01:31 +01:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2009-07-11 22:10:48 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-08-24 22:37:32 +02:00
|
|
|
using namespace llvm;
|
2008-02-06 23:27:42 +01:00
|
|
|
|
2015-08-12 00:32:00 +02:00
|
|
|
static const char *const PSVNames[] = {
|
2015-08-12 01:23:17 +02:00
|
|
|
"Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
|
|
|
|
"GlobalValueCallEntry", "ExternalSymbolCallEntry"};
|
2008-02-06 23:27:42 +01:00
|
|
|
|
2018-08-20 21:23:45 +02:00
|
|
|
PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII)
|
2017-09-14 22:53:51 +02:00
|
|
|
: Kind(Kind) {
|
|
|
|
AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind);
|
|
|
|
}
|
|
|
|
|
2014-04-15 09:22:52 +02:00
|
|
|
|
|
|
|
PseudoSourceValue::~PseudoSourceValue() {}
|
2008-02-06 23:27:42 +01:00
|
|
|
|
2009-09-23 03:33:16 +02:00
|
|
|
void PseudoSourceValue::printCustom(raw_ostream &O) const {
|
2017-03-28 22:33:12 +02:00
|
|
|
if (Kind < TargetCustom)
|
|
|
|
O << PSVNames[Kind];
|
|
|
|
else
|
|
|
|
O << "TargetCustom" << Kind;
|
2008-08-24 22:37:32 +02:00
|
|
|
}
|
2008-07-12 00:44:52 +02:00
|
|
|
|
2008-08-24 22:37:32 +02:00
|
|
|
bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
|
2015-08-12 00:32:00 +02:00
|
|
|
if (isStack())
|
2008-07-25 02:02:30 +02:00
|
|
|
return false;
|
2015-08-12 00:32:00 +02:00
|
|
|
if (isGOT() || isConstantPool() || isJumpTable())
|
2008-08-24 22:37:32 +02:00
|
|
|
return true;
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Unknown PseudoSourceValue!");
|
2008-08-24 22:37:32 +02:00
|
|
|
}
|
2008-07-25 02:02:30 +02:00
|
|
|
|
2015-08-12 00:32:00 +02:00
|
|
|
bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
|
|
|
|
if (isStack() || isGOT() || isConstantPool() || isJumpTable())
|
2009-10-18 20:16:27 +02:00
|
|
|
return false;
|
|
|
|
llvm_unreachable("Unknown PseudoSourceValue!");
|
|
|
|
}
|
|
|
|
|
2015-08-12 00:32:00 +02:00
|
|
|
bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
|
2015-10-25 01:11:13 +02:00
|
|
|
return !(isGOT() || isConstantPool() || isJumpTable());
|
2009-11-02 00:50:04 +01:00
|
|
|
}
|
|
|
|
|
2015-08-12 00:17:22 +02:00
|
|
|
bool FixedStackPseudoSourceValue::isConstant(
|
|
|
|
const MachineFrameInfo *MFI) const {
|
2008-08-24 22:37:32 +02:00
|
|
|
return MFI && MFI->isImmutableObjectIndex(FI);
|
2008-02-06 23:27:42 +01:00
|
|
|
}
|
2009-10-18 20:16:27 +02:00
|
|
|
|
2009-10-18 21:58:47 +02:00
|
|
|
bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
|
|
|
|
if (!MFI)
|
2014-08-16 02:17:02 +02:00
|
|
|
return true;
|
|
|
|
return MFI->isAliasedObjectIndex(FI);
|
2009-10-18 20:16:27 +02:00
|
|
|
}
|
2009-11-02 00:50:04 +01:00
|
|
|
|
|
|
|
bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const {
|
|
|
|
if (!MFI)
|
|
|
|
return true;
|
|
|
|
// Spill slots will not alias any LLVM IR value.
|
|
|
|
return !MFI->isSpillSlotObjectIndex(FI);
|
|
|
|
}
|
2009-11-12 22:49:55 +01:00
|
|
|
|
|
|
|
void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
|
|
|
|
OS << "FixedStack" << FI;
|
|
|
|
}
|
2015-08-12 01:09:45 +02:00
|
|
|
|
2017-09-14 22:53:51 +02:00
|
|
|
CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(
|
2018-08-20 21:23:45 +02:00
|
|
|
unsigned Kind, const TargetInstrInfo &TII)
|
2017-09-14 22:53:51 +02:00
|
|
|
: PseudoSourceValue(Kind, TII) {}
|
2015-08-12 01:23:17 +02:00
|
|
|
|
|
|
|
bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CallEntryPseudoSourceValue::isAliased(const MachineFrameInfo *) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CallEntryPseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue(
|
2017-09-14 22:53:51 +02:00
|
|
|
const GlobalValue *GV,
|
|
|
|
const TargetInstrInfo &TII)
|
|
|
|
: CallEntryPseudoSourceValue(GlobalValueCallEntry, TII), GV(GV) {}
|
|
|
|
ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(
|
|
|
|
const char *ES, const TargetInstrInfo &TII)
|
|
|
|
: CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TII), ES(ES) {}
|
|
|
|
|
|
|
|
PseudoSourceValueManager::PseudoSourceValueManager(
|
|
|
|
const TargetInstrInfo &TIInfo)
|
|
|
|
: TII(TIInfo),
|
|
|
|
StackPSV(PseudoSourceValue::Stack, TII),
|
|
|
|
GOTPSV(PseudoSourceValue::GOT, TII),
|
|
|
|
JumpTablePSV(PseudoSourceValue::JumpTable, TII),
|
|
|
|
ConstantPoolPSV(PseudoSourceValue::ConstantPool, TII) {}
|
2015-08-12 01:09:45 +02:00
|
|
|
|
|
|
|
const PseudoSourceValue *PseudoSourceValueManager::getStack() {
|
|
|
|
return &StackPSV;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
|
|
|
|
|
|
|
|
const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
|
|
|
|
return &ConstantPoolPSV;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
|
|
|
|
return &JumpTablePSV;
|
|
|
|
}
|
|
|
|
|
2017-09-14 22:53:51 +02:00
|
|
|
const PseudoSourceValue *
|
|
|
|
PseudoSourceValueManager::getFixedStack(int FI) {
|
2015-08-12 01:09:45 +02:00
|
|
|
std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
|
|
|
|
if (!V)
|
2019-08-15 17:54:37 +02:00
|
|
|
V = std::make_unique<FixedStackPseudoSourceValue>(FI, TII);
|
2015-08-12 01:09:45 +02:00
|
|
|
return V.get();
|
|
|
|
}
|
2015-08-12 01:23:17 +02:00
|
|
|
|
|
|
|
const PseudoSourceValue *
|
|
|
|
PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
|
|
|
|
std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
|
|
|
|
GlobalCallEntries[GV];
|
|
|
|
if (!E)
|
2019-08-15 17:54:37 +02:00
|
|
|
E = std::make_unique<GlobalValuePseudoSourceValue>(GV, TII);
|
2015-08-12 01:23:17 +02:00
|
|
|
return E.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const PseudoSourceValue *
|
|
|
|
PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
|
|
|
|
std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
|
|
|
|
ExternalCallEntries[ES];
|
|
|
|
if (!E)
|
2019-08-15 17:54:37 +02:00
|
|
|
E = std::make_unique<ExternalSymbolPseudoSourceValue>(ES, TII);
|
2015-08-12 01:23:17 +02:00
|
|
|
return E.get();
|
|
|
|
}
|