Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:44

0001 //===- SanitizerStats.h - Sanitizer statistics gathering  -------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Declares functions and data structures for sanitizer statistics gathering.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_TRANSFORMS_UTILS_SANITIZERSTATS_H
0014 #define LLVM_TRANSFORMS_UTILS_SANITIZERSTATS_H
0015 
0016 #include "llvm/IR/IRBuilder.h"
0017 
0018 namespace llvm {
0019 
0020 // Number of bits in data that are used for the sanitizer kind. Needs to match
0021 // __sanitizer::kKindBits in compiler-rt/lib/stats/stats.h
0022 enum { kSanitizerStatKindBits = 3 };
0023 
0024 enum SanitizerStatKind {
0025   SanStat_CFI_VCall,
0026   SanStat_CFI_NVCall,
0027   SanStat_CFI_DerivedCast,
0028   SanStat_CFI_UnrelatedCast,
0029   SanStat_CFI_ICall,
0030 };
0031 
0032 struct SanitizerStatReport {
0033   SanitizerStatReport(Module *M);
0034 
0035   /// Generates code into B that increments a location-specific counter tagged
0036   /// with the given sanitizer kind SK.
0037   void create(IRBuilder<> &B, SanitizerStatKind SK);
0038 
0039   /// Finalize module stats array and add global constructor to register it.
0040   void finish();
0041 
0042 private:
0043   Module *M;
0044   GlobalVariable *ModuleStatsGV;
0045   ArrayType *StatTy;
0046   StructType *EmptyModuleStatsTy;
0047 
0048   std::vector<Constant *> Inits;
0049   ArrayType *makeModuleStatsArrayTy();
0050   StructType *makeModuleStatsTy();
0051 };
0052 
0053 }
0054 
0055 #endif