当前位置: 首页>>代码示例>>C++>>正文


C++ BasicBlock::getFirstInsertionPt方法代码示例

本文整理汇总了C++中BasicBlock::getFirstInsertionPt方法的典型用法代码示例。如果您正苦于以下问题:C++ BasicBlock::getFirstInsertionPt方法的具体用法?C++ BasicBlock::getFirstInsertionPt怎么用?C++ BasicBlock::getFirstInsertionPt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BasicBlock的用法示例。


在下文中一共展示了BasicBlock::getFirstInsertionPt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CollectBasicBlocks

/// \brief Find an insertion point that dominates all uses.
Instruction *ConstantHoisting::
FindConstantInsertionPoint(Function &F, const ConstantInfo &CI) const {
  BasicBlock *Entry = &F.getEntryBlock();

  // Collect all basic blocks.
  SmallPtrSet<BasicBlock *, 4> BBs;
  ConstantInfo::RebasedConstantListType::const_iterator RCI, RCE;
  for (RCI = CI.RebasedConstants.begin(), RCE = CI.RebasedConstants.end();
       RCI != RCE; ++RCI)
    for (SmallVectorImpl<User *>::const_iterator U = RCI->Uses.begin(),
         E = RCI->Uses.end(); U != E; ++U)
        CollectBasicBlocks(BBs, F, *U);

  if (BBs.count(Entry))
    return Entry->getFirstInsertionPt();

  while (BBs.size() >= 2) {
    BasicBlock *BB, *BB1, *BB2;
    BB1 = *BBs.begin();
    BB2 = *llvm::next(BBs.begin());
    BB = DT->findNearestCommonDominator(BB1, BB2);
    if (BB == Entry)
      return Entry->getFirstInsertionPt();
    BBs.erase(BB1);
    BBs.erase(BB2);
    BBs.insert(BB);
  }
  assert((BBs.size() == 1) && "Expected only one element.");
  return (*BBs.begin())->getFirstInsertionPt();
}
开发者ID:Xmister,项目名称:llvm-onex,代码行数:31,代码来源:ConstantHoisting.cpp

示例2: AllocaInst

// TODO: Share loads when one use dominates another, or when a catchpad exit
// dominates uses (needs dominators).
AllocaInst *WinEHPrepare::insertPHILoads(PHINode *PN, Function &F) {
  BasicBlock *PHIBlock = PN->getParent();
  AllocaInst *SpillSlot = nullptr;
  Instruction *EHPad = PHIBlock->getFirstNonPHI();

  if (!EHPad->isTerminator()) {
    // If the EHPad isn't a terminator, then we can insert a load in this block
    // that will dominate all uses.
    SpillSlot = new AllocaInst(PN->getType(), DL->getAllocaAddrSpace(), nullptr,
                               Twine(PN->getName(), ".wineh.spillslot"),
                               &F.getEntryBlock().front());
    Value *V = new LoadInst(SpillSlot, Twine(PN->getName(), ".wineh.reload"),
                            &*PHIBlock->getFirstInsertionPt());
    PN->replaceAllUsesWith(V);
    return SpillSlot;
  }

  // Otherwise, we have a PHI on a terminator EHPad, and we give up and insert
  // loads of the slot before every use.
  DenseMap<BasicBlock *, Value *> Loads;
  for (Value::use_iterator UI = PN->use_begin(), UE = PN->use_end();
       UI != UE;) {
    Use &U = *UI++;
    auto *UsingInst = cast<Instruction>(U.getUser());
    if (isa<PHINode>(UsingInst) && UsingInst->getParent()->isEHPad()) {
      // Use is on an EH pad phi.  Leave it alone; we'll insert loads and
      // stores for it separately.
      continue;
    }
    replaceUseWithLoad(PN, U, SpillSlot, Loads, F);
  }
  return SpillSlot;
}
开发者ID:CTSRD-CHERI,项目名称:cheribsd,代码行数:35,代码来源:WinEHPrepare.cpp

示例3: instrumentBasicBlock

