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
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file 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"
|
2009-06-30 22:38:32 +00:00
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/Config/config.h"
|
2007-12-31 04:13:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2009-08-19 22:16:11 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2003-12-20 10:20:58 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2002-12-28 21:08:26 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2007-12-31 04:13:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2006-04-22 18:53:45 +00:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2007-12-31 04:13:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2003-12-20 10:20:58 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2010-01-26 05:58:28 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
2010-01-19 06:09:04 +00:00
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2010-01-04 23:39:17 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2006-05-12 06:33:49 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2009-06-30 22:38:32 +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"
|
2010-01-26 05:58:28 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2006-10-03 20:19:23 +00:00
|
|
|
#include "llvm/Support/GraphWriter.h"
|
2008-08-23 22:23:09 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2003-12-20 09:17:07 +00:00
|
|
|
using namespace llvm;
|
2002-02-03 07:54:50 +00:00
|
|
|
|
2002-10-28 01:12:41 +00:00
|
|
|
namespace {
|
2009-10-25 06:33:48 +00:00
|
|
|
struct Printer : public MachineFunctionPass {
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2007-05-01 21:15:47 +00:00
|
|
|
|
2009-08-23 03:13:20 +00:00
|
|
|
raw_ostream &OS;
|
2004-02-01 05:25:07 +00:00
|
|
|
const std::string Banner;
|
2004-01-30 21:53:46 +00:00
|
|
|
|
2009-08-23 03:13:20 +00:00
|
|
|
Printer(raw_ostream &os, const std::string &banner)
|
2008-09-04 17:05:41 +00:00
|
|
|
: MachineFunctionPass(&ID), OS(os), Banner(banner) {}
|
2004-01-30 21:53:46 +00:00
|
|
|
|
2002-10-30 00:48:05 +00:00
|
|
|
const char *getPassName() const { return "MachineFunction Printer"; }
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
2009-07-31 18:16:33 +00:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
|
|
|
|
2003-12-20 10:20:58 +00:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) {
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << "# " << Banner << ":\n";
|
2009-08-23 03:13:20 +00:00
|
|
|
MF.print(OS);
|
2002-10-30 00:48:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2007-05-03 01:11:54 +00:00
|
|
|
char Printer::ID = 0;
|
2002-10-28 01:12:41 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 01:02:24 +00:00
|
|
|
/// Returns a newly-created MachineFunction Printer pass. The default banner is
|
|
|
|
/// empty.
|
2004-01-30 21:53:46 +00:00
|
|
|
///
|
2009-08-23 03:13:20 +00:00
|
|
|
FunctionPass *llvm::createMachineFunctionPrinterPass(raw_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
|
|
|
}
|
|
|
|
|
2010-01-26 04:35:26 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-28 01:12:41 +00:00
|
|
|
// MachineFunction implementation
|
2010-01-26 04:35:26 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-01-29 18:41:25 +00:00
|
|
|
|
2009-09-15 22:44:26 +00:00
|
|
|
// Out of line virtual method.
|
|
|
|
MachineFunctionInfo::~MachineFunctionInfo() {}
|
|
|
|
|
2008-07-28 21:51:04 +00:00
|
|
|
void ilist_traits<MachineBasicBlock>::deleteNode(MachineBasicBlock *MBB) {
|
2008-07-07 23:14:23 +00:00
|
|
|
MBB->getParent()->DeleteMachineBasicBlock(MBB);
|
2004-05-24 06:11:51 +00:00
|
|
|
}
|
2002-10-28 01:12:41 +00:00
|
|
|
|
2010-01-26 04:35:26 +00:00
|
|
|
MachineFunction::MachineFunction(Function *F, const TargetMachine &TM,
|
|
|
|
unsigned FunctionNum)
|
2009-07-31 18:35:51 +00:00
|
|
|
: Fn(F), Target(TM) {
|
2008-10-13 12:37:16 +00:00
|
|
|
if (TM.getRegisterInfo())
|
|
|
|
RegInfo = new (Allocator.Allocate<MachineRegisterInfo>())
|
|
|
|
MachineRegisterInfo(*TM.getRegisterInfo());
|
|
|
|
else
|
|
|
|
RegInfo = 0;
|
2004-08-16 22:36:34 +00:00
|
|
|
MFInfo = 0;
|
2008-07-07 23:14:23 +00:00
|
|
|
FrameInfo = new (Allocator.Allocate<MachineFrameInfo>())
|
|
|
|
MachineFrameInfo(*TM.getFrameInfo());
|
2010-02-19 18:17:13 +00:00
|
|
|
if (Fn->hasFnAttr(Attribute::StackAlignment))
|
|
|
|
FrameInfo->setMaxAlignment(Attribute::getStackAlignmentFromAttrs(
|
|
|
|
Fn->getAttributes().getFnAttributes()));
|
2008-07-07 23:14:23 +00:00
|
|
|
ConstantPool = new (Allocator.Allocate<MachineConstantPool>())
|
|
|
|
MachineConstantPool(TM.getTargetData());
|
2009-06-30 22:38:32 +00:00
|
|
|
Alignment = TM.getTargetLowering()->getFunctionAlignment(F);
|
2010-01-26 04:35:26 +00:00
|
|
|
FunctionNumber = FunctionNum;
|
2010-01-25 23:26:13 +00:00
|
|
|
JumpTableInfo = 0;
|
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();
|
2008-07-07 23:14:23 +00:00
|
|
|
InstructionRecycler.clear(Allocator);
|
|
|
|
BasicBlockRecycler.clear(Allocator);
|
2009-06-25 00:32:48 +00:00
|
|
|
if (RegInfo) {
|
|
|
|
RegInfo->~MachineRegisterInfo();
|
|
|
|
Allocator.Deallocate(RegInfo);
|
|
|
|
}
|
2008-07-07 23:14:23 +00:00
|
|
|
if (MFInfo) {
|
2009-06-25 00:32:48 +00:00
|
|
|
MFInfo->~MachineFunctionInfo();
|
|
|
|
Allocator.Deallocate(MFInfo);
|
2008-07-07 23:14:23 +00:00
|
|
|
}
|
|
|
|
FrameInfo->~MachineFrameInfo(); Allocator.Deallocate(FrameInfo);
|
|
|
|
ConstantPool->~MachineConstantPool(); Allocator.Deallocate(ConstantPool);
|
2010-01-25 23:26:13 +00:00
|
|
|
|
|
|
|
if (JumpTableInfo) {
|
|
|
|
JumpTableInfo->~MachineJumpTableInfo();
|
|
|
|
Allocator.Deallocate(JumpTableInfo);
|
|
|
|
}
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 23:26:13 +00:00
|
|
|
/// getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it
|
|
|
|
/// does already exist, allocate one.
|
|
|
|
MachineJumpTableInfo *MachineFunction::
|
|
|
|
getOrCreateJumpTableInfo(unsigned EntryKind) {
|
|
|
|
if (JumpTableInfo) return JumpTableInfo;
|
|
|
|
|
|
|
|
JumpTableInfo = new (Allocator.Allocate<MachineJumpTableInfo>())
|
|
|
|
MachineJumpTableInfo((MachineJumpTableInfo::JTEntryKind)EntryKind);
|
|
|
|
return JumpTableInfo;
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
/// CreateMachineInstr - Allocate a new MachineInstr. Use this instead
|
|
|
|
/// of `new MachineInstr'.
|
|
|
|
///
|
|
|
|
MachineInstr *
|
2009-02-03 00:55:04 +00:00
|
|
|
MachineFunction::CreateMachineInstr(const TargetInstrDesc &TID,
|
|
|
|
DebugLoc DL, bool NoImp) {
|
2008-07-07 23:14:23 +00:00
|
|
|
return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
|
2009-02-03 00:55:04 +00:00
|
|
|
MachineInstr(TID, DL, NoImp);
|
2008-07-07 23:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// CloneMachineInstr - Create a new MachineInstr which is a copy of the
|
2010-02-10 16:03:48 +00:00
|
|
|
/// 'Orig' instruction, identical in all ways except the instruction
|
2008-07-07 23:14:23 +00:00
|
|
|
/// has no parent, prev, or next.
|
|
|
|
///
|
|
|
|
MachineInstr *
|
|
|
|
MachineFunction::CloneMachineInstr(const MachineInstr *Orig) {
|
|
|
|
return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
|
|
|
|
MachineInstr(*this, *Orig);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// DeleteMachineInstr - Delete the given MachineInstr.
|
|
|
|
///
|
|
|
|
void
|
|
|
|
MachineFunction::DeleteMachineInstr(MachineInstr *MI) {
|
|
|
|
MI->~MachineInstr();
|
|
|
|
InstructionRecycler.Deallocate(Allocator, MI);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this
|
|
|
|
/// instead of `new MachineBasicBlock'.
|
|
|
|
///
|
|
|
|
MachineBasicBlock *
|
|
|
|
MachineFunction::CreateMachineBasicBlock(const BasicBlock *bb) {
|
|
|
|
return new (BasicBlockRecycler.Allocate<MachineBasicBlock>(Allocator))
|
|
|
|
MachineBasicBlock(*this, bb);
|
|
|
|
}
|
2006-10-03 19:18:57 +00:00
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
/// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
|
|
|
|
///
|
|
|
|
void
|
|
|
|
MachineFunction::DeleteMachineBasicBlock(MachineBasicBlock *MBB) {
|
|
|
|
assert(MBB->getParent() == this && "MBB parent mismatch!");
|
|
|
|
MBB->~MachineBasicBlock();
|
|
|
|
BasicBlockRecycler.Deallocate(Allocator, MBB);
|
|
|
|
}
|
|
|
|
|
2009-09-25 20:36:54 +00:00
|
|
|
MachineMemOperand *
|
|
|
|
MachineFunction::getMachineMemOperand(const Value *v, unsigned f,
|
|
|
|
int64_t o, uint64_t s,
|
|
|
|
unsigned base_alignment) {
|
|
|
|
return new (Allocator.Allocate<MachineMemOperand>())
|
|
|
|
MachineMemOperand(v, f, o, s, base_alignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineMemOperand *
|
|
|
|
MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO,
|
|
|
|
int64_t Offset, uint64_t Size) {
|
|
|
|
return new (Allocator.Allocate<MachineMemOperand>())
|
|
|
|
MachineMemOperand(MMO->getValue(), MMO->getFlags(),
|
|
|
|
int64_t(uint64_t(MMO->getOffset()) +
|
|
|
|
uint64_t(Offset)),
|
|
|
|
Size, MMO->getBaseAlignment());
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineInstr::mmo_iterator
|
|
|
|
MachineFunction::allocateMemRefsArray(unsigned long Num) {
|
|
|
|
return Allocator.Allocate<MachineMemOperand *>(Num);
|
|
|
|
}
|
|
|
|
|
2009-10-09 18:10:05 +00:00
|
|
|
std::pair<MachineInstr::mmo_iterator, MachineInstr::mmo_iterator>
|
|
|
|
MachineFunction::extractLoadMemRefs(MachineInstr::mmo_iterator Begin,
|
|
|
|
MachineInstr::mmo_iterator End) {
|
|
|
|
// Count the number of load mem refs.
|
|
|
|
unsigned Num = 0;
|
|
|
|
for (MachineInstr::mmo_iterator I = Begin; I != End; ++I)
|
|
|
|
if ((*I)->isLoad())
|
|
|
|
++Num;
|
|
|
|
|
|
|
|
// Allocate a new array and populate it with the load information.
|
|
|
|
MachineInstr::mmo_iterator Result = allocateMemRefsArray(Num);
|
|
|
|
unsigned Index = 0;
|
|
|
|
for (MachineInstr::mmo_iterator I = Begin; I != End; ++I) {
|
|
|
|
if ((*I)->isLoad()) {
|
|
|
|
if (!(*I)->isStore())
|
|
|
|
// Reuse the MMO.
|
|
|
|
Result[Index] = *I;
|
|
|
|
else {
|
|
|
|
// Clone the MMO and unset the store flag.
|
|
|
|
MachineMemOperand *JustLoad =
|
|
|
|
getMachineMemOperand((*I)->getValue(),
|
|
|
|
(*I)->getFlags() & ~MachineMemOperand::MOStore,
|
|
|
|
(*I)->getOffset(), (*I)->getSize(),
|
|
|
|
(*I)->getBaseAlignment());
|
|
|
|
Result[Index] = JustLoad;
|
|
|
|
}
|
|
|
|
++Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::make_pair(Result, Result + Num);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<MachineInstr::mmo_iterator, MachineInstr::mmo_iterator>
|
|
|
|
MachineFunction::extractStoreMemRefs(MachineInstr::mmo_iterator Begin,
|
|
|
|
MachineInstr::mmo_iterator End) {
|
|
|
|
// Count the number of load mem refs.
|
|
|
|
unsigned Num = 0;
|
|
|
|
for (MachineInstr::mmo_iterator I = Begin; I != End; ++I)
|
|
|
|
if ((*I)->isStore())
|
|
|
|
++Num;
|
|
|
|
|
|
|
|
// Allocate a new array and populate it with the store information.
|
|
|
|
MachineInstr::mmo_iterator Result = allocateMemRefsArray(Num);
|
|
|
|
unsigned Index = 0;
|
|
|
|
for (MachineInstr::mmo_iterator I = Begin; I != End; ++I) {
|
|
|
|
if ((*I)->isStore()) {
|
|
|
|
if (!(*I)->isLoad())
|
|
|
|
// Reuse the MMO.
|
|
|
|
Result[Index] = *I;
|
|
|
|
else {
|
|
|
|
// Clone the MMO and unset the load flag.
|
|
|
|
MachineMemOperand *JustStore =
|
|
|
|
getMachineMemOperand((*I)->getValue(),
|
|
|
|
(*I)->getFlags() & ~MachineMemOperand::MOLoad,
|
|
|
|
(*I)->getOffset(), (*I)->getSize(),
|
|
|
|
(*I)->getBaseAlignment());
|
|
|
|
Result[Index] = JustStore;
|
|
|
|
}
|
|
|
|
++Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::make_pair(Result, Result + Num);
|
|
|
|
}
|
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
void MachineFunction::dump() const {
|
2010-01-04 23:39:17 +00:00
|
|
|
print(dbgs());
|
2008-07-07 23:14:23 +00:00
|
|
|
}
|
2002-10-30 00:48:05 +00:00
|
|
|
|
2009-08-23 01:12:47 +00:00
|
|
|
void MachineFunction::print(raw_ostream &OS) const {
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << "# Machine code for function " << Fn->getName() << ":\n";
|
2002-12-28 20:37:16 +00:00
|
|
|
|
|
|
|
// Print Frame Information
|
2008-07-07 23:14:23 +00:00
|
|
|
FrameInfo->print(*this, OS);
|
2006-04-22 18:53:45 +00:00
|
|
|
|
|
|
|
// Print JumpTable Information
|
2010-01-25 23:26:13 +00:00
|
|
|
if (JumpTableInfo)
|
|
|
|
JumpTableInfo->print(OS);
|
2003-01-13 00:23:03 +00:00
|
|
|
|
|
|
|
// Print Constant Pool
|
2009-08-23 01:12:47 +00:00
|
|
|
ConstantPool->print(OS);
|
2005-08-31 22:34:59 +00:00
|
|
|
|
2008-02-10 18:45:23 +00:00
|
|
|
const TargetRegisterInfo *TRI = getTarget().getRegisterInfo();
|
2005-08-31 22:34:59 +00:00
|
|
|
|
2008-10-13 12:37:16 +00:00
|
|
|
if (RegInfo && !RegInfo->livein_empty()) {
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << "Function Live Ins: ";
|
2007-12-31 04:13:23 +00:00
|
|
|
for (MachineRegisterInfo::livein_iterator
|
|
|
|
I = RegInfo->livein_begin(), E = RegInfo->livein_end(); I != E; ++I) {
|
2008-02-10 18:45:23 +00:00
|
|
|
if (TRI)
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << "%" << TRI->getName(I->first);
|
2005-08-31 22:34:59 +00:00
|
|
|
else
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << " %physreg" << I->first;
|
2006-05-16 05:55:30 +00:00
|
|
|
|
|
|
|
if (I->second)
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << " in reg%" << I->second;
|
|
|
|
|
2009-12-03 00:50:42 +00:00
|
|
|
if (llvm::next(I) != E)
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << ", ";
|
2005-08-31 22:34:59 +00:00
|
|
|
}
|
2009-08-23 01:12:47 +00:00
|
|
|
OS << '\n';
|
2005-08-31 22:34:59 +00:00
|
|
|
}
|
2008-10-13 12:37:16 +00:00
|
|
|
if (RegInfo && !RegInfo->liveout_empty()) {
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << "Function Live Outs: ";
|
2007-12-31 04:13:23 +00:00
|
|
|
for (MachineRegisterInfo::liveout_iterator
|
2009-10-31 20:19:03 +00:00
|
|
|
I = RegInfo->liveout_begin(), E = RegInfo->liveout_end(); I != E; ++I){
|
2008-02-10 18:45:23 +00:00
|
|
|
if (TRI)
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << '%' << TRI->getName(*I);
|
2005-08-31 22:34:59 +00:00
|
|
|
else
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << "%physreg" << *I;
|
|
|
|
|
2009-12-03 00:50:42 +00:00
|
|
|
if (llvm::next(I) != E)
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << " ";
|
|
|
|
}
|
2009-08-23 01:12:47 +00:00
|
|
|
OS << '\n';
|
2005-08-31 22:34:59 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 20:19:03 +00:00
|
|
|
for (const_iterator BB = begin(), E = end(); BB != E; ++BB) {
|
|
|
|
OS << '\n';
|
2009-08-23 00:47:04 +00:00
|
|
|
BB->print(OS);
|
2009-10-31 20:19:03 +00:00
|
|
|
}
|
2004-03-29 21:58:31 +00:00
|
|
|
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << "\n# End machine code for function " << Fn->getName() << ".\n\n";
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
|
|
|
|
2004-07-08 00:47:58 +00:00
|
|
|
namespace llvm {
|
2004-09-05 18:41:35 +00:00
|
|
|
template<>
|
|
|
|
struct DOTGraphTraits<const MachineFunction*> : public DefaultDOTGraphTraits {
|
2009-11-30 12:38:13 +00:00
|
|
|
|
|
|
|
DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
|
|
|
|
|
2004-09-05 18:41:35 +00:00
|
|
|
static std::string getGraphName(const MachineFunction *F) {
|
2009-07-24 08:24:36 +00:00
|
|
|
return "CFG for '" + F->getFunction()->getNameStr() + "' function";
|
2004-09-05 18:41:35 +00:00
|
|
|
}
|
2004-07-08 00:47:58 +00:00
|
|
|
|
2009-11-30 12:38:47 +00:00
|
|
|
std::string getNodeLabel(const MachineBasicBlock *Node,
|
|
|
|
const MachineFunction *Graph) {
|
|
|
|
if (isSimple () && Node->getBasicBlock() &&
|
2004-09-05 18:41:35 +00:00
|
|
|
!Node->getBasicBlock()->getName().empty())
|
2009-07-24 08:24:36 +00:00
|
|
|
return Node->getBasicBlock()->getNameStr() + ":";
|
2004-07-08 00:47:58 +00:00
|
|
|
|
2009-08-23 03:13:20 +00:00
|
|
|
std::string OutStr;
|
|
|
|
{
|
|
|
|
raw_string_ostream OSS(OutStr);
|
|
|
|
|
2009-11-30 12:38:47 +00:00
|
|
|
if (isSimple())
|
2009-08-23 03:13:20 +00:00
|
|
|
OSS << Node->getNumber() << ':';
|
|
|
|
else
|
|
|
|
Node->print(OSS);
|
2004-09-05 18:41:35 +00:00
|
|
|
}
|
2004-07-08 00:47:58 +00:00
|
|
|
|
2004-09-05 18:41:35 +00:00
|
|
|
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
|
2009-07-24 08:24:36 +00:00
|
|
|
ViewGraph(this, "mf" + getFunction()->getNameStr());
|
2006-06-27 16:49:46 +00:00
|
|
|
#else
|
2009-08-23 08:50:52 +00:00
|
|
|
errs() << "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
|
|
|
|
{
|
2009-06-24 17:37:09 +00:00
|
|
|
#ifndef NDEBUG
|
2009-07-24 08:24:36 +00:00
|
|
|
ViewGraph(this, "mf" + getFunction()->getNameStr(), true);
|
2009-06-24 17:37:09 +00:00
|
|
|
#else
|
2009-08-23 08:50:52 +00:00
|
|
|
errs() << "SelectionDAG::viewGraph is only available in debug builds on "
|
|
|
|
<< "systems with Graphviz or gv!\n";
|
2009-06-24 17:37:09 +00:00
|
|
|
#endif // NDEBUG
|
2004-07-08 00:47:58 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 18:36:57 +00:00
|
|
|
/// addLiveIn - Add the specified physical register as a live-in value and
|
|
|
|
/// create a corresponding virtual register for it.
|
|
|
|
unsigned MachineFunction::addLiveIn(unsigned PReg,
|
|
|
|
const TargetRegisterClass *RC) {
|
|
|
|
assert(RC->contains(PReg) && "Not the correct regclass!");
|
|
|
|
unsigned VReg = getRegInfo().createVirtualRegister(RC);
|
|
|
|
getRegInfo().addLiveIn(PReg, VReg);
|
|
|
|
return VReg;
|
|
|
|
}
|
|
|
|
|
2010-01-16 06:09:35 +00:00
|
|
|
/// getDILocation - Get the DILocation for a given DebugLoc object.
|
|
|
|
DILocation MachineFunction::getDILocation(DebugLoc DL) const {
|
2009-02-03 22:55:54 +00:00
|
|
|
unsigned Idx = DL.getIndex();
|
2009-02-03 22:49:58 +00:00
|
|
|
assert(Idx < DebugLocInfo.DebugLocations.size() &&
|
|
|
|
"Invalid index into debug locations!");
|
2010-01-16 06:09:35 +00:00
|
|
|
return DILocation(DebugLocInfo.DebugLocations[Idx]);
|
2009-02-03 22:49:58 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 06:28:43 +00:00
|
|
|
|
|
|
|
/// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
|
|
|
|
/// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
|
|
|
|
/// normal 'L' label is returned.
|
|
|
|
MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
|
|
|
|
bool isLinkerPrivate) const {
|
|
|
|
assert(JumpTableInfo && "No jump tables");
|
|
|
|
|
2010-01-27 10:27:10 +00:00
|
|
|
assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
|
2010-01-26 06:28:43 +00:00
|
|
|
const MCAsmInfo &MAI = *getTarget().getMCAsmInfo();
|
|
|
|
|
|
|
|
const char *Prefix = isLinkerPrivate ? MAI.getLinkerPrivateGlobalPrefix() :
|
|
|
|
MAI.getPrivateGlobalPrefix();
|
|
|
|
SmallString<60> Name;
|
|
|
|
raw_svector_ostream(Name)
|
|
|
|
<< Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
|
2010-03-10 02:25:11 +00:00
|
|
|
if (isLinkerPrivate)
|
|
|
|
return Ctx.GetOrCreateSymbol(Name.str());
|
|
|
|
return Ctx.GetOrCreateTemporarySymbol(Name.str());
|
2010-01-26 06:28:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-01-25 07:19:06 +00:00
|
|
|
/// CreateFixedObject - Create a new object at a fixed location on the stack.
|
|
|
|
/// All fixed objects should be created before other objects are created for
|
|
|
|
/// efficiency. By default, fixed objects are immutable. This returns an
|
|
|
|
/// index with a negative value.
|
|
|
|
///
|
|
|
|
int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t SPOffset,
|
2009-11-12 20:49:22 +00:00
|
|
|
bool Immutable, bool isSS) {
|
2008-01-25 07:19:06 +00:00
|
|
|
assert(Size != 0 && "Cannot allocate zero size fixed stack objects!");
|
2009-11-12 20:49:22 +00:00
|
|
|
Objects.insert(Objects.begin(), StackObject(Size, 1, SPOffset, Immutable,
|
|
|
|
isSS));
|
2008-01-25 07:19:06 +00:00
|
|
|
return -++NumFixedObjects;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-13 16:19:33 +00:00
|
|
|
BitVector
|
|
|
|
MachineFrameInfo::getPristineRegs(const MachineBasicBlock *MBB) const {
|
|
|
|
assert(MBB && "MBB must be valid");
|
|
|
|
const MachineFunction *MF = MBB->getParent();
|
|
|
|
assert(MF && "MBB must be part of a MachineFunction");
|
|
|
|
const TargetMachine &TM = MF->getTarget();
|
|
|
|
const TargetRegisterInfo *TRI = TM.getRegisterInfo();
|
|
|
|
BitVector BV(TRI->getNumRegs());
|
|
|
|
|
|
|
|
// Before CSI is calculated, no registers are considered pristine. They can be
|
|
|
|
// freely used and PEI will make sure they are saved.
|
|
|
|
if (!isCalleeSavedInfoValid())
|
|
|
|
return BV;
|
|
|
|
|
|
|
|
for (const unsigned *CSR = TRI->getCalleeSavedRegs(MF); CSR && *CSR; ++CSR)
|
|
|
|
BV.set(*CSR);
|
|
|
|
|
|
|
|
// The entry MBB always has all CSRs pristine.
|
|
|
|
if (MBB == &MF->front())
|
|
|
|
return BV;
|
|
|
|
|
|
|
|
// On other MBBs the saved CSRs are not pristine.
|
|
|
|
const std::vector<CalleeSavedInfo> &CSI = getCalleeSavedInfo();
|
|
|
|
for (std::vector<CalleeSavedInfo>::const_iterator I = CSI.begin(),
|
|
|
|
E = CSI.end(); I != E; ++I)
|
|
|
|
BV.reset(I->getReg());
|
|
|
|
|
|
|
|
return BV;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-23 01:12:47 +00:00
|
|
|
void MachineFrameInfo::print(const MachineFunction &MF, raw_ostream &OS) const{
|
2009-10-31 20:19:03 +00:00
|
|
|
if (Objects.empty()) return;
|
|
|
|
|
2008-11-03 11:16:43 +00:00
|
|
|
const TargetFrameInfo *FI = MF.getTarget().getFrameInfo();
|
|
|
|
int ValOffset = (FI ? FI->getOffsetOfLocalArea() : 0);
|
2003-01-16 18:35:57 +00:00
|
|
|
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << "Frame Objects:\n";
|
|
|
|
|
2002-12-28 20:37:16 +00:00
|
|
|
for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
|
|
|
|
const StackObject &SO = Objects[i];
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << " fi#" << (int)(i-NumFixedObjects) << ": ";
|
2008-02-27 03:04:06 +00:00
|
|
|
if (SO.Size == ~0ULL) {
|
|
|
|
OS << "dead\n";
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-28 20:37:16 +00:00
|
|
|
if (SO.Size == 0)
|
|
|
|
OS << "variable sized";
|
|
|
|
else
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << "size=" << SO.Size;
|
|
|
|
OS << ", align=" << SO.Alignment;
|
2004-09-05 18:41:35 +00:00
|
|
|
|
2002-12-28 20:37:16 +00:00
|
|
|
if (i < NumFixedObjects)
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << ", fixed";
|
2002-12-28 20:37:16 +00:00
|
|
|
if (i < NumFixedObjects || SO.SPOffset != -1) {
|
2007-04-25 04:20:54 +00:00
|
|
|
int64_t Off = SO.SPOffset - ValOffset;
|
2009-10-31 20:19:03 +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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-16 18:35:57 +00:00
|
|
|
void MachineFrameInfo::dump(const MachineFunction &MF) const {
|
2010-01-04 23:39:17 +00:00
|
|
|
print(MF, dbgs());
|
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
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-25 23:26:13 +00:00
|
|
|
/// getEntrySize - Return the size of each entry in the jump table.
|
|
|
|
unsigned MachineJumpTableInfo::getEntrySize(const TargetData &TD) const {
|
|
|
|
// The size of a jump table entry is 4 bytes unless the entry is just the
|
|
|
|
// address of a block, in which case it is the pointer size.
|
|
|
|
switch (getEntryKind()) {
|
|
|
|
case MachineJumpTableInfo::EK_BlockAddress:
|
|
|
|
return TD.getPointerSize();
|
|
|
|
case MachineJumpTableInfo::EK_GPRel32BlockAddress:
|
|
|
|
case MachineJumpTableInfo::EK_LabelDifference32:
|
2010-01-26 04:05:28 +00:00
|
|
|
case MachineJumpTableInfo::EK_Custom32:
|
2010-01-25 23:26:13 +00:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
assert(0 && "Unknown jump table encoding!");
|
|
|
|
return ~0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getEntryAlignment - Return the alignment of each entry in the jump table.
|
|
|
|
unsigned MachineJumpTableInfo::getEntryAlignment(const TargetData &TD) const {
|
|
|
|
// The alignment of a jump table entry is the alignment of int32 unless the
|
|
|
|
// entry is just the address of a block, in which case it is the pointer
|
|
|
|
// alignment.
|
|
|
|
switch (getEntryKind()) {
|
|
|
|
case MachineJumpTableInfo::EK_BlockAddress:
|
|
|
|
return TD.getPointerABIAlignment();
|
|
|
|
case MachineJumpTableInfo::EK_GPRel32BlockAddress:
|
|
|
|
case MachineJumpTableInfo::EK_LabelDifference32:
|
2010-01-26 04:05:28 +00:00
|
|
|
case MachineJumpTableInfo::EK_Custom32:
|
2010-01-25 23:26:13 +00:00
|
|
|
return TD.getABIIntegerTypeAlignment(32);
|
|
|
|
}
|
|
|
|
assert(0 && "Unknown jump table encoding!");
|
|
|
|
return ~0;
|
|
|
|
}
|
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
/// 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
|
|
|
JumpTables.push_back(MachineJumpTableEntry(DestBBs));
|
|
|
|
return JumpTables.size()-1;
|
|
|
|
}
|
|
|
|
|
2010-01-26 05:58:28 +00:00
|
|
|
|
2009-04-15 01:18:49 +00:00
|
|
|
/// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
|
|
|
|
/// the jump tables to branch to New instead.
|
2010-01-26 05:58:28 +00:00
|
|
|
bool MachineJumpTableInfo::ReplaceMBBInJumpTables(MachineBasicBlock *Old,
|
|
|
|
MachineBasicBlock *New) {
|
2009-04-15 01:18:49 +00:00
|
|
|
assert(Old != New && "Not making a change?");
|
|
|
|
bool MadeChange = false;
|
2009-11-14 20:09:13 +00:00
|
|
|
for (size_t i = 0, e = JumpTables.size(); i != e; ++i)
|
|
|
|
ReplaceMBBInJumpTable(i, Old, New);
|
|
|
|
return MadeChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update
|
|
|
|
/// the jump table to branch to New instead.
|
2010-01-26 05:58:28 +00:00
|
|
|
bool MachineJumpTableInfo::ReplaceMBBInJumpTable(unsigned Idx,
|
|
|
|
MachineBasicBlock *Old,
|
|
|
|
MachineBasicBlock *New) {
|
2009-11-14 20:09:13 +00:00
|
|
|
assert(Old != New && "Not making a change?");
|
|
|
|
bool MadeChange = false;
|
|
|
|
MachineJumpTableEntry &JTE = JumpTables[Idx];
|
|
|
|
for (size_t j = 0, e = JTE.MBBs.size(); j != e; ++j)
|
|
|
|
if (JTE.MBBs[j] == Old) {
|
|
|
|
JTE.MBBs[j] = New;
|
|
|
|
MadeChange = true;
|
|
|
|
}
|
2009-04-15 01:18:49 +00:00
|
|
|
return MadeChange;
|
|
|
|
}
|
2006-04-22 18:53:45 +00:00
|
|
|
|
2009-08-23 01:12:47 +00:00
|
|
|
void MachineJumpTableInfo::print(raw_ostream &OS) const {
|
2009-10-31 20:19:03 +00:00
|
|
|
if (JumpTables.empty()) return;
|
|
|
|
|
|
|
|
OS << "Jump Tables:\n";
|
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << " jt#" << i << ": ";
|
|
|
|
for (unsigned j = 0, f = JumpTables[i].MBBs.size(); j != f; ++j)
|
|
|
|
OS << " BB#" << JumpTables[i].MBBs[j]->getNumber();
|
2006-04-22 18:53:45 +00:00
|
|
|
}
|
2009-10-31 20:19:03 +00:00
|
|
|
|
|
|
|
OS << '\n';
|
2006-04-22 18:53:45 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 23:39:17 +00:00
|
|
|
void MachineJumpTableInfo::dump() const { print(dbgs()); }
|
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())
|
2009-07-21 23:34:23 +00:00
|
|
|
return Val.MachineCPVal->getType();
|
2006-09-14 05:50:57 +00:00
|
|
|
return Val.ConstVal->getType();
|
|
|
|
}
|
|
|
|
|
2009-07-21 23:34:23 +00:00
|
|
|
|
2009-07-21 23:36:01 +00:00
|
|
|
unsigned MachineConstantPoolEntry::getRelocationInfo() const {
|
2009-07-21 23:34:23 +00:00
|
|
|
if (isMachineConstantPoolEntry())
|
2009-07-21 23:36:01 +00:00
|
|
|
return Val.MachineCPVal->getRelocationInfo();
|
2009-07-22 00:05:44 +00:00
|
|
|
return Val.ConstVal->getRelocationInfo();
|
2009-07-21 23:34:23 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-10-28 01:12:16 +00:00
|
|
|
/// CanShareConstantPoolEntry - Test whether the given two constants
|
|
|
|
/// can be allocated the same constant pool entry.
|
|
|
|
static bool CanShareConstantPoolEntry(Constant *A, Constant *B,
|
|
|
|
const TargetData *TD) {
|
|
|
|
// Handle the trivial case quickly.
|
|
|
|
if (A == B) return true;
|
|
|
|
|
|
|
|
// If they have the same type but weren't the same constant, quickly
|
|
|
|
// reject them.
|
|
|
|
if (A->getType() == B->getType()) return false;
|
|
|
|
|
|
|
|
// For now, only support constants with the same size.
|
|
|
|
if (TD->getTypeStoreSize(A->getType()) != TD->getTypeStoreSize(B->getType()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If a floating-point value and an integer value have the same encoding,
|
|
|
|
// they can share a constant-pool entry.
|
|
|
|
if (ConstantFP *AFP = dyn_cast<ConstantFP>(A))
|
|
|
|
if (ConstantInt *BI = dyn_cast<ConstantInt>(B))
|
|
|
|
return AFP->getValueAPF().bitcastToAPInt() == BI->getValue();
|
|
|
|
if (ConstantFP *BFP = dyn_cast<ConstantFP>(B))
|
|
|
|
if (ConstantInt *AI = dyn_cast<ConstantInt>(A))
|
|
|
|
return BFP->getValueAPF().bitcastToAPInt() == AI->getValue();
|
|
|
|
|
|
|
|
// Two vectors can share an entry if each pair of corresponding
|
|
|
|
// elements could.
|
|
|
|
if (ConstantVector *AV = dyn_cast<ConstantVector>(A))
|
|
|
|
if (ConstantVector *BV = dyn_cast<ConstantVector>(B)) {
|
|
|
|
if (AV->getType()->getNumElements() != BV->getType()->getNumElements())
|
|
|
|
return false;
|
|
|
|
for (unsigned i = 0, e = AV->getType()->getNumElements(); i != e; ++i)
|
2009-10-31 14:12:53 +00:00
|
|
|
if (!CanShareConstantPoolEntry(AV->getOperand(i),
|
|
|
|
BV->getOperand(i), TD))
|
2009-10-28 01:12:16 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Handle other cases.
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-02-09 04:46:04 +00:00
|
|
|
/// getConstantPoolIndex - Create a new entry in the constant pool or return
|
2008-09-16 20:45:53 +00:00
|
|
|
/// an existing one. User must specify the log2 of the minimum required
|
|
|
|
/// alignment for the object.
|
2006-02-09 04:46:04 +00:00
|
|
|
///
|
|
|
|
unsigned MachineConstantPool::getConstantPoolIndex(Constant *C,
|
|
|
|
unsigned Alignment) {
|
|
|
|
assert(Alignment && "Alignment must be specified!");
|
|
|
|
if (Alignment > PoolAlignment) PoolAlignment = Alignment;
|
2009-10-28 01:12:16 +00:00
|
|
|
|
2006-02-09 04:46:04 +00:00
|
|
|
// Check to see if we already have this constant.
|
|
|
|
//
|
|
|
|
// FIXME, this could be made much more efficient for large constant pools.
|
|
|
|
for (unsigned i = 0, e = Constants.size(); i != e; ++i)
|
2009-10-28 01:12:16 +00:00
|
|
|
if (!Constants[i].isMachineConstantPoolEntry() &&
|
|
|
|
CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C, TD)) {
|
|
|
|
if ((unsigned)Constants[i].getAlignment() < Alignment)
|
|
|
|
Constants[i].Alignment = Alignment;
|
2006-02-09 04:46:04 +00:00
|
|
|
return i;
|
2009-10-28 01:12:16 +00:00
|
|
|
}
|
2006-02-09 04:46:04 +00:00
|
|
|
|
2009-03-13 07:51:59 +00:00
|
|
|
Constants.push_back(MachineConstantPoolEntry(C, Alignment));
|
2006-02-09 04:46:04 +00:00
|
|
|
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.
|
|
|
|
int Idx = V->getExistingMachineCPValue(this, Alignment);
|
|
|
|
if (Idx != -1)
|
|
|
|
return (unsigned)Idx;
|
2009-03-13 07:51:59 +00:00
|
|
|
|
|
|
|
Constants.push_back(MachineConstantPoolEntry(V, Alignment));
|
2006-09-12 21:00:35 +00:00
|
|
|
return Constants.size()-1;
|
|
|
|
}
|
|
|
|
|
2008-08-23 22:53:13 +00:00
|
|
|
void MachineConstantPool::print(raw_ostream &OS) const {
|
2009-10-31 20:19:03 +00:00
|
|
|
if (Constants.empty()) return;
|
|
|
|
|
|
|
|
OS << "Constant Pool:\n";
|
2006-01-31 22:23:14 +00:00
|
|
|
for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << " cp#" << i << ": ";
|
2006-09-12 21:00:35 +00:00
|
|
|
if (Constants[i].isMachineConstantPoolEntry())
|
|
|
|
Constants[i].Val.MachineCPVal->print(OS);
|
|
|
|
else
|
|
|
|
OS << *(Value*)Constants[i].Val.ConstVal;
|
2009-10-31 20:19:03 +00:00
|
|
|
OS << ", align=" << Constants[i].getAlignment();
|
2006-01-31 22:23:14 +00:00
|
|
|
OS << "\n";
|
|
|
|
}
|
2003-01-13 00:23:03 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 23:39:17 +00:00
|
|
|
void MachineConstantPool::dump() const { print(dbgs()); }
|