2009-06-02 17:52:33 +00:00
|
|
|
//===-- MachineFunction.cpp -----------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Collect native machine code information for a function. This allows
|
|
|
|
// target-specific information about the generated code to be stored with each
|
|
|
|
// function.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-04-14 13:54:10 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2012-08-15 19:34:23 +00:00
|
|
|
#include "llvm/DebugInfo.h"
|
2009-07-04 13:58:26 +00:00
|
|
|
#include "llvm/Function.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2010-04-06 15:52:58 +00:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2010-02-16 09:30:23 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
2012-04-14 13:54:10 +00:00
|
|
|
#include "llvm/Analysis/ConstantFolding.h"
|
2010-01-15 15:37:28 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2012-12-02 13:10:19 +00:00
|
|
|
#include "llvm/DataLayout.h"
|
2009-07-04 13:58:26 +00:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
2010-02-16 09:30:23 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
#include "llvm/Support/GraphWriter.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2010-02-16 09:30:23 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-02 17:52:33 +00:00
|
|
|
// MachineFunction implementation
|
2010-02-16 09:30:23 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2009-10-14 17:57:32 +00:00
|
|
|
// Out of line virtual method.
|
|
|
|
MachineFunctionInfo::~MachineFunctionInfo() {}
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
void ilist_traits<MachineBasicBlock>::deleteNode(MachineBasicBlock *MBB) {
|
|
|
|
MBB->getParent()->DeleteMachineBasicBlock(MBB);
|
|
|
|
}
|
|
|
|
|
2010-05-04 16:11:02 +00:00
|
|
|
MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM,
|
2011-02-20 12:57:14 +00:00
|
|
|
unsigned FunctionNum, MachineModuleInfo &mmi,
|
|
|
|
GCModuleInfo* gmi)
|
|
|
|
: Fn(F), Target(TM), Ctx(mmi.getContext()), MMI(mmi), GMI(gmi) {
|
2009-06-02 17:52:33 +00:00
|
|
|
if (TM.getRegisterInfo())
|
2010-03-21 10:49:05 +00:00
|
|
|
RegInfo = new (Allocator) MachineRegisterInfo(*TM.getRegisterInfo());
|
2009-06-02 17:52:33 +00:00
|
|
|
else
|
|
|
|
RegInfo = 0;
|
|
|
|
MFInfo = 0;
|
2011-02-20 12:57:14 +00:00
|
|
|
FrameInfo = new (Allocator) MachineFrameInfo(*TM.getFrameLowering());
|
2012-12-02 13:10:19 +00:00
|
|
|
if (Fn->getFnAttributes().hasAttribute(Attributes::StackAlignment))
|
|
|
|
FrameInfo->ensureMaxAlignment(Fn->getAttributes().
|
|
|
|
getFnAttributes().getStackAlignment());
|
|
|
|
ConstantPool = new (Allocator) MachineConstantPool(TM.getDataLayout());
|
2011-06-12 15:42:51 +00:00
|
|
|
Alignment = TM.getTargetLowering()->getMinFunctionAlignment();
|
|
|
|
// FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn.
|
2012-12-02 13:10:19 +00:00
|
|
|
if (!Fn->getFnAttributes().hasAttribute(Attributes::OptimizeForSize))
|
2011-06-12 15:42:51 +00:00
|
|
|
Alignment = std::max(Alignment,
|
|
|
|
TM.getTargetLowering()->getPrefFunctionAlignment());
|
2010-02-16 09:30:23 +00:00
|
|
|
FunctionNumber = FunctionNum;
|
|
|
|
JumpTableInfo = 0;
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MachineFunction::~MachineFunction() {
|
|
|
|
BasicBlocks.clear();
|
|
|
|
InstructionRecycler.clear(Allocator);
|
|
|
|
BasicBlockRecycler.clear(Allocator);
|
2009-06-27 10:44:33 +00:00
|
|
|
if (RegInfo) {
|
|
|
|
RegInfo->~MachineRegisterInfo();
|
|
|
|
Allocator.Deallocate(RegInfo);
|
|
|
|
}
|
2009-06-02 17:52:33 +00:00
|
|
|
if (MFInfo) {
|
2009-06-27 10:44:33 +00:00
|
|
|
MFInfo->~MachineFunctionInfo();
|
|
|
|
Allocator.Deallocate(MFInfo);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2012-08-15 19:34:23 +00:00
|
|
|
|
|
|
|
FrameInfo->~MachineFrameInfo();
|
|
|
|
Allocator.Deallocate(FrameInfo);
|
|
|
|
|
|
|
|
ConstantPool->~MachineConstantPool();
|
|
|
|
Allocator.Deallocate(ConstantPool);
|
|
|
|
|
2010-02-16 09:30:23 +00:00
|
|
|
if (JumpTableInfo) {
|
|
|
|
JumpTableInfo->~MachineJumpTableInfo();
|
|
|
|
Allocator.Deallocate(JumpTableInfo);
|
|
|
|
}
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2010-02-16 09:30:23 +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;
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2010-03-21 10:49:05 +00:00
|
|
|
JumpTableInfo = new (Allocator)
|
2010-02-16 09:30:23 +00:00
|
|
|
MachineJumpTableInfo((MachineJumpTableInfo::JTEntryKind)EntryKind);
|
|
|
|
return JumpTableInfo;
|
|
|
|
}
|
2009-06-02 17:52:33 +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;
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
// Figure out the block number this should have.
|
|
|
|
unsigned BlockNo = 0;
|
|
|
|
if (MBBI != begin())
|
|
|
|
BlockNo = prior(MBBI)->getNumber()+1;
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2009-06-02 17:52:33 +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;
|
|
|
|
}
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
// 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);
|
|
|
|
}
|
2012-08-15 19:34:23 +00:00
|
|
|
}
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
// Okay, all the blocks are renumbered. If we have compactified the block
|
|
|
|
// numbering, shrink MBBNumbering now.
|
|
|
|
assert(BlockNo <= MBBNumbering.size() && "Mismatch!");
|
|
|
|
MBBNumbering.resize(BlockNo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateMachineInstr - Allocate a new MachineInstr. Use this instead
|
|
|
|
/// of `new MachineInstr'.
|
|
|
|
///
|
|
|
|
MachineInstr *
|
2011-07-17 15:36:56 +00:00
|
|
|
MachineFunction::CreateMachineInstr(const MCInstrDesc &MCID,
|
2009-06-02 17:52:33 +00:00
|
|
|
DebugLoc DL, bool NoImp) {
|
|
|
|
return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
|
2011-07-17 15:36:56 +00:00
|
|
|
MachineInstr(MCID, DL, NoImp);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// CloneMachineInstr - Create a new MachineInstr which is a copy of the
|
2010-02-16 09:30:23 +00:00
|
|
|
/// 'Orig' instruction, identical in all ways except the instruction
|
2009-06-02 17:52:33 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
|
|
|
|
///
|
|
|
|
void
|
|
|
|
MachineFunction::DeleteMachineBasicBlock(MachineBasicBlock *MBB) {
|
|
|
|
assert(MBB->getParent() == this && "MBB parent mismatch!");
|
|
|
|
MBB->~MachineBasicBlock();
|
|
|
|
BasicBlockRecycler.Deallocate(Allocator, MBB);
|
|
|
|
}
|
|
|
|
|
2009-10-14 17:57:32 +00:00
|
|
|
MachineMemOperand *
|
2011-02-20 12:57:14 +00:00
|
|
|
MachineFunction::getMachineMemOperand(MachinePointerInfo PtrInfo, unsigned f,
|
|
|
|
uint64_t s, unsigned base_alignment,
|
2012-04-14 13:54:10 +00:00
|
|
|
const MDNode *TBAAInfo,
|
|
|
|
const MDNode *Ranges) {
|
2011-02-20 12:57:14 +00:00
|
|
|
return new (Allocator) MachineMemOperand(PtrInfo, f, s, base_alignment,
|
2012-04-14 13:54:10 +00:00
|
|
|
TBAAInfo, Ranges);
|
2009-10-14 17:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MachineMemOperand *
|
|
|
|
MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO,
|
|
|
|
int64_t Offset, uint64_t Size) {
|
2010-03-21 10:49:05 +00:00
|
|
|
return new (Allocator)
|
2011-02-20 12:57:14 +00:00
|
|
|
MachineMemOperand(MachinePointerInfo(MMO->getValue(),
|
|
|
|
MMO->getOffset()+Offset),
|
|
|
|
MMO->getFlags(), Size,
|
|
|
|
MMO->getBaseAlignment(), 0);
|
2009-10-14 17:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MachineInstr::mmo_iterator
|
|
|
|
MachineFunction::allocateMemRefsArray(unsigned long Num) {
|
|
|
|
return Allocator.Allocate<MachineMemOperand *>(Num);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 =
|
2011-02-20 12:57:14 +00:00
|
|
|
getMachineMemOperand((*I)->getPointerInfo(),
|
2009-10-14 17:57:32 +00:00
|
|
|
(*I)->getFlags() & ~MachineMemOperand::MOStore,
|
2011-02-20 12:57:14 +00:00
|
|
|
(*I)->getSize(), (*I)->getBaseAlignment(),
|
|
|
|
(*I)->getTBAAInfo());
|
2009-10-14 17:57:32 +00:00
|
|
|
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 =
|
2011-02-20 12:57:14 +00:00
|
|
|
getMachineMemOperand((*I)->getPointerInfo(),
|
2009-10-14 17:57:32 +00:00
|
|
|
(*I)->getFlags() & ~MachineMemOperand::MOLoad,
|
2011-02-20 12:57:14 +00:00
|
|
|
(*I)->getSize(), (*I)->getBaseAlignment(),
|
|
|
|
(*I)->getTBAAInfo());
|
2009-10-14 17:57:32 +00:00
|
|
|
Result[Index] = JustStore;
|
|
|
|
}
|
|
|
|
++Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::make_pair(Result, Result + Num);
|
|
|
|
}
|
|
|
|
|
2012-12-02 13:10:19 +00:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2009-06-02 17:52:33 +00:00
|
|
|
void MachineFunction::dump() const {
|
2010-01-15 15:37:28 +00:00
|
|
|
print(dbgs());
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2012-12-02 13:10:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
StringRef MachineFunction::getName() const {
|
|
|
|
assert(getFunction() && "No function!");
|
|
|
|
return getFunction()->getName();
|
|
|
|
}
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
void MachineFunction::print(raw_ostream &OS, SlotIndexes *Indexes) const {
|
2012-12-02 13:10:19 +00:00
|
|
|
OS << "# Machine code for function " << getName() << ": ";
|
2012-04-14 13:54:10 +00:00
|
|
|
if (RegInfo) {
|
|
|
|
OS << (RegInfo->isSSA() ? "SSA" : "Post SSA");
|
|
|
|
if (!RegInfo->tracksLiveness())
|
|
|
|
OS << ", not tracking liveness";
|
|
|
|
}
|
|
|
|
OS << '\n';
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
// Print Frame Information
|
|
|
|
FrameInfo->print(*this, OS);
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
// Print JumpTable Information
|
2010-02-16 09:30:23 +00:00
|
|
|
if (JumpTableInfo)
|
|
|
|
JumpTableInfo->print(OS);
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
// Print Constant Pool
|
2009-10-14 17:57:32 +00:00
|
|
|
ConstantPool->print(OS);
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
const TargetRegisterInfo *TRI = getTarget().getRegisterInfo();
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
if (RegInfo && !RegInfo->livein_empty()) {
|
2009-11-04 14:58:56 +00:00
|
|
|
OS << "Function Live Ins: ";
|
2009-06-02 17:52:33 +00:00
|
|
|
for (MachineRegisterInfo::livein_iterator
|
|
|
|
I = RegInfo->livein_begin(), E = RegInfo->livein_end(); I != E; ++I) {
|
2011-06-12 15:42:51 +00:00
|
|
|
OS << PrintReg(I->first, TRI);
|
2009-06-02 17:52:33 +00:00
|
|
|
if (I->second)
|
2011-06-12 15:42:51 +00:00
|
|
|
OS << " in " << PrintReg(I->second, TRI);
|
2009-12-15 18:09:07 +00:00
|
|
|
if (llvm::next(I) != E)
|
2009-11-04 14:58:56 +00:00
|
|
|
OS << ", ";
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2009-10-14 17:57:32 +00:00
|
|
|
OS << '\n';
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
if (RegInfo && !RegInfo->liveout_empty()) {
|
2011-06-12 15:42:51 +00:00
|
|
|
OS << "Function Live Outs:";
|
2009-06-02 17:52:33 +00:00
|
|
|
for (MachineRegisterInfo::liveout_iterator
|
2011-06-12 15:42:51 +00:00
|
|
|
I = RegInfo->liveout_begin(), E = RegInfo->liveout_end(); I != E; ++I)
|
|
|
|
OS << ' ' << PrintReg(*I, TRI);
|
2009-10-14 17:57:32 +00:00
|
|
|
OS << '\n';
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2009-11-04 14:58:56 +00:00
|
|
|
for (const_iterator BB = begin(), E = end(); BB != E; ++BB) {
|
|
|
|
OS << '\n';
|
2011-02-20 12:57:14 +00:00
|
|
|
BB->print(OS, Indexes);
|
2009-11-04 14:58:56 +00:00
|
|
|
}
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2012-12-02 13:10:19 +00:00
|
|
|
OS << "\n# End machine code for function " << getName() << ".\n\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
template<>
|
|
|
|
struct DOTGraphTraits<const MachineFunction*> : public DefaultDOTGraphTraits {
|
2009-12-01 11:07:05 +00:00
|
|
|
|
|
|
|
DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
static std::string getGraphName(const MachineFunction *F) {
|
2012-12-02 13:10:19 +00:00
|
|
|
return "CFG for '" + F->getName().str() + "' function";
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2009-12-01 11:07:05 +00:00
|
|
|
std::string getNodeLabel(const MachineBasicBlock *Node,
|
|
|
|
const MachineFunction *Graph) {
|
2009-10-14 17:57:32 +00:00
|
|
|
std::string OutStr;
|
|
|
|
{
|
|
|
|
raw_string_ostream OSS(OutStr);
|
2011-02-20 12:57:14 +00:00
|
|
|
|
|
|
|
if (isSimple()) {
|
|
|
|
OSS << "BB#" << Node->getNumber();
|
|
|
|
if (const BasicBlock *BB = Node->getBasicBlock())
|
|
|
|
OSS << ": " << BB->getName();
|
|
|
|
} else
|
2009-10-14 17:57:32 +00:00
|
|
|
Node->print(OSS);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineFunction::viewCFG() const
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
2012-12-02 13:10:19 +00:00
|
|
|
ViewGraph(this, "mf" + getName());
|
2009-06-02 17:52:33 +00:00
|
|
|
#else
|
2010-07-13 17:19:57 +00:00
|
|
|
errs() << "MachineFunction::viewCFG is only available in debug builds on "
|
2009-10-14 17:57:32 +00:00
|
|
|
<< "systems with Graphviz or gv!\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
#endif // NDEBUG
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineFunction::viewCFGOnly() const
|
|
|
|
{
|
2009-06-27 10:44:33 +00:00
|
|
|
#ifndef NDEBUG
|
2012-12-02 13:10:19 +00:00
|
|
|
ViewGraph(this, "mf" + getName(), true);
|
2009-06-27 10:44:33 +00:00
|
|
|
#else
|
2010-07-13 17:19:57 +00:00
|
|
|
errs() << "MachineFunction::viewCFGOnly is only available in debug builds on "
|
2009-10-14 17:57:32 +00:00
|
|
|
<< "systems with Graphviz or gv!\n";
|
2009-06-27 10:44:33 +00:00
|
|
|
#endif // NDEBUG
|
2009-06-02 17:52:33 +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,
|
2011-02-26 22:03:50 +00:00
|
|
|
const TargetRegisterClass *RC) {
|
2010-05-27 15:15:58 +00:00
|
|
|
MachineRegisterInfo &MRI = getRegInfo();
|
|
|
|
unsigned VReg = MRI.getLiveInVirtReg(PReg);
|
|
|
|
if (VReg) {
|
|
|
|
assert(MRI.getRegClass(VReg) == RC && "Register class mismatch!");
|
|
|
|
return VReg;
|
|
|
|
}
|
|
|
|
VReg = MRI.createVirtualRegister(RC);
|
|
|
|
MRI.addLiveIn(PReg, VReg);
|
2009-06-02 17:52:33 +00:00
|
|
|
return VReg;
|
|
|
|
}
|
|
|
|
|
2010-02-16 09:30:23 +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");
|
|
|
|
assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
|
|
|
|
const MCAsmInfo &MAI = *getTarget().getMCAsmInfo();
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2010-02-16 09:30:23 +00:00
|
|
|
const char *Prefix = isLinkerPrivate ? MAI.getLinkerPrivateGlobalPrefix() :
|
|
|
|
MAI.getPrivateGlobalPrefix();
|
|
|
|
SmallString<60> Name;
|
|
|
|
raw_svector_ostream(Name)
|
|
|
|
<< Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
|
2010-04-02 08:54:30 +00:00
|
|
|
return Ctx.GetOrCreateSymbol(Name.str());
|
2010-02-16 09:30:23 +00:00
|
|
|
}
|
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
/// getPICBaseSymbol - Return a function-local symbol to represent the PIC
|
|
|
|
/// base.
|
|
|
|
MCSymbol *MachineFunction::getPICBaseSymbol() const {
|
|
|
|
const MCAsmInfo &MAI = *Target.getMCAsmInfo();
|
|
|
|
return Ctx.GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix())+
|
|
|
|
Twine(getFunctionNumber())+"$pb");
|
|
|
|
}
|
2010-02-16 09:30:23 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineFrameInfo implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// 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,
|
2010-07-13 17:19:57 +00:00
|
|
|
bool Immutable) {
|
2009-06-02 17:52:33 +00:00
|
|
|
assert(Size != 0 && "Cannot allocate zero size fixed stack objects!");
|
2010-07-13 17:19:57 +00:00
|
|
|
// The alignment of the frame index can be determined from its offset from
|
|
|
|
// the incoming frame position. If the frame object is at offset 32 and
|
|
|
|
// the stack is guaranteed to be 16-byte aligned, then we know that the
|
|
|
|
// object is 16-byte aligned.
|
|
|
|
unsigned StackAlign = TFI.getStackAlignment();
|
|
|
|
unsigned Align = MinAlign(SPOffset, StackAlign);
|
|
|
|
Objects.insert(Objects.begin(), StackObject(Size, Align, SPOffset, Immutable,
|
2012-12-02 13:10:19 +00:00
|
|
|
/*isSS*/ false,
|
|
|
|
/*NeedSP*/ false,
|
|
|
|
/*Alloca*/ 0));
|
2009-06-02 17:52:33 +00:00
|
|
|
return -++NumFixedObjects;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-14 17:57:32 +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;
|
|
|
|
|
2012-04-14 13:54:10 +00:00
|
|
|
for (const uint16_t *CSR = TRI->getCalleeSavedRegs(MF); CSR && *CSR; ++CSR)
|
2009-10-14 17:57:32 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MachineFrameInfo::print(const MachineFunction &MF, raw_ostream &OS) const{
|
2009-11-04 14:58:56 +00:00
|
|
|
if (Objects.empty()) return;
|
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
const TargetFrameLowering *FI = MF.getTarget().getFrameLowering();
|
2009-06-02 17:52:33 +00:00
|
|
|
int ValOffset = (FI ? FI->getOffsetOfLocalArea() : 0);
|
|
|
|
|
2009-11-04 14:58:56 +00:00
|
|
|
OS << "Frame Objects:\n";
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
|
|
|
|
const StackObject &SO = Objects[i];
|
2009-11-04 14:58:56 +00:00
|
|
|
OS << " fi#" << (int)(i-NumFixedObjects) << ": ";
|
2009-06-02 17:52:33 +00:00
|
|
|
if (SO.Size == ~0ULL) {
|
|
|
|
OS << "dead\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (SO.Size == 0)
|
|
|
|
OS << "variable sized";
|
|
|
|
else
|
2009-11-04 14:58:56 +00:00
|
|
|
OS << "size=" << SO.Size;
|
|
|
|
OS << ", align=" << SO.Alignment;
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
if (i < NumFixedObjects)
|
2009-11-04 14:58:56 +00:00
|
|
|
OS << ", fixed";
|
2009-06-02 17:52:33 +00:00
|
|
|
if (i < NumFixedObjects || SO.SPOffset != -1) {
|
|
|
|
int64_t Off = SO.SPOffset - ValOffset;
|
2009-11-04 14:58:56 +00:00
|
|
|
OS << ", at location [SP";
|
2009-06-02 17:52:33 +00:00
|
|
|
if (Off > 0)
|
|
|
|
OS << "+" << Off;
|
|
|
|
else if (Off < 0)
|
|
|
|
OS << Off;
|
|
|
|
OS << "]";
|
|
|
|
}
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-02 13:10:19 +00:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2009-06-02 17:52:33 +00:00
|
|
|
void MachineFrameInfo::dump(const MachineFunction &MF) const {
|
2010-01-15 15:37:28 +00:00
|
|
|
print(MF, dbgs());
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2012-12-02 13:10:19 +00:00
|
|
|
#endif
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineJumpTableInfo implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-02-16 09:30:23 +00:00
|
|
|
/// getEntrySize - Return the size of each entry in the jump table.
|
2012-12-02 13:10:19 +00:00
|
|
|
unsigned MachineJumpTableInfo::getEntrySize(const DataLayout &TD) const {
|
2010-02-16 09:30:23 +00:00
|
|
|
// 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();
|
2012-04-14 13:54:10 +00:00
|
|
|
case MachineJumpTableInfo::EK_GPRel64BlockAddress:
|
|
|
|
return 8;
|
2010-02-16 09:30:23 +00:00
|
|
|
case MachineJumpTableInfo::EK_GPRel32BlockAddress:
|
|
|
|
case MachineJumpTableInfo::EK_LabelDifference32:
|
|
|
|
case MachineJumpTableInfo::EK_Custom32:
|
|
|
|
return 4;
|
2010-03-16 16:51:38 +00:00
|
|
|
case MachineJumpTableInfo::EK_Inline:
|
|
|
|
return 0;
|
2010-02-16 09:30:23 +00:00
|
|
|
}
|
2012-04-14 13:54:10 +00:00
|
|
|
llvm_unreachable("Unknown jump table encoding!");
|
2010-02-16 09:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getEntryAlignment - Return the alignment of each entry in the jump table.
|
2012-12-02 13:10:19 +00:00
|
|
|
unsigned MachineJumpTableInfo::getEntryAlignment(const DataLayout &TD) const {
|
2010-02-16 09:30:23 +00:00
|
|
|
// 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();
|
2012-04-14 13:54:10 +00:00
|
|
|
case MachineJumpTableInfo::EK_GPRel64BlockAddress:
|
|
|
|
return TD.getABIIntegerTypeAlignment(64);
|
2010-02-16 09:30:23 +00:00
|
|
|
case MachineJumpTableInfo::EK_GPRel32BlockAddress:
|
|
|
|
case MachineJumpTableInfo::EK_LabelDifference32:
|
|
|
|
case MachineJumpTableInfo::EK_Custom32:
|
|
|
|
return TD.getABIIntegerTypeAlignment(32);
|
2010-03-16 16:51:38 +00:00
|
|
|
case MachineJumpTableInfo::EK_Inline:
|
|
|
|
return 1;
|
2010-02-16 09:30:23 +00:00
|
|
|
}
|
2012-04-14 13:54:10 +00:00
|
|
|
llvm_unreachable("Unknown jump table encoding!");
|
2010-02-16 09:30:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-21 10:49:05 +00:00
|
|
|
/// createJumpTableIndex - Create a new jump table entry in the jump table info.
|
2009-06-02 17:52:33 +00:00
|
|
|
///
|
2010-03-21 10:49:05 +00:00
|
|
|
unsigned MachineJumpTableInfo::createJumpTableIndex(
|
2009-06-02 17:52:33 +00:00
|
|
|
const std::vector<MachineBasicBlock*> &DestBBs) {
|
|
|
|
assert(!DestBBs.empty() && "Cannot create an empty jump table!");
|
|
|
|
JumpTables.push_back(MachineJumpTableEntry(DestBBs));
|
|
|
|
return JumpTables.size()-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
|
|
|
|
/// the jump tables to branch to New instead.
|
2010-02-16 09:30:23 +00:00
|
|
|
bool MachineJumpTableInfo::ReplaceMBBInJumpTables(MachineBasicBlock *Old,
|
|
|
|
MachineBasicBlock *New) {
|
2009-06-02 17:52:33 +00:00
|
|
|
assert(Old != New && "Not making a change?");
|
|
|
|
bool MadeChange = false;
|
2009-11-18 14:58:34 +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-02-16 09:30:23 +00:00
|
|
|
bool MachineJumpTableInfo::ReplaceMBBInJumpTable(unsigned Idx,
|
|
|
|
MachineBasicBlock *Old,
|
|
|
|
MachineBasicBlock *New) {
|
2009-11-18 14:58:34 +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-06-02 17:52:33 +00:00
|
|
|
return MadeChange;
|
|
|
|
}
|
|
|
|
|
2009-10-14 17:57:32 +00:00
|
|
|
void MachineJumpTableInfo::print(raw_ostream &OS) const {
|
2009-11-04 14:58:56 +00:00
|
|
|
if (JumpTables.empty()) return;
|
|
|
|
|
|
|
|
OS << "Jump Tables:\n";
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
|
2009-11-04 14:58:56 +00:00
|
|
|
OS << " jt#" << i << ": ";
|
|
|
|
for (unsigned j = 0, f = JumpTables[i].MBBs.size(); j != f; ++j)
|
|
|
|
OS << " BB#" << JumpTables[i].MBBs[j]->getNumber();
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2009-11-04 14:58:56 +00:00
|
|
|
|
|
|
|
OS << '\n';
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2012-12-02 13:10:19 +00:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2010-01-15 15:37:28 +00:00
|
|
|
void MachineJumpTableInfo::dump() const { print(dbgs()); }
|
2012-12-02 13:10:19 +00:00
|
|
|
#endif
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineConstantPool implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-04-14 13:54:10 +00:00
|
|
|
void MachineConstantPoolValue::anchor() { }
|
|
|
|
|
2011-10-20 21:10:27 +00:00
|
|
|
Type *MachineConstantPoolEntry::getType() const {
|
2009-06-02 17:52:33 +00:00
|
|
|
if (isMachineConstantPoolEntry())
|
2009-10-14 17:57:32 +00:00
|
|
|
return Val.MachineCPVal->getType();
|
2009-06-02 17:52:33 +00:00
|
|
|
return Val.ConstVal->getType();
|
|
|
|
}
|
|
|
|
|
2009-10-14 17:57:32 +00:00
|
|
|
|
|
|
|
unsigned MachineConstantPoolEntry::getRelocationInfo() const {
|
|
|
|
if (isMachineConstantPoolEntry())
|
|
|
|
return Val.MachineCPVal->getRelocationInfo();
|
|
|
|
return Val.ConstVal->getRelocationInfo();
|
|
|
|
}
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
MachineConstantPool::~MachineConstantPool() {
|
|
|
|
for (unsigned i = 0, e = Constants.size(); i != e; ++i)
|
|
|
|
if (Constants[i].isMachineConstantPoolEntry())
|
|
|
|
delete Constants[i].Val.MachineCPVal;
|
2011-02-26 22:03:50 +00:00
|
|
|
for (DenseSet<MachineConstantPoolValue*>::iterator I =
|
|
|
|
MachineCPVsSharingEntries.begin(), E = MachineCPVsSharingEntries.end();
|
|
|
|
I != E; ++I)
|
|
|
|
delete *I;
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 14:58:56 +00:00
|
|
|
/// CanShareConstantPoolEntry - Test whether the given two constants
|
|
|
|
/// can be allocated the same constant pool entry.
|
2010-05-04 16:11:02 +00:00
|
|
|
static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
|
2012-12-02 13:10:19 +00:00
|
|
|
const DataLayout *TD) {
|
2009-11-04 14:58:56 +00:00
|
|
|
// 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;
|
|
|
|
|
2012-04-14 13:54:10 +00:00
|
|
|
// We can't handle structs or arrays.
|
|
|
|
if (isa<StructType>(A->getType()) || isa<ArrayType>(A->getType()) ||
|
|
|
|
isa<StructType>(B->getType()) || isa<ArrayType>(B->getType()))
|
|
|
|
return false;
|
|
|
|
|
2009-11-04 14:58:56 +00:00
|
|
|
// For now, only support constants with the same size.
|
2012-04-14 13:54:10 +00:00
|
|
|
uint64_t StoreSize = TD->getTypeStoreSize(A->getType());
|
|
|
|
if (StoreSize != TD->getTypeStoreSize(B->getType()) ||
|
|
|
|
StoreSize > 128)
|
2009-11-04 14:58:56 +00:00
|
|
|
return false;
|
|
|
|
|
2012-04-14 13:54:10 +00:00
|
|
|
Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8);
|
|
|
|
|
|
|
|
// Try constant folding a bitcast of both instructions to an integer. If we
|
|
|
|
// get two identical ConstantInt's, then we are good to share them. We use
|
|
|
|
// the constant folding APIs to do this so that we get the benefit of
|
2012-12-02 13:10:19 +00:00
|
|
|
// DataLayout.
|
2012-04-14 13:54:10 +00:00
|
|
|
if (isa<PointerType>(A->getType()))
|
|
|
|
A = ConstantFoldInstOperands(Instruction::PtrToInt, IntTy,
|
|
|
|
const_cast<Constant*>(A), TD);
|
|
|
|
else if (A->getType() != IntTy)
|
|
|
|
A = ConstantFoldInstOperands(Instruction::BitCast, IntTy,
|
|
|
|
const_cast<Constant*>(A), TD);
|
|
|
|
if (isa<PointerType>(B->getType()))
|
|
|
|
B = ConstantFoldInstOperands(Instruction::PtrToInt, IntTy,
|
|
|
|
const_cast<Constant*>(B), TD);
|
|
|
|
else if (B->getType() != IntTy)
|
|
|
|
B = ConstantFoldInstOperands(Instruction::BitCast, IntTy,
|
|
|
|
const_cast<Constant*>(B), TD);
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2012-04-14 13:54:10 +00:00
|
|
|
return A == B;
|
2009-11-04 14:58:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
/// getConstantPoolIndex - Create a new entry in the constant pool or return
|
|
|
|
/// an existing one. User must specify the log2 of the minimum required
|
|
|
|
/// alignment for the object.
|
|
|
|
///
|
2010-05-04 16:11:02 +00:00
|
|
|
unsigned MachineConstantPool::getConstantPoolIndex(const Constant *C,
|
2009-06-02 17:52:33 +00:00
|
|
|
unsigned Alignment) {
|
|
|
|
assert(Alignment && "Alignment must be specified!");
|
|
|
|
if (Alignment > PoolAlignment) PoolAlignment = Alignment;
|
2009-11-04 14:58:56 +00:00
|
|
|
|
2009-06-02 17:52:33 +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-11-04 14:58:56 +00:00
|
|
|
if (!Constants[i].isMachineConstantPoolEntry() &&
|
|
|
|
CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C, TD)) {
|
|
|
|
if ((unsigned)Constants[i].getAlignment() < Alignment)
|
|
|
|
Constants[i].Alignment = Alignment;
|
2009-06-02 17:52:33 +00:00
|
|
|
return i;
|
2009-11-04 14:58:56 +00:00
|
|
|
}
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
Constants.push_back(MachineConstantPoolEntry(C, Alignment));
|
|
|
|
return Constants.size()-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V,
|
|
|
|
unsigned Alignment) {
|
|
|
|
assert(Alignment && "Alignment must be specified!");
|
|
|
|
if (Alignment > PoolAlignment) PoolAlignment = Alignment;
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
// 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);
|
2011-02-26 22:03:50 +00:00
|
|
|
if (Idx != -1) {
|
|
|
|
MachineCPVsSharingEntries.insert(V);
|
2009-06-02 17:52:33 +00:00
|
|
|
return (unsigned)Idx;
|
2011-02-26 22:03:50 +00:00
|
|
|
}
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
Constants.push_back(MachineConstantPoolEntry(V, Alignment));
|
|
|
|
return Constants.size()-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineConstantPool::print(raw_ostream &OS) const {
|
2009-11-04 14:58:56 +00:00
|
|
|
if (Constants.empty()) return;
|
|
|
|
|
|
|
|
OS << "Constant Pool:\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
|
2009-11-04 14:58:56 +00:00
|
|
|
OS << " cp#" << i << ": ";
|
2009-06-02 17:52:33 +00:00
|
|
|
if (Constants[i].isMachineConstantPoolEntry())
|
|
|
|
Constants[i].Val.MachineCPVal->print(OS);
|
|
|
|
else
|
2012-12-02 13:10:19 +00:00
|
|
|
OS << *(const Value*)Constants[i].Val.ConstVal;
|
2009-11-04 14:58:56 +00:00
|
|
|
OS << ", align=" << Constants[i].getAlignment();
|
2009-06-02 17:52:33 +00:00
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-02 13:10:19 +00:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2010-01-15 15:37:28 +00:00
|
|
|
void MachineConstantPool::dump() const { print(dbgs()); }
|
2012-12-02 13:10:19 +00:00
|
|
|
#endif
|