56 : Fn(F),
Target(TM), Ctx(mmi.getContext()), MMI(mmi), GMI(gmi) {
69 getStackAlignment(AttributeSet::FunctionIndex));
77 Alignment = std::max(Alignment,
80 FunctionNumber = FunctionNum;
90 I->Insts.clearAndLeakNodesUnsafely();
92 InstructionRecycler.clear(Allocator);
93 OperandRecycler.
clear(Allocator);
94 BasicBlockRecycler.clear(Allocator);
104 FrameInfo->~MachineFrameInfo();
111 JumpTableInfo->~MachineJumpTableInfo();
120 if (JumpTableInfo)
return JumpTableInfo;
122 JumpTableInfo =
new (Allocator)
124 return JumpTableInfo;
133 if (
empty()) { MBBNumbering.clear();
return; }
141 unsigned BlockNo = 0;
143 BlockNo =
prior(MBBI)->getNumber()+1;
145 for (; MBBI != E; ++MBBI, ++BlockNo) {
146 if (MBBI->getNumber() != (int)BlockNo) {
148 if (MBBI->getNumber() != -1) {
149 assert(MBBNumbering[MBBI->getNumber()] == &*MBBI &&
150 "MBB number mismatch!");
151 MBBNumbering[MBBI->getNumber()] = 0;
155 if (MBBNumbering[BlockNo])
156 MBBNumbering[BlockNo]->setNumber(-1);
158 MBBNumbering[BlockNo] = MBBI;
159 MBBI->setNumber(BlockNo);
165 assert(BlockNo <= MBBNumbering.size() &&
"Mismatch!");
166 MBBNumbering.resize(BlockNo);
175 return new (InstructionRecycler.Allocate<
MachineInstr>(Allocator))
185 return new (InstructionRecycler.Allocate<
MachineInstr>(Allocator))
202 InstructionRecycler.Deallocate(Allocator, MI);
218 assert(MBB->
getParent() ==
this &&
"MBB parent mismatch!");
219 MBB->~MachineBasicBlock();
220 BasicBlockRecycler.Deallocate(Allocator, MBB);
225 uint64_t s,
unsigned base_alignment,
234 int64_t Offset, uint64_t Size) {
235 return new (Allocator)
247 std::pair<MachineInstr::mmo_iterator, MachineInstr::mmo_iterator>
260 if ((*I)->isLoad()) {
261 if (!(*I)->isStore())
269 (*I)->
getSize(), (*I)->getBaseAlignment(),
270 (*I)->getTBAAInfo());
271 Result[Index] = JustLoad;
276 return std::make_pair(Result, Result + Num);
279 std::pair<MachineInstr::mmo_iterator, MachineInstr::mmo_iterator>
292 if ((*I)->isStore()) {
301 (*I)->
getSize(), (*I)->getBaseAlignment(),
302 (*I)->getTBAAInfo());
303 Result[Index] = JustStore;
308 return std::make_pair(Result, Result + Num);
311 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
323 OS <<
"# Machine code for function " <<
getName() <<
": ";
325 OS << (RegInfo->
isSSA() ?
"SSA" :
"Post SSA");
327 OS <<
", not tracking liveness";
332 FrameInfo->
print(*
this, OS);
336 JumpTableInfo->
print(OS);
339 ConstantPool->
print(OS);
344 OS <<
"Function Live Ins: ";
349 OS <<
" in " << PrintReg(
I->second, TRI);
358 BB->print(OS, Indexes);
361 OS <<
"\n# End machine code for function " <<
getName() <<
".\n\n";
371 return "CFG for '" + F->
getName().
str() +
"' function";
383 OSS <<
": " << BB->getName();
388 if (OutStr[0] ==
'\n') OutStr.erase(OutStr.begin());
391 for (
unsigned i = 0; i != OutStr.length(); ++i)
392 if (OutStr[i] ==
'\n') {
394 OutStr.insert(OutStr.begin()+i+1,
'l');
406 errs() <<
"MachineFunction::viewCFG is only available in debug builds on "
407 <<
"systems with Graphviz or gv!\n";
416 errs() <<
"MachineFunction::viewCFGOnly is only available in debug builds on "
417 <<
"systems with Graphviz or gv!\n";
428 assert(MRI.
getRegClass(VReg) == RC &&
"Register class mismatch!");
440 bool isLinkerPrivate)
const {
441 assert(JumpTableInfo &&
"No jump tables");
442 assert(JTI < JumpTableInfo->getJumpTables().
size() &&
"Invalid JTI!");
466 return TM.getFrameLowering();
472 if (!getFrameLowering()->isStackRealignable() || !RealignOption)
473 assert(Align <= getFrameLowering()->getStackAlignment() &&
474 "For targets without stack realignment, Align is out of limit!");
475 if (MaxAlignment < Align) MaxAlignment =
Align;
480 unsigned StackAlign) {
481 if (!ShouldClamp || Align <= StackAlign)
483 DEBUG(
dbgs() <<
"Warning: requested alignment " << Align
484 <<
" exceeds the stack alignment " << StackAlign
485 <<
" when stack realignment is off" <<
'\n');
493 bool isSS,
bool MayNeedSP,
const AllocaInst *Alloca) {
494 assert(Size != 0 &&
"Cannot allocate zero size stack objects!");
498 Alignment, getFrameLowering()->getStackAlignment());
499 Objects.push_back(StackObject(Size, Alignment, 0,
false, isSS, MayNeedSP,
501 int Index = (int)
Objects.size() - NumFixedObjects - 1;
502 assert(Index >= 0 &&
"Bad frame index!");
512 unsigned Alignment) {
516 Alignment, getFrameLowering()->getStackAlignment());
518 int Index = (int)
Objects.size() - NumFixedObjects - 1;
529 HasVarSizedObjects =
true;
533 Alignment, getFrameLowering()->getStackAlignment());
534 Objects.push_back(StackObject(0, Alignment, 0,
false,
false,
true, 0));
536 return (
int)
Objects.size()-NumFixedObjects-1;
546 assert(Size != 0 &&
"Cannot allocate zero size fixed stack objects!");
556 Align, getFrameLowering()->getStackAlignment());
557 Objects.insert(
Objects.begin(), StackObject(Size, Align, SPOffset, Immutable,
561 return -++NumFixedObjects;
567 assert(MBB &&
"MBB must be valid");
569 assert(MF &&
"MBB must be part of a MachineFunction");
583 if (MBB == &MF->
front())
588 for (std::vector<CalleeSavedInfo>::const_iterator
I = CSI.begin(),
589 E = CSI.end();
I != E; ++
I)
590 BV.reset(
I->getReg());
607 if (FixedOff > Offset) Offset = FixedOff;
615 Offset = (Offset+Align-1)/Align*Align;
617 MaxAlign = std::max(Align, MaxAlign);
637 StackAlign = std::max(StackAlign, MaxAlign);
638 unsigned AlignMask = StackAlign - 1;
639 Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
641 return (
unsigned)Offset;
650 OS <<
"Frame Objects:\n";
652 for (
unsigned i = 0, e =
Objects.size(); i != e; ++i) {
653 const StackObject &SO =
Objects[i];
654 OS <<
" fi#" << (int)(i-NumFixedObjects) <<
": ";
655 if (SO.Size == ~0ULL) {
660 OS <<
"variable sized";
662 OS <<
"size=" << SO.Size;
663 OS <<
", align=" << SO.Alignment;
665 if (i < NumFixedObjects)
667 if (i < NumFixedObjects || SO.SPOffset != -1) {
668 int64_t Off = SO.SPOffset - ValOffset;
669 OS <<
", at location [SP";
680 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
732 const std::vector<MachineBasicBlock*> &DestBBs) {
733 assert(!DestBBs.empty() &&
"Cannot create an empty jump table!");
735 return JumpTables.size()-1;
742 assert(Old != New &&
"Not making a change?");
743 bool MadeChange =
false;
744 for (
size_t i = 0, e = JumpTables.size(); i != e; ++i)
754 assert(Old != New &&
"Not making a change?");
755 bool MadeChange =
false;
757 for (
size_t j = 0, e = JTE.
MBBs.size(); j != e; ++j)
758 if (JTE.
MBBs[j] == Old) {
766 if (JumpTables.empty())
return;
768 OS <<
"Jump Tables:\n";
770 for (
unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
771 OS <<
" jt#" << i <<
": ";
772 for (
unsigned j = 0, f = JumpTables[i].MBBs.size(); j != f; ++j)
773 OS <<
" BB#" << JumpTables[i].MBBs[j]->getNumber();
779 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
788 void MachineConstantPoolValue::anchor() { }
790 const DataLayout *MachineConstantPool::getDataLayout()
const {
791 return TM.getDataLayout();
796 return Val.MachineCPVal->getType();
797 return Val.ConstVal->getType();
803 return Val.MachineCPVal->getRelocationInfo();
804 return Val.ConstVal->getRelocationInfo();
808 for (
unsigned i = 0, e =
Constants.size(); i != e; ++i)
809 if (
Constants[i].isMachineConstantPoolEntry())
812 MachineCPVsSharingEntries.begin(), E = MachineCPVsSharingEntries.end();
822 if (A == B)
return true;
829 if (isa<StructType>(A->
getType()) || isa<ArrayType>(A->
getType()) ||
845 if (isa<PointerType>(A->
getType()))
847 const_cast<Constant*>(A), TD);
848 else if (A->
getType() != IntTy)
850 const_cast<Constant*>(A),
TD);
851 if (isa<PointerType>(B->
getType()))
853 const_cast<Constant*>(B), TD);
854 else if (B->
getType() != IntTy)
856 const_cast<Constant*>(B),
TD);
866 unsigned Alignment) {
867 assert(Alignment &&
"Alignment must be specified!");
868 if (Alignment > PoolAlignment) PoolAlignment = Alignment;
873 for (
unsigned i = 0, e =
Constants.size(); i != e; ++i)
874 if (!
Constants[i].isMachineConstantPoolEntry() &&
877 if ((
unsigned)
Constants[i].getAlignment() < Alignment)
887 unsigned Alignment) {
888 assert(Alignment &&
"Alignment must be specified!");
889 if (Alignment > PoolAlignment) PoolAlignment = Alignment;
896 MachineCPVsSharingEntries.insert(V);
897 return (
unsigned)Idx;
907 OS <<
"Constant Pool:\n";
908 for (
unsigned i = 0, e =
Constants.size(); i != e; ++i) {
909 OS <<
" cp#" << i <<
": ";
910 if (
Constants[i].isMachineConstantPoolEntry())
911 Constants[i].Val.MachineCPVal->print(OS);
914 OS <<
", align=" <<
Constants[i].getAlignment();
919 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
unsigned getStackAlignment() const
const MachineFunction * getParent() const
The machine constant pool.
virtual const TargetLowering * getTargetLowering() const
MachineInstr * CreateMachineInstr(const MCInstrDesc &MCID, DebugLoc DL, bool NoImp=false)
unsigned getPrefFunctionAlignment() const
Return the preferred function alignment.
livein_iterator livein_end() const
void print(raw_ostream &OS, SlotIndexes *=0) const
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
unsigned getPointerSize(unsigned AS=0) const
void addLiveIn(unsigned Reg, unsigned vreg=0)
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, unsigned f, uint64_t s, unsigned base_alignment, const MDNode *TBAAInfo=0, const MDNode *Ranges=0)
unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC)
const char * getPrivateGlobalPrefix() const
std::string getNodeLabel(const MachineBasicBlock *Node, const MachineFunction *Graph)
bool adjustsStack() const
const char * getLinkerPrivateGlobalPrefix() const
std::string str() const
str - Get the contents as an std::string.
MDNode - a tuple of other values.
const Function * getFunction() const
unsigned getFunctionNumber() const
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
void DeleteMachineBasicBlock(MachineBasicBlock *MBB)
bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old, MachineBasicBlock *New)
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF=0) const =0
StringRef getName() const
MachineJumpTableInfo * getOrCreateJumpTableInfo(unsigned JTEntryKind)
unsigned getMaxAlignment() const
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
unsigned getRelocationInfo() const
void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy=true, const Module *Context=0)
DOTGraphTraits(bool isSimple=false)
unsigned getPointerABIAlignment(unsigned AS=0) const
MCSymbol * GetOrCreateSymbol(StringRef Name)
static unsigned clampStackAlignment(bool ShouldClamp, unsigned Align, unsigned StackAlign)
clampStackAlignment - Clamp the alignment if requested and emit a warning.
const MCAsmInfo * getMCAsmInfo() const
#define llvm_unreachable(msg)
void Deallocate(const void *)
const TargetRegisterClass * getRegClass(unsigned Reg) const
Abstract Stack Frame Information.
std::pair< MachineInstr::mmo_iterator, MachineInstr::mmo_iterator > extractLoadMemRefs(MachineInstr::mmo_iterator Begin, MachineInstr::mmo_iterator End)
void print(raw_ostream &OS, SlotIndexes *=0) const
const MachineBasicBlock & front() const
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
void print(const MachineFunction &MF, raw_ostream &OS) const
int getObjectIndexBegin() const
unsigned createJumpTableIndex(const std::vector< MachineBasicBlock * > &DestBBs)
void RenumberBlocks(MachineBasicBlock *MBBFrom=0)
virtual int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment)=0
static std::string getGraphName(const MachineFunction *F)
An entry in a MachineConstantPool.
unsigned getTransientStackAlignment() const
const BasicBlock * getBasicBlock() const
unsigned estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
bool isMachineConstantPoolEntry() const
unsigned getEntrySize(const DataLayout &TD) const
getEntrySize - Return the size of each entry in the jump table.
unsigned getEntryAlignment(const DataLayout &TD) const
getEntryAlignment - Return the alignment of each entry in the jump table.
unsigned getABIIntegerTypeAlignment(unsigned BitWidth) const
unsigned int getFlags() const
getFlags - Return the raw flags of the source value,
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=0)
LLVM Basic Block Representation.
virtual bool needsStackRealignment(const MachineFunction &MF) const
LLVM Constant Representation.
static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B, const DataLayout *TD)
unsigned getLiveInVirtReg(unsigned PReg) const
bool tracksLiveness() const
virtual ~MachineFunctionInfo()
ItTy next(ItTy it, Dist n)
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
bool isCalleeSavedInfoValid() const
isCalleeSavedInfoValid - Has the callee saved info been calculated yet?
std::vector< MachineBasicBlock * > MBBs
MBBs - The vector of basic blocks from which to create the jump table.
union llvm::MachineConstantPoolEntry::@29 Val
The constant itself.
virtual const TargetFrameLowering * getFrameLowering() const
void DeleteMachineInstr(MachineInstr *MI)
int CreateSpillStackObject(uint64_t Size, unsigned Alignment)
LLVMContext & getContext() const
All values hold a context through their type.
iterator erase(iterator where)
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
int64_t getObjectOffset(int ObjectIdx) const
bool isDeadObjectIndex(int ObjectIdx) const
void print(raw_ostream &OS) const
BitVector getPristineRegs(const MachineBasicBlock *MBB) const
static IntegerType * get(LLVMContext &C, unsigned NumBits)
Get or create an IntegerType instance.
static ManagedStatic< LeakDetectorImpl< void > > Objects
void print(raw_ostream &OS) const
MCSymbol * getPICBaseSymbol() const
void dump() const
dump - Call print(cerr) to be called from the debugger.
MachineInstr * CloneMachineInstr(const MachineInstr *Orig)
bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New)
unsigned getObjectAlignment(int ObjectIdx) const
getObjectAlignment - Return the alignment of the specified stack object.
int getOffsetOfLocalArea() const
unsigned getMaxCallFrameSize() const
livein_iterator livein_begin() const
void clear(AllocatorType &Allocator)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
AttributeSet getAttributes() const
Return the attribute list for this Function.
MCSymbol * getJTISymbol(unsigned JTI, MCContext &Ctx, bool isLinkerPrivate=false) const
static void deleteNode(NodeTy *V)
const Value * getValue() const
void * Allocate(size_t Size, size_t Alignment)
StringRef str() const
Explicit conversion to StringRef.
int CreateVariableSizedObject(unsigned Alignment)
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
uint64_t MinAlign(uint64_t A, uint64_t B)
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, bool MayNeedSP=false, const AllocaInst *Alloca=0)
void ensureMaxAlignment(unsigned Align)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
MachineRegisterInfo & getRegInfo()
unsigned getMinFunctionAlignment() const
Return the minimum function alignment.
const TargetMachine & getTarget() const
virtual const TargetRegisterInfo * getRegisterInfo() const
uint64_t getTypeStoreSize(Type *Ty) const
bool hasVarSizedObjects() const
JTEntryKind getEntryKind() const
std::vector< std::pair< unsigned, unsigned > >::const_iterator livein_iterator
std::pair< MachineInstr::mmo_iterator, MachineInstr::mmo_iterator > extractStoreMemRefs(MachineInstr::mmo_iterator Begin, MachineInstr::mmo_iterator End)
void dump(const MachineFunction &MF) const
dump - Print the function to stderr.
int64_t getOffset() const
void deallocateOperandArray(OperandCapacity Cap, MachineOperand *Array)
bool livein_empty() const
Constant * ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, ArrayRef< Constant * > Ops, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0)
BasicBlockListType::iterator iterator
uint64_t getSize() const
getSize - Return the size in bytes of the memory reference.
ItTy prior(ItTy it, Dist n)
const MCRegisterInfo & MRI
int getObjectIndexEnd() const
StringRef getName() const
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable)
MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num)
int64_t getObjectSize(int ObjectIdx) const
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment)
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
uint64_t getBaseAlignment() const