[compiler-rt] r270256 - [esan] Add custom flag support

Derek Bruening via llvm-commits llvm-commits at lists.llvm.org
Fri May 20 12:26:53 PDT 2016


Author: bruening
Date: Fri May 20 14:26:52 2016
New Revision: 270256

URL: http://llvm.org/viewvc/llvm-project?rev=270256&view=rev
Log:
[esan] Add custom flag support

Summary:
Adds custom flag support to EfficiencySanitizer's runtime library.

Adds an initial flag cache_line_size which will be used by multiple tools.

Reviewers: aizatsky, vitalybuka

Subscribers: llvm-commits, eugenis, kcc, zhaoqin, aizatsky, kubabrecka

Differential Revision: http://reviews.llvm.org/D20478

Added:
    compiler-rt/trunk/lib/esan/esan_flags.cpp   (with props)
    compiler-rt/trunk/lib/esan/esan_flags.h   (with props)
    compiler-rt/trunk/lib/esan/esan_flags.inc
Modified:
    compiler-rt/trunk/lib/esan/CMakeLists.txt
    compiler-rt/trunk/lib/esan/esan.cpp

Modified: compiler-rt/trunk/lib/esan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/esan/CMakeLists.txt?rev=270256&r1=270255&r2=270256&view=diff
==============================================================================
--- compiler-rt/trunk/lib/esan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/esan/CMakeLists.txt Fri May 20 14:26:52 2016
@@ -9,6 +9,7 @@ include_directories(..)
 
 set(ESAN_SOURCES
   esan.cpp
+  esan_flags.cpp
   esan_interface.cpp
   esan_interceptors.cpp)
 

Modified: compiler-rt/trunk/lib/esan/esan.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/esan/esan.cpp?rev=270256&r1=270255&r2=270256&view=diff
==============================================================================
--- compiler-rt/trunk/lib/esan/esan.cpp (original)
+++ compiler-rt/trunk/lib/esan/esan.cpp Fri May 20 14:26:52 2016
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "esan.h"
+#include "esan_flags.h"
 #include "esan_interface_internal.h"
 #include "esan_shadow.h"
 #include "sanitizer_common/sanitizer_common.h"
@@ -30,8 +31,6 @@ bool EsanIsInitialized;
 ToolType WhichTool;
 ShadowMapping Mapping;
 
-static const char EsanOptsEnv[] = "ESAN_OPTIONS";
-
 // We are combining multiple performance tuning tools under the umbrella of
 // one EfficiencySanitizer super-tool.  Most of our tools have very similar
 // memory access instrumentation, shadow memory mapping, libc interception,
@@ -142,21 +141,6 @@ static void initializeShadow() {
   }
 }
 
