2008-02-07 06:27:42 +08:00
|
|
|
//===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the PseudoSourceValue class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2016-04-18 17:17:29 +08:00
|
|
|
#include "llvm/ADT/STLExtras.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"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/LLVMContext.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);
|
|
|
|
}
|
|
|
|
|
2014-04-15 15:22:52 +08:00
|
|
|
|
|
|
|
PseudoSourceValue::~PseudoSourceValue() {}
|
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)
|
2017-09-15 04:53:51 +08:00
|
|
|
V = llvm::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)
|
2017-09-15 04:53:51 +08:00
|
|
|
E = llvm::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)
|
2017-09-15 04:53:51 +08:00
|
|
|
E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES, TII);
|
2015-08-12 07:23:17 +08:00
|
|
|
return E.get();
|
|
|
|
}
|