llvm.org GIT mirror llvm / 438355c
[PM] Port Add discriminator pass to new PM git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272847 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 3 years ago
15 changed file(s) with 65 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
5757 void initializeAAEvalLegacyPassPass(PassRegistry&);
5858 void initializeAAResultsWrapperPassPass(PassRegistry &);
5959 void initializeADCELegacyPassPass(PassRegistry&);
60 void initializeAddDiscriminatorsPass(PassRegistry&);
60 void initializeAddDiscriminatorsLegacyPassPass(PassRegistry&);
6161 void initializeAddressSanitizerModulePass(PassRegistry&);
6262 void initializeAddressSanitizerPass(PassRegistry&);
6363 void initializeAliasSetPrinterPass(PassRegistry&);
0 //===- AddDiscriminators.h -------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass adds DWARF discriminators to the IR. Path discriminators are used
10 // to decide what CFG path was taken inside sub-graphs whose instructions share
11 // the same line and column number information.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TRANSFORMS_UTILS_ADDDISCRIMINATORS_H
16 #define LLVM_TRANSFORMS_UTILS_ADDDISCRIMINATORS_H
17
18 #include "llvm/IR/PassManager.h"
19
20 namespace llvm {
21
22 /// Converts loops into loop-closed SSA form.
23 class AddDiscriminatorsPass : public PassInfoMixin {
24 public:
25 PreservedAnalyses run(Function &F, AnalysisManager &AM);
26 };
27 } // end namespace llvm
28
29 #endif // LLVM_TRANSFORMS_UTILS_LCSSA_H
8989 #include "llvm/Transforms/Scalar/SROA.h"
9090 #include "llvm/Transforms/Scalar/SimplifyCFG.h"
9191 #include "llvm/Transforms/Scalar/Sink.h"
92 #include "llvm/Transforms/Utils/AddDiscriminators.h"
9293 #include "llvm/Transforms/Scalar/SLPVectorizer.h"
9394 #include "llvm/Transforms/Utils/LCSSA.h"
9495 #include "llvm/Transforms/Utils/Mem2Reg.h"
118118 #endif
119119 FUNCTION_PASS("aa-eval", AAEvaluator())
120120 FUNCTION_PASS("adce", ADCEPass())
121 FUNCTION_PASS("add-discriminators", AddDiscriminatorsPass())
121122 FUNCTION_PASS("alignment-from-assumptions", AlignmentFromAssumptionsPass())
122123 FUNCTION_PASS("bdce", BDCEPass())
123124 FUNCTION_PASS("dce", DCEPass())
5151 // http://wiki.dwarfstd.org/index.php?title=Path_Discriminators
5252 //===----------------------------------------------------------------------===//
5353
54 #include "llvm/Transforms/Utils/AddDiscriminators.h"
5455 #include "llvm/ADT/DenseMap.h"
5556 #include "llvm/ADT/DenseSet.h"
5657 #include "llvm/IR/BasicBlock.h"
7273 #define DEBUG_TYPE "add-discriminators"
7374
7475 namespace {
75 struct AddDiscriminators : public FunctionPass {
76 // The legacy pass of AddDiscriminators.
77 struct AddDiscriminatorsLegacyPass : public FunctionPass {
7678 static char ID; // Pass identification, replacement for typeid
77 AddDiscriminators() : FunctionPass(ID) {
78 initializeAddDiscriminatorsPass(*PassRegistry::getPassRegistry());
79 AddDiscriminatorsLegacyPass() : FunctionPass(ID) {
80 initializeAddDiscriminatorsLegacyPassPass(*PassRegistry::getPassRegistry());
7981 }
8082
8183 bool runOnFunction(Function &F) override;
8284 };
85
8386 } // end anonymous namespace
8487
85 char AddDiscriminators::ID = 0;
86 INITIALIZE_PASS_BEGIN(AddDiscriminators, "add-discriminators",
88 char AddDiscriminatorsLegacyPass::ID = 0;
89 INITIALIZE_PASS_BEGIN(AddDiscriminatorsLegacyPass, "add-discriminators",
8790 "Add DWARF path discriminators", false, false)
88 INITIALIZE_PASS_END(AddDiscriminators, "add-discriminators",
91 INITIALIZE_PASS_END(AddDiscriminatorsLegacyPass, "add-discriminators",
8992 "Add DWARF path discriminators", false, false)
9093
9194 // Command line option to disable discriminator generation even in the
9598 "no-discriminators", cl::init(false),
9699 cl::desc("Disable generation of discriminator information."));
97100
101 // Create the legacy AddDiscriminatorsPass.
98102 FunctionPass *llvm::createAddDiscriminatorsPass() {
99 return new AddDiscriminators();
103 return new AddDiscriminatorsLegacyPass();
100104 }
101105
102106 /// \brief Assign DWARF discriminators.
150154 /// lexical block for I2 and all the instruction in B2 that share the same
151155 /// file and line location as I2. This new lexical block will have a
152156 /// different discriminator number than I1.
153 bool AddDiscriminators::runOnFunction(Function &F) {
157 bool addDiscriminators(Function &F) {
154158 // If the function has debug information, but the user has disabled
155159 // discriminators, do nothing.
156160 // Simlarly, if the function has no debug info, do nothing.
239243 }
240244 return Changed;
241245 }
246
247 bool AddDiscriminatorsLegacyPass::runOnFunction(Function &F) {
248 return addDiscriminators(F);
249 }
250 PreservedAnalyses AddDiscriminatorsPass::run(Function &F,
251 AnalysisManager &AM) {
252 addDiscriminators(F);
253 // Only modifies debug info.
254 return PreservedAnalyses::all();
255 }
2020 /// initializeTransformUtils - Initialize all passes in the TransformUtils
2121 /// library.
2222 void llvm::initializeTransformUtils(PassRegistry &Registry) {
23 initializeAddDiscriminatorsPass(Registry);
23 initializeAddDiscriminatorsLegacyPassPass(Registry);
2424 initializeBreakCriticalEdgesPass(Registry);
2525 initializeInstNamerPass(Registry);
2626 initializeLCSSAWrapperPassPass(Registry);
0 ; RUN: opt < %s -add-discriminators -S | FileCheck %s
1 ; RUN: opt < %s -passes=add-discriminators -S | FileCheck %s
12
23 ; Basic DWARF discriminator test. All the instructions in block
34 ; 'if.then' should have a different discriminator value than
0 ; RUN: opt < %s -add-discriminators -S | FileCheck %s
1 ; RUN: opt < %s -passes=add-discriminators -S | FileCheck %s
12
23 ; Discriminator support for calls that are defined in one line:
34 ; #1 int foo(int, int);
0 ; RUN: opt < %s -add-discriminators -S | FileCheck %s
1 ; RUN: opt < %s -passes=add-discriminators -S | FileCheck %s
12
23 ; Discriminator support for calls that are defined in one line:
34 ; #1 void bar();
0 ; RUN: opt -S -add-discriminators < %s | FileCheck %s
1 ; RUN: opt -S -passes=add-discriminators < %s | FileCheck %s
12
23 declare void @llvm.dbg.declare(metadata, metadata, metadata)
34
0 ; RUN: opt < %s -add-discriminators -S | FileCheck %s
1 ; RUN: opt < %s -passes=add-discriminators -S | FileCheck %s
12
23 ; Discriminator support for diamond-shaped CFG.:
34 ; #1 void bar(int);
0 ; RUN: opt < %s -add-discriminators -S | FileCheck %s
1 ; RUN: opt < %s -passes=add-discriminators -S | FileCheck %s
12
23 ; Test that the only instructions that receive a new discriminator in
34 ; the block 'if.then' are those that share the same line number as
0 ; RUN: opt < %s -add-discriminators -S | FileCheck %s
1 ; RUN: opt < %s -passes=add-discriminators -S | FileCheck %s
12
23 ; Discriminator support for multiple CFG paths on the same line.
34 ;
0 ; RUN: opt < %s -add-discriminators -S | FileCheck %s
1 ; RUN: opt < %s -passes=add-discriminators -S | FileCheck %s
12
23 ; We should not generate discriminators for DWARF versions prior to 4.
34 ;
0 ; RUN: opt < %s -add-discriminators -S | FileCheck %s
1 ; RUN: opt < %s -passes=add-discriminators -S | FileCheck %s
12
23 ; Discriminator support for code that is written in one line:
34 ; #1 int foo(int i) {