void TracingNoGiri::instrumentBasicBlock(BasicBlock &BB) {
  // Ignore the Giri Constructor function where the it is not set up yet
  if (BB.getParent()->getName() == "giriCtor")
    return;

  // Lookup the ID of this basic block and create an LLVM value for it.
  unsigned id = bbNumPass->getID(&BB);
  assert(id && "Basic block does not have an ID!\n");
  Value *BBID = ConstantInt::get(Int32Type, id);

  // Get a pointer to the function in which the basic block belongs.
  Value *FP = castTo(BB.getParent(), VoidPtrType, "", BB.getTerminator());

  Value *LastBB;
  if (isa<ReturnInst>(BB.getTerminator()))
     LastBB = ConstantInt::get(Int32Type, 1);
  else
     LastBB = ConstantInt::get(Int32Type, 0);

  // Insert code at the end of the basic block to record that it was executed.
  std::vector<Value *> args = make_vector<Value *>(BBID, FP, LastBB, 0);
  instrumentLock(BB.getTerminator());
  Instruction *RBB = CallInst::Create(RecordBB, args, "", BB.getTerminator());
  instrumentUnlock(RBB);

  // Insert code at the beginning of the basic block to record that it started
  // execution.
  args = make_vector<Value *>(BBID, FP, 0);
  Instruction *F = BB.getFirstInsertionPt();
  Instruction *S = CallInst::Create(RecordStartBB, args, "", F);
  instrumentLock(S);
  instrumentUnlock(S);
}
开发者ID:Justme0,项目名称:giri,代码行数:33,代码来源:TracingNoGiri.cpp

示例4: Builder

void llvm::TripCountProfiler::saveTripCount(std::set<BasicBlock*> BBs, AllocaInst* tripCountPtr, Value* estimatedTripCount,  BasicBlock* loopHeader, int LoopClass) {


    for(std::set<BasicBlock*>::iterator it = BBs.begin(), end = BBs.end(); it != end; it++) {

        BasicBlock* BB = *it;

        IRBuilder<> Builder(BB->getFirstInsertionPt());

        ConstantInt* loopIdentifier = ConstantInt::get(Type::getInt64Ty(*context), (int64_t)loopHeader);
        ConstantInt* loopClass = ConstantInt::get(Type::getInt32Ty(*context), (int64_t)LoopClass);


        //Value* stderr = Builder.CreateAlignedLoad(GVstderr, 4);
        Value* tripCount = Builder.CreateAlignedLoad(tripCountPtr, 4);

        std::vector<Value*> args;
        args.push_back(loopIdentifier);
        args.push_back(tripCount);
        args.push_back(estimatedTripCount);
        args.push_back(loopClass);
        llvm::ArrayRef<llvm::Value *> arrayArgs(args);
        Builder.CreateCall(collectLoopData, arrayArgs, "");


        int count = 0;
        for(pred_iterator pred = pred_begin(BB); pred != pred_end(BB); pred++) {
            count ++;
        }

    }

}
开发者ID:lisqu,项目名称:selective-page-migration-ccnuma,代码行数:33,代码来源:TripCountProfiler.cpp

示例5: collectPossibleIVs

// Collect the list of loop induction variables with respect to which it might
// be possible to reroll the loop.
void LoopReroll::collectPossibleIVs(Loop *L,
                                    SmallInstructionVector &PossibleIVs) {
  BasicBlock *Header = L->getHeader();
  for (BasicBlock::iterator I = Header->begin(),
       IE = Header->getFirstInsertionPt(); I != IE; ++I) {
    if (!isa<PHINode>(I))
      continue;
    if (!I->getType()->isIntegerTy())
      continue;

    if (const SCEVAddRecExpr *PHISCEV =
        dyn_cast<SCEVAddRecExpr>(SE->getSCEV(I))) {
      if (PHISCEV->getLoop() != L)
        continue;
      if (!PHISCEV->isAffine())
        continue;
      if (const SCEVConstant *IncSCEV =
          dyn_cast<SCEVConstant>(PHISCEV->getStepRecurrence(*SE))) {
        if (!IncSCEV->getValue()->getValue().isStrictlyPositive())
          continue;
        if (IncSCEV->getValue()->uge(MaxInc))
          continue;

        DEBUG(dbgs() << "LRR: Possible IV: " << *I << " = " <<
              *PHISCEV << "\n");
        PossibleIVs.push_back(I);
      }
    }
  }
}
开发者ID:dongAxis,项目名称:clang-700.0.72,代码行数:32,代码来源:LoopRerollPass.cpp

示例6: finish

