[原创]ollvm控制流平坦化的改进 | 宜武汇-ag真人国际厅网站

irbuilder<> irb(&*oldentry->getfirstinsertionpt());                                // generate context info key for each block

value *visitedarray=irb.createalloca(irb.getint8ty(),irb.getint32(origbb.size()));

value *keyarray=irb.createalloca(irb.getint32ty(),irb.getint32(origbb.size()));

irb.creatememset(visitedarray,irb.getint8(0),origbb.size(),(maybealign)0);

irb.creatememset(keyarray,irb.getint8(0),origbb.size()*4,(maybealign)0);

int idx=0;

std::vectorint> key_list;

dominatortree tree(*f);

std::map*,unsigned int> key_map;

std::map*,unsigned int> index_map;

for(std::vector*>::iterator b=origbb.begin();b!=origbb.end();b )

  basicblock *block=*b;

  unsigned int num=getuniquenumber(&key_list);

  key_list.push_back(num);

  key_map[block]=0;

for(std::vector*>::iterator b=origbb.begin();b!=origbb.end();b ,idx )

  basicblock *block=*b;

  std::vector*> doms;

  int i=0;

  for(std::vector*>::iterator bb=origbb.begin();bb!=origbb.end();bb ,i )

  {

      basicblock *block0=*bb;

      if(block0!=block && tree.dominates(block,block0))

      {

          doms.push_back(irb.getint32(i));

          key_map[block0]^=key_list[idx];

      }

 

  }

  irb.setinsertpoint(block->getterminator());

  value *ptr=irb.creategep(irb.getint8ty(),visitedarray,irb.getint32(idx));

  value *visited=irb.createload(ptr);

  if(doms.size()!=0)

  {

      arraytype *arraytype=arraytype::get(irb.getint32ty(),doms.size());

      constant *doms_array=constantarray::get(arraytype,arrayref*>(doms));

      globalvariable *dom_variable=new globalvariable(*(f->getparent()),arraytype,false,globalvalue::linkagetypes::privatelinkage,doms_array,"doms");

      irb.createcall(functioncallee(updatefunc),{visited,irb.getint32(doms.size()),irb.creategep(dom_variable,{irb.getint32(0),irb.getint32(0)}),keyarray,irb.getint32(key_list[idx])});

  }

 

  irb.createstore(irb.getint8(1),ptr);

  index_map[block]=idx;

原文链接:https://bbs.kanxue.com/thread-274778.htm

网络摘文,本文作者:15h,如若转载,请注明出处:https://www.15cov.cn/2023/08/27/原创ollvm控制流平坦化的改进/

发表评论

邮箱地址不会被公开。 必填项已用*标注

网站地图