Thomas Lively | aab7099 | 2016-06-07 13:54:59 -0700 | [diff] [blame] | 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 | |
Thomas Lively | 2c9992a | 2016-07-20 11:19:17 -0700 | [diff] [blame] | 33 | #include <condition_variable> |
| 34 | |
Thomas Lively | aab7099 | 2016-06-07 13:54:59 -0700 | [diff] [blame] | 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: |
| 45 | Instrumentation(GlobalContext *Ctx) : Ctx(Ctx) {} |
Thomas Lively | 2c9992a | 2016-07-20 11:19:17 -0700 | [diff] [blame] | 46 | virtual ~Instrumentation() = default; |
Thomas Lively | 3f5cb6f | 2016-06-13 11:23:29 -0700 | [diff] [blame] | 47 | virtual void instrumentGlobals(VariableDeclarationList &) {} |
Thomas Lively | aab7099 | 2016-06-07 13:54:59 -0700 | [diff] [blame] | 48 | void instrumentFunc(Cfg *Func); |
Thomas Lively | 2c9992a | 2016-07-20 11:19:17 -0700 | [diff] [blame] | 49 | void setHasSeenGlobals(); |
Thomas Lively | aab7099 | 2016-06-07 13:54:59 -0700 | [diff] [blame] | 50 | |
Thomas Lively | 1fd80c7 | 2016-06-27 14:47:21 -0700 | [diff] [blame] | 51 | protected: |
| 52 | virtual void instrumentInst(LoweringContext &Context); |
Thomas Lively | 2c9992a | 2016-07-20 11:19:17 -0700 | [diff] [blame] | 53 | LockedPtr<VariableDeclarationList> getGlobals(); |
Thomas Lively | 1fd80c7 | 2016-06-27 14:47:21 -0700 | [diff] [blame] | 54 | |
Thomas Lively | aab7099 | 2016-06-07 13:54:59 -0700 | [diff] [blame] | 55 | private: |
Thomas Lively | 3f97afb | 2016-07-07 14:56:21 -0700 | [diff] [blame] | 56 | virtual bool isInstrumentable(Cfg *) { return true; } |
Thomas Lively | 3f5cb6f | 2016-06-13 11:23:29 -0700 | [diff] [blame] | 57 | virtual void instrumentFuncStart(LoweringContext &) {} |
Thomas Lively | 227c9f3 | 2016-06-21 11:43:07 -0700 | [diff] [blame] | 58 | virtual void instrumentAlloca(LoweringContext &, class InstAlloca *) {} |
Thomas Lively | 26c4306 | 2016-06-17 15:53:24 -0700 | [diff] [blame] | 59 | virtual void instrumentArithmetic(LoweringContext &, class InstArithmetic *) { |
| 60 | } |
| 61 | virtual void instrumentBr(LoweringContext &, class InstBr *) {} |
| 62 | virtual void instrumentCall(LoweringContext &, class InstCall *) {} |
| 63 | virtual void instrumentCast(LoweringContext &, class InstCast *) {} |
Thomas Lively | 3f5cb6f | 2016-06-13 11:23:29 -0700 | [diff] [blame] | 64 | virtual void instrumentExtractElement(LoweringContext &, |
Thomas Lively | 26c4306 | 2016-06-17 15:53:24 -0700 | [diff] [blame] | 65 | class InstExtractElement *) {} |
| 66 | virtual void instrumentFcmp(LoweringContext &, class InstFcmp *) {} |
| 67 | virtual void instrumentIcmp(LoweringContext &, class InstIcmp *) {} |
Thomas Lively | 3f5cb6f | 2016-06-13 11:23:29 -0700 | [diff] [blame] | 68 | virtual void instrumentInsertElement(LoweringContext &, |
Thomas Lively | 26c4306 | 2016-06-17 15:53:24 -0700 | [diff] [blame] | 69 | class InstInsertElement *) {} |
Thomas Lively | 3f5cb6f | 2016-06-13 11:23:29 -0700 | [diff] [blame] | 70 | virtual void instrumentIntrinsicCall(LoweringContext &, |
Thomas Lively | 26c4306 | 2016-06-17 15:53:24 -0700 | [diff] [blame] | 71 | class InstIntrinsicCall *) {} |
| 72 | virtual void instrumentLoad(LoweringContext &, class InstLoad *) {} |
| 73 | virtual void instrumentPhi(LoweringContext &, class InstPhi *) {} |
| 74 | virtual void instrumentRet(LoweringContext &, class InstRet *) {} |
| 75 | virtual void instrumentSelect(LoweringContext &, class InstSelect *) {} |
| 76 | virtual void instrumentStore(LoweringContext &, class InstStore *) {} |
| 77 | virtual void instrumentSwitch(LoweringContext &, class InstSwitch *) {} |
Thomas Lively | 3f5cb6f | 2016-06-13 11:23:29 -0700 | [diff] [blame] | 78 | virtual void instrumentUnreachable(LoweringContext &, |
Thomas Lively | 26c4306 | 2016-06-17 15:53:24 -0700 | [diff] [blame] | 79 | class InstUnreachable *) {} |
Thomas Lively | 4e81fe0 | 2016-06-15 10:00:21 -0700 | [diff] [blame] | 80 | virtual void instrumentStart(Cfg *) {} |
Thomas Lively | 3f5cb6f | 2016-06-13 11:23:29 -0700 | [diff] [blame] | 81 | virtual void instrumentLocalVars(Cfg *) {} |
Thomas Lively | 1fd80c7 | 2016-06-27 14:47:21 -0700 | [diff] [blame] | 82 | virtual void finishFunc(Cfg *) {} |
Thomas Lively | aab7099 | 2016-06-07 13:54:59 -0700 | [diff] [blame] | 83 | |
| 84 | protected: |
| 85 | GlobalContext *Ctx; |
Thomas Lively | 2c9992a | 2016-07-20 11:19:17 -0700 | [diff] [blame] | 86 | |
| 87 | private: |
| 88 | bool HasSeenGlobals = false; |
| 89 | std::mutex GlobalsSeenMutex; |
| 90 | std::condition_variable GlobalsSeenCV; |
Thomas Lively | aab7099 | 2016-06-07 13:54:59 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // end of namespace Ice |
| 94 | |
| 95 | #endif // SUBZERO_SRC_ICEINSTRUMENTATION_H |