Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/include/polly/CodeGen/IRBuilder.h
Line
Count
Source
1
//===- Codegen/IRBuilder.h - The IR builder used by Polly -*- 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
// The Polly IRBuilder file contains Polly specific extensions for the IRBuilder
11
// that are used e.g. to emit the llvm.loop.parallel metadata.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef POLLY_CODEGEN_IRBUILDER_H
16
#define POLLY_CODEGEN_IRBUILDER_H
17
18
#include "llvm/ADT/MapVector.h"
19
#include "llvm/Analysis/LoopInfo.h"
20
#include "llvm/Analysis/ScalarEvolution.h"
21
#include "llvm/IR/IRBuilder.h"
22
#include "llvm/IR/ValueMap.h"
23
24
namespace llvm {
25
class ScalarEvolution;
26
} // namespace llvm
27
28
namespace polly {
29
class Scop;
30
31
/// Helper class to annotate newly generated SCoPs with metadata.
32
///
33
/// The annotations are twofold:
34
///   1) Loops are stored in a stack-like structure in the order they are
35
///      constructed and the LoopID metadata node is added to the backedge.
36
///      Contained memory instructions and loop headers are annotated according
37
///      to all parallel surrounding loops.
38
///   2) The new SCoP is assumed alias free (either due to the result of
39
///      AliasAnalysis queries or runtime alias checks). We annotate therefore
40
///      all memory instruction with alias scopes to indicate that fact to
41
///      later optimizations.
42
///      These alias scopes live in a new alias domain only used in this SCoP.
43
///      Each base pointer has its own alias scope and is annotated to not
44
///      alias with any access to different base pointers.
45
class ScopAnnotator {
46
public:
47
  ScopAnnotator();
48
49
  /// Build all alias scopes for the given SCoP.
50
  void buildAliasScopes(Scop &S);
51
52
  /// Add a new loop @p L which is parallel if @p IsParallel is true.
53
  void pushLoop(llvm::Loop *L, bool IsParallel);
54
55
  /// Remove the last added loop.
56
  void popLoop(bool isParallel);
57
58
  /// Annotate the new instruction @p I for all parallel loops.
59
  void annotate(llvm::Instruction *I);
60
61
  /// Annotate the loop latch @p B wrt. @p L.
62
  void annotateLoopLatch(llvm::BranchInst *B, llvm::Loop *L, bool IsParallel,
63
                         bool IsLoopVectorizerDisabled) const;
64
65
  /// Add alternative alias based pointers
66
  ///
67
  /// When annotating instructions with alias scope metadata, the right metadata
68
  /// is identified through the base pointer of the memory access. In some cases
69
  /// (e.g. OpenMP code generation), the base pointer of the memory accesses is
70
  /// not the original base pointer, but was changed when passing the original
71
  /// base pointer over a function boundary. This function allows to provide a
72
  /// map that maps from these new base pointers to the original base pointers
73
  /// to allow the ScopAnnotator to still find the right alias scop annotations.
74
  ///
75
  /// @param NewMap A map from new base pointers to original base pointers.
76
  void addAlternativeAliasBases(
77
      llvm::DenseMap<llvm::AssertingVH<llvm::Value>,
78
132
                     llvm::AssertingVH<llvm::Value>> &NewMap) {
79
132
    AlternativeAliasBases.insert(NewMap.begin(), NewMap.end());
80
132
  }
81
82
  /// Delete the set of alternative alias bases
83
27
  void resetAlternativeAliasBases() { AlternativeAliasBases.clear(); }
84
85
  /// Add inter iteration alias-free base pointer @p BasePtr.
86
  void addInterIterationAliasFreeBasePtr(llvm::Value *BasePtr);
87
88
private:
89
  /// Annotate with the second level alias metadata
90
  ///
91
  /// Annotate the instruction @p I with the second level alias metadata
92
  /// to distinguish the individual non-aliasing accesses that have inter
93
  /// iteration alias-free base pointers.
94
  ///
95
  /// @param I The instruction to be annotated.
96
  /// @param BasePtr The base pointer of @p I.
97
  void annotateSecondLevel(llvm::Instruction *I, llvm::Value *BasePtr);
98
99
  /// The ScalarEvolution analysis we use to find base pointers.
100
  llvm::ScalarEvolution *SE;
101
102
  /// All loops currently under construction.
103
  llvm::SmallVector<llvm::Loop *, 8> ActiveLoops;
104
105
  /// Metadata pointing to parallel loops currently under construction.
106
  llvm::SmallVector<llvm::MDNode *, 8> ParallelLoops;
107
108
  /// The alias scope domain for the current SCoP.
109
  llvm::MDNode *AliasScopeDomain;
110
111
  /// A map from base pointers to its alias scope.
112
  llvm::MapVector<llvm::AssertingVH<llvm::Value>, llvm::MDNode *> AliasScopeMap;
113
114
  /// A map from base pointers to an alias scope list of other pointers.
115
  llvm::DenseMap<llvm::AssertingVH<llvm::Value>, llvm::MDNode *>
116
      OtherAliasScopeListMap;
117
118
  /// A map from pointers to second level alias scopes.
119
  llvm::DenseMap<const llvm::SCEV *, llvm::MDNode *> SecondLevelAliasScopeMap;
120
121
  /// A map from pointers to second level alias scope list of other pointers.
122
  llvm::DenseMap<const llvm::SCEV *, llvm::MDNode *>
123
      SecondLevelOtherAliasScopeListMap;
124
125
  /// Inter iteration alias-free base pointers.
126
  llvm::SmallPtrSet<llvm::Value *, 4> InterIterationAliasFreeBasePtrs;
127
128
  llvm::DenseMap<llvm::AssertingVH<llvm::Value>, llvm::AssertingVH<llvm::Value>>
129
      AlternativeAliasBases;
130
};
131
132
/// Add Polly specifics when running IRBuilder.
133
///
134
/// This is used to add additional items such as e.g. the llvm.loop.parallel
135
/// metadata.
136
class IRInserter : protected llvm::IRBuilderDefaultInserter {
137
public:
138
293
  IRInserter() = default;
139
288
  IRInserter(class ScopAnnotator &A) : Annotator(&A) {}
140
141
protected:
142
  void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
143
                    llvm::BasicBlock *BB,
144
10.2k
                    llvm::BasicBlock::iterator InsertPt) const {
145
10.2k
    llvm::IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
146
10.2k
    if (Annotator)
147
9.18k
      Annotator->annotate(I);
148
10.2k
  }
149
150
private:
151
  class ScopAnnotator *Annotator = nullptr;
152
};
153
154
// TODO: We should not name instructions in NDEBUG builds.
155
//
156
// We currently always name instructions, as the polly test suite currently
157
// matches for certain names.
158
typedef llvm::IRBuilder<llvm::ConstantFolder, IRInserter> PollyIRBuilder;
159
160
/// Return an IR builder pointed before the @p BB terminator.
161
static inline PollyIRBuilder createPollyIRBuilder(llvm::BasicBlock *BB,
162
288
                                                  ScopAnnotator &LA) {
163
288
  PollyIRBuilder Builder(BB->getContext(), llvm::ConstantFolder(),
164
288
                         polly::IRInserter(LA));
165
288
  Builder.SetInsertPoint(BB->getTerminator());
166
288
  return Builder;
167
288
}
Unexecuted instantiation: BlockGenerators.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
Unexecuted instantiation: IslAst.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
Unexecuted instantiation: IslExprBuilder.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
Unexecuted instantiation: IslNodeBuilder.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
CodeGeneration.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
Line
Count
Source
162
288
                                                  ScopAnnotator &LA) {
163
288
  PollyIRBuilder Builder(BB->getContext(), llvm::ConstantFolder(),
164
288
                         polly::IRInserter(LA));
165
288
  Builder.SetInsertPoint(BB->getTerminator());
166
288
  return Builder;
167
288
}
Unexecuted instantiation: LoopGenerators.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
Unexecuted instantiation: IRBuilder.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
Unexecuted instantiation: Utils.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
Unexecuted instantiation: RuntimeDebugBuilder.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
Unexecuted instantiation: PerfMonitor.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
Unexecuted instantiation: RegisterPasses.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
Unexecuted instantiation: ScheduleOptimizer.cpp:polly::createPollyIRBuilder(llvm::BasicBlock*, polly::ScopAnnotator&)
168
} // namespace polly
169
#endif