-static void initializeFlags() {
-  // Once we add our own flags we'll parse them here.
-  // For now the common ones are sufficient.
-  FlagParser Parser;
-  SetCommonFlagsDefaults();
-  RegisterCommonFlags(&Parser);
-  Parser.ParseString(GetEnv(EsanOptsEnv));
-  InitializeCommonFlags();
-  if (Verbosity())
-    ReportUnrecognizedFlags();
-  if (common_flags()->help)
-    Parser.PrintFlagDescriptions();
-  __sanitizer_set_report_path(common_flags()->log_path);
-}
-
 void initializeLibrary(ToolType Tool) {
   // We assume there is only one thread during init.
   if (EsanIsInitialized) {

Added: compiler-rt/trunk/lib/esan/esan_flags.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/esan/esan_flags.cpp?rev=270256&view=auto
==============================================================================
--- compiler-rt/trunk/lib/esan/esan_flags.cpp (added)
+++ compiler-rt/trunk/lib/esan/esan_flags.cpp Fri May 20 14:26:52 2016
@@ -0,0 +1,58 @@
+//===-- esan_flags.cc -------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of EfficiencySanitizer, a family of performance tuners.
+//
+// Esan flag parsing logic.
+//===----------------------------------------------------------------------===//
+
+#include "esan_flags.h"
+#include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_flag_parser.h"
+#include "sanitizer_common/sanitizer_flags.h"
+
+namespace __esan {
+
+static const char EsanOptsEnv[] = "ESAN_OPTIONS";
+
+Flags EsanFlagsDontUseDirectly;
+
+void Flags::setDefaults() {
+#define ESAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
+#include "esan_flags.inc"
+#undef ESAN_FLAG
+}
+
+static void registerEsanFlags(FlagParser *Parser, Flags *F) {
+#define ESAN_FLAG(Type, Name, DefaultValue, Description) \
+  RegisterFlag(Parser, #Name, Description, &F->Name);
+#include "esan_flags.inc"
+#undef ESAN_FLAG
+}
+
+void initializeFlags() {
+  SetCommonFlagsDefaults();
+  Flags *F = getFlags();
+  F->setDefaults();
+
+  FlagParser Parser;
+  registerEsanFlags(&Parser, F);
+  RegisterCommonFlags(&Parser);
+  Parser.ParseString(GetEnv(EsanOptsEnv));
+
+  InitializeCommonFlags();
+  if (Verbosity())
+    ReportUnrecognizedFlags();
+  if (common_flags()->help)
+    Parser.PrintFlagDescriptions();
+
+  __sanitizer_set_report_path(common_flags()->log_path);
+}
+
+} // namespace __esan

Propchange: compiler-rt/trunk/lib/esan/esan_flags.cpp
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: compiler-rt/trunk/lib/esan/esan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/esan/esan_flags.h?rev=270256&view=auto
==============================================================================
--- compiler-rt/trunk/lib/esan/esan_flags.h (added)
+++ compiler-rt/trunk/lib/esan/esan_flags.h Fri May 20 14:26:52 2016
@@ -0,0 +1,41 @@
+//===-- esan_flags.h --------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of EfficiencySanitizer, a family of performance tuners.
+//
+// Esan runtime flags.
+//===----------------------------------------------------------------------===//
+
+#ifndef ESAN_FLAGS_H
+#define ESAN_FLAGS_H
+
+#include "sanitizer_common/sanitizer_internal_defs.h"
+#include "sanitizer_common/sanitizer_flag_parser.h"
+
+namespace __esan {
+
+class Flags {
+public:
+#define ESAN_FLAG(Type, Name, DefaultValue, Description) Type Name;
+#include "esan_flags.inc"
+#undef ESAN_FLAG
+
+  void setDefaults();
+};
+
+extern Flags EsanFlagsDontUseDirectly;
+inline Flags *getFlags() {
+  return &EsanFlagsDontUseDirectly;
+}
+
+void initializeFlags();
+
+} // namespace __esan
+
+#endif // ESAN_FLAGS_H

Propchange: compiler-rt/trunk/lib/esan/esan_flags.h
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: compiler-rt/trunk/lib/esan/esan_flags.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/esan/esan_flags.inc?rev=270256&view=auto
==============================================================================
--- compiler-rt/trunk/lib/esan/esan_flags.inc (added)
+++ compiler-rt/trunk/lib/esan/esan_flags.inc Fri May 20 14:26:52 2016
@@ -0,0 +1,25 @@
+//===-- esan_flags.inc ------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Esan runtime flags.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef ESAN_FLAG
+# error "Define ESAN_FLAG prior to including this file!"
+#endif
+
+// ESAN_FLAG(Type, Name, DefaultValue, Description)
+// See COMMON_FLAG in sanitizer_flags.inc for more details.
+
+// Cross-tool options:
+ESAN_FLAG(int, cache_line_size, 64,
+          "The number of bytes in a cache line.  For the working-set tool, this "
+          "cannot be changed without also changing the compiler "
+          "instrumentation.")




More information about the llvm-commits mailing list