// Delete the instructions that we scalarized.  If a full vector result
// is still needed, recreate it using InsertElements.
bool Scalarizer::finish() {
  // The presence of data in Gathered or Scattered indicates changes
  // made to the Function.
  if (Gathered.empty() && Scattered.empty())
    return false;
  for (GatherList::iterator GMI = Gathered.begin(), GME = Gathered.end();
       GMI != GME; ++GMI) {
    Instruction *Op = GMI->first;
    ValueVector &CV = *GMI->second;
    if (!Op->use_empty()) {
      // The value is still needed, so recreate it using a series of
      // InsertElements.
      Type *Ty = Op->getType();
      Value *Res = UndefValue::get(Ty);
      BasicBlock *BB = Op->getParent();
      unsigned Count = Ty->getVectorNumElements();
      IRBuilder<> Builder(Op);
      if (isa<PHINode>(Op))
        Builder.SetInsertPoint(BB, BB->getFirstInsertionPt());
      for (unsigned I = 0; I < Count; ++I)
        Res = Builder.CreateInsertElement(Res, CV[I], Builder.getInt32(I),
                                          Op->getName() + ".upto" + Twine(I));
      Res->takeName(Op);
      Op->replaceAllUsesWith(Res);
    }
    Op->eraseFromParent();
  }
  Gathered.clear();
  Scattered.clear();
  return true;
}
开发者ID:julaiti-graphsql,项目名称:llvm,代码行数:33,代码来源:Scalarizer.cpp

示例7: SinkInstruction

/// SinkInstruction - Determine whether it is safe to sink the specified machine
/// instruction out of its current block into a successor.
bool Sinking::SinkInstruction(Instruction *Inst,
                              SmallPtrSetImpl<Instruction *> &Stores) {

  // Don't sink static alloca instructions.  CodeGen assumes allocas outside the
  // entry block are dynamically sized stack objects.
  if (AllocaInst *AI = dyn_cast<AllocaInst>(Inst))
    if (AI->isStaticAlloca())
      return false;

  // Check if it's safe to move the instruction.
  if (!isSafeToMove(Inst, AA, Stores))
    return false;

  // FIXME: This should include support for sinking instructions within the
  // block they are currently in to shorten the live ranges.  We often get
  // instructions sunk into the top of a large block, but it would be better to
  // also sink them down before their first use in the block.  This xform has to
  // be careful not to *increase* register pressure though, e.g. sinking
  // "x = y + z" down if it kills y and z would increase the live ranges of y
  // and z and only shrink the live range of x.

  // SuccToSinkTo - This is the successor to sink this instruction to, once we
  // decide.
  BasicBlock *SuccToSinkTo = nullptr;

  // Instructions can only be sunk if all their uses are in blocks
  // dominated by one of the successors.
  // Look at all the postdominators and see if we can sink it in one.
  DomTreeNode *DTN = DT->getNode(Inst->getParent());
  for (DomTreeNode::iterator I = DTN->begin(), E = DTN->end();
      I != E && SuccToSinkTo == nullptr; ++I) {
    BasicBlock *Candidate = (*I)->getBlock();
    if ((*I)->getIDom()->getBlock() == Inst->getParent() &&
        IsAcceptableTarget(Inst, Candidate))
      SuccToSinkTo = Candidate;
  }

  // If no suitable postdominator was found, look at all the successors and
  // decide which one we should sink to, if any.
  for (succ_iterator I = succ_begin(Inst->getParent()),
      E = succ_end(Inst->getParent()); I != E && !SuccToSinkTo; ++I) {
    if (IsAcceptableTarget(Inst, *I))
      SuccToSinkTo = *I;
  }

  // If we couldn't find a block to sink to, ignore this instruction.
  if (!SuccToSinkTo)
    return false;

  DEBUG(dbgs() << "Sink" << *Inst << " (";
        Inst->getParent()->printAsOperand(dbgs(), false);
        dbgs() << " -> ";
        SuccToSinkTo->printAsOperand(dbgs(), false);
        dbgs() << ")\n");

  // Move the instruction.
  Inst->moveBefore(SuccToSinkTo->getFirstInsertionPt());
  return true;
}
开发者ID:AmesianX,项目名称:llvm-othergen,代码行数:61,代码来源:Sink.cpp

示例8: InsertSlots

