#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_H
#define LLVM_TRANSFORMS_INSTRUMENTATION_H
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/BasicBlock.h"
#include <vector>
#if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
inline void *getDFSanArgTLSPtrForJIT() {
extern __thread __attribute__((tls_model("initial-exec")))
void *__dfsan_arg_tls;
return (void *)&__dfsan_arg_tls;
}
inline void *getDFSanRetValTLSPtrForJIT() {
extern __thread __attribute__((tls_model("initial-exec")))
void *__dfsan_retval_tls;
return (void *)&__dfsan_retval_tls;
}
#endif
namespace llvm {
class TargetMachine;
BasicBlock::iterator PrepareToSplitEntryBlock(BasicBlock &BB,
BasicBlock::iterator IP);
class ModulePass;
class FunctionPass;
struct GCOVOptions {
static GCOVOptions getDefault();
bool EmitNotes;
bool EmitData;
char Version[4];
bool UseCfgChecksum;
bool NoRedZone;
bool FunctionNamesInData;
bool ExitBlockBeforeBody;
};
ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
GCOVOptions::getDefault());
ModulePass *createPGOInstrumentationGenPass();
ModulePass *
createPGOInstrumentationUsePass(StringRef Filename = StringRef(""));
ModulePass *createPGOIndirectCallPromotionPass(bool InLTO = false);
struct InstrProfOptions {
InstrProfOptions() : NoRedZone(false) {}
bool NoRedZone;
std::string InstrProfileOutput;
};
ModulePass *createInstrProfilingPass(
const InstrProfOptions &Options = InstrProfOptions());
FunctionPass *createAddressSanitizerFunctionPass(bool CompileKernel = false,
bool Recover = false);
ModulePass *createAddressSanitizerModulePass(bool CompileKernel = false,
bool Recover = false);
FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0);
FunctionPass *createThreadSanitizerPass();
ModulePass *createDataFlowSanitizerPass(
const std::vector<std::string> &ABIListFiles = std::vector<std::string>(),
void *(*getArgTLS)() = nullptr, void *(*getRetValTLS)() = nullptr);
struct SanitizerCoverageOptions {
SanitizerCoverageOptions()
: CoverageType(SCK_None), IndirectCalls(false), TraceBB(false),
TraceCmp(false), Use8bitCounters(false) {}
enum Type {
SCK_None = 0,
SCK_Function,
SCK_BB,
SCK_Edge
} CoverageType;
bool IndirectCalls;
bool TraceBB;
bool TraceCmp;
bool Use8bitCounters;
};
ModulePass *createSanitizerCoverageModulePass(
const SanitizerCoverageOptions &Options = SanitizerCoverageOptions());
#if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
inline ModulePass *createDataFlowSanitizerPassForJIT(
const std::vector<std::string> &ABIListFiles = std::vector<std::string>()) {
return createDataFlowSanitizerPass(ABIListFiles, getDFSanArgTLSPtrForJIT,
getDFSanRetValTLSPtrForJIT);
}
#endif
FunctionPass *createBoundsCheckingPass();
FunctionPass *createSafeStackPass(const TargetMachine *TM = nullptr);
static inline uint64_t calculateCountScale(uint64_t MaxCount) {
return MaxCount < UINT32_MAX ? 1 : MaxCount / UINT32_MAX + 1;
}
static inline uint32_t scaleBranchCount(uint64_t Count, uint64_t Scale) {
uint64_t Scaled = Count / Scale;
assert(Scaled <= UINT32_MAX && "overflow 32-bits");
return Scaled;
}
}
#endif