This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Getting GCC output of OpenMP before compilation?


Hi!  When you compile an OpenMP program (say, in C) with GCC using the -fopenmp flag, GCC puts the code through a transformation step within the parsing phase, i.e., between preprocessing (earlier) and compilation to assembly code (later).  Most or all of the code for this transformation is in gcc/gcc/omp-low.c.  For a typical transformation, suppose you have the following source code:

#include <stdio.h>
#include <stdlib.h>
#include <omp.h>

int main(void) {

#pragma omp parallel
  printf("Hello from a teammate!\n");

  return EXIT_SUCCESS;
}


GCC creates an external function called main.omp_fn.0, which contains the code in the OMP Parallel block (the printf statement), and replaces the printf statement in main with the sequence

GOMP_parallel_start(&main.omp_fn.0, NULL);
main.omp_fn.0();
GOMP_larallel_end();

The second argument to GOMP_parallel_start would be a pointer to a data structure containing the arguments to be passed to main.omp_fn.0, if there were any.

I know this because I can see it in the compiled assembly code, e.g.,

        .text
.globl _main
_main:
LFB6:
        pushq   %rbp
LCFI0:
        movq    %rsp, %rbp
LCFI1:
      	movl    $0, %edx
        movl    $0, %esi
        leaq    _main.omp_fn.0(%rip), %rdi
	call    _GOMP_parallel_start
	movl    $0, %edi
	call    _main.omp_fn.0
	call    _GOMP_parallel_end
	movl    $0, %eax
	leave
	ret
LFE6:
     	.cstring
LC0:
    	.ascii "Hello from a teammate!\0"
	.text
_main.omp_fn.0:
LFB7:
     	pushq   %rbp
LCFI2:
      	movq    %rsp, %rbp
LCFI3:
      	subq    $16, %rsp
LCFI4:
      	movq    %rdi, -8(%rbp)
	leaq    LC0(%rip), %rdi
	call    _puts
	leave
	ret

But is there any way that I can get GCC to give me as output some C code that represents its refactoring before it generates the assembly code?

Thanks!

Amittai Aviram
PhD Student in Computer Science
Yale University
646 483 2639
amittai.aviram@yale.edu
http://www.amittai.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]