本文整理汇总了C++中machinefunction::iterator类的典型用法代码示例。如果您正苦于以下问题:C++ iterator类的具体用法?C++ iterator怎么用?C++ iterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateCallsInformation
/// calculateCallsInformation - Calculate the MaxCallFrameSize and AdjustsStack
/// variables for the function's frame information and eliminate call frame
/// pseudo instructions.
void PEI::calculateCallsInformation(MachineFunction &Fn) {
const TargetInstrInfo &TII = *Fn.getTarget().getInstrInfo();
const TargetFrameLowering *TFI = Fn.getTarget().getFrameLowering();
MachineFrameInfo *MFI = Fn.getFrameInfo();
unsigned MaxCallFrameSize = 0;
bool AdjustsStack = MFI->adjustsStack();
// Get the function call frame set-up and tear-down instruction opcode
int FrameSetupOpcode = TII.getCallFrameSetupOpcode();
int FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
// Early exit for targets which have no call frame setup/destroy pseudo
// instructions.
if (FrameSetupOpcode == -1 && FrameDestroyOpcode == -1)
return;
std::vector<MachineBasicBlock::iterator> FrameSDOps;
for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB)
for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I)
if (I->getOpcode() == FrameSetupOpcode ||
I->getOpcode() == FrameDestroyOpcode) {
assert(I->getNumOperands() >= 1 && "Call Frame Setup/Destroy Pseudo"
" instructions should have a single immediate argument!");
unsigned Size = I->getOperand(0).getImm();
if (Size > MaxCallFrameSize) MaxCallFrameSize = Size;
AdjustsStack = true;
FrameSDOps.push_back(I);
} else if (I->isInlineAsm()) {
// Some inline asm's need a stack frame, as indicated by operand 1.
unsigned ExtraInfo = I->getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
if (ExtraInfo & InlineAsm::Extra_IsAlignStack)
AdjustsStack = true;
}
MFI->setAdjustsStack(AdjustsStack);
MFI->setMaxCallFrameSize(MaxCallFrameSize);
for (std::vector<MachineBasicBlock::iterator>::iterator
i = FrameSDOps.begin(), e = FrameSDOps.end(); i != e; ++i) {
MachineBasicBlock::iterator I = *i;
// If call frames are not being included as part of the stack frame, and
// the target doesn't indicate otherwise, remove the call frame pseudos
// here. The sub/add sp instruction pairs are still inserted, but we don't
// need to track the SP adjustment for frame index elimination.
if (TFI->canSimplifyCallFramePseudos(Fn))
TFI->eliminateCallFramePseudoInstr(Fn, *I->getParent(), I);
}
}
示例2: printInstructions
unsigned Disassembler::printInstructions(formatted_raw_ostream &Out,
unsigned Address, unsigned Size, bool PrintTypes) {
MachineFunction *MF = disassemble(Address);
MachineFunction::iterator BI = MF->begin(), BE = MF->end();
// Skip to first basic block with instruction in desired address
// Out << BI->instr_rbegin()->getDebugLoc().getLine() << "\n";
while (BI != BE
&& getDebugOffset(BI->instr_rbegin()->getDebugLoc()) < Address) {
++BI;
}
if (BI == BE) {
printError("Could not disassemble, reached end of function's basic blocks"
" when looking for first instruction.");
return 0;
}
MachineBasicBlock::iterator II = BI->instr_begin(), IE = BI->instr_end();
// skip to first instruction
while (getDebugOffset(II->getDebugLoc()) < Address) {
if (II == IE) {
printError("Unreachable: reached end of basic block whe looking for first"
" instruction.");
++BI;
II = BI->instr_begin();
IE = BI->instr_end();
}
++II;
}
if (Address != getDebugOffset(II->getDebugLoc())) {
Out << "Warning: starting at " << getDebugOffset(II->getDebugLoc())
<< " instead of " << Address << ".\n";
}
// Function Name and Offset
Out << "<" << MF->getName();
if (getDebugOffset(MF->begin()->instr_begin()->getDebugLoc()) != Address) {
Out << "+"
<< (Address
- getDebugOffset(MF->begin()->instr_begin()->getDebugLoc()));
}
Out << ">:\n";
// Print each instruction
unsigned InstrCount = 0;
while (BI != BE && (Size == 0 || InstrCount < Size)) {
printInstruction(Out, II, PrintTypes);
++InstrCount;
++II;
if (II == IE) {
++BI;
II = BI->instr_begin();
IE = BI->instr_end();
}
}
return InstrCount;
}
示例3: scavengeFrameVirtualRegs
/// scavengeFrameVirtualRegs - Replace all frame index virtual registers
/// with physical registers. Use the register scavenger to find an
/// appropriate register to use.
void PEI::scavengeFrameVirtualRegs(MachineFunction &Fn) {
// Run through the instructions and find any virtual registers.
for (MachineFunction::iterator BB = Fn.begin(),
E = Fn.end(); BB != E; ++BB) {
RS->enterBasicBlock(BB);
unsigned VirtReg = 0;
unsigned ScratchReg = 0;
int SPAdj = 0;
// The instruction stream may change in the loop, so check BB->end()
// directly.
for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
MachineInstr *MI = I;
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
if (MI->getOperand(i).isReg()) {
MachineOperand &MO = MI->getOperand(i);
unsigned Reg = MO.getReg();
if (Reg == 0)
continue;
if (!TargetRegisterInfo::isVirtualRegister(Reg))
continue;
++NumVirtualFrameRegs;
// Have we already allocated a scratch register for this virtual?
if (Reg != VirtReg) {
// When we first encounter a new virtual register, it
// must be a definition.
assert(MI->getOperand(i).isDef() &&
"frame index virtual missing def!");
// Scavenge a new scratch register
VirtReg = Reg;
const TargetRegisterClass *RC = Fn.getRegInfo().getRegClass(Reg);
ScratchReg = RS->scavengeRegister(RC, I, SPAdj);
++NumScavengedRegs;
}
// Replace this reference to the virtual register with the
// scratch register.
assert (ScratchReg && "Missing scratch register!");
MI->getOperand(i).setReg(ScratchReg);
}
}
RS->forward(I);
++I;
}
}
}
示例4: FindSafePoints
void GCMachineCodeAnalysis::FindSafePoints(MachineFunction &MF) {
for (MachineFunction::iterator BBI = MF.begin(), BBE = MF.end(); BBI != BBE;
++BBI)
for (MachineBasicBlock::iterator MI = BBI->begin(), ME = BBI->end();
MI != ME; ++MI)
if (MI->isCall()) {
// Do not treat tail or sibling call sites as safe points. This is
// legal since any arguments passed to the callee which live in the
// remnants of the callers frame will be owned and updated by the
// callee if required.
if (MI->isTerminator())
continue;
VisitCallPoint(MI);
}
}
示例5:
void ARM64BranchRelaxation::adjustBlockOffsets(MachineBasicBlock *Start) {
unsigned PrevNum = Start->getNumber();
MachineFunction::iterator MBBI = Start, E = MF->end();
for (++MBBI; MBBI != E; ++MBBI) {
MachineBasicBlock *MBB = MBBI;
unsigned Num = MBB->getNumber();
if (!Num) // block zero is never changed from offset zero.
continue;
// Get the offset and known bits at the end of the layout predecessor.
// Include the alignment of the current block.
unsigned LogAlign = MBBI->getAlignment();
BlockInfo[Num].Offset = BlockInfo[PrevNum].postOffset(LogAlign);
PrevNum = Num;
}
}
示例6: Splice
/// Splice - Move the sequence of instructions [Begin,End) to just before
/// InsertPt. Update branch instructions as needed to account for broken
/// fallthrough edges and to take advantage of newly exposed fallthrough
/// opportunities.
///
void CodePlacementOpt::Splice(MachineFunction &MF,
MachineFunction::iterator InsertPt,
MachineFunction::iterator Begin,
MachineFunction::iterator End) {
assert(Begin != MF.begin() && End != MF.begin() && InsertPt != MF.begin() &&
"Splice can't change the entry block!");
MachineFunction::iterator OldBeginPrior = prior(Begin);
MachineFunction::iterator OldEndPrior = prior(End);
MF.splice(InsertPt, Begin, End);
prior(Begin)->updateTerminator();
OldBeginPrior->updateTerminator();
OldEndPrior->updateTerminator();
}
示例7: estimateRSStackSizeLimit
/// estimateRSStackSizeLimit - Look at each instruction that references stack
/// frames and return the stack size limit beyond which some of these
/// instructions will require a scratch register during their expansion later.
// FIXME: Move to TII?
static unsigned estimateRSStackSizeLimit(MachineFunction &MF,
const TargetFrameLowering *TFI) {
const ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
unsigned Limit = (1 << 12) - 1;
for (MachineFunction::iterator BB = MF.begin(),E = MF.end(); BB != E; ++BB) {
for (MachineBasicBlock::iterator I = BB->begin(), E = BB->end();
I != E; ++I) {
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
if (!I->getOperand(i).isFI()) continue;
// When using ADDri to get the address of a stack object, 255 is the
// largest offset guaranteed to fit in the immediate offset.
if (I->getOpcode() == ARM::ADDri) {
Limit = std::min(Limit, (1U << 8) - 1);
break;
}
// Otherwise check the addressing mode.
switch (I->getDesc().TSFlags & ARMII::AddrModeMask) {
case ARMII::AddrMode3:
case ARMII::AddrModeT2_i8:
Limit = std::min(Limit, (1U << 8) - 1);
break;
case ARMII::AddrMode5:
case ARMII::AddrModeT2_i8s4:
Limit = std::min(Limit, ((1U << 8) - 1) * 4);
break;
case ARMII::AddrModeT2_i12:
// i12 supports only positive offset so these will be converted to
// i8 opcodes. See llvm::rewriteT2FrameIndex.
if (TFI->hasFP(MF) && AFI->hasStackFrame())
Limit = std::min(Limit, (1U << 8) - 1);
break;
case ARMII::AddrMode4:
case ARMII::AddrMode6:
// Addressing modes 4 & 6 (load/store) instructions can't encode an
// immediate offset for stack references.
return 0;
default:
break;
}
break; // At most one FI per instruction
}
}
}
return Limit;
}
示例8: processFunctionAfterISel
void MipsSEDAGToDAGISel::processFunctionAfterISel(MachineFunction &MF) {
initGlobalBaseReg(MF);
MachineRegisterInfo *MRI = &MF.getRegInfo();
for (MachineFunction::iterator MFI = MF.begin(), MFE = MF.end(); MFI != MFE;
++MFI)
for (MachineBasicBlock::iterator I = MFI->begin(); I != MFI->end(); ++I) {
if (I->getOpcode() == Mips::RDDSP)
addDSPCtrlRegOperands(false, *I, MF);
else if (I->getOpcode() == Mips::WRDSP)
addDSPCtrlRegOperands(true, *I, MF);
else
replaceUsesWithZeroReg(MRI, *I);
}
}
示例9: scanAndRewriteCalls
void PatmosSPMark::scanAndRewriteCalls(MachineFunction *MF, Worklist &W) {
for (MachineFunction::iterator MBB = MF->begin(), MBBE = MF->end();
MBB != MBBE; ++MBB) {
for( MachineBasicBlock::iterator MI = MBB->begin(),
ME = MBB->getFirstTerminator();
MI != ME; ++MI) {
if (MI->isCall()) {
MachineFunction *MF = getCallTargetMF(MI);
if (!MF) {
dbgs() << "[Single-Path] WARNING: Cannot rewrite call in "
<< MBB->getParent()->getFunction()->getName()
<< " (indirect call?)\n";
continue;
};
const Function *Target = getCallTarget(MI);
if (Target->getName() == "__udivsi3") {
//DEBUG(dbgs() << "[Single-Path] skipping call to "
// << Target->getName() << "\n");
//continue;
}
PatmosMachineFunctionInfo *PMFI =
MF->getInfo<PatmosMachineFunctionInfo>();
if (!PMFI->isSinglePath()) {
// rewrite call to _sp variant
rewriteCall(MI);
// set _sp MF to single path in PMFI (MF has changed!)
MachineFunction *MF = getCallTargetMF(MI);
PatmosMachineFunctionInfo *PMFI =
MF->getInfo<PatmosMachineFunctionInfo>();
// we possibly have already marked the _sp variant as single-path
// in an earlier call
if (!PMFI->isSinglePath()) {
PMFI->setSinglePath();
// add the new single-path function to the worklist
W.push_back(MF);
NumSPTotal++; // bump STATISTIC
NumSPMaybe++; // bump STATISTIC
}
}
}
}
}
}
示例10: runOnMachineFunction
bool Inserter::runOnMachineFunction(MachineFunction &F) {
Cpu0FunctionInfo *Cpu0FI = F.getInfo<Cpu0FunctionInfo>();
if ((TM.getRelocationModel() != Reloc::PIC_) ||
(!Cpu0FI->globalBaseRegFixed()))
return false;
bool Changed = false;
int FI = Cpu0FI->getGPFI();
for (MachineFunction::iterator MFI = F.begin(), MFE = F.end();
MFI != MFE; ++MFI) {
MachineBasicBlock& MBB = *MFI;
MachineBasicBlock::iterator I = MFI->begin();
/// IsLandingPad - Indicate that this basic block is entered via an
/// exception handler.
// If MBB is a landing pad, insert instruction that restores $gp after
// EH_LABEL.
if (MBB.isLandingPad()) {
// Find EH_LABEL first.
for (; I->getOpcode() != TargetOpcode::EH_LABEL; ++I) ;
// Insert ld.
++I;
DebugLoc dl = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
BuildMI(MBB, I, dl, TII->get(Cpu0::LD), Cpu0::GP).addFrameIndex(FI)
.addImm(0);
Changed = true;
}
while (I != MFI->end()) {
if (I->getOpcode() != Cpu0::JALR) {
++I;
continue;
}
DebugLoc dl = I->getDebugLoc();
// emit lw $gp, ($gp save slot on stack) after jalr
BuildMI(MBB, ++I, dl, TII->get(Cpu0::LD), Cpu0::GP).addFrameIndex(FI)
.addImm(0);
Changed = true;
}
}
return Changed;
}
示例11: runOnMachineFunction
bool HexagonCopyToCombine::runOnMachineFunction(MachineFunction &MF) {
if (IsCombinesDisabled) return false;
bool HasChanged = false;
// Get target info.
TRI = MF.getSubtarget().getRegisterInfo();
TII = MF.getSubtarget<HexagonSubtarget>().getInstrInfo();
// Combine aggressively (for code size)
ShouldCombineAggressively =
MF.getTarget().getOptLevel() <= CodeGenOpt::Default;
// Traverse basic blocks.
for (MachineFunction::iterator BI = MF.begin(), BE = MF.end(); BI != BE;
++BI) {
PotentiallyNewifiableTFR.clear();
findPotentialNewifiableTFRs(*BI);
// Traverse instructions in basic block.
for(MachineBasicBlock::iterator MI = BI->begin(), End = BI->end();
MI != End;) {
MachineInstr *I1 = MI++;
// Don't combine a TFR whose user could be newified (instructions that
// define double registers can not be newified - Programmer's Ref Manual
// 5.4.2 New-value stores).
if (ShouldCombineAggressively && PotentiallyNewifiableTFR.count(I1))
continue;
// Ignore instructions that are not combinable.
if (!isCombinableInstType(I1, TII, ShouldCombineAggressively))
continue;
// Find a second instruction that can be merged into a combine
// instruction.
bool DoInsertAtI1 = false;
MachineInstr *I2 = findPairable(I1, DoInsertAtI1);
if (I2) {
HasChanged = true;
combine(I1, I2, MI, DoInsertAtI1);
}
}
}
return HasChanged;
}
示例12: findCustomSafePoints
bool VmkitGC::findCustomSafePoints(GCFunctionInfo& FI, MachineFunction &MF) {
for (MachineFunction::iterator BBI = MF.begin(),
BBE = MF.end(); BBI != BBE; ++BBI) {
for (MachineBasicBlock::iterator MI = BBI->begin(),
ME = BBI->end(); MI != ME; ++MI) {
if (MI->getDesc().isCall()) {
MachineBasicBlock::iterator RAI = MI; ++RAI;
MCSymbol* Label = InsertLabel(*MI->getParent(), RAI, MI->getDebugLoc());
FI.addSafePoint(GC::PostCall, Label, MI->getDebugLoc());
} else if (MI->getDebugLoc().getCol() == 1) {
MCSymbol* Label = InsertLabel(*MI->getParent(), MI, MI->getDebugLoc());
FI.addSafePoint(GC::Loop, Label, MI->getDebugLoc());
}
}
}
return false;
}
示例13: emitPrologue
void SystemZRegisterInfo::emitPrologue(MachineFunction &MF) const {
MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
MachineFrameInfo *MFI = MF.getFrameInfo();
SystemZMachineFunctionInfo *SystemZMFI =
MF.getInfo<SystemZMachineFunctionInfo>();
MachineBasicBlock::iterator MBBI = MBB.begin();
DebugLoc DL = (MBBI != MBB.end() ? MBBI->getDebugLoc() :
DebugLoc::getUnknownLoc());
// Get the number of bytes to allocate from the FrameInfo.
// Note that area for callee-saved stuff is already allocated, thus we need to
// 'undo' the stack movement.
uint64_t StackSize = MFI->getStackSize();
StackSize -= SystemZMFI->getCalleeSavedFrameSize();
uint64_t NumBytes = StackSize - TFI.getOffsetOfLocalArea();
// Skip the callee-saved push instructions.
while (MBBI != MBB.end() &&
(MBBI->getOpcode() == SystemZ::MOV64mr ||
MBBI->getOpcode() == SystemZ::MOV64mrm))
++MBBI;
if (MBBI != MBB.end())
DL = MBBI->getDebugLoc();
// adjust stack pointer: R15 -= numbytes
if (StackSize || MFI->hasCalls()) {
assert(MF.getRegInfo().isPhysRegUsed(SystemZ::R15D) &&
"Invalid stack frame calculation!");
emitSPUpdate(MBB, MBBI, -(int64_t)NumBytes, TII);
}
if (hasFP(MF)) {
// Update R11 with the new base value...
BuildMI(MBB, MBBI, DL, TII.get(SystemZ::MOV64rr), SystemZ::R11D)
.addReg(SystemZ::R15D);
// Mark the FramePtr as live-in in every block except the entry.
for (MachineFunction::iterator I = llvm::next(MF.begin()), E = MF.end();
I != E; ++I)
I->addLiveIn(SystemZ::R11D);
}
}
示例14: emitEpilogue
void XTCFrameLowering::emitEpilogue(MachineFunction &MF,
MachineBasicBlock &MBB) const {
MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
MachineFrameInfo *MFI = MF.getFrameInfo();
XTCFunctionInfo *XTCFI = MF.getInfo<XTCFunctionInfo>();
const XTCInstrInfo &TII =
*static_cast<const XTCInstrInfo*>(MF.getTarget().getInstrInfo());
DebugLoc dl = MBBI->getDebugLoc();
CallingConv::ID CallConv = MF.getFunction()->getCallingConv();
// Get the FI's where RA and FP are saved.
int FPOffset = XTCFI->getFPStackOffset();
int RAOffset = XTCFI->getRAStackOffset();
if (hasFP(MF)) {
/* Save current FP into stack */
// BuildMI(MBB, MBBI, dl, TII.get(XTC::STWPREI)).addReg(XTC::r14, RegState::Kill).addReg(XTC::r15).addImm(-4);
/* Copy from current SP */
BuildMI(MBB, MBBI, dl, TII.get(XTC::COPY), XTC::r15).addReg(XTC::r14);
// Mark the FramePtr as live-in in every block except the entry.
for (MachineFunction::iterator I = llvm::next(MF.begin()), E = MF.end();
I != E; ++I)
I->addLiveIn(XTC::r14);
}
/*
// lwi R15, R1, stack_loc
if (MFI->adjustsStack() || requiresRA) {
BuildMI(MBB, MBBI, dl, TII.get(XTC::LWI), XTC::R15)
.addReg(XTC::R1).addImm(RAOffset);
*/
// Get the number of bytes from FrameInfo
int StackSize = (int) MFI->getStackSize();
if (StackSize) {
BuildMI(MBB, MBBI, dl, TII.get(XTC::ADDI), XTC::r15)
.addReg(XTC::r15).addImm(StackSize);
}
}
示例15: NaClAlignIndirectJumpTargets
// Align all targets of indirect branches on bundle size. Used only if target
// is NaCl.
void MipsAsmPrinter::NaClAlignIndirectJumpTargets(MachineFunction &MF) {
// Align all blocks that are jumped to through jump table.
if (MachineJumpTableInfo *JtInfo = MF.getJumpTableInfo()) {
const std::vector<MachineJumpTableEntry> &JT = JtInfo->getJumpTables();
for (unsigned I = 0; I < JT.size(); ++I) {
const std::vector<MachineBasicBlock*> &MBBs = JT[I].MBBs;
for (unsigned J = 0; J < MBBs.size(); ++J)
MBBs[J]->setAlignment(MIPS_NACL_BUNDLE_ALIGN);
}
}
// If basic block address is taken, block can be target of indirect branch.
for (MachineFunction::iterator MBB = MF.begin(), E = MF.end();
MBB != E; ++MBB) {
if (MBB->hasAddressTaken())
MBB->setAlignment(MIPS_NACL_BUNDLE_ALIGN);
}
}