int main(int argc, const char *argv[]) {
  unsigned S, NS = 10, V;
  const __llvm_profile_data *Data, *DataEnd;

  setFunctionPointers();
  Data = __llvm_profile_begin_data();
  DataEnd = __llvm_profile_end_data();
  for (; Data < DataEnd; Data = __llvm_profile_iterate_data(Data)) {
    void *func = __llvm_get_function_addr(Data);
    if (func == caller_without_value_site1 ||
        func == caller_without_value_site2 ||
        func == callee1 || func == callee2 || func == main)
      continue;

    __llvm_profile_set_num_value_sites((__llvm_profile_data *)Data,
                                       0 /*IPVK_IndirectCallTarget */, 10);

    if (func == caller_with_value_site_never_called1 ||
        func == caller_with_value_site_never_called2)
      continue;
    for (S = 0; S < NS; S++) {
      unsigned C;
      for (C = 0; C < S + 1; C++) {
        __llvm_profile_instrument_target((uint64_t)callee1Ptr, (void *)Data, S);
        if (C % 2 == 0)
          __llvm_profile_instrument_target((uint64_t)callee2Ptr, (void *)Data, S);
      }
    }
  }
}
Exemplo n.º 2
0
int main(int argc, const char *argv[]) {
  unsigned S, NS = 0, I, V, doInstrument = 1;
  const __llvm_profile_data *Data, *DataEnd;

  if (argc >= 2 && !strcmp(argv[1], "DO_NOT_INSTRUMENT"))
    doInstrument = 0;

  for (I = 0; I < 128; I++) {
     CallerInfos[I].CallerAddr = CallerAddrs[I];
     CallerInfos[I].NS = I;
  }
  qsort(CallerInfos, sizeof(CallerInfos) / sizeof(CallerInfo), sizeof(CallerInfo),
        cmpaddr);

  /* We will synthesis value profile data for 128 callers functions declared.
   * The number of value sites for each caller function is recorded in
   * the NS field of the CallerInfo object. For each value site, the number of
   * callee values is determined by the site index (modulo 8). The frequency
   * of each callee target synthesized is equal to V + 1, in which V is the
   * index of the target value for the callsite. */

  Data = __llvm_profile_begin_data();
  DataEnd = __llvm_profile_end_data();

  for (; Data < DataEnd; Data = __llvm_profile_iterate_data(Data)) {
    void *func = __llvm_get_function_addr(Data);
    CallerInfo Key, *Res;
    Key.CallerAddr = func;
    Res = (CallerInfo *) bsearch(&Key, CallerInfos, sizeof(CallerInfos) / sizeof(CallerInfo),
                                 sizeof(CallerInfo), cmpaddr);
    if (Res) {
      NS = Res->NS;
      __llvm_profile_set_num_value_sites((__llvm_profile_data *)Data,
                                         0 /*IPVK_IndirectCallTarget */, NS);
      if (!doInstrument) {
        continue;
      }
      for (S = 0; S < NS; S++) {
        for (V = 0; V < S % 8; V++) {
          unsigned C;
          for (C = 0; C < V + 1; C++)
            __llvm_profile_instrument_target((uint64_t)CalleeAddrs[V],
                                             (void *)Data, S);
        }
      }
    }
  }
}
Exemplo n.º 3
0
int main(int argc, const char *argv[]) {
  unsigned S, NS = 0, V, doInstrument = 1;
  const __llvm_profile_data *Data, *DataEnd;

  if (argc < 2)
    doInstrument = 0;

  qsort(CallerAddrs, sizeof(CallerAddrs) / sizeof(void *), sizeof(void *),
        cmpaddr);

  /* We will synthesis value profile data for 128 callers functions.
   * The number of * value sites. The number values for each value site
   * ranges from 0 to 8.  */

  Data = __llvm_profile_begin_data();
  DataEnd = __llvm_profile_end_data();

  for (; Data < DataEnd; Data = __llvm_profile_iterate_data(Data)) {
    void *func = __llvm_get_function_addr(Data);
    if (bsearch(&func, CallerAddrs, sizeof(CallerAddrs) / sizeof(void *),
                sizeof(void *), cmpaddr)) {
      __llvm_profile_set_num_value_sites((__llvm_profile_data *)Data,
                                         0 /*IPVK_IndirectCallTarget */, NS);
      if (!doInstrument) {
        NS++;
        continue;
      }
      for (S = 0; S < NS; S++) {
        for (V = 0; V < S % 8; V++) {
          unsigned C;
          for (C = 0; C < V + 1; C++)
            __llvm_profile_instrument_target((uint64_t)CalleeAddrs[V],
                                             (void *)Data, S);
        }
      }
      NS++;
    }
  }
}