本文整理汇总了C++中basicblock::iterator::print方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::print方法的具体用法?C++ iterator::print怎么用?C++ iterator::print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类basicblock::iterator
的用法示例。
在下文中一共展示了iterator::print方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExampleCode
void ConditionalConstantPropagation::ExampleCode(raw_ostream& O, Function& F) {
std::set<StringRef> var_set;
var_set.clear();
BasicBlock* bb_entry = NULL;
BasicBlock* bb_if_then = NULL;
BasicBlock* bb_if_else = NULL;
BasicBlock* bb_if_end = NULL;
// TA: The fol lowing code shows how you iterate over variables
// defined in this function
O << "All Variables Defined in Function " << F.getName() << "\n";
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) {
BasicBlock* BB = dyn_cast<BasicBlock>(&*FI);
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();
BI != BE; ++BI) {
Instruction *instr = dyn_cast<Instruction>(&*BI);
LatticeMap[instr] = new Lattice();
LatticeMap[instr]->TOP = true;
LatticeMap[instr]->BOT = false;
if ( BI->hasName() )
{
StringRef var_name = BI->getValueName()->first();
O << "VARIABLE:\t" << var_name << "\tdefined in ";
BI->print(O);
O << "\n";
}
}
if ( !bb_entry )
bb_entry = BB;
else if ( !bb_if_then )
bb_if_then = BB;
else if ( !bb_if_else )
bb_if_else = BB;
else if ( !bb_if_end )
bb_if_end = BB;
}
/*
//intialization
CFGWorklist.push(bb_entry); //need to initialize bb_entry as the first node, caution: I do not know what entry node contains
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
{
BasicBlock* BB = dyn_cast<BasicBlock>(&*FI);
ExecutableMap[BB->getName()] = 0;
int count = 0;
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
{
count++;
}
ExecutableMax[BB->getName()] = count;
}
//initialize the VALUE OBJECTS (THIS SHOULD ALREADY BE DONE ABOVE IN EXAMPLE CODE)
while (CFGWorklist.size()!=0 || SSAWorklist.size()!=0)
{
while(CFGWorklist.size()!=0)
{
BasicBlock* BB = CFGWorklist.front();
CFGWorklist.pop();
if((ExecutableMap[BB->getName()]==0) || (ExecutableMap[BB->getName()] < ExecutableMax[BB->getName()] ))
{
ExecutableMap[BB->getName()]+=1;
//evaluate each phi-function in BB <----- can this be done in Evaluate()?
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();BI != BE; ++BI)
{
//evaluate BI (and update lattice?) <------
Instruction* definition = dyn_cast<Instruction> (&*BI);
O<< "reached before evaluate" << *definition << BB->getName()<<"\n";
O << "\ninst lattice of:" << *definition << "\n \t\t--TOP ::" << LatticeMap[definition]->TOP <<" \t " << "BOT::"<< LatticeMap[definition]->BOT <<" \t " << "constant:: " << LatticeMap[definition]->constant <<" \n\n " ;
*LatticeMap[definition] = Evaluate(O,definition);
O<< "reached after evaluate" << *definition << BB->getName()<<"\n";
O << "\ninst lattice of:" << *definition << "\n \t\t--TOP ::" << LatticeMap[definition]->TOP <<" \t " << "BOT::"<< LatticeMap[definition]->BOT <<" \t " << "constant:: " << LatticeMap[definition]->constant <<" \n\n " ;
for (Instruction::use_iterator UI= definition->use_begin(), UE=definition->use_end(); UI!=UE; ++UI)
{
Instruction* usage = dyn_cast<Instruction> (*UI);
///NOTE, WE CANNOT DO &* HERE LIKE FOR 'definition' ABOVE. DOES THIS CAUSE PROBLEMS??
BasicBlock* parent = usage->getParent();
if (ExecutableMap[parent->getName()] > 0)
{
SSAWorklist.push(usage);
}
//DEBUGGING CODE IS COMMENTED OUT BELOW:
//if ( UI->hasName() )
//{
//StringRef var_name = BI->getValueName()->first();
//O << "USE :::" << UI->getValueName()->first()<<" " << "VARIABLE:\t" << var_name<<"\tdefined in ";
//UI->print(O);
//O << "\n";
//}
}
}
}
}
//.........这里部分代码省略.........