How do I find how C++ compiler implements something except inspecting emitted machine code?

后端 未结 8 1808
渐次进展
渐次进展 2020-12-17 14:28

Suppose I crafted a set of classes to abstract something and now I worry whether my C++ compiler will be able to peel off those wrappings and emit really clean, concise and

8条回答
  •  生来不讨喜
    2020-12-17 15:04

    I was actually wondering about that.

    I have been quite interested, for the last few months, in the Clang project.

    One of Clang particular interests, wrt optimization, is that you can emit the optimized LLVM IR code instead of machine code. The IR is a high-level assembly language, with the notion of structure and type.

    Most of the optimizations passes in the Clang compiler suite are indeed performed on the IR (the last round is of course architecture specific and performed by the backend depending on the available operations), this means that you could actually see, right in the IR, if the object creation (as in your linked question) was optimized out or not.

    I know it is still assembly (though of higher level), but it does seem more readable to me:

    • far less opcodes
    • typed objects / pointers
    • no "register" things or "magic" knowledge required

    Would that suit you :) ?

提交回复
热议问题