[PATCH] D21752: Comprehensive Static Instrumentation (1/2): LLVM pass

Tyler Denniston via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 27 08:02:04 PDT 2016


tdenniston created this revision.
tdenniston added reviewers: kcc, zhaoqin, bruening, mehdi_amini.
tdenniston added subscribers: llvm-commits, neboat, aizatsky, vitalybuka, pcc, eugenis.
tdenniston set the repository for this revision to rL LLVM.
tdenniston added a project: Comprehensive Static Instrumentation.

The Comprehensive Static Instrumentation (CSI) framework provides static instrumentation that a compiler inserts into a program-under-test so that dynamic-analysis tools -- memory checkers, race detectors, cache simulators, performance profilers, code-coverage analyzers, etc. -- can observe and investigate runtime behavior. Heretofore, tools based on compiler instrumentation would each separately modify the compiler to insert their own instrumentation. In contrast, CSI inserts a standard collection of instrumentation hooks into the program-under-test. Each CSI-tool is implemented as a library that defines relevant hooks, and the remaining hooks are "nulled'" out and elided during link-time optimization (LTO), resulting in instrumented runtimes on par with custom instrumentation. CSI allows many compiler-based tools to be written as simple libraries without modifying the compiler, greatly lowering the bar for developing dynamic-analysis tools.

This diff encompasses a skeleton compiler pass for CSI. For an extended usage doc, please see the docs/CSI.rst document submitted with the clang diff. We will be submitting further diffs that incrementally add functionality to CSI.

Repository:
  rL LLVM

http://reviews.llvm.org/D21752

Files:
  include/llvm/InitializePasses.h
  include/llvm/Transforms/Instrumentation.h
  lib/Transforms/Instrumentation/CMakeLists.txt
  lib/Transforms/Instrumentation/ComprehensiveStaticInstrumentation.cpp
  lib/Transforms/Instrumentation/Instrumentation.cpp

Index: lib/Transforms/Instrumentation/Instrumentation.cpp
===================================================================
--- lib/Transforms/Instrumentation/Instrumentation.cpp
+++ lib/Transforms/Instrumentation/Instrumentation.cpp
@@ -69,6 +69,7 @@
   initializeSanitizerCoverageModulePass(Registry);
   initializeDataFlowSanitizerPass(Registry);
   initializeEfficiencySanitizerPass(Registry);
+  initializeComprehensiveStaticInstrumentationPass(Registry);
 }
 
 /// LLVMInitializeInstrumentation - C binding for
Index: lib/Transforms/Instrumentation/ComprehensiveStaticInstrumentation.cpp
===================================================================
--- /dev/null
+++ lib/Transforms/Instrumentation/ComprehensiveStaticInstrumentation.cpp
@@ -0,0 +1,37 @@
+#include "llvm/IR/Module.h"
+#include "llvm/Transforms/Instrumentation.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "csi"
+
+namespace {
+/// The Comprehensive Static Instrumentation pass.
+/// Inserts calls to user-defined hooks at predefined points in the IR.
+struct ComprehensiveStaticInstrumentation : public ModulePass {
+  static char ID;
+
+  ComprehensiveStaticInstrumentation() : ModulePass(ID) {}
+  const char *getPassName() const override;
+  bool runOnModule(Module &M) override;
+};
+} // End anonymous namespace
+
+char ComprehensiveStaticInstrumentation::ID = 0;
+
+INITIALIZE_PASS(ComprehensiveStaticInstrumentation, "csi",
+                "ComprehensiveStaticInstrumentation: inserts calls to "
+                "user-defined hooks in the IR.",
+                false, false)
+
+const char *ComprehensiveStaticInstrumentation::getPassName() const {
+  return "ComprehensiveStaticInstrumentation";
+}
+
+ModulePass *llvm::createComprehensiveStaticInstrumentationPass() {
+  return new ComprehensiveStaticInstrumentation();
+}
+
+bool ComprehensiveStaticInstrumentation::runOnModule(Module &M) {
+  return false;
+}
Index: lib/Transforms/Instrumentation/CMakeLists.txt
===================================================================
--- lib/Transforms/Instrumentation/CMakeLists.txt
+++ lib/Transforms/Instrumentation/CMakeLists.txt
@@ -11,6 +11,7 @@
   SanitizerCoverage.cpp
   ThreadSanitizer.cpp
   EfficiencySanitizer.cpp
+  ComprehensiveStaticInstrumentation.cpp
 
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms
Index: include/llvm/Transforms/Instrumentation.h
===================================================================
--- include/llvm/Transforms/Instrumentation.h
+++ include/llvm/Transforms/Instrumentation.h
@@ -163,6 +163,9 @@
 }
 #endif
 
+// Insert ComprehensiveStaticInstrumentation instrumentation
+ModulePass *createComprehensiveStaticInstrumentationPass();
+
 // BoundsChecking - This pass instruments the code to perform run-time bounds
 // checking on loads, stores, and other memory intrinsics.
 FunctionPass *createBoundsCheckingPass();
Index: include/llvm/InitializePasses.h
===================================================================
--- include/llvm/InitializePasses.h
+++ include/llvm/InitializePasses.h
@@ -118,6 +118,7 @@
 void initializeEarlyIfConverterPass(PassRegistry&);
 void initializeEdgeBundlesPass(PassRegistry&);
 void initializeEfficiencySanitizerPass(PassRegistry&);
+void initializeComprehensiveStaticInstrumentationPass(PassRegistry&);
 void initializeEliminateAvailableExternallyLegacyPassPass(PassRegistry &);
 void initializeExpandISelPseudosPass(PassRegistry&);
 void initializeExpandPostRAPass(PassRegistry&);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21752.61964.patch
Type: text/x-patch
Size: 3492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160627/ef540167/attachment.bin>


More information about the llvm-commits mailing list