OLD | NEW |
(Empty) | |
| 1 //===- subzero/src/IceInstrumentation.cpp - ICE instrumentation framework -===// |
| 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 Implements the Ice::Instrumentation class. |
| 12 /// |
| 13 /// Subclasses can override particular instrumentation methods to specify how |
| 14 /// the the target program should be instrumented. |
| 15 /// |
| 16 //===----------------------------------------------------------------------===// |
| 17 |
| 18 #include "IceInstrumentation.h" |
| 19 |
| 20 #include "IceCfg.h" |
| 21 #include "IceInst.h" |
| 22 #include "IceTargetLowering.h" |
| 23 |
| 24 namespace Ice { |
| 25 |
| 26 // Iterate through the instructions in the given CFG and instrument each one. |
| 27 // Also instrument the beginning of the function. |
| 28 void Instrumentation::instrumentFunc(Cfg *Func) { |
| 29 assert(Func); |
| 30 assert(!Func->getNodes().empty()); |
| 31 |
| 32 LoweringContext Context; |
| 33 Context.init(Func->getNodes().front()); |
| 34 instrumentFuncStart(Context); |
| 35 for (CfgNode *Node : Func->getNodes()) { |
| 36 Context.init(Node); |
| 37 while (!Context.atEnd()) { |
| 38 instrumentInst(Context); |
| 39 // go to next undeleted instruction |
| 40 Context.advanceCur(); |
| 41 Context.advanceNext(); |
| 42 } |
| 43 } |
| 44 } |
| 45 |
| 46 void Instrumentation::instrumentInst(LoweringContext &Context) { |
| 47 assert(!Context.atEnd()); |
| 48 Inst *Instr = iteratorToInst(Context.getCur()); |
| 49 switch (Instr->getKind()) { |
| 50 case Inst::Alloca: |
| 51 instrumentAlloca(Context, llvm::cast<InstAlloca>(Instr)); |
| 52 break; |
| 53 case Inst::Arithmetic: |
| 54 instrumentArithmetic(Context, llvm::cast<InstArithmetic>(Instr)); |
| 55 break; |
| 56 case Inst::Br: |
| 57 instrumentBr(Context, llvm::cast<InstBr>(Instr)); |
| 58 break; |
| 59 case Inst::Call: |
| 60 instrumentCall(Context, llvm::cast<InstCall>(Instr)); |
| 61 break; |
| 62 case Inst::Cast: |
| 63 instrumentCast(Context, llvm::cast<InstCast>(Instr)); |
| 64 break; |
| 65 case Inst::ExtractElement: |
| 66 instrumentExtractElement(Context, llvm::cast<InstExtractElement>(Instr)); |
| 67 break; |
| 68 case Inst::Fcmp: |
| 69 instrumentFcmp(Context, llvm::cast<InstFcmp>(Instr)); |
| 70 break; |
| 71 case Inst::Icmp: |
| 72 instrumentIcmp(Context, llvm::cast<InstIcmp>(Instr)); |
| 73 break; |
| 74 case Inst::InsertElement: |
| 75 instrumentInsertElement(Context, llvm::cast<InstInsertElement>(Instr)); |
| 76 break; |
| 77 case Inst::IntrinsicCall: |
| 78 instrumentIntrinsicCall(Context, llvm::cast<InstIntrinsicCall>(Instr)); |
| 79 break; |
| 80 case Inst::Load: |
| 81 instrumentLoad(Context, llvm::cast<InstLoad>(Instr)); |
| 82 break; |
| 83 case Inst::Phi: |
| 84 instrumentPhi(Context, llvm::cast<InstPhi>(Instr)); |
| 85 break; |
| 86 case Inst::Ret: |
| 87 instrumentRet(Context, llvm::cast<InstRet>(Instr)); |
| 88 break; |
| 89 case Inst::Select: |
| 90 instrumentSelect(Context, llvm::cast<InstSelect>(Instr)); |
| 91 break; |
| 92 case Inst::Store: |
| 93 instrumentStore(Context, llvm::cast<InstStore>(Instr)); |
| 94 break; |
| 95 case Inst::Switch: |
| 96 instrumentSwitch(Context, llvm::cast<InstSwitch>(Instr)); |
| 97 break; |
| 98 case Inst::Unreachable: |
| 99 instrumentUnreachable(Context, llvm::cast<InstUnreachable>(Instr)); |
| 100 break; |
| 101 default: |
| 102 // Only instrument high-level ICE instructions |
| 103 assert(false && "Instrumentation encountered an unexpected instruction"); |
| 104 break; |
| 105 } |
| 106 } |
| 107 |
| 108 } // end of namespace Ice |
OLD | NEW |