2002-10-28 01:16:38 +00:00
|
|
|
//===-- MachineFunction.cpp -----------------------------------------------===//
|
2004-09-05 18:41:35 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2004-09-05 18:41:35 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-09-05 18:41:35 +00:00
|
|
|
//
|
2002-10-28 01:16:38 +00:00
|
|
|
// Collect native machine code information for a function. This allows
|
|
|
|
// target-specific information about the generated code to be stored with each
|
|
|
|
// function.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-02-03 07:54:50 +00:00
|
|
|
|
2007-02-14 05:52:17 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2003-12-20 10:20:58 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2002-12-25 05:03:22 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/SSARegMap.h"
|
2002-12-28 21:08:26 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2003-01-13 00:23:03 +00:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2006-04-22 18:53:45 +00:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2003-12-20 10:20:58 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2006-05-12 06:33:49 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2006-12-14 19:17:33 +00:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2002-02-03 07:54:50 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2002-12-28 21:00:25 +00:00
|
|
|
#include "llvm/Target/TargetFrameInfo.h"
|
2002-04-07 20:49:59 +00:00
|
|
|
#include "llvm/Function.h"
|
2004-07-29 17:30:56 +00:00
|
|
|
#include "llvm/Instructions.h"
|
2006-08-27 12:54:02 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2006-10-03 20:19:23 +00:00
|
|
|
#include "llvm/Support/GraphWriter.h"
|
|
|
|
#include "llvm/Support/LeakDetector.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2005-10-12 12:09:05 +00:00
|
|
|
#include "llvm/Config/config.h"
|
2004-07-08 00:47:58 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
2003-12-20 09:17:07 +00:00
|
|
|
using namespace llvm;
|
2002-02-03 07:54:50 +00:00
|
|
|
|
2002-10-29 23:18:43 +00:00
|
|
|
static AnnotationID MF_AID(
|
2004-09-05 18:41:35 +00:00
|
|
|
AnnotationManager::getID("CodeGen::MachineCodeForFunction"));
|
2002-02-03 07:54:50 +00:00
|
|
|
|
2006-07-14 23:08:47 +00:00
|
|
|
// Out of line virtual function to home classes.
|
|
|
|
void MachineFunctionPass::virtfn() {}
|
2002-10-28 01:12:41 +00:00
|
|
|
|
|
|
|
namespace {
|
2006-06-28 22:17:39 +00:00
|
|
|
struct VISIBILITY_HIDDEN Printer : public MachineFunctionPass {
|
2004-01-30 21:53:46 +00:00
|
|
|
std::ostream *OS;
|
2004-02-01 05:25:07 +00:00
|
|
|
const std::string Banner;
|
2004-01-30 21:53:46 +00:00
|
|
|
|
|
|
|
Printer (std::ostream *_OS, const std::string &_Banner) :
|
|
|
|
OS (_OS), Banner (_Banner) { }
|
|
|
|
|
2002-10-30 00:48:05 +00:00
|
|
|
const char *getPassName() const { return "MachineFunction Printer"; }
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2003-12-20 10:20:58 +00:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) {
|
2004-01-30 21:53:46 +00:00
|
|
|
(*OS) << Banner;
|
|
|
|
MF.print (*OS);
|
2002-10-30 00:48:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2002-10-28 01:12:41 +00:00
|
|
|
}
|
|
|
|
|
2004-01-30 21:53:46 +00:00
|
|
|
/// Returns a newly-created MachineFunction Printer pass. The default output
|
|
|
|
/// stream is std::cerr; the default banner is empty.
|
|
|
|
///
|
|
|
|
FunctionPass *llvm::createMachineFunctionPrinterPass(std::ostream *OS,
|
2005-01-23 22:13:58 +00:00
|
|
|
const std::string &Banner){
|
2004-01-30 21:53:46 +00:00
|
|
|
return new Printer(OS, Banner);
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
|
|
|
|
2004-02-15 00:03:15 +00:00
|
|
|
namespace {
|
2006-06-28 22:17:39 +00:00
|
|
|
struct VISIBILITY_HIDDEN Deleter : public MachineFunctionPass {
|
2004-02-15 00:03:15 +00:00
|
|
|
const char *getPassName() const { return "Machine Code Deleter"; }
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
// Delete the annotation from the function now.
|
|
|
|
MachineFunction::destruct(MF.getFunction());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// MachineCodeDeletion Pass - This pass deletes all of the machine code for
|
|
|
|
/// the current function, which should happen after the function has been
|
|
|
|
/// emitted to a .s file or to memory.
|
|
|
|
FunctionPass *llvm::createMachineCodeDeleter() {
|
|
|
|
return new Deleter();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-28 01:12:41 +00:00
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// MachineFunction implementation
|
|
|
|
//===---------------------------------------------------------------------===//
|
2005-01-29 18:41:25 +00:00
|
|
|
|
2005-01-30 00:09:23 +00:00
|
|
|
MachineBasicBlock* ilist_traits<MachineBasicBlock>::createSentinel() {
|
2004-09-05 18:41:35 +00:00
|
|
|
MachineBasicBlock* dummy = new MachineBasicBlock();
|
|
|
|
LeakDetector::removeGarbageObject(dummy);
|
|
|
|
return dummy;
|
2004-05-24 06:11:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ilist_traits<MachineBasicBlock>::transferNodesFromList(
|
2004-09-05 18:41:35 +00:00
|
|
|
iplist<MachineBasicBlock, ilist_traits<MachineBasicBlock> >& toList,
|
|
|
|
ilist_iterator<MachineBasicBlock> first,
|
2005-01-29 18:41:25 +00:00
|
|
|
ilist_iterator<MachineBasicBlock> last) {
|
2004-09-05 18:41:35 +00:00
|
|
|
if (Parent != toList.Parent)
|
|
|
|
for (; first != last; ++first)
|
|
|
|
first->Parent = toList.Parent;
|
2004-05-24 06:11:51 +00:00
|
|
|
}
|
2002-10-28 01:12:41 +00:00
|
|
|
|
2002-10-30 00:48:05 +00:00
|
|
|
MachineFunction::MachineFunction(const Function *F,
|
2002-12-28 20:37:16 +00:00
|
|
|
const TargetMachine &TM)
|
2006-01-04 13:43:56 +00:00
|
|
|
: Annotation(MF_AID), Fn(F), Target(TM), UsedPhysRegs(0) {
|
2002-11-20 18:55:27 +00:00
|
|
|
SSARegMapping = new SSARegMap();
|
2004-08-16 22:36:34 +00:00
|
|
|
MFInfo = 0;
|
2002-12-28 21:08:26 +00:00
|
|
|
FrameInfo = new MachineFrameInfo();
|
2006-02-09 04:46:04 +00:00
|
|
|
ConstantPool = new MachineConstantPool(TM.getTargetData());
|
2006-12-14 19:17:33 +00:00
|
|
|
|
|
|
|
// Set up jump table.
|
|
|
|
const TargetData &TD = *TM.getTargetData();
|
|
|
|
bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
|
|
|
|
unsigned EntrySize = IsPic ? 4 : TD.getPointerSize();
|
2007-02-14 05:52:17 +00:00
|
|
|
unsigned Alignment = IsPic ? TD.getABITypeAlignment(Type::Int32Ty)
|
2007-01-20 22:35:55 +00:00
|
|
|
: TD.getPointerABIAlignment();
|
2006-12-14 19:17:33 +00:00
|
|
|
JumpTableInfo = new MachineJumpTableInfo(EntrySize, Alignment);
|
|
|
|
|
2004-05-24 07:14:35 +00:00
|
|
|
BasicBlocks.Parent = this;
|
2002-12-25 05:03:22 +00:00
|
|
|
}
|
|
|
|
|
2004-09-05 18:41:35 +00:00
|
|
|
MachineFunction::~MachineFunction() {
|
2004-07-01 06:29:07 +00:00
|
|
|
BasicBlocks.clear();
|
2002-12-25 05:03:22 +00:00
|
|
|
delete SSARegMapping;
|
2002-12-28 20:37:16 +00:00
|
|
|
delete MFInfo;
|
|
|
|
delete FrameInfo;
|
2003-01-13 00:23:03 +00:00
|
|
|
delete ConstantPool;
|
2006-04-22 18:53:45 +00:00
|
|
|
delete JumpTableInfo;
|
2005-01-23 22:13:58 +00:00
|
|
|
delete[] UsedPhysRegs;
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
|
|
|
|
2006-10-03 19:18:57 +00:00
|
|
|
|
|
|
|
/// RenumberBlocks - This discards all of the MachineBasicBlock numbers and
|
|
|
|
/// recomputes them. This guarantees that the MBB numbers are sequential,
|
|
|
|
/// dense, and match the ordering of the blocks within the function. If a
|
|
|
|
/// specific MachineBasicBlock is specified, only that block and those after
|
|
|
|
/// it are renumbered.
|
|
|
|
void MachineFunction::RenumberBlocks(MachineBasicBlock *MBB) {
|
|
|
|
if (empty()) { MBBNumbering.clear(); return; }
|
|
|
|
MachineFunction::iterator MBBI, E = end();
|
|
|
|
if (MBB == 0)
|
|
|
|
MBBI = begin();
|
|
|
|
else
|
|
|
|
MBBI = MBB;
|
|
|
|
|
|
|
|
// Figure out the block number this should have.
|
|
|
|
unsigned BlockNo = 0;
|
2006-10-03 20:19:23 +00:00
|
|
|
if (MBBI != begin())
|
|
|
|
BlockNo = prior(MBBI)->getNumber()+1;
|
2006-10-03 19:18:57 +00:00
|
|
|
|
|
|
|
for (; MBBI != E; ++MBBI, ++BlockNo) {
|
|
|
|
if (MBBI->getNumber() != (int)BlockNo) {
|
|
|
|
// Remove use of the old number.
|
|
|
|
if (MBBI->getNumber() != -1) {
|
|
|
|
assert(MBBNumbering[MBBI->getNumber()] == &*MBBI &&
|
|
|
|
"MBB number mismatch!");
|
|
|
|
MBBNumbering[MBBI->getNumber()] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If BlockNo is already taken, set that block's number to -1.
|
|
|
|
if (MBBNumbering[BlockNo])
|
|
|
|
MBBNumbering[BlockNo]->setNumber(-1);
|
|
|
|
|
|
|
|
MBBNumbering[BlockNo] = MBBI;
|
|
|
|
MBBI->setNumber(BlockNo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay, all the blocks are renumbered. If we have compactified the block
|
|
|
|
// numbering, shrink MBBNumbering now.
|
|
|
|
assert(BlockNo <= MBBNumbering.size() && "Mismatch!");
|
|
|
|
MBBNumbering.resize(BlockNo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-07 20:28:15 +00:00
|
|
|
void MachineFunction::dump() const { print(*cerr.stream()); }
|
2002-10-30 00:48:05 +00:00
|
|
|
|
|
|
|
void MachineFunction::print(std::ostream &OS) const {
|
2004-03-29 21:58:31 +00:00
|
|
|
OS << "# Machine code for " << Fn->getName () << "():\n";
|
2002-12-28 20:37:16 +00:00
|
|
|
|
|
|
|
// Print Frame Information
|
2003-01-16 18:35:57 +00:00
|
|
|
getFrameInfo()->print(*this, OS);
|
2006-04-22 18:53:45 +00:00
|
|
|
|
|
|
|
// Print JumpTable Information
|
|
|
|
getJumpTableInfo()->print(OS);
|
2003-01-13 00:23:03 +00:00
|
|
|
|
|
|
|
// Print Constant Pool
|
|
|
|
getConstantPool()->print(OS);
|
2005-08-31 22:34:59 +00:00
|
|
|
|
|
|
|
const MRegisterInfo *MRI = getTarget().getRegisterInfo();
|
|
|
|
|
|
|
|
if (livein_begin() != livein_end()) {
|
|
|
|
OS << "Live Ins:";
|
|
|
|
for (livein_iterator I = livein_begin(), E = livein_end(); I != E; ++I) {
|
|
|
|
if (MRI)
|
|
|
|
OS << " " << MRI->getName(I->first);
|
|
|
|
else
|
|
|
|
OS << " Reg #" << I->first;
|
2006-05-16 05:55:30 +00:00
|
|
|
|
|
|
|
if (I->second)
|
|
|
|
OS << " in VR#" << I->second << " ";
|
2005-08-31 22:34:59 +00:00
|
|
|
}
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
if (liveout_begin() != liveout_end()) {
|
|
|
|
OS << "Live Outs:";
|
|
|
|
for (liveout_iterator I = liveout_begin(), E = liveout_end(); I != E; ++I)
|
|
|
|
if (MRI)
|
|
|
|
OS << " " << MRI->getName(*I);
|
|
|
|
else
|
|
|
|
OS << " Reg #" << *I;
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2004-02-13 04:39:55 +00:00
|
|
|
for (const_iterator BB = begin(); BB != end(); ++BB)
|
|
|
|
BB->print(OS);
|
2004-03-29 21:58:31 +00:00
|
|
|
|
|
|
|
OS << "\n# End machine code for " << Fn->getName () << "().\n\n";
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
|
|
|
|
2004-07-08 00:47:58 +00:00
|
|
|
/// CFGOnly flag - This is used to control whether or not the CFG graph printer
|
|
|
|
/// prints out the contents of basic blocks or not. This is acceptable because
|
|
|
|
/// this code is only really used for debugging purposes.
|
|
|
|
///
|
|
|
|
static bool CFGOnly = false;
|
|
|
|
|
|
|
|
namespace llvm {
|
2004-09-05 18:41:35 +00:00
|
|
|
template<>
|
|
|
|
struct DOTGraphTraits<const MachineFunction*> : public DefaultDOTGraphTraits {
|
|
|
|
static std::string getGraphName(const MachineFunction *F) {
|
|
|
|
return "CFG for '" + F->getFunction()->getName() + "' function";
|
|
|
|
}
|
2004-07-08 00:47:58 +00:00
|
|
|
|
2004-09-05 18:41:35 +00:00
|
|
|
static std::string getNodeLabel(const MachineBasicBlock *Node,
|
|
|
|
const MachineFunction *Graph) {
|
|
|
|
if (CFGOnly && Node->getBasicBlock() &&
|
|
|
|
!Node->getBasicBlock()->getName().empty())
|
|
|
|
return Node->getBasicBlock()->getName() + ":";
|
2004-07-08 00:47:58 +00:00
|
|
|
|
2004-09-05 18:41:35 +00:00
|
|
|
std::ostringstream Out;
|
|
|
|
if (CFGOnly) {
|
|
|
|
Out << Node->getNumber() << ':';
|
|
|
|
return Out.str();
|
|
|
|
}
|
2004-07-08 00:47:58 +00:00
|
|
|
|
2004-09-05 18:41:35 +00:00
|
|
|
Node->print(Out);
|
2004-07-08 00:47:58 +00:00
|
|
|
|
2004-09-05 18:41:35 +00:00
|
|
|
std::string OutStr = Out.str();
|
|
|
|
if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
|
2004-07-08 00:47:58 +00:00
|
|
|
|
2004-09-05 18:41:35 +00:00
|
|
|
// Process string output to make it nicer...
|
|
|
|
for (unsigned i = 0; i != OutStr.length(); ++i)
|
|
|
|
if (OutStr[i] == '\n') { // Left justify
|
|
|
|
OutStr[i] = '\\';
|
|
|
|
OutStr.insert(OutStr.begin()+i+1, 'l');
|
|
|
|
}
|
|
|
|
return OutStr;
|
|
|
|
}
|
|
|
|
};
|
2004-07-08 00:47:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MachineFunction::viewCFG() const
|
|
|
|
{
|
2005-10-12 12:09:05 +00:00
|
|
|
#ifndef NDEBUG
|
2006-06-27 16:49:46 +00:00
|
|
|
ViewGraph(this, "mf" + getFunction()->getName());
|
|
|
|
#else
|
2006-12-07 20:28:15 +00:00
|
|
|
cerr << "SelectionDAG::viewGraph is only available in debug builds on "
|
|
|
|
<< "systems with Graphviz or gv!\n";
|
2006-06-27 16:49:46 +00:00
|
|
|
#endif // NDEBUG
|
2004-07-08 00:47:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MachineFunction::viewCFGOnly() const
|
|
|
|
{
|
|
|
|
CFGOnly = true;
|
|
|
|
viewCFG();
|
|
|
|
CFGOnly = false;
|
|
|
|
}
|
|
|
|
|
2002-02-03 07:54:50 +00:00
|
|
|
// The next two methods are used to construct and to retrieve
|
2002-04-07 20:49:59 +00:00
|
|
|
// the MachineCodeForFunction object for the given function.
|
|
|
|
// construct() -- Allocates and initializes for a given function and target
|
2002-02-03 07:54:50 +00:00
|
|
|
// get() -- Returns a handle to the object.
|
|
|
|
// This should not be called before "construct()"
|
2002-04-07 20:49:59 +00:00
|
|
|
// for a given Function.
|
2004-09-05 18:41:35 +00:00
|
|
|
//
|
2002-10-28 00:28:31 +00:00
|
|
|
MachineFunction&
|
2002-10-28 05:58:46 +00:00
|
|
|
MachineFunction::construct(const Function *Fn, const TargetMachine &Tar)
|
2002-03-18 03:36:30 +00:00
|
|
|
{
|
2002-10-29 23:18:43 +00:00
|
|
|
assert(Fn->getAnnotation(MF_AID) == 0 &&
|
2002-04-07 20:49:59 +00:00
|
|
|
"Object already exists for this function!");
|
2002-10-28 05:58:46 +00:00
|
|
|
MachineFunction* mcInfo = new MachineFunction(Fn, Tar);
|
|
|
|
Fn->addAnnotation(mcInfo);
|
2002-02-03 07:54:50 +00:00
|
|
|
return *mcInfo;
|
|
|
|
}
|
|
|
|
|
2003-12-20 10:20:58 +00:00
|
|
|
void MachineFunction::destruct(const Function *Fn) {
|
2002-10-29 23:18:43 +00:00
|
|
|
bool Deleted = Fn->deleteAnnotation(MF_AID);
|
2002-04-07 20:49:59 +00:00
|
|
|
assert(Deleted && "Machine code did not exist for function!");
|
2002-02-03 07:54:50 +00:00
|
|
|
}
|
|
|
|
|
2002-10-28 05:58:46 +00:00
|
|
|
MachineFunction& MachineFunction::get(const Function *F)
|
2002-03-18 03:36:30 +00:00
|
|
|
{
|
2002-10-29 23:18:43 +00:00
|
|
|
MachineFunction *mc = (MachineFunction*)F->getAnnotation(MF_AID);
|
2002-02-03 07:54:50 +00:00
|
|
|
assert(mc && "Call construct() method first to allocate the object");
|
|
|
|
return *mc;
|
|
|
|
}
|
|
|
|
|
2002-12-25 05:03:22 +00:00
|
|
|
void MachineFunction::clearSSARegMap() {
|
|
|
|
delete SSARegMapping;
|
|
|
|
SSARegMapping = 0;
|
|
|
|
}
|
|
|
|
|
2002-12-28 20:37:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-28 21:08:26 +00:00
|
|
|
// MachineFrameInfo implementation
|
2002-12-28 20:37:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-01-16 18:35:57 +00:00
|
|
|
void MachineFrameInfo::print(const MachineFunction &MF, std::ostream &OS) const{
|
2004-06-02 05:56:52 +00:00
|
|
|
int ValOffset = MF.getTarget().getFrameInfo()->getOffsetOfLocalArea();
|
2003-01-16 18:35:57 +00:00
|
|
|
|
2002-12-28 20:37:16 +00:00
|
|
|
for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
|
|
|
|
const StackObject &SO = Objects[i];
|
2005-05-13 22:54:44 +00:00
|
|
|
OS << " <fi #" << (int)(i-NumFixedObjects) << ">: ";
|
2002-12-28 20:37:16 +00:00
|
|
|
if (SO.Size == 0)
|
|
|
|
OS << "variable sized";
|
|
|
|
else
|
2005-05-13 22:54:44 +00:00
|
|
|
OS << "size is " << SO.Size << " byte" << (SO.Size != 1 ? "s," : ",");
|
|
|
|
OS << " alignment is " << SO.Alignment << " byte"
|
|
|
|
<< (SO.Alignment != 1 ? "s," : ",");
|
2004-09-05 18:41:35 +00:00
|
|
|
|
2002-12-28 20:37:16 +00:00
|
|
|
if (i < NumFixedObjects)
|
|
|
|
OS << " fixed";
|
|
|
|
if (i < NumFixedObjects || SO.SPOffset != -1) {
|
2004-06-11 06:37:11 +00:00
|
|
|
int Off = SO.SPOffset - ValOffset;
|
2002-12-28 20:37:16 +00:00
|
|
|
OS << " at location [SP";
|
2003-01-16 18:35:57 +00:00
|
|
|
if (Off > 0)
|
2004-09-05 18:41:35 +00:00
|
|
|
OS << "+" << Off;
|
2003-01-16 18:35:57 +00:00
|
|
|
else if (Off < 0)
|
2004-09-05 18:41:35 +00:00
|
|
|
OS << Off;
|
2002-12-28 20:37:16 +00:00
|
|
|
OS << "]";
|
|
|
|
}
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HasVarSizedObjects)
|
|
|
|
OS << " Stack frame contains variable sized objects\n";
|
|
|
|
}
|
|
|
|
|
2003-01-16 18:35:57 +00:00
|
|
|
void MachineFrameInfo::dump(const MachineFunction &MF) const {
|
2006-12-07 20:28:15 +00:00
|
|
|
print(MF, *cerr.stream());
|
2003-01-16 18:35:57 +00:00
|
|
|
}
|
2002-12-28 20:37:16 +00:00
|
|
|
|
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineJumpTableInfo implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// getJumpTableIndex - Create a new jump table entry in the jump table info
|
|
|
|
/// or return an existing one.
|
|
|
|
///
|
|
|
|
unsigned MachineJumpTableInfo::getJumpTableIndex(
|
2006-10-28 18:17:09 +00:00
|
|
|
const std::vector<MachineBasicBlock*> &DestBBs) {
|
2006-10-28 18:11:20 +00:00
|
|
|
assert(!DestBBs.empty() && "Cannot create an empty jump table!");
|
2006-04-22 18:53:45 +00:00
|
|
|
for (unsigned i = 0, e = JumpTables.size(); i != e; ++i)
|
|
|
|
if (JumpTables[i].MBBs == DestBBs)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
JumpTables.push_back(MachineJumpTableEntry(DestBBs));
|
|
|
|
return JumpTables.size()-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MachineJumpTableInfo::print(std::ostream &OS) const {
|
|
|
|
// FIXME: this is lame, maybe we could print out the MBB numbers or something
|
|
|
|
// like {1, 2, 4, 5, 3, 0}
|
|
|
|
for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
|
|
|
|
OS << " <jt #" << i << "> has " << JumpTables[i].MBBs.size()
|
|
|
|
<< " entries\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-07 20:28:15 +00:00
|
|
|
void MachineJumpTableInfo::dump() const { print(*cerr.stream()); }
|
2006-04-22 18:53:45 +00:00
|
|
|
|
|
|
|
|
2003-01-13 00:23:03 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineConstantPool implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-09-14 05:50:57 +00:00
|
|
|
const Type *MachineConstantPoolEntry::getType() const {
|
|
|
|
if (isMachineConstantPoolEntry())
|
|
|
|
return Val.MachineCPVal->getType();
|
|
|
|
return Val.ConstVal->getType();
|
|
|
|
}
|
|
|
|
|
2006-09-12 21:00:35 +00:00
|
|
|
MachineConstantPool::~MachineConstantPool() {
|
|
|
|
for (unsigned i = 0, e = Constants.size(); i != e; ++i)
|
|
|
|
if (Constants[i].isMachineConstantPoolEntry())
|
|
|
|
delete Constants[i].Val.MachineCPVal;
|
|
|
|
}
|
|
|
|
|
2006-02-09 04:46:04 +00:00
|
|
|
/// getConstantPoolIndex - Create a new entry in the constant pool or return
|
|
|
|
/// an existing one. User must specify an alignment in bytes for the object.
|
|
|
|
///
|
|
|
|
unsigned MachineConstantPool::getConstantPoolIndex(Constant *C,
|
|
|
|
unsigned Alignment) {
|
|
|
|
assert(Alignment && "Alignment must be specified!");
|
|
|
|
if (Alignment > PoolAlignment) PoolAlignment = Alignment;
|
|
|
|
|
|
|
|
// Check to see if we already have this constant.
|
|
|
|
//
|
|
|
|
// FIXME, this could be made much more efficient for large constant pools.
|
|
|
|
unsigned AlignMask = (1 << Alignment)-1;
|
|
|
|
for (unsigned i = 0, e = Constants.size(); i != e; ++i)
|
2006-09-12 21:00:35 +00:00
|
|
|
if (Constants[i].Val.ConstVal == C && (Constants[i].Offset & AlignMask)== 0)
|
2006-02-09 04:46:04 +00:00
|
|
|
return i;
|
|
|
|
|
|
|
|
unsigned Offset = 0;
|
|
|
|
if (!Constants.empty()) {
|
2006-09-14 07:41:12 +00:00
|
|
|
Offset = Constants.back().getOffset();
|
2006-09-14 05:50:57 +00:00
|
|
|
Offset += TD->getTypeSize(Constants.back().getType());
|
2006-02-09 04:46:04 +00:00
|
|
|
Offset = (Offset+AlignMask)&~AlignMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
Constants.push_back(MachineConstantPoolEntry(C, Offset));
|
|
|
|
return Constants.size()-1;
|
|
|
|
}
|
|
|
|
|
2006-09-12 21:00:35 +00:00
|
|
|
unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V,
|
|
|
|
unsigned Alignment) {
|
|
|
|
assert(Alignment && "Alignment must be specified!");
|
|
|
|
if (Alignment > PoolAlignment) PoolAlignment = Alignment;
|
|
|
|
|
|
|
|
// Check to see if we already have this constant.
|
|
|
|
//
|
|
|
|
// FIXME, this could be made much more efficient for large constant pools.
|
|
|
|
unsigned AlignMask = (1 << Alignment)-1;
|
|
|
|
int Idx = V->getExistingMachineCPValue(this, Alignment);
|
|
|
|
if (Idx != -1)
|
|
|
|
return (unsigned)Idx;
|
|
|
|
|
|
|
|
unsigned Offset = 0;
|
|
|
|
if (!Constants.empty()) {
|
2006-09-14 07:41:12 +00:00
|
|
|
Offset = Constants.back().getOffset();
|
2006-09-14 05:50:57 +00:00
|
|
|
Offset += TD->getTypeSize(Constants.back().getType());
|
2006-09-12 21:00:35 +00:00
|
|
|
Offset = (Offset+AlignMask)&~AlignMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
Constants.push_back(MachineConstantPoolEntry(V, Offset));
|
|
|
|
return Constants.size()-1;
|
|
|
|
}
|
|
|
|
|
2006-02-09 04:46:04 +00:00
|
|
|
|
2003-01-13 00:23:03 +00:00
|
|
|
void MachineConstantPool::print(std::ostream &OS) const {
|
2006-01-31 22:23:14 +00:00
|
|
|
for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
|
2006-09-12 21:00:35 +00:00
|
|
|
OS << " <cp #" << i << "> is";
|
|
|
|
if (Constants[i].isMachineConstantPoolEntry())
|
|
|
|
Constants[i].Val.MachineCPVal->print(OS);
|
|
|
|
else
|
|
|
|
OS << *(Value*)Constants[i].Val.ConstVal;
|
2006-12-22 02:04:05 +00:00
|
|
|
OS << " , offset=" << Constants[i].getOffset();
|
2006-01-31 22:23:14 +00:00
|
|
|
OS << "\n";
|
|
|
|
}
|
2003-01-13 00:23:03 +00:00
|
|
|
}
|
|
|
|
|
2006-12-07 20:28:15 +00:00
|
|
|
void MachineConstantPool::dump() const { print(*cerr.stream()); }
|