forked from OSchip/llvm-project
parent
1561709d57
commit
341890ad70
|
@ -1550,16 +1550,13 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
|
|||
// If the switch has a condition wrapped by __builtin_unpredictable,
|
||||
// create metadata that specifies that the switch is unpredictable.
|
||||
// Don't bother if not optimizing because that metadata would not be used.
|
||||
if (CGM.getCodeGenOpts().OptimizationLevel != 0) {
|
||||
if (const CallExpr *Call = dyn_cast<CallExpr>(S.getCond())) {
|
||||
const Decl *TargetDecl = Call->getCalleeDecl();
|
||||
if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
|
||||
if (FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
|
||||
llvm::MDBuilder MDHelper(getLLVMContext());
|
||||
SwitchInsn->setMetadata(llvm::LLVMContext::MD_unpredictable,
|
||||
MDHelper.createUnpredictable());
|
||||
}
|
||||
}
|
||||
auto *Call = dyn_cast<CallExpr>(S.getCond());
|
||||
if (Call && CGM.getCodeGenOpts().OptimizationLevel != 0) {
|
||||
auto *FD = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl());
|
||||
if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
|
||||
llvm::MDBuilder MDHelper(getLLVMContext());
|
||||
SwitchInsn->setMetadata(llvm::LLVMContext::MD_unpredictable,
|
||||
MDHelper.createUnpredictable());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue