‹ BackHN Continuity

Thread

EDG C++ front-end goes public

249 points · 129 comments · iandinwoodie

  1. compiler-guy · · focus · HN ↗
    One interesting thing about the EDG front end is that it can emulate all the others (and in various versions of the others) and what they support, and the errors they might detect.

    It isn't perfect, but it is awfully good.

    Another interesting thing is that in 1999ish, when SGI open-sourced the Irix compiler (known as sgicc) into open-64, the it used a terribly hacked version of gcc as a front end to generate its internal intermediate representation.

    This was because sgicc, even back then, used EDG as a front end, and EDG wasn't open and couldn't be opened up at the time.

    The combination worked OK, but was pretty hacky, and I wonder if open64 would have gotten more traction than it did if it had been able to use EDG, or perhaps some other front end actually designed as a front end instead of the hacky thing.

    1. feelamee · · focus · HN ↗
      what do you mean under "emulation"? and why EDG is frontend? It's not a full compiler with optimizations and code generation?
      1. daveedvdv · · focus · HN ↗
        No, we only parse the language, do full semantic analysis, and optionally lower the representation to something that roughly matches C-language semantics. (That lowering can do some minimal inlining if needed, but that's a historical thing.)

        We have two "back ends": c_gen_be.c generates C code from the lower IL ("intermediate language"; EDG's term for the AST) and cp_gen_be.c generates C++ code from the unlowered IL.

        1. rramadass · · focus · HN ↗
          What are some usecases for C++ source-to-source transformations ?
          1. daveedvdv · · focus · HN ↗
            Several of our customers instrument the AST to add security-probing and/or other dynamic-analysis features. NVCC uses it to separate out "device" constructs.
            1. saagarjha · · focus · HN ↗
              Wait, nvcc uses EDG?
              1. compiler-guy · · focus · HN ↗
                Yes. And this is why the nvcc preprocessor is so effective at working with the various host compilers. It emulates properties of the host compiler so that the device code and host agree on things.

                You can see some discussion here:

                <a href="https:&#x2F;&#x2F;forums.developer.nvidia.com&#x2F;t&#x2F;nvcc-preprocessing&#x2F;64939&#x2F;7" rel="nofollow">https:&#x2F;&#x2F;forums.developer.nvidia.com&#x2F;t&#x2F;nvcc-preprocessing&#x2F;649...

                1. rramadass · · focus · HN ↗
                  Thank you.

                  But i could not find Thibaut Lutz&#x27;s presentation slides linked to in the above discussion. Any idea where i can find it?

                  I presume the control flow in the above presentation is the same as found in &quot;The CUDA Compilation Trajectory&quot; chapter in the NVCC documentation (cudafe++ is EDG) - <a href="https:&#x2F;&#x2F;docs.nvidia.com&#x2F;cuda&#x2F;cuda-compiler-driver-nvcc&#x2F;index.html#the-cuda-compilation-trajectory" rel="nofollow">https:&#x2F;&#x2F;docs.nvidia.com&#x2F;cuda&#x2F;cuda-compiler-driver-nvcc&#x2F;index...

            2. rramadass · · focus · HN ↗
              That is quite interesting. I haven&#x27;t thought much about source-to-source transformation within C++.

              Do you have any articles&#x2F;papers&#x2F;books&#x2F;etc. you can point us to for understanding this better?

              Two usecases i have in mind are;

              1) Transforming legacy C++98&#x2F;C++03 codebases into &quot;modern&quot; C++11&#x2F;14&#x2F;17&#x2F;20&#x2F;23&#x2F;26. Is this possible with current edg?

              2) Adding verification conditions based on code analysis; both runtime contract asserts and compile time proofs (possible?) so as to convert &quot;normal&quot; C++ code into &quot;somewhat verified&quot; C++ code.

              Some resources that Google brought up;

              Challenges and Opportunities in C&#x2F;C++ Source-To-Source Compilation - <a href="https:&#x2F;&#x2F;drops.dagstuhl.de&#x2F;entities&#x2F;document&#x2F;10.4230&#x2F;OASIcs.PARMA-DITAM.2023.2" rel="nofollow">https:&#x2F;&#x2F;drops.dagstuhl.de&#x2F;entities&#x2F;document&#x2F;10.4230&#x2F;OASIcs.P...

              C++ Insights - See your source code with the eyes of a compiler - <a href="https:&#x2F;&#x2F;github.com&#x2F;andreasfertig&#x2F;cppinsights" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;andreasfertig&#x2F;cppinsights Tool at <a href="https:&#x2F;&#x2F;cppinsights.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;cppinsights.io&#x2F;

      2. rramadass · · focus · HN ↗
        <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=49919630">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=49919630
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.