3 ms·
>In the absence of a stunningly advanced global optimization that peeks into other previously compiled units You'll be surprised, but this stuff exists since l
by DenisM 12y ago
>In the absence of a stunningly advanced global optimization that peeks into other previously compiled units
You'll be surprised, but this stuff exists since late last century, known as Link-Time Code Generation (LTCG):
http://msdn.microsoft.com/en-us/magazine/cc301698.aspx http://msdn.microsoft.com/en-us/magazine/cc301698.aspx
- kazinator 12y agoI've just been digging through the C99 standard (official) and the N1570 (final C11 draft) and have come to the conclusion that these optimizations break the language. This is probably not something you should be compiling your OpenSSL shared library or SSH with. A C program consists of translation units which may be preserved in translation form. That happens in translation phases 1 through 7. Multiple translation units may be linked, which is translation phase 8. Phase 8 only consists of resolving references; the last semantic analysis takes place in phase 7. An example under 5.1.2.3 gives the range of adherence between actual semantics and abstract semantics. Though it is just an example, and not normative, it is very clear from the wording that the locus of valid optimizations is the translation unit. Selected citations: 5.1.1.1 Program Structure A C program need not all be translated at the same time. [...] After preprocessing, a preprocessing translation unit is called a translation unit. Previously translated translation units may be preserved individually or in libraries. [...] Translation units may be separately translated and then later linked to produce an executable program. 5.1.1.2 Translation Phases [...] 7. White-space characters separating tokens are no longer significant. Each preprocessing token is converted into a token. The resulting tokens are syntactically and semantically analyzed and translated as a translation unit. 8. All external object and function references are resolved. Library components are linked to satisfy external references to functions and objects not defined in the current translation. All such translator output is collected into a program image which contains information needed for execution in its execution environment. 5.1.2.3 Program Execution 8. EXAMPLE 1 An implementation might define a one-to-one correspondence between abstract and actual semantics: at every sequence point, the values of the actual objects would agree with those specified by the abstract semantics. The keyword volatile would then be redundant. 9. Alternatively, an implementation might perform various optimizations within each translation unit, such that the actual semantics would agree with the abstract semantics only when making function calls across translation unit boundaries. In such an implementation, at the time of each function entry and function return where the calling function and the called function are in different translation units, the values of all externally linked objects and of all objects accessible via pointers therein would agree with the abstract semantics. Furthermore, at the time of each such function entry the values of the parameters of the called function and of all objects accessible via pointers therein would agree with the abstract semantics. In this type of implementation, objects referred to by interrupt service routines activated by the signal function would require explicit specification of volatile storage, as well as other implementation-defined restrictions.
- __david__ 12y ago> Though it is just an example, and not normative, it is very clear from the wording that the locus of valid optimizations is the translation unit. I don't think that's clear at all. As you said, it's just an example. > Phase 8 only consists of resolving references; the last semantic analysis takes place in phase 7. Why do you think that the only place you can optimize is during the "semantic analysis" phase? To me the phrase "All such translator output is collected into a program image" (from step 8) is vague enough to not rule out optimization during "collection".
- kazinator 12y agoThe word "all" in "all such translator output" seems to rule out removing any code, such as the zero memset. "Translator output" suggests that translation is complete and we just have its output to link together. Optimization is "semantic analysis"; you cannot optimize without reasoning about meaning, and optimization also implies that translation is still going on: the output of earlier translation is still being tweaked, with regard to the meaning of the original source.
- DenisM 12y agoWhen it's a choice between standards and a 10% performance gain, the latter will win.