liberty/lib/SLAMP/SLAMP.cpp
/// Handle each instruction (load, store) outside of the targeted loop.
/// We don't care about about call insts in this case
Handle each instruction (load, store) outside of the targeted loop.
We don't care about about call insts in this case
Handle each instruction ( load store ) outside of the targeted loop . We don ' t care about about call insts in this case
void SLAMP::instrumentExtInst(Module &m, Instruction *inst, uint32_t id) {
  const DataLayout &DL = m.getDataLayout();
  string lf_name[] = {"SLAMP_load1_ext", "SLAMP_load2_ext", "SLAMP_load4_ext",
                      "SLAMP_load8_ext", "SLAMP_loadn_ext"};
  vector<Function *> lf(5);
  for (unsigned i = 0; i < 5; i++) {
    lf[i] = cast<Function>(
        m.getOrInsertFunction(lf_name[i], Void, I64, I32, I64).getCallee());
  }
  string sf_name[] = {"SLAMP_store1_ext", "SLAMP_store2_ext",
                      "SLAMP_store4_ext", "SLAMP_store8_ext",
                      "SLAMP_storen_ext"};
  vector<Function *> sf(5);
  for (unsigned i = 0; i < 4; i++) {
    sf[i] = cast<Function>(
        m.getOrInsertFunction(sf_name[i], Void, I64, I32).getCallee());
  }
  sf[4] = cast<Function>(
      m.getOrInsertFunction(sf_name[4], Void, I64, I32, I64).getCallee());
  if (auto *li = dyn_cast<LoadInst>(inst)) {
    InstInsertPt pt = InstInsertPt::After(li);
    Value *ptr = li->getPointerOperand();
    vector<Value *> args;
    args.push_back(castToInt64Ty(ptr, pt));
    size_t size;
    int index = getIndex(cast<PointerType>(ptr->getType()), size, DL);
    if (index == 4) {
      args.push_back(ConstantInt::get(I32, id));
      args.push_back(ConstantInt::get(I64, size));
    } else {
      args.push_back(ConstantInt::get(I32, id));
      args.push_back(castToInt64Ty(li, pt));
    }
    pt << CallInst::Create(lf[index], args);
  } else if (auto *si = dyn_cast<StoreInst>(inst)) {
    InstInsertPt pt = InstInsertPt::After(si);
    Value *ptr = si->getPointerOperand();
    vector<Value *> args;
    args.push_back(castToInt64Ty(ptr, pt));
    size_t size;
    int index = getIndex(cast<PointerType>(ptr->getType()), size, DL);
    args.push_back(ConstantInt::get(I32, id));
    if (index == 4) {
      args.push_back(ConstantInt::get(I64, size));
    }
    pt << CallInst::Create(sf[index], args);
  }
}
void SLAMP :: instrumentExtInst ( Module & m , Instruction * inst , uint32_t id ) { const DataLayout & DL = m . getDataLayout ( ) ; string lf_name [ ] = { " " , " " , " " , " " , " " } ; vector < Function * > lf ( 5 ) ; for ( unsigned i = 0 ; i < 5 ; i ++ ) { lf [ i ] = cast < Function > ( m . getOrInsertFunction ( lf_name [ i ] , Void , I64 , I32 , I64 ) . getCallee ( ) ) ; } string sf_name [ ] = { " " , " " , " " , " " , " " } ; vector < Function * > sf ( 5 ) ; for ( unsigned i = 0 ; i < 4 ; i ++ ) { sf [ i ] = cast < Function > ( m . getOrInsertFunction ( sf_name [ i ] , Void , I64 , I32 ) . getCallee ( ) ) ; } sf [ 4 ] = cast < Function > ( m . getOrInsertFunction ( sf_name [ 4 ] , Void , I64 , I32 , I64 ) . getCallee ( ) ) ; if ( auto * li = dyn_cast < LoadInst > ( inst ) ) { InstInsertPt pt = InstInsertPt :: After ( li ) ; Value * ptr = li -> getPointerOperand ( ) ; vector < Value * > args ; args . push_back ( castToInt64Ty ( ptr , pt ) ) ; size_t size ; int index = getIndex ( cast < PointerType > ( ptr -> getType ( ) ) , size , DL ) ; if ( index == 4 ) { args . push_back ( ConstantInt :: get ( I32 , id ) ) ; args . push_back ( ConstantInt :: get ( I64 , size ) ) ; } else { args . push_back ( ConstantInt :: get ( I32 , id ) ) ; args . push_back ( castToInt64Ty ( li , pt ) ) ; } pt << CallInst :: Create ( lf [ index ] , args ) ; } else if ( auto * si = dyn_cast < StoreInst > ( inst ) ) { InstInsertPt pt = InstInsertPt :: After ( si ) ; Value * ptr = si -> getPointerOperand ( ) ; vector < Value * > args ; args . push_back ( castToInt64Ty ( ptr , pt ) ) ; size_t size ; int index = getIndex ( cast < PointerType > ( ptr -> getType ( ) ) , size , DL ) ; args . push_back ( ConstantInt :: get ( I32 , id ) ) ; if ( index == 4 ) { args . push_back ( ConstantInt :: get ( I64 , size ) ) ; } pt << CallInst :: Create ( sf [ index ] , args ) ; } }
Handle each instruction (load, store) outside of the targeted loop.
Handle each instruction ( load store ) outside of the targeted loop .
// --- loads // lf[i] = cast<Function>( m.getOrInsertFunction(lf_name[i], Void, I64, I32, // I64, (Type*)0) ); // --- stores // sf[i] = cast<Function>( m.getOrInsertFunction(sf_name[i], Void, I64, I32, // (Type*)0) ); // sf[4] = cast<Function>( m.getOrInsertFunction(sf_name[4], Void, I64, I32, // I64, (Type*)0) );