2008-02-06 22:27:42 +00: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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-07-25 00:02:30 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2008-02-06 22:27:42 +00:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
2008-07-11 22:44:52 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2008-02-06 22:27:42 +00:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2008-08-24 18:51:20 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-07-11 22:44:52 +00:00
|
|
|
#include <map>
|
2008-08-24 20:37:32 +00:00
|
|
|
using namespace llvm;
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
static ManagedStatic<PseudoSourceValue[4]> PSVs;
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
const PseudoSourceValue *PseudoSourceValue::getStack()
|
|
|
|
{ return &(*PSVs)[0]; }
|
|
|
|
const PseudoSourceValue *PseudoSourceValue::getGOT()
|
|
|
|
{ return &(*PSVs)[1]; }
|
|
|
|
const PseudoSourceValue *PseudoSourceValue::getJumpTable()
|
|
|
|
{ return &(*PSVs)[2]; }
|
|
|
|
const PseudoSourceValue *PseudoSourceValue::getConstantPool()
|
|
|
|
{ return &(*PSVs)[3]; }
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
static const char *const PSVNames[] = {
|
|
|
|
"Stack",
|
|
|
|
"GOT",
|
|
|
|
"JumpTable",
|
|
|
|
"ConstantPool"
|
|
|
|
};
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2009-08-13 21:58:54 +00:00
|
|
|
// FIXME: THIS IS A HACK!!!!
|
|
|
|
// Eventually these should be uniqued on LLVMContext rather than in a managed
|
|
|
|
// static. For now, we can safely use the global context for the time being to
|
|
|
|
// squeak by.
|
2008-08-24 20:37:32 +00:00
|
|
|
PseudoSourceValue::PseudoSourceValue() :
|
2009-08-13 21:58:54 +00:00
|
|
|
Value(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext())),
|
|
|
|
PseudoSourceValueVal) {}
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2008-12-03 21:37:21 +00:00
|
|
|
void PseudoSourceValue::dump() const {
|
2009-03-23 15:57:19 +00:00
|
|
|
print(errs()); errs() << '\n';
|
2008-12-03 21:37:21 +00:00
|
|
|
}
|
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
void PseudoSourceValue::print(raw_ostream &OS) const {
|
|
|
|
OS << PSVNames[this - *PSVs];
|
|
|
|
}
|
2008-07-11 22:44:52 +00:00
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
namespace {
|
2008-07-11 22:44:52 +00:00
|
|
|
/// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
|
|
|
|
/// for holding FixedStack values, which must include a frame
|
|
|
|
/// index.
|
|
|
|
class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
|
|
|
|
: public PseudoSourceValue {
|
|
|
|
const int FI;
|
|
|
|
public:
|
|
|
|
explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
|
2008-07-25 00:02:30 +00:00
|
|
|
|
|
|
|
virtual bool isConstant(const MachineFrameInfo *MFI) const;
|
|
|
|
|
2008-08-24 18:51:20 +00:00
|
|
|
virtual void print(raw_ostream &OS) const {
|
|
|
|
OS << "FixedStack" << FI;
|
|
|
|
}
|
2008-07-11 22:44:52 +00:00
|
|
|
};
|
2008-08-24 20:37:32 +00:00
|
|
|
}
|
2008-07-11 22:44:52 +00:00
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
|
2008-07-11 22:44:52 +00:00
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
|
|
|
|
const PseudoSourceValue *&V = (*FSValues)[FI];
|
|
|
|
if (!V)
|
|
|
|
V = new FixedStackPseudoSourceValue(FI);
|
|
|
|
return V;
|
|
|
|
}
|
2008-07-25 00:02:30 +00:00
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
|
|
|
|
if (this == getStack())
|
2008-07-25 00:02:30 +00:00
|
|
|
return false;
|
2008-08-24 20:37:32 +00:00
|
|
|
if (this == getGOT() ||
|
|
|
|
this == getConstantPool() ||
|
|
|
|
this == getJumpTable())
|
|
|
|
return true;
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unknown PseudoSourceValue!");
|
2008-08-24 20:37:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-07-25 00:02:30 +00:00
|
|
|
|
2008-08-24 20:37:32 +00:00
|
|
|
bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
|
|
|
|
return MFI && MFI->isImmutableObjectIndex(FI);
|
2008-02-06 22:27:42 +00:00
|
|
|
}
|