clang  6.0.0svn
CoverageMappingGen.h
Go to the documentation of this file.
1 //===---- CoverageMappingGen.h - Coverage mapping generation ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Instrumentation-based code coverage mapping generator
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_CODEGEN_COVERAGEMAPPINGGEN_H
15 #define LLVM_CLANG_LIB_CODEGEN_COVERAGEMAPPINGGEN_H
16 
17 #include "clang/Basic/LLVM.h"
20 #include "clang/Lex/PPCallbacks.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/IR/GlobalValue.h"
23 #include "llvm/Support/raw_ostream.h"
24 
25 namespace clang {
26 
27 class LangOptions;
28 class SourceManager;
29 class FileEntry;
30 class Preprocessor;
31 class Decl;
32 class Stmt;
33 
34 /// \brief Stores additional source code information like skipped ranges which
35 /// is required by the coverage mapping generator and is obtained from
36 /// the preprocessor.
38  std::vector<SourceRange> SkippedRanges;
39 public:
40  ArrayRef<SourceRange> getSkippedRanges() const { return SkippedRanges; }
41 
42  void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override;
43 };
44 
45 namespace CodeGen {
46 
47 class CodeGenModule;
48 
49 /// \brief Organizes the cross-function state that is used while generating
50 /// code coverage mapping data.
52  CodeGenModule &CGM;
53  CoverageSourceInfo &SourceInfo;
54  llvm::SmallDenseMap<const FileEntry *, unsigned, 8> FileEntries;
55  std::vector<llvm::Constant *> FunctionRecords;
56  std::vector<llvm::Constant *> FunctionNames;
57  llvm::StructType *FunctionRecordTy;
58  std::vector<std::string> CoverageMappings;
59 
60 public:
62  : CGM(CGM), SourceInfo(SourceInfo), FunctionRecordTy(nullptr) {}
63 
65  return SourceInfo;
66  }
67 
68  /// \brief Add a function's coverage mapping record to the collection of the
69  /// function mapping records.
70  void addFunctionMappingRecord(llvm::GlobalVariable *FunctionName,
71  StringRef FunctionNameValue,
72  uint64_t FunctionHash,
73  const std::string &CoverageMapping,
74  bool IsUsed = true);
75 
76  /// \brief Emit the coverage mapping data for a translation unit.
77  void emit();
78 
79  /// \brief Return the coverage mapping translation unit file id
80  /// for the given file.
81  unsigned getFileID(const FileEntry *File);
82 };
83 
84 /// \brief Organizes the per-function state that is used while generating
85 /// code coverage mapping data.
89  const LangOptions &LangOpts;
90  llvm::DenseMap<const Stmt *, unsigned> *CounterMap;
91 
92 public:
94  const LangOptions &LangOpts)
95  : CVM(CVM), SM(SM), LangOpts(LangOpts), CounterMap(nullptr) {}
96 
98  const LangOptions &LangOpts,
99  llvm::DenseMap<const Stmt *, unsigned> *CounterMap)
100  : CVM(CVM), SM(SM), LangOpts(LangOpts), CounterMap(CounterMap) {}
101 
102  /// \brief Emit the coverage mapping data which maps the regions of
103  /// code to counters that will be used to find the execution
104  /// counts for those regions.
105  void emitCounterMapping(const Decl *D, llvm::raw_ostream &OS);
106 
107  /// \brief Emit the coverage mapping data for an unused function.
108  /// It creates mapping regions with the counter of zero.
109  void emitEmptyMapping(const Decl *D, llvm::raw_ostream &OS);
110 };
111 
112 } // end namespace CodeGen
113 } // end namespace clang
114 
115 #endif
Organizes the per-function state that is used while generating code coverage mapping data...
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
CoverageMappingGen(CoverageMappingModuleGen &CVM, SourceManager &SM, const LangOptions &LangOpts, llvm::DenseMap< const Stmt *, unsigned > *CounterMap)
Stores additional source code information like skipped ranges which is required by the coverage mappi...
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
This interface provides a way to observe the actions of the preprocessor as it does its thing...
Definition: PPCallbacks.h:36
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Organizes the cross-function state that is used while generating code coverage mapping data...
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override
Hook called when a source range is skipped.
CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo)
const SourceManager & SM
Definition: Format.cpp:1308
Encodes a location in the source.
ArrayRef< SourceRange > getSkippedRanges() const
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:59
CoverageSourceInfo & getSourceInfo() const
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
CoverageMappingGen(CoverageMappingModuleGen &CVM, SourceManager &SM, const LangOptions &LangOpts)
Defines the PPCallbacks interface.
Defines the clang::SourceLocation class and associated facilities.
A trivial tuple used to represent a source range.
This class handles loading and caching of source files into memory.