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