//===--------------------------------------------------------------------===//
private:
- /// \brief Helper to add branch weight metadata onto an instruction.
+ /// \brief Helper to add branch weight and unpredictable metadata onto an
+ /// instruction.
/// \returns The annotated instruction.
template <typename InstTy>
- InstTy *addBranchWeights(InstTy *I, MDNode *Weights) {
+ InstTy *addBranchMetadata(InstTy *I, MDNode *Weights, MDNode *Unpredictable) {
if (Weights)
I->setMetadata(LLVMContext::MD_prof, Weights);
+ if (Unpredictable)
+ I->setMetadata(LLVMContext::MD_unpredictable, Unpredictable);
return I;
}
/// \brief Create a conditional 'br Cond, TrueDest, FalseDest'
/// instruction.
BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
- MDNode *BranchWeights = nullptr) {
- return Insert(addBranchWeights(BranchInst::Create(True, False, Cond),
- BranchWeights));
+ MDNode *BranchWeights = nullptr,
+ MDNode *Unpredictable = nullptr) {
+ return Insert(addBranchMetadata(BranchInst::Create(True, False, Cond),
+ BranchWeights, Unpredictable));
}
/// \brief Create a switch instruction with the specified value, default dest,
/// allocation).
SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
MDNode *BranchWeights = nullptr) {
- return Insert(addBranchWeights(SwitchInst::Create(V, Dest, NumCases),
- BranchWeights));
+ // TODO: Add unpredictable metadata for a switch.
+ return Insert(addBranchMetadata(SwitchInst::Create(V, Dest, NumCases),
+ BranchWeights, nullptr));
}
/// \brief Create an indirect branch instruction with the specified address