void BBCloner::InsertSlots(BasicBlock &B) {
  IDAssigner &IDA = getAnalysis<IDAssigner>();
  // PHINodes and landingpad should be groupted at top of BB. We use
  // <Insertable> to indicate whether <I> already passes the first insertion
  // position. If so, insert LoomSlot before <I>; otherwise insert LoomSlot at
  // the first insertion position.
  Instruction *FirstInsertPos = B.getFirstInsertionPt();
  bool Insertable = false;
  for (BasicBlock::iterator I = B.begin(); I != B.end(); ++I) {
    if (FirstInsertPos == I)
      Insertable = true;
    unsigned InsID = IDA.getInstructionID(I);
    if (InsID != IDAssigner::InvalidID) {
      assert(InsID < MaxNumInsts);
      // <I> exists in the original program.
      BasicBlock::iterator InsertPos;
      if (!Insertable) {
        InsertPos = FirstInsertPos;
      } else {
        // We want to keep LoomBeforeBlocking and LoomAfterBlocking tightly
        // around a blocking callsite, LoomEnterThread right at the thread
        // entry, and LoomExitThread right before the thread exit.  Threfore, be
        // super careful about the insertion position of LoomSlot.  e.g., after
        // inserting LoomSlot to the following code snippet
        //   call LoomBeforeBlocking
        //   call read
        //   call LoomAfterBlocking
        //   ret void
        // the code should look like:
        //   call LoomSlot
        //   call LoomBeforeBlocking
        //   call read
        //   call LoomAfterBlocking
        //   call LoomSlot
        //   ret void
        InsertPos = I;
        while (InsertPos != B.begin()) {
          BasicBlock::iterator Prev = InsertPos; --Prev;
          CallSite CS(Prev);
          if (!CS)
            break;
          Function *Callee = CS.getCalledFunction();
          if (!Callee)
            break;
          if (Callee->getName() != "LoomBeforeBlocking" &&
              Callee->getName() != "LoomExitThread")
            break;
          InsertPos = Prev;
        }
      }
      CallInst::Create(Slot, ConstantInt::get(IntType, InsID), "", InsertPos);
    }
  }

  // Verify LoomSlots are in a correct order.
  verifyLoomSlots(B);
}
开发者ID:columbia,项目名称:loom,代码行数:57,代码来源:BBCloner.cpp

示例9: Create

/// \brief Recursively handle the condition leading to a loop
Value *SIAnnotateControlFlow::handleLoopCondition(Value *Cond, PHINode *Broken) {
  if (PHINode *Phi = dyn_cast<PHINode>(Cond)) {
    BasicBlock *Parent = Phi->getParent();
    PHINode *NewPhi = PHINode::Create(Int64, 0, "", &Parent->front());
    Value *Ret = NewPhi;

    // Handle all non-constant incoming values first
    for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) {
      Value *Incoming = Phi->getIncomingValue(i);
      BasicBlock *From = Phi->getIncomingBlock(i);
      if (isa<ConstantInt>(Incoming)) {
        NewPhi->addIncoming(Broken, From);
        continue;
      }

      Phi->setIncomingValue(i, BoolFalse);
      Value *PhiArg = handleLoopCondition(Incoming, Broken);
      NewPhi->addIncoming(PhiArg, From);
    }

    BasicBlock *IDom = DT->getNode(Parent)->getIDom()->getBlock();

    for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) {

      Value *Incoming = Phi->getIncomingValue(i);
      if (Incoming != BoolTrue)
        continue;

      BasicBlock *From = Phi->getIncomingBlock(i);
      if (From == IDom) {
        CallInst *OldEnd = dyn_cast<CallInst>(Parent->getFirstInsertionPt());
        if (OldEnd && OldEnd->getCalledFunction() == EndCf) {
          Value *Args[] = { OldEnd->getArgOperand(0), NewPhi };
          Ret = CallInst::Create(ElseBreak, Args, "", OldEnd);
          continue;
        }
      }
      TerminatorInst *Insert = From->getTerminator();
      Value *PhiArg = CallInst::Create(Break, Broken, "", Insert);
      NewPhi->setIncomingValue(i, PhiArg);
    }
    eraseIfUnused(Phi);
    return Ret;

  } else if (Instruction *Inst = dyn_cast<Instruction>(Cond)) {
    BasicBlock *Parent = Inst->getParent();
    TerminatorInst *Insert = Parent->getTerminator();
    Value *Args[] = { Cond, Broken };
    return CallInst::Create(IfBreak, Args, "", Insert);

  } else {
    llvm_unreachable("Unhandled loop condition!");
  }
  return 0;
}
开发者ID:FulcronZ,项目名称:NyuziToolchain,代码行数:56,代码来源:SIAnnotateControlFlow.cpp

示例10: handleLoopCondition

