brintos

brintos / llvm-project-archived public Read only

0
0
Text · 760 B · 7387f47 Raw
30 lines · cpp
1// REQUIRES: continuous-mode2 3// RUN: rm -rf %t.dir4// RUN: %clangxx_pgogen=%t.dir -fprofile-continuous -lpthread %s -o %t.exe -mllvm -disable-vp -fprofile-update=atomic5// RUN: %run %t.exe6// RUN: llvm-profdata show --counts --function=accum  %t.dir/default_*.profraw | FileCheck %s7// CHECK:    Block counts: [100000, 4]8 9#include <thread>10 11int x = 0;12void accum(int n) {13  for (int i = 0; i < n; i++)14    x += i; // don't care about accuracy, no need for atomic.15}16 17int main() {18  int init_value = 10000;19  auto t1 = std::thread(accum, 1*init_value);20  auto t2 = std::thread(accum, 2*init_value);21  auto t3 = std::thread(accum, 3*init_value);22  auto t4 = std::thread(accum, 4*init_value);23 24  t1.join();25  t2.join();26  t3.join();27  t4.join();28  return !x;29}30