2008-02-06 22:27:42 +00:00
|
|
|
//===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00: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 22:27:42 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the PseudoSourceValue class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2022-04-26 20:35:01 -04:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
using namespace llvm;
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2015-08-11 22:32:00 +00:00
|
|
|
static const char *const PSVNames[] = {
|
2015-08-11 23:23:17 +00:00
|
|
|
"Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
|
|
|
|
"GlobalValueCallEntry", "ExternalSymbolCallEntry"};
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2022-04-26 20:35:01 -04:00
|
|
|
PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetMachine &TM)
|
2017-09-14 20:53:51 +00:00
|
|
|
: Kind(Kind) {
|
2022-04-26 20:35:01 -04:00
|
|
|
AddressSpace = TM.getAddressSpaceForPseudoSourceKind(Kind);
|
2017-09-14 20:53:51 +00:00
|
|
|
}
|
|
|
|
|
2022-02-06 10:54:44 -08:00
|
|
|
PseudoSourceValue::~PseudoSourceValue() = default;
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2009-09-23 01:33:16 +00:00
|
|
|
void PseudoSourceValue::printCustom(raw_ostream &O) const {
|
2017-03-28 20:33:12 +00:00
|
|
|
if (Kind < TargetCustom)
|
|
|
|
O << PSVNames[Kind];
|
|
|
|
else
|
|
|
|
O << "TargetCustom" << Kind;
|
2008-08-24 20:37:32 +00:00
|
|
|
}
|
2008-07-11 22:44:52 +00:00
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
|
2015-08-11 22:32:00 +00:00
|
|
|
if (isStack())
|
2008-07-25 00:02:30 +00:00
|
|
|
return false;
|
2015-08-11 22:32:00 +00:00
|
|
|
if (isGOT() || isConstantPool() || isJumpTable())
|
2008-08-24 20:37:32 +00:00
|
|
|
return true;
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unknown PseudoSourceValue!");
|
2008-08-24 20:37:32 +00:00
|
|
|
}
|
2008-07-25 00:02:30 +00:00
|
|
|
|
2015-08-11 22:32:00 +00:00
|
|
|
bool PseudoSourceValue::isAliased(const MachineFrameInfo *) const {
|
|
|
|
if (isStack() || isGOT() || isConstantPool() || isJumpTable())
|
2009-10-18 18:16:27 +00:00
|
|
|
return false;
|
|
|
|
llvm_unreachable("Unknown PseudoSourceValue!");
|
|
|
|
}
|
|
|
|
|
2015-08-11 22:32:00 +00:00
|
|
|
bool PseudoSourceValue::mayAlias(const MachineFrameInfo *) const {
|
2015-10-24 23:11:13 +00:00
|
|
|
return !(isGOT() || isConstantPool() || isJumpTable());
|
2009-11-01 23:50:04 +00:00
|
|
|
}
|
|
|
|
|
2015-08-11 22:17:22 +00:00
|
|
|
bool FixedStackPseudoSourceValue::isConstant(
|
|
|
|
const MachineFrameInfo *MFI) const {
|
2008-08-24 20:37:32 +00:00
|
|
|
return MFI && MFI->isImmutableObjectIndex(FI);
|
2008-02-06 22:27:42 +00:00
|
|
|
}
|
2009-10-18 18:16:27 +00:00
|
|
|
|
2009-10-18 19:58:47 +00:00
|
|
|
bool FixedStackPseudoSourceValue::isAliased(const MachineFrameInfo *MFI) const {
|
|
|
|
if (!MFI)
|
2014-08-16 00:17:02 +00:00
|
|
|
return true;
|
|
|
|
return MFI->isAliasedObjectIndex(FI);
|
2009-10-18 18:16:27 +00:00
|
|
|
}
|
2009-11-01 23:50:04 +00: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 21:49:55 +00:00
|
|
|
|
|
|
|
void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
|
|
|
|
OS << "FixedStack" << FI;
|
|
|
|
}
|
2015-08-11 23:09:45 +00:00
|
|
|
|
2022-04-26 20:35:01 -04:00
|
|
|
CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(unsigned Kind,
|
|
|
|
const TargetMachine &TM)
|
|
|
|
: PseudoSourceValue(Kind, TM) {}
|
2015-08-11 23:23:17 +00: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(
|
2022-04-26 20:35:01 -04:00
|
|
|
const GlobalValue *GV, const TargetMachine &TM)
|
|
|
|
: CallEntryPseudoSourceValue(GlobalValueCallEntry, TM), GV(GV) {}
|
2017-09-14 20:53:51 +00:00
|
|
|
ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(
|
2022-04-26 20:35:01 -04:00
|
|
|
const char *ES, const TargetMachine &TM)
|
|
|
|
: CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TM), ES(ES) {}
|
2017-09-14 20:53:51 +00:00
|
|
|
|
2022-04-26 20:35:01 -04:00
|
|
|
PseudoSourceValueManager::PseudoSourceValueManager(const TargetMachine &TMInfo)
|
|
|
|
: TM(TMInfo), StackPSV(PseudoSourceValue::Stack, TM),
|
|
|
|
GOTPSV(PseudoSourceValue::GOT, TM),
|
|
|
|
JumpTablePSV(PseudoSourceValue::JumpTable, TM),
|
|
|
|
ConstantPoolPSV(PseudoSourceValue::ConstantPool, TM) {}
|
2015-08-11 23:09:45 +00: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 20:53:51 +00:00
|
|
|
const PseudoSourceValue *
|
|
|
|
PseudoSourceValueManager::getFixedStack(int FI) {
|
2015-08-11 23:09:45 +00:00
|
|
|
std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
|
|
|
|
if (!V)
|
2022-04-26 20:35:01 -04:00
|
|
|
V = std::make_unique<FixedStackPseudoSourceValue>(FI, TM);
|
2015-08-11 23:09:45 +00:00
|
|
|
return V.get();
|
|
|
|
}
|
2015-08-11 23:23:17 +00:00
|
|
|
|
|
|
|
const PseudoSourceValue *
|
|
|
|
PseudoSourceValueManager::getGlobalValueCallEntry(const GlobalValue *GV) {
|
|
|
|
std::unique_ptr<const GlobalValuePseudoSourceValue> &E =
|
|
|
|
GlobalCallEntries[GV];
|
|
|
|
if (!E)
|
2022-04-26 20:35:01 -04:00
|
|
|
E = std::make_unique<GlobalValuePseudoSourceValue>(GV, TM);
|
2015-08-11 23:23:17 +00:00
|
|
|
return E.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const PseudoSourceValue *
|
|
|
|
PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
|
|
|
|
std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
|
|
|
|
ExternalCallEntries[ES];
|
|
|
|
if (!E)
|
2022-04-26 20:35:01 -04:00
|
|
|
E = std::make_unique<ExternalSymbolPseudoSourceValue>(ES, TM);
|
2015-08-11 23:23:17 +00:00
|
|
|
return E.get();
|
|
|
|
}
|