/// \brief Recursively handle the condition leading to a loop
void SIAnnotateControlFlow::handleLoopCondition(Value *Cond) {
  if (PHINode *Phi = dyn_cast<PHINode>(Cond)) {

    // Handle all non-constant incoming values first
    for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) {
      Value *Incoming = Phi->getIncomingValue(i);
      if (isa<ConstantInt>(Incoming))
        continue;

      Phi->setIncomingValue(i, BoolFalse);
      handleLoopCondition(Incoming);
    }

    BasicBlock *Parent = Phi->getParent();
    BasicBlock *IDom = DT->getNode(Parent)->getIDom()->getBlock();

    for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) {

      Value *Incoming = Phi->getIncomingValue(i);
      if (Incoming != BoolTrue)
        continue;

      BasicBlock *From = Phi->getIncomingBlock(i);
      if (From == IDom) {
        CallInst *OldEnd = dyn_cast<CallInst>(Parent->getFirstInsertionPt());
        if (OldEnd && OldEnd->getCalledFunction() == EndCf) {
          Value *Args[] = {
            OldEnd->getArgOperand(0),
            PhiInserter.GetValueAtEndOfBlock(Parent)
          };
          Value *Ret = CallInst::Create(ElseBreak, Args, "", OldEnd);
          PhiInserter.AddAvailableValue(Parent, Ret);
          continue;
        }
      }

      TerminatorInst *Insert = From->getTerminator();
      Value *Arg = PhiInserter.GetValueAtEndOfBlock(From);
      Value *Ret = CallInst::Create(Break, Arg, "", Insert);
      PhiInserter.AddAvailableValue(From, Ret);
    }
    eraseIfUnused(Phi);

  } else if (Instruction *Inst = dyn_cast<Instruction>(Cond)) {
    BasicBlock *Parent = Inst->getParent();
    TerminatorInst *Insert = Parent->getTerminator();
    Value *Args[] = { Cond, PhiInserter.GetValueAtEndOfBlock(Parent) };
    Value *Ret = CallInst::Create(IfBreak, Args, "", Insert);
    PhiInserter.AddAvailableValue(Parent, Ret);

  } else {
    llvm_unreachable("Unhandled loop condition!");
  }
}
开发者ID:compnerd,项目名称:llvm,代码行数:55,代码来源:SIAnnotateControlFlow.cpp

示例11: OptimizeCmpExpression

/// OptimizeCmpExpression - sink the given CmpInst into user blocks to reduce
/// the number of virtual registers that must be created and coalesced.  This is
/// a clear win except on targets with multiple condition code registers
///  (PowerPC), where it might lose; some adjustment may be wanted there.
///
/// Return true if any changes are made.
static bool OptimizeCmpExpression(CmpInst *CI) {
    BasicBlock *DefBB = CI->getParent();

    /// InsertedCmp - Only insert a cmp in each block once.
    DenseMap<BasicBlock*, CmpInst*> InsertedCmps;

    bool MadeChange = false;
    for (Value::use_iterator UI = CI->use_begin(), E = CI->use_end();
            UI != E; ) {
        Use &TheUse = UI.getUse();
        Instruction *User = cast<Instruction>(*UI);

        // Preincrement use iterator so we don't invalidate it.
        ++UI;

        // Don't bother for PHI nodes.
        if (isa<PHINode>(User))
            continue;

        // Figure out which BB this cmp is used in.
        BasicBlock *UserBB = User->getParent();

        // If this user is in the same block as the cmp, don't change the cmp.
        if (UserBB == DefBB) continue;

        // If we have already inserted a cmp into this block, use it.
        CmpInst *&InsertedCmp = InsertedCmps[UserBB];

        if (!InsertedCmp) {
            BasicBlock::iterator InsertPt = UserBB->getFirstInsertionPt();
            InsertedCmp =
                CmpInst::Create(CI->getOpcode(),
                                CI->getPredicate(),  CI->getOperand(0),
                                CI->getOperand(1), "", InsertPt);
            MadeChange = true;
        }

        // Replace a use of the cmp with a use of the new cmp.
        TheUse = InsertedCmp;
        ++NumCmpUses;
    }

    // If we removed all uses, nuke the cmp.
    if (CI->use_empty())
        CI->eraseFromParent();

    return MadeChange;
}
开发者ID:PhongNgo,项目名称:llvm,代码行数:54,代码来源:CodeGenPrepare.cpp

示例12: cutEdge

