Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What, in short words, does the GCC option -fipa-pta do?

According to the GCC manual, the -fipa-pta optimization does:

-fipa-pta: Perform interprocedural pointer analysis and interprocedural modification and reference analysis. This option can cause excessive memory and compile-time usage on large compilation units. It is not enabled by default at any optimization level.

What I assume is that GCC tries to differentiate mutable and immutable data based on pointers and references used in a procedure. Can someone with more in-depth GCC knowledge explain what -fipa-pta does?

like image 584
muehlbau Avatar asked Oct 25 '12 10:10

muehlbau


People also ask

What does GCC option do?

gcc -c compiles source files without linking.

What is the GCC in simple terms?

Meaning of the GCC in English abbreviation for Gulf Cooperation Council: a group of six countries in the Persian Gulf: Bahrain, Kuwait, Qatar, Oman, Saudi Arabia, and the United Arab Emirates. GCC countries make decisions together on trade, military spending, etc. Want to learn more?

What does GCC mean in C?

GCC stands for “GNU Compiler Collection”. GCC is an integrated distribution of compilers for several major programming languages. These languages currently include C, C++, Objective-C, Objective-C++, Fortran, Ada, D, and Go.

Where is GCC used?

GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++.

What are the options in GCC?

Options: Description: Gcc –c: Compiles source files to object files without linking to any other object files. gcc –Idir: Includes the directories of header files: gcc –llib: link the code with the library files: gcc -o output file: Build the output generated to output file: gcc –w: Disables all warning messages during the compilation. gcc –Wall

What is GCC -C command in Linux?

GCC Command Options When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The "overall options" allow you to stop this process at an intermediate stage. For example, the -coption says not to run the linker.

What does-O mean in GCC?

This is the same as specifying file as the second non-option argument to cpp. gcc has a different interpretation of a second non-option argument, so you must use '-o' to specify the output file. Turns on all optional warnings which are desirable for normal code. At present this is '-Wcomment' and '-Wtrigraphs'.

How to specify the output file name of the GCC compiler?

1. Specify the Output Executable Name. In its most basic form, gcc compiler can be used as : gcc main.c. The above command executes the complete compilation process and outputs an executable with name a.out. Use option -o, as shown below, to specify the output file name for the executable. gcc main.c -o main. The command above would produce an ...


1 Answers

I think the word "interprocedural" is the key here.

I'm not intimately familiar with gcc's optimizer, but I've worked on optimizing compilers before. The following is somewhat speculative; take it with a small grain of salt, or confirm it with someone who knows gcc's internals.

An optimizing compiler typically performs analysis and optimization only within each individual function (or subroutine, or procedure, depending on the language). For example, given code like this contrived example:

double *ptr = ...;

void foo(void) {
    ...
    *ptr = 123.456;
    some_other_function();
    printf("*ptr = %f\n", *ptr);
}

the optimizer will not be able to determine whether the value of *ptr has been changed by the call to some_other_function().

If interprocedural analysis is enabled, then the optimizer can analyze the behavior of some_other_function(), and it may be able to prove that it can't modify *ptr. Given such analysis, it can determine that the expression *ptr must still evaluate to 123.456, and in principle it could even replace the printf call with puts("ptr = 123.456");.

(In fact, with a small program similar to the above code snippet I got the same generated code with -O3 and -O3 -fipa-pta, so I'm probably missing something.)

Since a typical program contains a large number of functions, with a huge number of possible call sequences, this kind of analysis can be very expensive.

like image 52
Keith Thompson Avatar answered Nov 11 '22 07:11

Keith Thompson