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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-08-12 07:09:45 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2008-02-07 06:27:42 +08:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.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"
|
2008-02-07 06:27:42 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/Mutex.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-07-12 06:44:52 +08:00
|
|
|
#include <map>
|
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
|
|
|
|
2015-08-12 06:32:00 +08:00
|
|
|
PseudoSourceValue::PseudoSourceValue(PSVKind Kind) : Kind(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 {
|
2015-08-12 06:32:00 +08:00
|
|
|
O << PSVNames[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
|
|
|
|
2015-08-12 07:23:17 +08:00
|
|
|
CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(PSVKind Kind)
|
|
|
|
: PseudoSourceValue(Kind) {}
|
|
|
|
|
|
|
|
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(
|
|
|
|
const GlobalValue *GV)
|
|
|
|
: CallEntryPseudoSourceValue(GlobalValueCallEntry), GV(GV) {}
|
|
|
|
|
|
|
|
ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue(const char *ES)
|
|
|
|
: CallEntryPseudoSourceValue(ExternalSymbolCallEntry), ES(ES) {}
|
|
|
|
|
2015-08-12 07:09:45 +08:00
|
|
|
PseudoSourceValueManager::PseudoSourceValueManager()
|
|
|
|
: StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
|
|
|
|
JumpTablePSV(PseudoSourceValue::JumpTable),
|
|
|
|
ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
|
|
|
|
|
|
|
|
const PseudoSourceValue *PseudoSourceValueManager::getStack() {
|
|
|
|
return &StackPSV;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; }
|
|
|
|
|
|
|
|
const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() {
|
|
|
|
return &ConstantPoolPSV;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {
|
|
|
|
return &JumpTablePSV;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) {
|
|
|
|
std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
|
|
|
|
if (!V)
|
|
|
|
V = llvm::make_unique<FixedStackPseudoSourceValue>(FI);
|
|
|
|
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)
|
|
|
|
E = llvm::make_unique<GlobalValuePseudoSourceValue>(GV);
|
|
|
|
return E.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const PseudoSourceValue *
|
|
|
|
PseudoSourceValueManager::getExternalSymbolCallEntry(const char *ES) {
|
|
|
|
std::unique_ptr<const ExternalSymbolPseudoSourceValue> &E =
|
|
|
|
ExternalCallEntries[ES];
|
|
|
|
if (!E)
|
|
|
|
E = llvm::make_unique<ExternalSymbolPseudoSourceValue>(ES);
|
|
|
|
return E.get();
|
|
|
|
}
|