1 //===- subzero/src/IceInstrumentation.h - ICE instrumentation ---*- C++ -*-===// 2 // 3 // The Subzero Code Generator 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// 10 /// \file 11 /// \brief Declares the Ice::Instrumentation class. 12 /// 13 /// Instrumentation is an abstract class used to drive the instrumentation 14 /// process for tools such as AddressSanitizer and MemorySanitizer. It uses a 15 /// LoweringContext to enable the insertion of new instructions into a given 16 /// Cfg. Although Instrumentation is an abstract class, each of its virtual 17 /// functions has a trivial default implementation to make subclasses more 18 /// succinct. 19 /// 20 /// If instrumentation is required by the command line arguments, a single 21 /// Instrumentation subclass is instantiated and installed in the 22 /// GlobalContext. If multiple types of instrumentation are requested, a single 23 /// subclass is still responsible for driving the instrumentation, but it can 24 /// use other Instrumentation subclasses however it needs to. 25 /// 26 //===----------------------------------------------------------------------===// 27 28 #ifndef SUBZERO_SRC_ICEINSTRUMENTATION_H 29 #define SUBZERO_SRC_ICEINSTRUMENTATION_H 30 31 #include "IceDefs.h" 32 33 #include <condition_variable> 34 35 namespace Ice { 36 37 class LoweringContext; 38 39 class Instrumentation { 40 Instrumentation() = delete; 41 Instrumentation(const Instrumentation &) = delete; 42 Instrumentation &operator=(const Instrumentation &) = delete; 43 44 public: Instrumentation(GlobalContext * Ctx)45 Instrumentation(GlobalContext *Ctx) : Ctx(Ctx) {} 46 virtual ~Instrumentation() = default; instrumentGlobals(VariableDeclarationList &)47 virtual void instrumentGlobals(VariableDeclarationList &) {} 48 void instrumentFunc(Cfg *Func); 49 void setHasSeenGlobals(); 50 51 protected: 52 virtual void instrumentInst(LoweringContext &Context); 53 LockedPtr<VariableDeclarationList> getGlobals(); 54 55 private: isInstrumentable(Cfg *)56 virtual bool isInstrumentable(Cfg *) { return true; } instrumentFuncStart(LoweringContext &)57 virtual void instrumentFuncStart(LoweringContext &) {} instrumentAlloca(LoweringContext &,class InstAlloca *)58 virtual void instrumentAlloca(LoweringContext &, class InstAlloca *) {} instrumentArithmetic(LoweringContext &,class InstArithmetic *)59 virtual void instrumentArithmetic(LoweringContext &, class InstArithmetic *) { 60 } instrumentBr(LoweringContext &,class InstBr *)61 virtual void instrumentBr(LoweringContext &, class InstBr *) {} instrumentCall(LoweringContext &,class InstCall *)62 virtual void instrumentCall(LoweringContext &, class InstCall *) {} instrumentCast(LoweringContext &,class InstCast *)63 virtual void instrumentCast(LoweringContext &, class InstCast *) {} instrumentExtractElement(LoweringContext &,class InstExtractElement *)64 virtual void instrumentExtractElement(LoweringContext &, 65 class InstExtractElement *) {} instrumentFcmp(LoweringContext &,class InstFcmp *)66 virtual void instrumentFcmp(LoweringContext &, class InstFcmp *) {} instrumentIcmp(LoweringContext &,class InstIcmp *)67 virtual void instrumentIcmp(LoweringContext &, class InstIcmp *) {} instrumentInsertElement(LoweringContext &,class InstInsertElement *)68 virtual void instrumentInsertElement(LoweringContext &, 69 class InstInsertElement *) {} instrumentIntrinsicCall(LoweringContext &,class InstIntrinsicCall *)70 virtual void instrumentIntrinsicCall(LoweringContext &, 71 class InstIntrinsicCall *) {} instrumentLoad(LoweringContext &,class InstLoad *)72 virtual void instrumentLoad(LoweringContext &, class InstLoad *) {} instrumentPhi(LoweringContext &,class InstPhi *)73 virtual void instrumentPhi(LoweringContext &, class InstPhi *) {} instrumentRet(LoweringContext &,class InstRet *)74 virtual void instrumentRet(LoweringContext &, class InstRet *) {} instrumentSelect(LoweringContext &,class InstSelect *)75 virtual void instrumentSelect(LoweringContext &, class InstSelect *) {} instrumentStore(LoweringContext &,class InstStore *)76 virtual void instrumentStore(LoweringContext &, class InstStore *) {} instrumentSwitch(LoweringContext &,class InstSwitch *)77 virtual void instrumentSwitch(LoweringContext &, class InstSwitch *) {} instrumentUnreachable(LoweringContext &,class InstUnreachable *)78 virtual void instrumentUnreachable(LoweringContext &, 79 class InstUnreachable *) {} instrumentStart(Cfg *)80 virtual void instrumentStart(Cfg *) {} instrumentLocalVars(Cfg *)81 virtual void instrumentLocalVars(Cfg *) {} finishFunc(Cfg *)82 virtual void finishFunc(Cfg *) {} 83 84 protected: 85 GlobalContext *Ctx; 86 87 private: 88 bool HasSeenGlobals = false; 89 std::mutex GlobalsSeenMutex; 90 std::condition_variable GlobalsSeenCV; 91 }; 92 93 } // end of namespace Ice 94 95 #endif // SUBZERO_SRC_ICEINSTRUMENTATION_H 96