Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- LowerWidenableCondition.cpp - Lower the guard intrinsic ---------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This pass lowers the llvm.widenable.condition intrinsic to default value
10
// which is i1 true.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "llvm/Transforms/Scalar/LowerWidenableCondition.h"
15
#include "llvm/ADT/SmallVector.h"
16
#include "llvm/Analysis/GuardUtils.h"
17
#include "llvm/IR/BasicBlock.h"
18
#include "llvm/IR/Function.h"
19
#include "llvm/IR/InstIterator.h"
20
#include "llvm/IR/Instructions.h"
21
#include "llvm/IR/Intrinsics.h"
22
#include "llvm/IR/Module.h"
23
#include "llvm/IR/PatternMatch.h"
24
#include "llvm/Pass.h"
25
#include "llvm/Transforms/Scalar.h"
26
#include "llvm/Transforms/Utils/GuardUtils.h"
27
28
using namespace llvm;
29
30
namespace {
31
struct LowerWidenableConditionLegacyPass : public FunctionPass {
32
  static char ID;
33
1
  LowerWidenableConditionLegacyPass() : FunctionPass(ID) {
34
1
    initializeLowerWidenableConditionLegacyPassPass(
35
1
        *PassRegistry::getPassRegistry());
36
1
  }
37
38
  bool runOnFunction(Function &F) override;
39
};
40
}
41
42
2
static bool lowerWidenableCondition(Function &F) {
43
2
  // Check if we can cheaply rule out the possibility of not having any work to
44
2
  // do.
45
2
  auto *WCDecl = F.getParent()->getFunction(
46
2
      Intrinsic::getName(Intrinsic::experimental_widenable_condition));
47
2
  if (!WCDecl || WCDecl->use_empty())
48
0
    return false;
49
2
50
2
  using namespace llvm::PatternMatch;
51
2
  SmallVector<CallInst *, 8> ToLower;
52
2
  for (auto &I : instructions(F))
53
18
    if (match(&I, m_Intrinsic<Intrinsic::experimental_widenable_condition>()))
54
4
      ToLower.push_back(cast<CallInst>(&I));
55
2
56
2
  if (ToLower.empty())
57
0
    return false;
58
2
59
4
  
for (auto *CI : ToLower)2
{
60
4
    CI->replaceAllUsesWith(ConstantInt::getTrue(CI->getContext()));
61
4
    CI->eraseFromParent();
62
4
  }
63
2
  return true;
64
2
}
65
66
1
bool LowerWidenableConditionLegacyPass::runOnFunction(Function &F) {
67
1
  return lowerWidenableCondition(F);
68
1
}
69
70
char LowerWidenableConditionLegacyPass::ID = 0;
71
INITIALIZE_PASS(LowerWidenableConditionLegacyPass, "lower-widenable-condition",
72
                "Lower the widenable condition to default true value", false,
73
                false)
74
75
0
Pass *llvm::createLowerWidenableConditionPass() {
76
0
  return new LowerWidenableConditionLegacyPass();
77
0
}
78
79
PreservedAnalyses LowerWidenableConditionPass::run(Function &F,
80
1
                                               FunctionAnalysisManager &AM) {
81
1
  if (lowerWidenableCondition(F))
82
1
    return PreservedAnalyses::none();
83
0
84
0
  return PreservedAnalyses::all();
85
0
}