Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/lib/Transform/RewriteByReferenceParameters.cpp
Line
Count
Source (jump to first uncovered line)
1
//===------ RewriteByReferenceParameters.cpp --------------------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This pass introduces separate 'alloca' instructions for read-only
11
// by-reference function parameters to indicate that these paramters are
12
// read-only. After this transformation -mem2reg has more freedom to promote
13
// variables to registers, which allows SCEV to work in more cases.
14
//
15
//===----------------------------------------------------------------------===//
16
17
#include "polly/LinkAllPasses.h"
18
#include "llvm/IR/Instruction.h"
19
#include "llvm/IR/Instructions.h"
20
#include "llvm/IR/PassManager.h"
21
22
#define DEBUG_TYPE "polly-rewrite-byref-params"
23
24
using namespace llvm;
25
26
namespace {
27
28
class RewriteByrefParams : public FunctionPass {
29
private:
30
  RewriteByrefParams(const RewriteByrefParams &) = delete;
31
  const RewriteByrefParams &operator=(const RewriteByrefParams &) = delete;
32
33
public:
34
  static char ID;
35
2
  explicit RewriteByrefParams() : FunctionPass(ID) {}
36
37
2
  virtual void getAnalysisUsage(AnalysisUsage &AU) const override {}
38
39
27
  void tryRewriteInstruction(Instruction &Inst) {
40
27
    BasicBlock *Entry = &Inst.getParent()->getParent()->getEntryBlock();
41
27
42
27
    auto *Call = dyn_cast<CallInst>(&Inst);
43
27
44
27
    if (!Call)
45
26
      return;
46
1
47
1
    llvm::Function *F = Call->getCalledFunction();
48
1
49
1
    if (!F)
50
0
      return;
51
1
52
1
    // We currently match for a very specific function. In case this proves
53
1
    // useful, we can make this code dependent on readonly metadata.
54
1
    
if (1
!F->hasName() || 1
F->getName() != "_gfortran_transfer_integer_write"1
)
55
0
      return;
56
1
57
1
    auto *BitCast = dyn_cast<BitCastInst>(Call->getOperand(1));
58
1
59
1
    if (!BitCast)
60
0
      return;
61
1
62
1
    auto *Alloca = dyn_cast<AllocaInst>(BitCast->getOperand(0));
63
1
64
1
    if (!Alloca)
65
0
      return;
66
1
67
1
    std::string InstName = Alloca->getName();
68
1
69
1
    auto NewAlloca =
70
1
        new AllocaInst(Alloca->getType()->getElementType(), 0,
71
1
                       "polly_byref_alloca_" + InstName, &*Entry->begin());
72
1
73
1
    auto *LoadedVal =
74
1
        new LoadInst(Alloca, "polly_byref_load_" + InstName, &Inst);
75
1
76
1
    new StoreInst(LoadedVal, NewAlloca, &Inst);
77
1
    auto *NewBitCast = new BitCastInst(NewAlloca, BitCast->getType(),
78
1
                                       "polly_byref_cast_" + InstName, &Inst);
79
1
    Call->setOperand(1, NewBitCast);
80
1
  }
81
82
2
  virtual bool runOnFunction(Function &F) override {
83
2
    for (BasicBlock &BB : F)
84
11
      for (Instruction &Inst : BB)
85
27
        tryRewriteInstruction(Inst);
86
2
87
2
    return true;
88
2
  }
89
};
90
91
char RewriteByrefParams::ID;
92
} // anonymous namespace
93
94
1
Pass *polly::createRewriteByrefParamsPass() { return new RewriteByrefParams(); }
95
96
41.7k
INITIALIZE_PASS_BEGIN41.7k
(RewriteByrefParams, "polly-rewrite-byref-params",
97
41.7k
                      "Polly - Rewrite by reference parameters", false, false)
98
41.7k
INITIALIZE_PASS_END(RewriteByrefParams, "polly-rewrite-byref-params",
99
                    "Polly - Rewrite by reference parameters", false, false)