liberty/lib/SLAMP/SLAMP.cpp
/// Instrument all instructions in a loop
Instrument all instructions in a loop
Instrument all instructions in a loop
void SLAMP::instrumentInstructions(Module &m, Loop *loop) {
  set<Instruction *> loopinsts;
  for (auto &bb : loop->getBlocks())
    for (auto &ii : *bb)
      loopinsts.insert(&ii);
  for (auto &&f : m) {
    if (f.isDeclaration())
      continue;
    for (auto &&inst : instructions(f)) {
      if (const auto Intrinsic = dyn_cast<IntrinsicInst>(&inst)) {
        const auto Id = Intrinsic->getIntrinsicID();
        if (Id == Intrinsic::lifetime_start || Id == Intrinsic::lifetime_end) {
          instrumentLifetimeIntrinsics(m, &inst);
          continue;
        }
      }
      if (auto *mi = dyn_cast<MemIntrinsic>(&inst)) {
        instrumentMemIntrinsics(m, mi);
      } else if (loopinsts.find(&inst) != loopinsts.end()) {
        instrumentLoopInst(m, &inst, Namer::getInstrId(&inst));
      } else {
        instrumentExtInst(m, &inst, Namer::getInstrId(&inst));
      }
    }
  }
}
void SLAMP :: instrumentInstructions ( Module & m , Loop * loop ) { set < Instruction * > loopinsts ; for ( auto & bb : loop -> getBlocks ( ) ) for ( auto & ii : * bb ) loopinsts . insert ( & ii ) ; for ( auto && f : m ) { if ( f . isDeclaration ( ) ) continue ; for ( auto && inst : instructions ( f ) ) { if ( const auto Intrinsic = dyn_cast < IntrinsicInst > ( & inst ) ) { const auto Id = Intrinsic -> getIntrinsicID ( ) ; if ( Id == Intrinsic :: lifetime_start || Id == Intrinsic :: lifetime_end ) { instrumentLifetimeIntrinsics ( m , & inst ) ; continue ; } } if ( auto * mi = dyn_cast < MemIntrinsic > ( & inst ) ) { instrumentMemIntrinsics ( m , mi ) ; } else if ( loopinsts . find ( & inst ) != loopinsts . end ( ) ) { instrumentLoopInst ( m , & inst , Namer :: getInstrId ( & inst ) ) ; } else { instrumentExtInst ( m , & inst , Namer :: getInstrId ( & inst ) ) ; } } } }
Instrument all instructions in a loop
Instrument all instructions in a loop
// collect loop instructions // go over all instructions in the module // - change some intrinsics functions // - for instructions within the loop, replace it with normal load/store // - for instructions outside of the loop, replace it with external load/store // instrumentExtInst(m, &inst, sid.getFuncLocalIDWithInst(&*fi, &inst));