Skip to content

Commit 5acd5ab

Browse files
kevinsalajdoerfertivanradanovEthanLuisMcDonough
committed
[Instrumentor] Add Instrumentor pass
This commit adds the basic infrastructure for the Instrumentor pass, which allows instrumenting code in a simple and customizable way. This commit adds support for instrumenting load and store instructions. The Instrumentor can be configured with a JSON file that describes what should be instrumented, or can be used programmatically from another pass. This is only a squash commit of several contributions to the Instrumentor. The following are the authors and contributors of this pass: Co-authored-by: Johannes Doerfert <[email protected]> Co-authored-by: Kevin Sala <[email protected]> Co-authored-by: Ivan Radanov Ivanov <[email protected]> Co-authored-by: Ethan Luis McDonough <[email protected]>
1 parent 8b9ae65 commit 5acd5ab

19 files changed

+2698
-0
lines changed

llvm/include/llvm/Transforms/IPO/Instrumentor.h

Lines changed: 739 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===- Transforms/IPO/InstrumentorConfigFile.h ----------------------------===//
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+
// Utilities for the Instrumentor JSON configuration file.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_TRANSFORMS_IPO_INSTRUMENTOR_CONFIGFILE_H
14+
#define LLVM_TRANSFORMS_IPO_INSTRUMENTOR_CONFIGFILE_H
15+
16+
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/Transforms/IPO/Instrumentor.h"
18+
19+
namespace llvm {
20+
namespace instrumentor {
21+
22+
void writeConfigToJSON(InstrumentationConfig &IConf, StringRef OutputFile);
23+
24+
bool readConfigFromJSON(InstrumentationConfig &IConf, StringRef InputFile);
25+
26+
} // end namespace instrumentor
27+
} // end namespace llvm
28+
29+
#endif // LLVM_TRANSFORMS_IPO_INSTRUMENTOR_CONFIGFILE_H

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
#include "llvm/Transforms/IPO/IROutliner.h"
222222
#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
223223
#include "llvm/Transforms/IPO/Inliner.h"
224+
#include "llvm/Transforms/IPO/Instrumentor.h"
224225
#include "llvm/Transforms/IPO/Internalize.h"
225226
#include "llvm/Transforms/IPO/LoopExtractor.h"
226227
#include "llvm/Transforms/IPO/LowerTypeTests.h"

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "llvm/Transforms/IPO/IROutliner.h"
6464
#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
6565
#include "llvm/Transforms/IPO/Inliner.h"
66+
#include "llvm/Transforms/IPO/Instrumentor.h"
6667
#include "llvm/Transforms/IPO/LowerTypeTests.h"
6768
#include "llvm/Transforms/IPO/MemProfContextDisambiguation.h"
6869
#include "llvm/Transforms/IPO/MergeFunctions.h"
@@ -212,6 +213,10 @@ static cl::opt<bool> EnableLoopFlatten("enable-loop-flatten", cl::init(false),
212213
cl::Hidden,
213214
cl::desc("Enable the LoopFlatten Pass"));
214215

216+
static cl::opt<bool>
217+
EnableInstrumentor("enable-instrumentor", cl::init(false), cl::Hidden,
218+
cl::desc("Enable the Instrumentor Pass"));
219+
215220
// Experimentally allow loop header duplication. This should allow for better
216221
// optimization at Oz, since loop-idiom recognition can then recognize things
217222
// like memcpy. If this ends up being useful for many targets, we should drop
@@ -1594,6 +1599,10 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
15941599

15951600
invokeOptimizerLastEPCallbacks(MPM, Level, LTOPhase);
15961601

1602+
// Run the Instrumentor pass late.
1603+
if (EnableInstrumentor)
1604+
MPM.addPass(InstrumentorPass());
1605+
15971606
// Split out cold code. Splitting is done late to avoid hiding context from
15981607
// other optimizations and inadvertently regressing performance. The tradeoff
15991608
// is that this has a higher code size cost than splitting early.
@@ -2306,6 +2315,9 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
23062315

23072316
invokeOptimizerLastEPCallbacks(MPM, Level, Phase);
23082317

2318+
if (EnableInstrumentor)
2319+
MPM.addPass(InstrumentorPass());
2320+
23092321
if (isLTOPreLink(Phase))
23102322
addRequiredLTOPreLinkPasses(MPM);
23112323

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ MODULE_PASS("instrprof", InstrProfilingLoweringPass())
9494
MODULE_PASS("ctx-instr-lower", PGOCtxProfLoweringPass())
9595
MODULE_PASS("print<ctx-prof-analysis>", CtxProfAnalysisPrinterPass(errs()))
9696
MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
97+
MODULE_PASS("instrumentor", InstrumentorPass())
9798
MODULE_PASS("iroutliner", IROutlinerPass())
9899
MODULE_PASS("jmc-instrumenter", JMCInstrumenterPass())
99100
MODULE_PASS("lower-emutls", LowerEmuTLSPass())

llvm/lib/Transforms/IPO/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ add_llvm_component_library(LLVMipo
2727
IROutliner.cpp
2828
InferFunctionAttrs.cpp
2929
Inliner.cpp
30+
Instrumentor.cpp
31+
InstrumentorConfigFile.cpp
3032
Internalize.cpp
3133
LoopExtractor.cpp
3234
LowerTypeTests.cpp
@@ -62,6 +64,7 @@ add_llvm_component_library(LLVMipo
6264
BitReader
6365
BitWriter
6466
Core
67+
Demangle
6568
FrontendOpenMP
6669
InstCombine
6770
IRReader

0 commit comments

Comments
 (0)