Esempio n. 1
0
void BBCloner::CreateFastPath(Function &F) {
  CloneMap.clear();

  for (Function::arg_iterator AI = F.arg_begin(); AI != F.arg_end(); ++AI)
    CloneMap[AI] = AI;

  BBSet OldBBs;
  for (Function::iterator B = F.begin(); B != F.end(); ++B)
    OldBBs.insert(B);

  for (BBSet::iterator I = OldBBs.begin(); I != OldBBs.end(); ++I) {
    BasicBlock *B = *I;
    // Skip the back edge blocks inserted by CheckInserter.
    if (IsBackEdgeBlock(*B)) {
      CloneMap[B] = B;
      continue;
    }
    BasicBlock *B2 = CloneBasicBlock(B, CloneMap, ".fast", &F, NULL);
    // Strip DebugLoc from all cloned instructions; otherwise, the code
    // generator would assert fail. TODO: Figure out why it would fail.
    for (BasicBlock::iterator Ins = B2->begin(); Ins != B2->end(); ++Ins) {
      if (!Ins->getDebugLoc().isUnknown())
        Ins->setDebugLoc(DebugLoc());
    }
    CloneMap[B] = B2;
  }

  for (Function::iterator B2 = F.begin(); B2 != F.end(); ++B2) {
    if (OldBBs.count(B2))
      continue;
    for (BasicBlock::iterator I = B2->begin(); I != B2->end(); ++I)
      RemapInstruction(I, CloneMap);
  }
}
Esempio n. 2
0
// StripDebugInfo - Strip debug info in the module if it exists.  
// To do this, we remove llvm.dbg.func.start, llvm.dbg.stoppoint, and 
// llvm.dbg.region.end calls, and any globals they point to if now dead.
static bool StripDebugInfo(Module &M) {

  bool Changed = false;

  // Remove all of the calls to the debugger intrinsics, and remove them from
  // the module.
  if (Function *Declare = M.getFunction("llvm.dbg.declare")) {
    while (!Declare->use_empty()) {
      CallInst *CI = cast<CallInst>(Declare->use_back());
      CI->eraseFromParent();
    }
    Declare->eraseFromParent();
    Changed = true;
  }

  if (Function *DbgVal = M.getFunction("llvm.dbg.value")) {
    while (!DbgVal->use_empty()) {
      CallInst *CI = cast<CallInst>(DbgVal->use_back());
      CI->eraseFromParent();
    }
    DbgVal->eraseFromParent();
    Changed = true;
  }

  for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
         NME = M.named_metadata_end(); NMI != NME;) {
    NamedMDNode *NMD = NMI;
    ++NMI;
    if (NMD->getName().startswith("llvm.dbg.")) {
      NMD->eraseFromParent();
      Changed = true;
    }
  }

  for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI)
    for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE;
         ++FI)
      for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE;
           ++BI) {
        if (!BI->getDebugLoc().isUnknown()) {
          Changed = true;
          BI->setDebugLoc(DebugLoc());
        }
      }

  return Changed;
}
Esempio n. 3
0
/// fixupLineNumbers - Update inlined instructions' line numbers to 
/// to encode location where these instructions are inlined.
static void fixupLineNumbers(Function *Fn, Function::iterator FI,
                             Instruction *TheCall) {
  DebugLoc TheCallDL = TheCall->getDebugLoc();
  if (TheCallDL.isUnknown())
    return;

  for (; FI != Fn->end(); ++FI) {
    for (BasicBlock::iterator BI = FI->begin(), BE = FI->end();
         BI != BE; ++BI) {
      DebugLoc DL = BI->getDebugLoc();
      if (!DL.isUnknown()) {
        BI->setDebugLoc(updateInlinedAtInfo(DL, TheCallDL, BI->getContext()));
        if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(BI)) {
          LLVMContext &Ctx = BI->getContext();
          MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt(Ctx);
          DVI->setOperand(2, createInlinedVariable(DVI->getVariable(), 
                                                   InlinedAt, Ctx));
        }
      }
    }
  }
}