Hacker News new | past | comments | ask | show | jobs | submit login

> C isn't converted into assembler language unless you ask the compiler to. For example, LLVM lowers IR AST structures into target specific machine code. Assembler is never involved

That depends on the compiler. GCC, for instance, most certainly emits assembler code as part of its standard compilation process.




GCC to my knowledge has long-switched to IR as well. It’s called GIMPLE [1]. Can you please substantiate your claim?

[1]. https://gcc.gnu.org/wiki/GIMPLE


Well, there this[1] page that describes the GCC architecture:

"The SSA form is also used for optimizations. GCC performs more than 20 different optimizations on SSA trees. After the SSA optimization pass, the tree is converted back to the GIMPLE form which is then used to generate a register-transfer language (RTL) form of a tree. RTL is a hardware-based representation that corresponds to an abstract target architecture with an infinite number of registers. An RTL optimization pass optimizes the tree in the RTL form. *Finally, a GCC back-end generates the assembly code for the target architecture using the RTL representation.* Examples of back-ends are x86 back end, mips back end, etc."

Then, there's the official GCC documentation[2]:

"Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order. GCC is capable of preprocessing and compiling several files either into several assembler input files, or into one assembler input file; then each assembler input file produces an object file, and linking combines all the object files (those newly compiled, and those specified as input) into an executable file."

You can also just run GCC -- either with --verbose or --save-temps -- and observe what the compiler toolchain is doing.

[1] https://en.m.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU...

[2] https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Overall-Option...


Not really sure what you’re arguing for. All optimization passes operate on GIMPLE.

> SSA GIMPLE is low level GIMPLE rewritten in SSA form.

I’m by no means a compiler internals expert, but to my knowledge there’s no translation from RTL to assembly. The compiler is directly emitting the machine code directly without first emitting assembler. You have to ask the compiler to serialize to assembly explicitly.

> several assembler input files, or into one assembler input file; then each assembler input file produces an object file,

That doesn’t sound right. Seems more like an abstract description. You can’t dump assembly out of an object file either. You have to do a conversion from an intermediary form to get back out a form of the assembly.

I think at this point it’s splitting hairs but assembly is not used as an intermediary at any point, even for generating machine code.


> Not really sure what you’re arguing for. All optimization passes operate on GIMPLE.

You asked me for a citation. I provided two, as well as a means by which you could see for yourself that what I am saying is correct.

Believe what you want, but all of the GCC documentation, as well as the output of the compiler if you run with --verbose or --save-temps supports what I have described of GCC's operation.

The compiler internals manual[1] also describes the backend machine descriptions, and how they are used in detail:

"There are three main conversions that happen in the compiler:

1. The front end reads the source code and builds a parse tree.

2. The parse tree is used to generate an RTL insn list based on named instruction patterns.

3. The insn list is matched against the RTL templates to produce assembler code."

[1] - https://gcc.gnu.org/onlinedocs/gccint/Overview.html




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: