本文整理汇总了C++中BasicBlock::getIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ BasicBlock::getIndex方法的具体用法?C++ BasicBlock::getIndex怎么用?C++ BasicBlock::getIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BasicBlock
的用法示例。
在下文中一共展示了BasicBlock::getIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: interposeBlock
void FlowGraph::interposeBlock(BasicBlock* bb){
ASSERT(bb->getNumberOfSources() == 1 && bb->getNumberOfTargets() == 1);
BasicBlock* sourceBlock = bb->getSourceBlock(0);
BasicBlock* targetBlock = bb->getTargetBlock(0);
//sourceBlock->print();
//targetBlock->print();
bool linkFound = false;
for (uint32_t i = 0; i < sourceBlock->getNumberOfTargets(); i++){
if (sourceBlock->getTargetBlock(i)->getIndex() == targetBlock->getIndex()){
linkFound = true;
break;
}
}
if (!linkFound){
function->print();
print();
sourceBlock->print();
targetBlock->print();
}
ASSERT(linkFound && "There should be a source -> target block relationship between the blocks passed to this function");
ASSERT(sourceBlock->getBaseAddress() + sourceBlock->getNumberOfBytes() != targetBlock->getBaseAddress() && "Source shouldn't fall through to target");
bb->setBaseAddress(blocks.back()->getBaseAddress() + blocks.back()->getNumberOfBytes());
bb->setIndex(basicBlocks.size());
basicBlocks.append(bb);
//PRINT_INFOR("now there are %d bbs in function %s", basicBlocks.size(), function->getName());
//PRINT_INFOR("new block has base addres %#llx", bb->getBaseAddress());
blocks.append(bb);
sourceBlock->removeTargetBlock(targetBlock);
sourceBlock->addTargetBlock(bb);
targetBlock->removeSourceBlock(sourceBlock);
targetBlock->addSourceBlock(bb);
X86Instruction* jumpToTarget = bb->getLeader();
jumpToTarget->setBaseAddress(blocks.back()->getBaseAddress() + blocks.back()->getSizeInBytes());
jumpToTarget->setIndex(0);
ASSERT(sourceBlock->getExitInstruction());
ASSERT(sourceBlock->getExitInstruction()->getAddressAnchor());
ASSERT(sourceBlock->getExitInstruction()->getTargetAddress() == targetBlock->getBaseAddress());
sourceBlock->getExitInstruction()->getAddressAnchor()->updateLink(jumpToTarget);
//bb->print();
//bb->printInstructions();
}
示例2: immediateDominators
void LengauerTarjan::immediateDominators(){
uint32_t dfsNo = 0;
depthFirstSearch(rootLoc,&dfsNo);
size[0] = 0;
label[0] = 0;
semi[0] = 0;
for(int32_t i=reachableCount;i>1;i--){
uint32_t vertexW = vertex[i];
BasicBlock* bb = locToBasicBlock[vertexW];
ASSERT(bb && "Basic Block should be initialized");
uint32_t numberOfSources = bb->getNumberOfSources();
for(uint32_t j=0;j<numberOfSources;j++){
BasicBlock* source = bb->getSourceBlock(j);
if(!source->isUnreachable()){
uint32_t vertexV = basicBlockToLoc[source->getIndex()];
uint32_t vertexU = EVAL(vertexV);
if(semi[vertexU] < semi[vertexW]){
semi[vertexW] = semi[vertexU];
}
}
}
bucket[vertex[semi[vertexW]]].insert(vertexW);
LINK(parent[vertexW],vertexW);
LinkedList<uint32_t>* bs = &(bucket[parent[vertexW]]);
while(!bs->empty()){
uint32_t vertexV = bs->shift();
uint32_t vertexU = EVAL(vertexV);
dom[vertexV] = ( semi[vertexU] < semi[vertexV] ) ? vertexU : parent[vertexW];
}
}
for(uint32_t i=2;i<=reachableCount;i++){
uint32_t vertexW = vertex[i];
if(dom[vertexW] != vertex[semi[vertexW]]){
dom[vertexW] = dom[dom[vertexW]];
}
}
dom[rootLoc] = 0;
PRINT_DEBUG("ROOT is %d",rootLoc);
for(uint32_t i=1;i<=reachableCount;i++){
uint32_t vertexW = vertex[i];
BasicBlock* bb = locToBasicBlock[vertexW];
ASSERT(!bb->isUnreachable());
BasicBlock* immDom = locToBasicBlock[dom[vertexW]];
if(immDom){
PRINT_DEBUG("Reachable : Immediate Dominator of %d is %d",bb->getIndex(),immDom->getIndex());
bb->setImmDominator(immDom);
} else {
PRINT_DEBUG("Reachable : Immediate Dominator of %d is Entry",bb->getIndex());
}
}
for(int32_t i=nodeCount;i>reachableCount;i--){
BasicBlock* bb = locToBasicBlock[i];
ASSERT(bb->isUnreachable());
BasicBlock* immDom = locToBasicBlock[rootLoc];
PRINT_DEBUG("Un-Reachable : Immediate Dominator of %d is %d",bb->getIndex(),immDom->getIndex());
bb->setImmDominator(immDom);
}
}
示例3: depthFirstSearch
void LengauerTarjan::depthFirstSearch(uint32_t vertexV,uint32_t* dfsNo){
semi[vertexV] = ++(*dfsNo);
vertex[*dfsNo] = vertexV;
label[vertexV] = vertexV;
ancestor[vertexV] = 0;
child[vertexV] = 0;
size[vertexV] = 1;
BasicBlock* bb = locToBasicBlock[vertexV];
PRINT_DEBUG_CFG("Mark %d with %d (vertex[%d] = %d)",bb->getIndex(),*dfsNo,*dfsNo,vertexV);
uint32_t numberOfTargets = bb->getNumberOfTargets();
for(uint32_t i=0;i<numberOfTargets;i++){
BasicBlock* target = bb->getTargetBlock(i);
uint32_t vertexW = basicBlockToLoc[target->getIndex()];
if(semi[vertexW] == 0){
parent[vertexW] = vertexV;
depthFirstSearch(vertexW,dfsNo);
}
}
ASSERT(!bb->isUnreachable());
#if 0
LinkedList<uint32_t> searchStack;
searchStack.insert(vertexV);
while(!searchStack.empty()){
vertexV = searchStack.shift();
if(semi[vertexV] != 0){
continue;
}
semi[vertexV] = ++(*dfsNo);
vertex[*dfsNo] = vertexV;
label[vertexV] = vertexV;
ancestor[vertexV] = 0;
child[vertexV] = 0;
size[vertexV] = 1;
BasicBlock* bb = locToBasicBlock[vertexV];
ASSERT(!bb->isUnreachable());
uint32_t numberOfTargets = bb->getNumberOfTargets();
// for(int32_t i=numberOfTargets-1;i>=0;i--){
for(uint32_t i=0;i<numberOfTargets;i++){
BasicBlock* target = bb->getTargetBlock(i);
uint32_t vertexW = basicBlockToLoc[target->getIndex()];
if(semi[vertexW] == 0){
parent[vertexW] = vertexV;
searchStack.insert(vertexW);
}
}
PRINT_DEBUG("Mark %d with %d\n",bb->getIndex(),*dfsNo);
ASSERT(!bb->isUnreachable());
}
#endif
}
示例4: instrument
//.........这里部分代码省略.........
Vector<LoopPoint*>* points = NULL;
// if addr already exists, it means that two loops share a head and we are going to merge them logically here
if (loops.count(addr) == 0){
ControlInfo f = ControlInfo();
f.name = c;
f.file = "";
f.line = 0;
f.index = sequenceId++;
f.baseaddr = addr;
f.type = ControlType_Loop;
points = new Vector<LoopPoint*>();
f.info = points;
LineInfo* li = NULL;
if (lineInfoFinder){
li = lineInfoFinder->lookupLineInfo(addr);
}
if (li){
f.file.append(li->getFileName());
f.line = li->GET(lr_line);
}
loops[addr] = f;
orderedloops.push_back(addr);
// find entries into this loop
for (uint32_t k = 0; k < head->getNumberOfSources(); k++){
BasicBlock* source = head->getSourceBlock(k);
if (!loop->isBlockIn(source->getIndex())){
LoopPoint* lp = new LoopPoint();
points->append(lp);
lp->flowgraph = flowgraph;
lp->source = source;
lp->target = NULL;
lp->entry = true;
lp->interpose = false;
if (source->getBaseAddress() + source->getNumberOfBytes() != head->getBaseAddress()){
lp->interpose = true;
lp->target = head;
}
entryc++;
}
}
}
ControlInfo f = loops[addr];
points = f.info;
// find exits from this loop
uint32_t exitc = 0;
for (uint32_t k = 0; k < loop->getNumberOfBlocks(); k++){
BasicBlock* bb = allLoopBlocks[k];
if (bb->endsWithReturn()){
LoopPoint* lp = new LoopPoint();
points->append(lp);
lp->flowgraph = flowgraph;
lp->source = bb;
lp->target = NULL;
示例5: computeDefUseDist
void FlowGraph::computeDefUseDist(){
uint32_t fcnt = function->getNumberOfInstructions();
std::pebil_map_type<uint64_t, X86Instruction*> imap;
std::pebil_map_type<uint64_t, BasicBlock*> bmap;
std::pebil_map_type<uint64_t, LinkedList<X86Instruction::ReachingDefinition*>*> alliuses;
std::pebil_map_type<uint64_t, LinkedList<X86Instruction::ReachingDefinition*>*> allidefs;
for (uint32_t i = 0; i < basicBlocks.size(); i++){
BasicBlock* bb = basicBlocks[i];
for (uint32_t j = 0; j < bb->getNumberOfInstructions(); j++){
X86Instruction* x = bb->getInstruction(j);
for (uint32_t k = 0; k < x->getSizeInBytes(); k++){
ASSERT(imap.count(x->getBaseAddress() + k) == 0);
ASSERT(bmap.count(x->getBaseAddress() + k) == 0);
imap[x->getBaseAddress() + k] = x;
bmap[x->getBaseAddress() + k] = bb;
}
ASSERT(alliuses.count(x->getBaseAddress()) == 0);
ASSERT(allidefs.count(x->getBaseAddress()) == 0);
alliuses[x->getBaseAddress()] = x->getUses();
allidefs[x->getBaseAddress()] = x->getDefs();
}
}
// For each loop
for (uint32_t i = 0; i < loops.size(); ++i) {
BasicBlock** allLoopBlocks = new BasicBlock*[loops[i]->getNumberOfBlocks()];
loops[i]->getAllBlocks(allLoopBlocks);
uint64_t loopLeader = loops[i]->getHead()->getBaseAddress();
// For each block
for (uint32_t j = 0; j < loops[i]->getNumberOfBlocks(); ++j){
BasicBlock* bb = allLoopBlocks[j];
// For each instruction
for (uint32_t k = 0; k < bb->getNumberOfInstructions(); ++k){
X86Instruction* ins = bb->getInstruction(k);
// Skip the instruction if it can't define anything
if (!ins->isIntegerOperation() && !ins->isFloatPOperation() && !ins->isMoveOperation()) {
continue;
}
ASSERT(!ins->usesControlTarget());
singleDefUse(this, ins, bb, loops[i], imap, bmap, alliuses, allidefs, k, loopLeader, fcnt);
}
}
delete[] allLoopBlocks;
}
// handle all non-loop blocks
for (uint32_t i = 0; i < getNumberOfBasicBlocks(); i++){
BasicBlock* bb = basicBlocks[i];
if (!isBlockInLoop(bb->getIndex())){
for (uint32_t k = 0; k < bb->getNumberOfInstructions(); ++k){
X86Instruction* ins = bb->getInstruction(k);
if (!ins->isIntegerOperation() && !ins->isFloatPOperation() && !ins->isMoveOperation()) {
continue;
}
ASSERT(!ins->usesControlTarget());
singleDefUse(this, ins, bb, NULL, imap, bmap, alliuses, allidefs, k, 0, fcnt);
}
}
}
for (uint32_t i = 0; i < basicBlocks.size(); i++){
BasicBlock* bb = basicBlocks[i];
for (uint32_t j = 0; j < bb->getNumberOfInstructions(); j++){
X86Instruction* x = bb->getInstruction(j);
uint64_t addr = x->getBaseAddress();
ASSERT(alliuses.count(addr) == 1);
LinkedList<X86Instruction::ReachingDefinition*>* l = alliuses[addr];
alliuses.erase(addr);
while (!l->empty()){
delete l->shift();
}
delete l;
ASSERT(allidefs.count(addr) == 1);
l = allidefs[addr];
allidefs.erase(addr);
while (!l->empty()){
delete l->shift();
}
delete l;
}
}
ASSERT(alliuses.size() == 0);
ASSERT(allidefs.size() == 0);
}
示例6: singleDefUse
inline void singleDefUse(FlowGraph* fg, X86Instruction* ins, BasicBlock* bb, Loop* loop,
std::pebil_map_type<uint64_t, X86Instruction*>& ipebil_map_type,
std::pebil_map_type<uint64_t, BasicBlock*>& bpebil_map_type,
std::pebil_map_type<uint64_t, LinkedList<X86Instruction::ReachingDefinition*>*>& alliuses,
std::pebil_map_type<uint64_t, LinkedList<X86Instruction::ReachingDefinition*>*>& allidefs,
int k, uint64_t loopLeader, uint32_t fcnt){
// Get defintions for this instruction: ins
LinkedList<X86Instruction::ReachingDefinition*>* idefs = ins->getDefs();
LinkedList<X86Instruction::ReachingDefinition*>* allDefs = idefs;
// Skip instruction if it doesn't define anything
if (idefs == NULL) {
return;
}
if (idefs->empty()) {
delete idefs;
return;
}
set<LinkedList<X86Instruction::ReachingDefinition*>*> allDefLists;
allDefLists.insert(idefs);
PriorityQueue<struct path*, uint32_t> paths = PriorityQueue<struct path*, uint32_t>();
bool blockTouched[fg->getFunction()->getNumberOfBasicBlocks()];
bzero(&blockTouched, sizeof(bool) * fg->getFunction()->getNumberOfBasicBlocks());
// Initialize worklist with the path from this instruction
// Only take paths inside the loop. Since the definitions are in a loop, uses in the loop will be most relevant.
if (k == bb->getNumberOfInstructions() - 1){
ASSERT(ins->controlFallsThrough());
if (bb->getNumberOfTargets() > 0){
ASSERT(bb->getNumberOfTargets() == 1);
if (flowsInDefUseScope(bb->getTargetBlock(0), loop)){
// Path flows to the first instruction of the next block
paths.insert(new path(bb->getTargetBlock(0)->getLeader(), idefs), 1);
}
}
} else {
// path flows to the next instruction in this block
paths.insert(new path(bb->getInstruction(k+1), idefs), 1);
}
// while there are paths in worklist
while (!paths.isEmpty()) {
// take the shortest path in list
uint32_t currDist;
struct path* p = paths.deleteMin(&currDist);
X86Instruction* cand = p->ins;
idefs = p->defs;
delete p;
LinkedList<X86Instruction::ReachingDefinition*>* i2uses, *i2defs, *newdefs;
i2uses = alliuses[cand->getBaseAddress()];
// Check if any of idefs is used
if(i2uses != NULL && anyDefsAreUsed(idefs, i2uses)){
// Check if use is shortest
uint32_t duDist;
duDist = trueDefUseDist(currDist, fcnt);
if (!ins->getDefUseDist() || ins->getDefUseDist() > duDist) {
ins->setDefUseDist(duDist);
}
// If dist has increased beyond size of function, we must be looping?
if (currDist > fcnt) {
ins->setDefXIter();
break;
}
// Stop searching along this path
continue;
}
// Check if any defines are overwritten
i2defs = allidefs[cand->getBaseAddress()];
newdefs = removeInvalidated(idefs, i2defs);
// If all definitions killed, stop searching along this path
if (newdefs == NULL)
continue;
allDefLists.insert(newdefs);
// end of block that is a branch
if (cand->usesControlTarget() && !cand->isCall()){
BasicBlock* tgtBlock = bpebil_map_type[cand->getTargetAddress()];
if (tgtBlock && !blockTouched[tgtBlock->getIndex()] && flowsInDefUseScope(tgtBlock, loop)){
blockTouched[tgtBlock->getIndex()] = true;
if (tgtBlock->getBaseAddress() == loopLeader){
paths.insert(new path(tgtBlock->getLeader(), newdefs), loopXDefUseDist(currDist + 1, fcnt));
} else {
paths.insert(new path(tgtBlock->getLeader(), newdefs), currDist + 1);
}
}
}
//.........这里部分代码省略.........