void RealizeRMC::cutEdge(RMCEdge &edge) {
  if (isCut(edge)) return;

  // As a first pass, we just insert lwsyncs at the start of the destination.
  // (Or syncs if it is a push edge)
  BasicBlock *bb = edge.dst->bb;
  Instruction *i_point = &*bb->getFirstInsertionPt();
  if (edge.edgeType == PushEdge) {
    makeSync(i_point);
  } else {
    makeLwsync(i_point);
  }
  // XXX: we need to make sure we can't ever fail to track a cut at one side
  // of a block because we inserted one at the other! Argh!
  cuts_[bb] = BlockCut(CutLwsync, true);
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例13: cutPushes

void RealizeRMC::cutPushes() {
  // We just insert pushes wherever we see one, for now.
  // We could also have a notion of push edges derived from
  // the edges to and from a push action.
  for (auto action : pushes_) {
    assert(action->isPush);
    BasicBlock *bb = action->bb;
    makeSync(&*bb->getFirstInsertionPt());
    cuts_[bb] = BlockCut(CutSync, true);
    // XXX: since we can't actually handle cuts on the front and the
    // back and because the sync is the only thing in the block and so
    // cuts at both the front and back, we insert a bogus BlockCut in
    // the next block.
    cuts_[getSingleSuccessor(action->outBlock)] = BlockCut(CutSync, true);
  }
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例14: killTerminator

/// \brief Create a new or reuse the previous node as flow node
BasicBlock *StructurizeCFG::needPrefix(bool NeedEmpty) {
  BasicBlock *Entry = PrevNode->getEntry();

  if (!PrevNode->isSubRegion()) {
    killTerminator(Entry);
    if (!NeedEmpty || Entry->getFirstInsertionPt() == Entry->end())
      return Entry;
  }

  // create a new flow node
  BasicBlock *Flow = getNextFlow(Entry);

  // and wire it up
  changeExit(PrevNode, Flow, true);
  PrevNode = ParentRegion->getBBNode(Flow);
  return Flow;
}
开发者ID:BNieuwenhuizen,项目名称:llvm,代码行数:18,代码来源:StructurizeCFG.cpp

示例15: InjectCoverageAtBlock

void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F,
                                                    BasicBlock &BB) {
  BasicBlock::iterator IP = BB.getFirstInsertionPt(), BE = BB.end();
  // Skip static allocas at the top of the entry block so they don't become
  // dynamic when we split the block.  If we used our optimized stack layout,
  // then there will only be one alloca and it will come first.
  for (; IP != BE; ++IP) {
    AllocaInst *AI = dyn_cast<AllocaInst>(IP);
    if (!AI || !AI->isStaticAlloca())
      break;
  }

  bool IsEntryBB = &BB == &F.getEntryBlock();
  DebugLoc EntryLoc =
      IsEntryBB ? IP->getDebugLoc().getFnDebugLoc(*C) : IP->getDebugLoc();
  IRBuilder<> IRB(IP);
  IRB.SetCurrentDebugLocation(EntryLoc);
  SmallVector<Value *, 1> Indices;
  Value *GuardP = IRB.CreateAdd(
      IRB.CreatePointerCast(GuardArray, IntptrTy),
      ConstantInt::get(IntptrTy, (1 + SanCovFunction->getNumUses()) * 4));
  Type *Int32PtrTy = PointerType::getUnqual(IRB.getInt32Ty());
  GuardP = IRB.CreateIntToPtr(GuardP, Int32PtrTy);
  LoadInst *Load = IRB.CreateLoad(GuardP);
  Load->setAtomic(Monotonic);
  Load->setAlignment(4);
  Load->setMetadata(F.getParent()->getMDKindID("nosanitize"),
                    MDNode::get(*C, None));
  Value *Cmp = IRB.CreateICmpSGE(Constant::getNullValue(Load->getType()), Load);
  Instruction *Ins = SplitBlockAndInsertIfThen(
      Cmp, IP, false, MDBuilder(*C).createBranchWeights(1, 100000));
  IRB.SetInsertPoint(Ins);
  IRB.SetCurrentDebugLocation(EntryLoc);
  // __sanitizer_cov gets the PC of the instruction using GET_CALLER_PC.
  IRB.CreateCall(SanCovFunction, GuardP);
  IRB.CreateCall(EmptyAsm);  // Avoids callback merge.

  if (ClExperimentalTracing) {
    // Experimental support for tracing.
    // Insert a callback with the same guard variable as used for coverage.
    IRB.SetInsertPoint(IP);
    IRB.CreateCall(IsEntryBB ? SanCovTraceEnter : SanCovTraceBB, GuardP);
  }
}
开发者ID:IamSpid3r,项目名称:cheerp-llvm,代码行数:44,代码来源:SanitizerCoverage.cpp


注:本文中的BasicBlock::getFirstInsertionPt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。