gcc使用多少遍历代码?

时间:2020-12-01 02:28:28
  • Specifically for C and C++, how many passes are used by default?
  • 特别是对于C和c++,默认使用了多少遍?
  • Does this number change depending on the level of optimization used? (it should)
  • 这个数字是否会随所使用的优化级别而变化?(应该)
  • Can it be changed directly?
  • 可以直接改变吗?

I was searching for this information in http://gcc.gnu.org/, but googling using site:http://gcc.gnu.org/ did not yield anything.

我在http://gcc.gnu.org/中搜索了这个信息,但是在google上搜索的网址是:http://gcc.gnu.org/没有提供任何东西。

Any pointers to any documentation about this will also be helpful.

任何有关这方面的文档的指针都将非常有用。


By pass I meant a pass over the original representation of the source code only and not the multiple pass definition suggested by Wikipedia.

pass指的是只传递源代码的原始表示,而不是*建议的多重传递定义。

8 个解决方案

#1


6  

Passes and Files of the Compiler might be the closest thing to what you're looking for.

编译器的传递和文件可能是您要查找的最接近的东西。

#2


2  

As others pointed out above, modern compilers do only one single pass at the parsing stage and then multiple ones at later stages using an internal representation (usually trees or other in-memory graph-like data structure).

正如上面其他人指出的,现代编译器在解析阶段只执行一次传递,然后在以后的阶段使用内部表示(通常是树或其他类似于内存中的图形数据结构)进行多次传递。

Concretely GCC use this approach. See: https://gcc.gnu.org/onlinedocs/gccint/Parsing-pass.html#Parsing-pass

具体地说,GCC使用这种方法。见:https://gcc.gnu.org/onlinedocs/gccint/Parsing-pass.html Parsing-pass

#3


1  

I've never heard of a compiler passing multiple times over the textual representation (excepted if you count the preprocessor as one pass). Even when compilers had multiple passes communicating by files, the files contained an intermediate representation (serialized AST + symbol table).

我从未听说过编译器在文本表示法上传递多次(如果将预处理程序算作一次传递,则除外)。即使编译器有多个通过文件通信的传递,文件也包含一个中间表示(序列化的AST +符号表)。

Assemblers on the other hand routinely did two (or more) passes over the source code. Their preprocessor often allows to do things specifically on one pass, allowing to play some more or less dirty trick.

另一方面,汇编器通常执行两个(或多个)传递源代码。他们的预处理器通常允许在一次操作中做一些特别的事情,允许玩一些或多或少有点肮脏的把戏。

#4


1  

In gcc, basically, there are two types of passes, namely : gimple, rtl. In gcc 4.6.2 total unique passes are 207. Yes total number of passes on a given program depend on the optimization level. And some of these passes are taken more then one time. If anyone want to go through these passes, go through the passes.c file in gcc source code. Path for passes.c in gcc 4.6.2 : gcc source -> gcc -> passes.c

在gcc中,基本上有两种类型的传递,即gimple和rtl。在gcc 4.6.2中,唯一通行证的总数是207。是的,给定程序上传递的总数取决于优化级别。其中的一些传球次数不止一次。如果有人想通过这些通道,请通过这些通道。c文件中的gcc源代码。经过的路径。c在gcc 4.6.2中:gcc source -> gcc -> passes.c

Yes you can change the number of passes by adding your passes as dynamic plugin in gcc.

是的,您可以通过在gcc中添加作为动态插件的pass来更改传递的数量。

#5


0  

From what I was told by somebody in my compiler design class, gcc does a single pass, whereas other compilers like those used by Visual Studio (default) use two passes. This is why you must forward-declare classes in c++ if you are using them in a circular fasion.

从我的编译器设计类中有人告诉我的情况来看,gcc只执行一次传递,而像Visual Studio(默认)使用的其他编译器则使用两次传递。这就是为什么如果您在循环fasion中使用它们,您必须使用c++中的forward-declare类。

Class A {
   B* b; 
}

Class B {
   A* a;
}

C# and other languages do not require this, since the first pass builds the references and the second pass compiles.

c#和其他语言不需要这个,因为第一次传递构建引用,第二次传递编译。

But then again I'm not expert in compilers.

但话说回来,我对编译器并不在行。

#6


0  

Exactly one. I don't see any meaningful reason for any modern compiler to make more than one pass over the source code, if by "code" you mean the original textual representation of program's source. The whole point of that single pass is to convert the source code into some internal representation, which will be used for further analysis. That internal representation is no longer required to have any linear structure and/or no longer required to be restricted to sequential processing only, which means that the notion of "making a pass" over it is simply no longer applicable.

一个。我看不出任何现代编译器有任何有意义的理由让一个以上传递源代码,如果“代码”指的是程序源代码的原始文本表示。单次传递的全部要点是将源代码转换为一些内部表示,将用于进一步分析。这种内部表示不再需要具有任何线性结构,也不再需要仅局限于顺序处理,这意味着“传递”的概念不再适用。

