Chromium Code Reviews

Unified Diff: src/IceInstrumentation.cpp

Issue 2042063002: Created Ice::Instrumentation base class and accompanying hooks. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Style and comment fixes Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « src/IceInstrumentation.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceInstrumentation.cpp
diff --git a/src/IceInstrumentation.cpp b/src/IceInstrumentation.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..383e1512cde1198989d2be9626f261618504077f
--- /dev/null
+++ b/src/IceInstrumentation.cpp
@@ -0,0 +1,108 @@
+//===- subzero/src/IceInstrumentation.cpp - ICE instrumentation framework -===//
+//
+// The Subzero Code Generator
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implements the Ice::Instrumentation class.
+///
+/// Subclasses can override particular instrumentation methods to specify how
+/// the the target program should be instrumented.
+///
+//===----------------------------------------------------------------------===//
+
+#include "IceInstrumentation.h"
+
+#include "IceCfg.h"
+#include "IceInst.h"
+#include "IceTargetLowering.h"
+
+namespace Ice {
+
+// Iterate through the instructions in the given CFG and instrument each one.
+// Also instrument the beginning of the function.
+void Instrumentation::instrumentFunc(Cfg *Func) {
+ assert(Func);
+ assert(!Func->getNodes().empty());
+
+ LoweringContext Context;
+ Context.init(Func->getNodes().front());
+ instrumentFuncStart(Context);
+ for (CfgNode *Node : Func->getNodes()) {
+ Context.init(Node);
+ while (!Context.atEnd()) {
+ instrumentInst(Context);
+ // go to next undeleted instruction
+ Context.advanceCur();
+ Context.advanceNext();
+ }
+ }
+}
+
+void Instrumentation::instrumentInst(LoweringContext &Context) {
+ assert(!Context.atEnd());
+ Inst *Instr = iteratorToInst(Context.getCur());
+ switch (Instr->getKind()) {
+ case Inst::Alloca:
+ instrumentAlloca(Context, llvm::cast<InstAlloca>(Instr));
+ break;
+ case Inst::Arithmetic:
+ instrumentArithmetic(Context, llvm::cast<InstArithmetic>(Instr));
+ break;
+ case Inst::Br:
+ instrumentBr(Context, llvm::cast<InstBr>(Instr));
+ break;
+ case Inst::Call:
+ instrumentCall(Context, llvm::cast<InstCall>(Instr));
+ break;
+ case Inst::Cast:
+ instrumentCast(Context, llvm::cast<InstCast>(Instr));
+ break;
+ case Inst::ExtractElement:
+ instrumentExtractElement(Context, llvm::cast<InstExtractElement>(Instr));
+ break;
+ case Inst::Fcmp:
+ instrumentFcmp(Context, llvm::cast<InstFcmp>(Instr));
+ break;
+ case Inst::Icmp:
+ instrumentIcmp(Context, llvm::cast<InstIcmp>(Instr));
+ break;
+ case Inst::InsertElement:
+ instrumentInsertElement(Context, llvm::cast<InstInsertElement>(Instr));
+ break;
+ case Inst::IntrinsicCall:
+ instrumentIntrinsicCall(Context, llvm::cast<InstIntrinsicCall>(Instr));
+ break;
+ case Inst::Load:
+ instrumentLoad(Context, llvm::cast<InstLoad>(Instr));
+ break;
+ case Inst::Phi:
+ instrumentPhi(Context, llvm::cast<InstPhi>(Instr));
+ break;
+ case Inst::Ret:
+ instrumentRet(Context, llvm::cast<InstRet>(Instr));
+ break;
+ case Inst::Select:
+ instrumentSelect(Context, llvm::cast<InstSelect>(Instr));
+ break;
+ case Inst::Store:
+ instrumentStore(Context, llvm::cast<InstStore>(Instr));
+ break;
+ case Inst::Switch:
+ instrumentSwitch(Context, llvm::cast<InstSwitch>(Instr));
+ break;
+ case Inst::Unreachable:
+ instrumentUnreachable(Context, llvm::cast<InstUnreachable>(Instr));
+ break;
+ default:
+ // Only instrument high-level ICE instructions
+ assert(false && "Instrumentation encountered an unexpected instruction");
+ break;
+ }
+}
+
+} // end of namespace Ice
« no previous file with comments | « src/IceInstrumentation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine