diff options
Diffstat (limited to 'contrib/llvm/lib/CodeGen/MachineFunction.cpp')
-rw-r--r-- | contrib/llvm/lib/CodeGen/MachineFunction.cpp | 124 |
1 files changed, 78 insertions, 46 deletions
diff --git a/contrib/llvm/lib/CodeGen/MachineFunction.cpp b/contrib/llvm/lib/CodeGen/MachineFunction.cpp index f6604f3..a7c63ef 100644 --- a/contrib/llvm/lib/CodeGen/MachineFunction.cpp +++ b/contrib/llvm/lib/CodeGen/MachineFunction.cpp @@ -54,6 +54,30 @@ static cl::opt<unsigned> void MachineFunctionInitializer::anchor() {} +void MachineFunctionProperties::print(raw_ostream &ROS, bool OnlySet) const { + // Leave this function even in NDEBUG as an out-of-line anchor. +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) + for (BitVector::size_type i = 0; i < Properties.size(); ++i) { + bool HasProperty = Properties[i]; + if (OnlySet && !HasProperty) + continue; + switch(static_cast<Property>(i)) { + case Property::IsSSA: + ROS << (HasProperty ? "SSA, " : "Post SSA, "); + break; + case Property::TracksLiveness: + ROS << (HasProperty ? "" : "not ") << "tracking liveness, "; + break; + case Property::AllVRegsAllocated: + ROS << (HasProperty ? "AllVRegsAllocated" : "HasVRegs"); + break; + default: + break; + } + } +#endif +} + //===----------------------------------------------------------------------===// // MachineFunction implementation //===----------------------------------------------------------------------===// @@ -65,20 +89,34 @@ void ilist_traits<MachineBasicBlock>::deleteNode(MachineBasicBlock *MBB) { MBB->getParent()->DeleteMachineBasicBlock(MBB); } +static inline unsigned getFnStackAlignment(const TargetSubtargetInfo *STI, + const Function *Fn) { + if (Fn->hasFnAttribute(Attribute::StackAlignment)) + return Fn->getFnStackAlignment(); + return STI->getFrameLowering()->getStackAlignment(); +} + MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM, unsigned FunctionNum, MachineModuleInfo &mmi) : Fn(F), Target(TM), STI(TM.getSubtargetImpl(*F)), Ctx(mmi.getContext()), MMI(mmi) { + // Assume the function starts in SSA form with correct liveness. + Properties.set(MachineFunctionProperties::Property::IsSSA); + Properties.set(MachineFunctionProperties::Property::TracksLiveness); if (STI->getRegisterInfo()) RegInfo = new (Allocator) MachineRegisterInfo(this); else RegInfo = nullptr; MFInfo = nullptr; - FrameInfo = new (Allocator) - MachineFrameInfo(STI->getFrameLowering()->getStackAlignment(), - STI->getFrameLowering()->isStackRealignable(), - !F->hasFnAttribute("no-realign-stack")); + // We can realign the stack if the target supports it and the user hasn't + // explicitly asked us not to. + bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() && + !F->hasFnAttribute("no-realign-stack"); + FrameInfo = new (Allocator) MachineFrameInfo( + getFnStackAlignment(STI, Fn), /*StackRealignable=*/CanRealignSP, + /*ForceRealign=*/CanRealignSP && + F->hasFnAttribute(Attribute::StackAlignment)); if (Fn->hasFnAttribute(Attribute::StackAlignment)) FrameInfo->ensureMaxAlignment(Fn->getFnStackAlignment()); @@ -209,9 +247,9 @@ void MachineFunction::RenumberBlocks(MachineBasicBlock *MBB) { } /// Allocate a new MachineInstr. Use this instead of `new MachineInstr'. -MachineInstr * -MachineFunction::CreateMachineInstr(const MCInstrDesc &MCID, - DebugLoc DL, bool NoImp) { +MachineInstr *MachineFunction::CreateMachineInstr(const MCInstrDesc &MCID, + const DebugLoc &DL, + bool NoImp) { return new (InstructionRecycler.Allocate<MachineInstr>(Allocator)) MachineInstr(*this, MCID, DL, NoImp); } @@ -256,13 +294,11 @@ MachineFunction::DeleteMachineBasicBlock(MachineBasicBlock *MBB) { BasicBlockRecycler.Deallocate(Allocator, MBB); } -MachineMemOperand * -MachineFunction::getMachineMemOperand(MachinePointerInfo PtrInfo, unsigned f, - uint64_t s, unsigned base_alignment, - const AAMDNodes &AAInfo, - const MDNode *Ranges) { - return new (Allocator) MachineMemOperand(PtrInfo, f, s, base_alignment, - AAInfo, Ranges); +MachineMemOperand *MachineFunction::getMachineMemOperand( + MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, + unsigned base_alignment, const AAMDNodes &AAInfo, const MDNode *Ranges) { + return new (Allocator) + MachineMemOperand(PtrInfo, f, s, base_alignment, AAInfo, Ranges); } MachineMemOperand * @@ -358,7 +394,7 @@ const char *MachineFunction::createExternalSymbolName(StringRef Name) { } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) -void MachineFunction::dump() const { +LLVM_DUMP_METHOD void MachineFunction::dump() const { print(dbgs()); } #endif @@ -368,14 +404,11 @@ StringRef MachineFunction::getName() const { return getFunction()->getName(); } -void MachineFunction::print(raw_ostream &OS, SlotIndexes *Indexes) const { +void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const { OS << "# Machine code for function " << getName() << ": "; - if (RegInfo) { - OS << (RegInfo->isSSA() ? "SSA" : "Post SSA"); - if (!RegInfo->tracksLiveness()) - OS << ", not tracking liveness"; - } - OS << '\n'; + OS << "Properties: <"; + getProperties().print(OS); + OS << ">\n"; // Print Frame Information FrameInfo->print(*this, OS); @@ -523,7 +556,7 @@ MCSymbol *MachineFunction::getPICBaseSymbol() const { /// Make sure the function is at least Align bytes aligned. void MachineFrameInfo::ensureMaxAlignment(unsigned Align) { - if (!StackRealignable || !RealignOption) + if (!StackRealignable) assert(Align <= StackAlignment && "For targets without stack realignment, Align is out of limit!"); if (MaxAlignment < Align) MaxAlignment = Align; @@ -545,8 +578,7 @@ static inline unsigned clampStackAlignment(bool ShouldClamp, unsigned Align, int MachineFrameInfo::CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca) { assert(Size != 0 && "Cannot allocate zero size stack objects!"); - Alignment = clampStackAlignment(!StackRealignable || !RealignOption, - Alignment, StackAlignment); + Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment); Objects.push_back(StackObject(Size, Alignment, 0, false, isSS, Alloca, !isSS)); int Index = (int)Objects.size() - NumFixedObjects - 1; @@ -559,8 +591,7 @@ int MachineFrameInfo::CreateStackObject(uint64_t Size, unsigned Alignment, /// returning a nonnegative identifier to represent it. int MachineFrameInfo::CreateSpillStackObject(uint64_t Size, unsigned Alignment) { - Alignment = clampStackAlignment(!StackRealignable || !RealignOption, - Alignment, StackAlignment); + Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment); CreateStackObject(Size, Alignment, true); int Index = (int)Objects.size() - NumFixedObjects - 1; ensureMaxAlignment(Alignment); @@ -573,8 +604,7 @@ int MachineFrameInfo::CreateSpillStackObject(uint64_t Size, int MachineFrameInfo::CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca) { HasVarSizedObjects = true; - Alignment = clampStackAlignment(!StackRealignable || !RealignOption, - Alignment, StackAlignment); + Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment); Objects.push_back(StackObject(0, Alignment, 0, false, false, Alloca, true)); ensureMaxAlignment(Alignment); return (int)Objects.size()-NumFixedObjects-1; @@ -590,10 +620,11 @@ int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t SPOffset, // 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 Align = MinAlign(SPOffset, StackAlignment); - Align = clampStackAlignment(!StackRealignable || !RealignOption, Align, - StackAlignment); + // object is 16-byte aligned. Note that unlike the non-fixed case, if the + // stack needs realignment, we can't assume that the stack will in fact be + // aligned. + unsigned Align = MinAlign(SPOffset, ForcedRealign ? 1 : StackAlignment); + Align = clampStackAlignment(!StackRealignable, Align, StackAlignment); Objects.insert(Objects.begin(), StackObject(Size, Align, SPOffset, Immutable, /*isSS*/ false, /*Alloca*/ nullptr, isAliased)); @@ -604,9 +635,8 @@ int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t SPOffset, /// Returns an index with a negative value. int MachineFrameInfo::CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset) { - unsigned Align = MinAlign(SPOffset, StackAlignment); - Align = clampStackAlignment(!StackRealignable || !RealignOption, Align, - StackAlignment); + unsigned Align = MinAlign(SPOffset, ForcedRealign ? 1 : StackAlignment); + Align = clampStackAlignment(!StackRealignable, Align, StackAlignment); Objects.insert(Objects.begin(), StackObject(Size, Align, SPOffset, /*Immutable*/ true, /*isSS*/ true, @@ -819,7 +849,7 @@ void MachineJumpTableInfo::print(raw_ostream &OS) const { } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) -void MachineJumpTableInfo::dump() const { print(dbgs()); } +LLVM_DUMP_METHOD void MachineJumpTableInfo::dump() const { print(dbgs()); } #endif @@ -852,6 +882,8 @@ MachineConstantPoolEntry::getSectionKind(const DataLayout *DL) const { return SectionKind::getMergeableConst8(); case 16: return SectionKind::getMergeableConst16(); + case 32: + return SectionKind::getMergeableConst32(); default: return SectionKind::getReadOnly(); } @@ -895,17 +927,17 @@ static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B, // the constant folding APIs to do this so that we get the benefit of // DataLayout. if (isa<PointerType>(A->getType())) - A = ConstantFoldInstOperands(Instruction::PtrToInt, IntTy, - const_cast<Constant *>(A), DL); + A = ConstantFoldCastOperand(Instruction::PtrToInt, + const_cast<Constant *>(A), IntTy, DL); else if (A->getType() != IntTy) - A = ConstantFoldInstOperands(Instruction::BitCast, IntTy, - const_cast<Constant *>(A), DL); + A = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(A), + IntTy, DL); if (isa<PointerType>(B->getType())) - B = ConstantFoldInstOperands(Instruction::PtrToInt, IntTy, - const_cast<Constant *>(B), DL); + B = ConstantFoldCastOperand(Instruction::PtrToInt, + const_cast<Constant *>(B), IntTy, DL); else if (B->getType() != IntTy) - B = ConstantFoldInstOperands(Instruction::BitCast, IntTy, - const_cast<Constant *>(B), DL); + B = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(B), + IntTy, DL); return A == B; } @@ -966,5 +998,5 @@ void MachineConstantPool::print(raw_ostream &OS) const { } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) -void MachineConstantPool::dump() const { print(dbgs()); } +LLVM_DUMP_METHOD void MachineConstantPool::dump() const { print(dbgs()); } #endif |