2008-02-06 23:27:42 +01: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 02:02:30 +02:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2008-02-06 23:27:42 +01:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
2008-07-12 00:44:52 +02:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2008-02-06 23:27:42 +01:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2008-08-24 20:51:20 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-07-12 00:44:52 +02:00
|
|
|
#include <map>
|
2008-08-24 22:37:32 +02:00
|
|
|
using namespace llvm;
|
2008-02-06 23:27:42 +01:00
|
|
|
|
2008-08-24 22:37:32 +02:00
|
|
|
static ManagedStatic<PseudoSourceValue[4]> PSVs;
|
2008-02-06 23:27:42 +01:00
|
|
|
|
2008-08-24 22:37:32 +02: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 23:27:42 +01:00
|
|
|
|
2008-08-24 22:37:32 +02:00
|
|
|
static const char *const PSVNames[] = {
|
|
|
|
"Stack",
|
|
|
|
"GOT",
|
|
|
|
"JumpTable",
|
|
|
|
"ConstantPool"
|
|
|
|
};
|
2008-02-06 23:27:42 +01:00
|
|
|
|
2008-08-24 22:37:32 +02:00
|
|
|
PseudoSourceValue::PseudoSourceValue() :
|
|
|
|
Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {}
|
2008-02-06 23:27:42 +01:00
|
|
|
|
2008-12-03 22:37:21 +01:00
|
|
|
void PseudoSourceValue::dump() const {
|
2009-03-23 16:57:19 +01:00
|
|
|
print(errs()); errs() << '\n';
|
2008-12-03 22:37:21 +01:00
|
|
|
}
|
|
|
|
|
2008-08-24 22:37:32 +02:00
|
|
|
void PseudoSourceValue::print(raw_ostream &OS) const {
|
|
|
|
OS << PSVNames[this - *PSVs];
|
|
|
|
}
|
2008-07-12 00:44:52 +02:00
|
|
|
|
2008-08-24 22:37:32 +02:00
|
|
|
namespace {
|
2008-07-12 00:44:52 +02: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 02:02:30 +02:00
|
|
|
|
|
|
|
virtual bool isConstant(const MachineFrameInfo *MFI) const;
|
|
|
|
|
2008-08-24 20:51:20 +02:00
|
|
|
virtual void print(raw_ostream &OS) const {
|
|
|
|
OS << "FixedStack" << FI;
|
|
|
|
}
|
2008-07-12 00:44:52 +02:00
|
|
|
};
|
2008-08-24 22:37:32 +02:00
|
|
|
}
|
2008-07-12 00:44:52 +02:00
|
|
|
|
2008-08-24 22:37:32 +02:00
|
|
|
static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
|
2008-07-12 00:44:52 +02:00
|
|
|
|
2008-08-24 22:37:32 +02:00
|
|
|
const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
|
|
|
|
const PseudoSourceValue *&V = (*FSValues)[FI];
|
|
|
|
if (!V)
|
|
|
|
V = new FixedStackPseudoSourceValue(FI);
|
|
|
|
return V;
|
|
|
|
}
|
2008-07-25 02:02:30 +02:00
|
|
|
|
2008-08-24 22:37:32 +02:00
|
|
|
bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const {
|
|
|
|
if (this == getStack())
|
2008-07-25 02:02:30 +02:00
|
|
|
return false;
|
2008-08-24 22:37:32 +02:00
|
|
|
if (this == getGOT() ||
|
|
|
|
this == getConstantPool() ||
|
|
|
|
this == getJumpTable())
|
|
|
|
return true;
|
|
|
|
assert(0 && "Unknown PseudoSourceValue!");
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-25 02:02:30 +02:00
|
|
|
|
2008-08-24 22:37:32 +02:00
|
|
|
bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
|
|
|
|
return MFI && MFI->isImmutableObjectIndex(FI);
|
2008-02-06 23:27:42 +01:00
|
|
|
}
|