//===--- SILGenProfiling.h - Instrumentation based profiling ----*- C++ -*-===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See http://swift.org/LICENSE.txt for license information // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// #ifndef SWIFT_SILGEN_PROFILING_H #define SWIFT_SILGEN_PROFILING_H #include "llvm/ADT/DenseMap.h" #include "swift/AST/ASTNode.h" #include "swift/AST/Stmt.h" #include "swift/SIL/SILBuilder.h" namespace llvm { using swift::ASTNode; template <> struct DenseMapInfo { static inline ASTNode getEmptyKey() { return DenseMapInfo::getEmptyKey(); } static inline ASTNode getTombstoneKey() { return DenseMapInfo::getTombstoneKey(); } static unsigned getHashValue(const ASTNode Val) { return DenseMapInfo::getHashValue(Val.getOpaqueValue()); } static bool isEqual(const ASTNode LHS, const ASTNode RHS) { return LHS.getOpaqueValue() == RHS.getOpaqueValue(); } }; } namespace swift { namespace Lowering { class SILGenModule; /// RAII object to set up profiling for a function. struct ProfilerRAII { SILGenModule &SGM; ProfilerRAII(SILGenModule &SGM, AbstractFunctionDecl *D); ~ProfilerRAII(); }; /// Profiling state. class SILGenProfiling { private: SILGenModule &SGM; bool EmitCoverageMapping; // The current function's name and counter data. std::string CurrentFuncName; unsigned NumRegionCounters; uint64_t FunctionHash; llvm::DenseMap RegionCounterMap; std::vector> CoverageData; public: SILGenProfiling(SILGenModule &SGM, bool EmitCoverageMapping) : SGM(SGM), EmitCoverageMapping(EmitCoverageMapping), NumRegionCounters(0), FunctionHash(0) {} bool hasRegionCounters() const { return NumRegionCounters != 0; } /// Map counters to ASTNodes and set them up for profiling the given function. void assignRegionCounters(AbstractFunctionDecl *Root); /// Emit SIL to increment the counter for \c Node. void emitCounterIncrement(SILBuilder &Builder, ASTNode Node); }; } // end namespace Lowering } // end namespace swift #endif // SWIFT_SILGEN_PROFILING