If this answer doesn't satisfy you, you should probably provide a more precise explanation of what you define as a "pass" over the source code.

如果这个答案不能使您满意,那么您应该对您定义的“传递”源代码提供更精确的解释。

#7


0  

Your definition of multi-pass seems to be the old one, stemming from the times where (a representation of) whole program sources just didn't fit into the available memory. These times are gone now and I know not a single, current multi-pass (old definition) compiler.

您对多通道的定义似乎是旧的,源自于(一个表示)整个程序源不适合可用内存的时代。这些时间已经过去了,我不知道有一个单一的、当前的多遍(旧定义)编译器。

In the German Wikipedia entry for Compiler, both definitions are given: http://de.wikipedia.org/wiki/Compiler

在德国*的编译器条目中,两个定义都给出了:http://de.wikipedia.org/wiki/Compiler。

Multi-pass-Compiler

Multi-pass-Compiler

Bei diesem Compilertyp wird der Quellcode in mehreren Schritten in den Zielcode übersetzt. In den Anfangszeiten des Compilerbaus wurde der Übersetzungsprozess hauptsächlich deshalb in mehrere Durchläufe zerlegt, weil die Kapazität der Computer oft nicht ausreichte, um den vollständigen Compiler und das zu übersetzende Programm gleichzeitig im Hauptspeicher zu halten. Heutzutage dient ein Multi-pass-Compiler vor allem dazu, Vorwärtsreferenzen (Deklaration eines Bezeichners nach dessen erster Verwendung) aufzulösen und aufwendige Optimierungen durchzuführen.

在此基础上,我们将对其进行编码。在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在美国,在德国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国在多通道编译器方面有很多的改进,比如对所有的优化。

#8


-3  

Do you mean passes over the source code? Just once. That's called the "tokenization" or "lexical analysis" phase, or, more broadly, "parsing".

你的意思是通过源代码吗?只有一次。这被称为“标记化”或“词汇分析”阶段,或者更广泛地称为“解析”。

Do you mean phases in the compiler? There are several. The term "pass" is really more of an old assembler concept than a compiler concept these days, and even then it is only used roughly. The term "pass" doesn't have a single definition.

你是说编译器中的阶段吗?有几个。“pass”这个词实际上是一个旧的汇编器概念,而不是现在的编译器概念,即使它只是粗略地使用。“pass”一词没有单一的定义。

Compilers are broken down into "phases". Read the intro to any compiler textbook. It will explain the phases (there are about a dozen logical phases), and GCC follows the textbook models pretty faithfully. Some phases are typically combined into a single "pass", others are separate "passes".

编译器被分解成“阶段”。阅读任何编译器教科书的介绍。它将解释各个阶段(大约有十几个逻辑阶段),GCC非常忠实地遵循教科书模型。有些阶段通常合并为一个“通行证”,其他阶段则是单独的“通行证”。

The pass concept is really not as useful in terms of discussing compilers as the phase concept is.

pass概念在讨论编译器时并不像阶段概念那样有用。

#1


6  

Passes and Files of the Compiler might be the closest thing to what you're looking for.

编译器的传递和文件可能是您要查找的最接近的东西。

#2


2  

As others pointed out above, modern compilers do only one single pass at the parsing stage and then multiple ones at later stages using an internal representation (usually trees or other in-memory graph-like data structure).

正如上面其他人指出的,现代编译器在解析阶段只执行一次传递,然后在以后的阶段使用内部表示(通常是树或其他类似于内存中的图形数据结构)进行多次传递。

Concretely GCC use this approach. See: https://gcc.gnu.org/onlinedocs/gccint/Parsing-pass.html#Parsing-pass

具体地说,GCC使用这种方法。见:https://gcc.gnu.org/onlinedocs/gccint/Parsing-pass.html Parsing-pass

#3


1  

I've never heard of a compiler passing multiple times over the textual representation (excepted if you count the preprocessor as one pass). Even when compilers had multiple passes communicating by files, the files contained an intermediate representation (serialized AST + symbol table).

我从未听说过编译器在文本表示法上传递多次(如果将预处理程序算作一次传递,则除外)。即使编译器有多个通过文件通信的传递,文件也包含一个中间表示(序列化的AST +符号表)。

Assemblers on the other hand routinely did two (or more) passes over the source code. Their preprocessor often allows to do things specifically on one pass, allowing to play some more or less dirty trick.

另一方面,汇编器通常执行两个(或多个)传递源代码。他们的预处理器通常允许在一次操作中做一些特别的事情,允许玩一些或多或少有点肮脏的把戏。

#4


1  

In gcc, basically, there are two types of passes, namely : gimple, rtl. In gcc 4.6.2 total unique passes are 207. Yes total number of passes on a given program depend on the optimization level. And some of these passes are taken more then one time. If anyone want to go through these passes, go through the passes.c file in gcc source code. Path for passes.c in gcc 4.6.2 : gcc source -> gcc -> passes.c

