blob: 2392f9607d23ebec5d83c91ebcc39452807fef27 [file] [log] [blame]
Thomas Livelyaab70992016-06-07 13:54:59 -07001//===- 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 Lively2c9992a2016-07-20 11:19:17 -070033#include <condition_variable>
34
Thomas Livelyaab70992016-06-07 13:54:59 -070035namespace Ice {
36
37class LoweringContext;
38
39class Instrumentation {
40 Instrumentation() = delete;
41 Instrumentation(const Instrumentation &) = delete;
42 Instrumentation &operator=(const Instrumentation &) = delete;
43
44public:
45 Instrumentation(GlobalContext *Ctx) : Ctx(Ctx) {}
Thomas Lively2c9992a2016-07-20 11:19:17 -070046 virtual ~Instrumentation() = default;
Thomas Lively3f5cb6f2016-06-13 11:23:29 -070047 virtual void instrumentGlobals(VariableDeclarationList &) {}
Thomas Livelyaab70992016-06-07 13:54:59 -070048 void instrumentFunc(Cfg *Func);
Thomas Lively2c9992a2016-07-20 11:19:17 -070049 void setHasSeenGlobals();
Thomas Livelyaab70992016-06-07 13:54:59 -070050
Thomas Lively1fd80c72016-06-27 14:47:21 -070051protected:
52 virtual void instrumentInst(LoweringContext &Context);
Thomas Lively2c9992a2016-07-20 11:19:17 -070053 LockedPtr<VariableDeclarationList> getGlobals();
Thomas Lively1fd80c72016-06-27 14:47:21 -070054
Thomas Livelyaab70992016-06-07 13:54:59 -070055private:
Thomas Lively3f97afb2016-07-07 14:56:21 -070056 virtual bool isInstrumentable(Cfg *) { return true; }
Thomas Lively3f5cb6f2016-06-13 11:23:29 -070057 virtual void instrumentFuncStart(LoweringContext &) {}
Thomas Lively227c9f32016-06-21 11:43:07 -070058 virtual void instrumentAlloca(LoweringContext &, class InstAlloca *) {}
Thomas Lively26c43062016-06-17 15:53:24 -070059 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 Lively3f5cb6f2016-06-13 11:23:29 -070064 virtual void instrumentExtractElement(LoweringContext &,
Thomas Lively26c43062016-06-17 15:53:24 -070065 class InstExtractElement *) {}
66 virtual void instrumentFcmp(LoweringContext &, class InstFcmp *) {}
67 virtual void instrumentIcmp(LoweringContext &, class InstIcmp *) {}
Thomas Lively3f5cb6f2016-06-13 11:23:29 -070068 virtual void instrumentInsertElement(LoweringContext &,
Thomas Lively26c43062016-06-17 15:53:24 -070069 class InstInsertElement *) {}
Thomas Lively3f5cb6f2016-06-13 11:23:29 -070070 virtual void instrumentIntrinsicCall(LoweringContext &,
Thomas Lively26c43062016-06-17 15:53:24 -070071 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 Lively3f5cb6f2016-06-13 11:23:29 -070078 virtual void instrumentUnreachable(LoweringContext &,
Thomas Lively26c43062016-06-17 15:53:24 -070079 class InstUnreachable *) {}
Thomas Lively4e81fe02016-06-15 10:00:21 -070080 virtual void instrumentStart(Cfg *) {}
Thomas Lively3f5cb6f2016-06-13 11:23:29 -070081 virtual void instrumentLocalVars(Cfg *) {}
Thomas Lively1fd80c72016-06-27 14:47:21 -070082 virtual void finishFunc(Cfg *) {}
Thomas Livelyaab70992016-06-07 13:54:59 -070083
84protected:
85 GlobalContext *Ctx;
Thomas Lively2c9992a2016-07-20 11:19:17 -070086
87private:
88 bool HasSeenGlobals = false;
89 std::mutex GlobalsSeenMutex;
90 std::condition_variable GlobalsSeenCV;
Thomas Livelyaab70992016-06-07 13:54:59 -070091};
92
93} // end of namespace Ice
94
95#endif // SUBZERO_SRC_ICEINSTRUMENTATION_H