Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/NVPTX/NVPTXAllocaHoisting.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- AllocaHoisting.cpp - Hoist allocas to the entry block --*- C++ -*-===//
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
// Hoist the alloca instructions in the non-entry blocks to the entry blocks.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "NVPTXAllocaHoisting.h"
14
#include "llvm/CodeGen/StackProtector.h"
15
#include "llvm/IR/Constants.h"
16
#include "llvm/IR/Function.h"
17
#include "llvm/IR/Instructions.h"
18
using namespace llvm;
19
20
namespace {
21
// Hoisting the alloca instructions in the non-entry blocks to the entry
22
// block.
23
class NVPTXAllocaHoisting : public FunctionPass {
24
public:
25
  static char ID; // Pass ID
26
263
  NVPTXAllocaHoisting() : FunctionPass(ID) {}
27
28
261
  void getAnalysisUsage(AnalysisUsage &AU) const override {
29
261
    AU.addPreserved<StackProtector>();
30
261
  }
31
32
1.69k
  StringRef getPassName() const override {
33
1.69k
    return "NVPTX specific alloca hoisting";
34
1.69k
  }
35
36
  bool runOnFunction(Function &function) override;
37
};
38
} // namespace
39
40
1.69k
bool NVPTXAllocaHoisting::runOnFunction(Function &function) {
41
1.69k
  bool functionModified = false;
42
1.69k
  Function::iterator I = function.begin();
43
1.69k
  Instruction *firstTerminatorInst = (I++)->getTerminator();
44
1.69k
45
1.85k
  for (Function::iterator E = function.end(); I != E; 
++I158
) {
46
699
    for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE;) {
47
541
      AllocaInst *allocaInst = dyn_cast<AllocaInst>(BI++);
48
541
      if (allocaInst && 
isa<ConstantInt>(allocaInst->getArraySize())0
) {
49
0
        allocaInst->moveBefore(firstTerminatorInst);
50
0
        functionModified = true;
51
0
      }
52
541
    }
53
158
  }
54
1.69k
55
1.69k
  return functionModified;
56
1.69k
}
57
58
char NVPTXAllocaHoisting::ID = 0;
59
60
namespace llvm {
61
void initializeNVPTXAllocaHoistingPass(PassRegistry &);
62
}
63
64
INITIALIZE_PASS(
65
    NVPTXAllocaHoisting, "alloca-hoisting",
66
    "Hoisting alloca instructions in non-entry blocks to the entry block",
67
    false, false)
68
69
263
FunctionPass *llvm::createAllocaHoisting() { return new NVPTXAllocaHoisting; }