在gcc中,基本上有两种类型的传递,即gimple和rtl。在gcc 4.6.2中,唯一通行证的总数是207。是的,给定程序上传递的总数取决于优化级别。其中的一些传球次数不止一次。如果有人想通过这些通道,请通过这些通道。c文件中的gcc源代码。经过的路径。c在gcc 4.6.2中:gcc source -> gcc -> passes.c

Yes you can change the number of passes by adding your passes as dynamic plugin in gcc.

是的,您可以通过在gcc中添加作为动态插件的pass来更改传递的数量。

#5


0  

From what I was told by somebody in my compiler design class, gcc does a single pass, whereas other compilers like those used by Visual Studio (default) use two passes. This is why you must forward-declare classes in c++ if you are using them in a circular fasion.

从我的编译器设计类中有人告诉我的情况来看,gcc只执行一次传递,而像Visual Studio(默认)使用的其他编译器则使用两次传递。这就是为什么如果您在循环fasion中使用它们,您必须使用c++中的forward-declare类。

Class A {
   B* b; 
}

Class B {
   A* a;
}

C# and other languages do not require this, since the first pass builds the references and the second pass compiles.

c#和其他语言不需要这个,因为第一次传递构建引用,第二次传递编译。

But then again I'm not expert in compilers.

但话说回来,我对编译器并不在行。

#6


0  

Exactly one. I don't see any meaningful reason for any modern compiler to make more than one pass over the source code, if by "code" you mean the original textual representation of program's source. The whole point of that single pass is to convert the source code into some internal representation, which will be used for further analysis. That internal representation is no longer required to have any linear structure and/or no longer required to be restricted to sequential processing only, which means that the notion of "making a pass" over it is simply no longer applicable.

一个。我看不出任何现代编译器有任何有意义的理由让一个以上传递源代码,如果“代码”指的是程序源代码的原始文本表示。单次传递的全部要点是将源代码转换为一些内部表示,将用于进一步分析。这种内部表示不再需要具有任何线性结构,也不再需要仅局限于顺序处理,这意味着“传递”的概念不再适用。

If this answer doesn't satisfy you, you should probably provide a more precise explanation of what you define as a "pass" over the source code.

如果这个答案不能使您满意,那么您应该对您定义的“传递”源代码提供更精确的解释。

#7


0  

Your definition of multi-pass seems to be the old one, stemming from the times where (a representation of) whole program sources just didn't fit into the available memory. These times are gone now and I know not a single, current multi-pass (old definition) compiler.

您对多通道的定义似乎是旧的,源自于(一个表示)整个程序源不适合可用内存的时代。这些时间已经过去了,我不知道有一个单一的、当前的多遍(旧定义)编译器。

In the German Wikipedia entry for Compiler, both definitions are given: http://de.wikipedia.org/wiki/Compiler

在德国*的编译器条目中,两个定义都给出了:http://de.wikipedia.org/wiki/Compiler。

Multi-pass-Compiler

Multi-pass-Compiler

Bei diesem Compilertyp wird der Quellcode in mehreren Schritten in den Zielcode übersetzt. In den Anfangszeiten des Compilerbaus wurde der Übersetzungsprozess hauptsächlich deshalb in mehrere Durchläufe zerlegt, weil die Kapazität der Computer oft nicht ausreichte, um den vollständigen Compiler und das zu übersetzende Programm gleichzeitig im Hauptspeicher zu halten. Heutzutage dient ein Multi-pass-Compiler vor allem dazu, Vorwärtsreferenzen (Deklaration eines Bezeichners nach dessen erster Verwendung) aufzulösen und aufwendige Optimierungen durchzuführen.

在此基础上,我们将对其进行编码。在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在德国,在美国,在德国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国,在美国在多通道编译器方面有很多的改进,比如对所有的优化。

#8


-3  

Do you mean passes over the source code? Just once. That's called the "tokenization" or "lexical analysis" phase, or, more broadly, "parsing".

你的意思是通过源代码吗?只有一次。这被称为“标记化”或“词汇分析”阶段,或者更广泛地称为“解析”。

Do you mean phases in the compiler? There are several. The term "pass" is really more of an old assembler concept than a compiler concept these days, and even then it is only used roughly. The term "pass" doesn't have a single definition.

你是说编译器中的阶段吗?有几个。“pass”这个词实际上是一个旧的汇编器概念,而不是现在的编译器概念,即使它只是粗略地使用。“pass”一词没有单一的定义。

Compilers are broken down into "phases". Read the intro to any compiler textbook. It will explain the phases (there are about a dozen logical phases), and GCC follows the textbook models pretty faithfully. Some phases are typically combined into a single "pass", others are separate "passes".

编译器被分解成“阶段”。阅读任何编译器教科书的介绍。它将解释各个阶段(大约有十几个逻辑阶段),GCC非常忠实地遵循教科书模型。有些阶段通常合并为一个“通行证”,其他阶段则是单独的“通行证”。

The pass concept is really not as useful in terms of discussing compilers as the phase concept is.

pass概念在讨论编译器时并不像阶段概念那样有用。