[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

llvm-svn: 270256
This commit is contained in:
Derek Bruening 2016-05-20 19:26:52 +00:00
parent c7f4922524
commit a85de06dd2
5 changed files with 126 additions and 17 deletions

View File

@ -9,6 +9,7 @@ include_directories(..)
set(ESAN_SOURCES
esan.cpp
esan_flags.cpp
esan_interface.cpp
esan_interceptors.cpp)

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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.")