Coverage Report

Created: 2017-06-28 17:40

/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/IR/IRBuilder.h"
21
#include "llvm/IR/ValueMap.h"
22
23
namespace llvm {
24
class ScalarEvolution;
25
} // namespace llvm
26
27
namespace polly {
28
class Scop;
29
30
/// Helper class to annotate newly generated SCoPs with metadata.
31
///
32
/// The annotations are twofold:
33
///   1) Loops are stored in a stack-like structure in the order they are
34
///      constructed and the LoopID metadata node is added to the backedge.
35
///      Contained memory instructions and loop headers are annotated according
36
///      to all parallel surrounding loops.
37
///   2) The new SCoP is assumed alias free (either due to the result of
38
///      AliasAnalysis queries or runtime alias checks). We annotate therefore
39
///      all memory instruction with alias scopes to indicate that fact to
40
///      later optimizations.
41
///      These alias scopes live in a new alias domain only used in this SCoP.
42
///      Each base pointer has its own alias scope and is annotated to not
43
///      alias with any access to different base pointers.
44
class ScopAnnotator {
45
public:
46
  ScopAnnotator();
47
48
  /// Build all alias scopes for the given SCoP.
49
  void buildAliasScopes(Scop &S);
50
51
  /// Add a new loop @p L which is parallel if @p IsParallel is true.
52
  void pushLoop(llvm::Loop *L, bool IsParallel);
53
54
  /// Remove the last added loop.
55
  void popLoop(bool isParallel);
56
57
  /// Annotate the new instruction @p I for all parallel loops.
58
  void annotate(llvm::Instruction *I);
59
60
  /// Annotate the loop latch @p B wrt. @p L.
61
  void annotateLoopLatch(llvm::BranchInst *B, llvm::Loop *L,
62
                         bool IsParallel) const;
63
64
  /// Add alternative alias based pointers
65
  ///
66
  /// When annotating instructions with alias scope metadata, the right metadata
67
  /// is identified through the base pointer of the memory access. In some cases
68
  /// (e.g. OpenMP code generation), the base pointer of the memory accesses is
69
  /// not the original base pointer, but was changed when passing the original
70
  /// base pointer over a function boundary. This function allows to provide a
71
  /// map that maps from these new base pointers to the original base pointers
72
  /// to allow the ScopAnnotator to still find the right alias scop annotations.
73
  ///
74
  /// @param NewMap A map from new base pointers to original base pointers.
75
  void addAlternativeAliasBases(
76
      llvm::DenseMap<llvm::AssertingVH<llvm::Value>,
77
136
                     llvm::AssertingVH<llvm::Value>> &NewMap) {
78
136
    AlternativeAliasBases.insert(NewMap.begin(), NewMap.end());
79
136
  }
80
81
  /// Delete the set of alternative alias bases
82
26
  void resetAlternativeAliasBases() { AlternativeAliasBases.clear(); }
83
84
  /// Add inter iteration alias-free base pointer @p BasePtr.
85
  void addInterIterationAliasFreeBasePtr(llvm::Value *BasePtr);
86
87
private:
88
  /// Annotate with the second level alias metadata
89
  ///
90
  /// Annotate the instruction @p I with the second level alias metadata
91
  /// to distinguish the individual non-aliasing accesses that have inter
92
  /// iteration alias-free base pointers.
93
  ///
94
  /// @param I The instruction to be annotated.
95
  /// @param BasePtr The base pointer of @p I.
96
  void annotateSecondLevel(llvm::Instruction *I, llvm::Value *BasePtr);
97
98
  /// The ScalarEvolution analysis we use to find base pointers.
99
  llvm::ScalarEvolution *SE;
100
101
  /// All loops currently under construction.
102
  llvm::SmallVector<llvm::Loop *, 8> ActiveLoops;
103
104
  /// Metadata pointing to parallel loops currently under construction.
105
  llvm::SmallVector<llvm::MDNode *, 8> ParallelLoops;
106
107
  /// The alias scope domain for the current SCoP.
108
  llvm::MDNode *AliasScopeDomain;
109
110
  /// A map from base pointers to its alias scope.
111
  llvm::MapVector<llvm::AssertingVH<llvm::Value>, llvm::MDNode *> AliasScopeMap;
112
113
  /// A map from base pointers to an alias scope list of other pointers.
114
  llvm::DenseMap<llvm::AssertingVH<llvm::Value>, llvm::MDNode *>
115
      OtherAliasScopeListMap;
116
117
  /// A map from pointers to second level alias scopes.
118
  llvm::DenseMap<llvm::AssertingVH<llvm::Value>, llvm::MDNode *>
119
      SecondLevelAliasScopeMap;
120
121
  /// A map from pointers to second level alias scope list of other pointers.
122
  llvm::DenseMap<llvm::AssertingVH<llvm::Value>, 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
285
  IRInserter() = default;
139
280
  IRInserter(class ScopAnnotator &A) : Annotator(&A) {}
140
141
protected:
142
  void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
143
                    llvm::BasicBlock *BB,
144
8.99k
                    llvm::BasicBlock::iterator InsertPt) const {
145
8.99k
    llvm::IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
146
8.99k
    if (Annotator)
147
7.96k
      Annotator->annotate(I);
148
8.99k
  }
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
280
                                                  ScopAnnotator &LA) {
163
280
  PollyIRBuilder Builder(BB->getContext(), llvm::ConstantFolder(),
164
280
                         polly::IRInserter(LA));
165
280
  Builder.SetInsertPoint(BB->getTerminator());
166
280
  return Builder;
167
280
}
Unexecuted instantiation: BlockGenerators.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
280
                                                  ScopAnnotator &LA) {
163
280
  PollyIRBuilder Builder(BB->getContext(), llvm::ConstantFolder(),
164
280
                         polly::IRInserter(LA));
165
280
  Builder.SetInsertPoint(BB->getTerminator());
166
280
  return Builder;
167
280
}
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&)
168
} // namespace polly
169
#endif