Compiler construction 使用LLVM prof收集LLVM边缘分析

Compiler construction 使用LLVM prof收集LLVM边缘分析,compiler-construction,profiling,llvm,Compiler Construction,Profiling,Llvm,我正在使用这些命令编译下面的代码,以便收集 主干llvm中的边缘/块评测: clang -emit-llvm -c sort.c -o sort.bc opt -insert-edge-profiling sort.bc -o sort_prof.bc clang sort_prof.bc -lprofile_rt -L/llvms/lib -o sort_prof 然后我运行程序并使用 llvm prof sort_prof.bc,结果是: ===----------------------

我正在使用这些命令编译下面的代码,以便收集 主干llvm中的边缘/块评测:

clang -emit-llvm -c sort.c -o sort.bc
opt -insert-edge-profiling sort.bc -o sort_prof.bc
clang sort_prof.bc -lprofile_rt -L/llvms/lib -o sort_prof
然后我运行程序并使用 llvm prof sort_prof.bc,结果是:

===-------------------------------------------------------------------------===
Function execution frequencies:

 ##   Frequency
  1. 4.3e+05/708539 main
  2. 2.8e+05/708539 quickSort

  NOTE: 2 functions were never executed!
.....
我的问题是关于执行频率。有什么好处吗 传感主执行4.3e+05次? 为什么会这样?下面是我正在编译的代码

###################### sort.c ########################
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

const int MAX = 1000000;

void swap(int* a, int* b) {
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

int partition(int vec[], int left, int right) {
  int i, j;

  i = left;
  for (j = left + 1; j <= right; ++j) {
    if (vec[j] < vec[left]) {
      ++i;
      swap(&vec[i], &vec[j]);
    }
  }
  swap(&vec[left], &vec[i]);

  return i;
}

void quickSort(int vec[], int left, int right) {
  int r;

  if (right > left) {
    r = partition(vec, left, right);
    quickSort(vec, left, r - 1);
    quickSort(vec, r + 1, right);
  }
}

int main(void) {

        int vet[MAX], i=0;

        srand(time(NULL));

        for (i=0; i<MAX; i++) {
                vet[i] = rand() % 654321;
        }

        quickSort(vet, 0, MAX-1);

        for (i=0; i<MAX; i++) {
                if ((rand() % 7) > 2) {
                        printf("Num$[%d] = %d\n", i, vet[i]);
                }
                else if ((rand() % 4) > 2) {
                        printf("Num@[%d] = %d\n", i, vet[i]);
                }
                else if ((rand() % 2) > 1) {
                        printf("Num#[%d] = %d\n", i, vet[i]);
                }
        }

        return 0;
}
##########################排序.c########################
#包括
#包括
#包括
const int MAX=1000000;
无效交换(int*a,int*b){
int tmp;
tmp=*a;
*a=*b;
*b=tmp;
}
整数分区(整数向量[],整数左,整数右){
int i,j;
i=左;
对于(j=左+1;j左){
r=分区(vec、左、右);
快速排序(vec,左,r-1);
快速排序(vec,r+1,右);
}
}
内部主(空){
int-vet[MAX],i=0;
srand(时间(空));
对于(i=0;i 2){
printf(“Num@[%d]=%d\n”,i,vet[i]);
}
如果((rand()%2)>1,则为else{
printf(“Num#[%d]=%d\n”,i,vet[i]);
}
}
返回0;
}

问题在于我将位码文件与插装一起传递给llvm prof,正确的做法是使用原始文件(不带插装):

与llvm prof相关的另一个问题是,由于科学记数法,它将函数/块执行频率四舍五入。我已经向llvm提交了一个补丁来纠正这个问题

另一个技巧是llvm prof per default仅显示前20个执行最频繁的基本块,它不向用户提供任何更改方法。我已经提交了另一个补丁,它添加了一个命令行参数,使用户可以设置他/她希望在输出中包含多少基本块

llvm-prof sort.bc