liberty/lib/LAMP/LAMPLoopSample.cpp
/* Create copies of the functions of the program with no lamp calls
   * ensure these functions only call other sanitized functions
   */
Create copies of the functions of the program with no lamp calls
ensure these functions only call other sanitized functions
Create copies of the functions of the program with no lamp calls ensure these functions only call other sanitized functions
void LAMPLoopSample::sanitizeFunctions(Module &M)
  {
    intList delList;
    intList callList;
    for(Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
    {
      if(!I->isDeclaration())
      {
        Function *orig = &*I;
        std::string nstr = orig->getName();
        if(nstr.find("__nolamp_") != std::string::npos || nstr == "main")
        {
          continue;
        }
        ValueToValueMapTy VMap;
        Function *clone = CloneFunction(orig, VMap);
        assert(clone->hasName() && "Function did not have name");
        clone->setName("__nolamp_" + orig->getName());
        funcMap[orig] = clone;
        for(Function::iterator BBB = clone->begin(), BBE = clone->end(); BBB != BBE; ++BBB)
        {
          for(BasicBlock::iterator IB = BBB->begin(), IE = BBB->end(); IB != IE; IB++)
          {
            if(isa<CallInst>(IB) || isa<InvokeInst>(IB))
            {
              CallSite call = CallSite(&*IB);
              Function *f = call.getCalledFunction();
              if(f == NULL || f->hasAvailableExternallyLinkage())
              {
                continue;
              }
              std::string cname = f->getName();
              if( cname.find("LAMP") != std::string::npos )
              {
                delList.push_front(&*IB);
              }
              else
              {
                callList.push_front(&*IB);
              }
            }
          }
        }
      }
    }
    removeLampCalls(delList);
    replaceCalls(M, callList);
  }
void LAMPLoopSample :: sanitizeFunctions ( Module & M ) { intList delList ; intList callList ; for ( Module :: iterator I = M . begin ( ) , E = M . end ( ) ; I != E ; ++ I ) { if ( ! I -> isDeclaration ( ) ) { Function * orig = & * I ; std :: string nstr = orig -> getName ( ) ; if ( nstr . find ( " " ) != std :: string :: npos || nstr == " " ) { continue ; } ValueToValueMapTy VMap ; Function * clone = CloneFunction ( orig , VMap ) ; assert ( clone -> hasName ( ) && " " ) ; clone -> setName ( " " + orig -> getName ( ) ) ; funcMap [ orig ] = clone ; for ( Function :: iterator BBB = clone -> begin ( ) , BBE = clone -> end ( ) ; BBB != BBE ; ++ BBB ) { for ( BasicBlock :: iterator IB = BBB -> begin ( ) , IE = BBB -> end ( ) ; IB != IE ; IB ++ ) { if ( isa < CallInst > ( IB ) || isa < InvokeInst > ( IB ) ) { CallSite call = CallSite ( & * IB ) ; Function * f = call . getCalledFunction ( ) ; if ( f == NULL || f -> hasAvailableExternallyLinkage ( ) ) { continue ; } std :: string cname = f -> getName ( ) ; if ( cname . find ( " " ) != std :: string :: npos ) { delList . push_front ( & * IB ) ; } else { callList . push_front ( & * IB ) ; } } } } } } removeLampCalls ( delList ) ; replaceCalls ( M , callList ) ; }
Create copies of the functions of the program with no lamp calls
 ensure these functions only call other sanitized functions
Create copies of the functions of the program with no lamp calls ensure these functions only call other sanitized functions
// Need to clone each function, remove lamp calls (leave iteration/invocation calls?) // and re-name the function so that the non-prof loops can call into clean functions // && !I->hasAvailableExternallyLinkage() ) // We have already modified this function, ignore //LLVM_DEBUG(errs() << "~Considering function " << nstr << "\n"); // sot: CloneFunction in LLVM 5.0 inserts the cloned function in the function's module //I->getParent()->getFunctionList().push_back(clone); //LLVM_DEBUG(errs() << "~~Created cloned version " << clone->getName() << "\n"); // Duplicate is created, now remove all lamp calls from the function // and change all function calls to their non-lamp versions // indirect call, can't fix it // Calls to LAMP that need to be removed //LLVM_DEBUG( errs() << "~~~Removing " << cname << " from the function " //              << clone->getName() << "\n");