Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where can I find the LLVM documentation for the features used here? #2

Closed
cesss opened this issue Apr 15, 2020 · 4 comments
Closed

Comments

@cesss
Copy link

cesss commented Apr 15, 2020

Hi!

While looking for tools that could perform source-to-source transformation of C/C++ arithmetic expressions for speed optimization purposes, I came into this little tool that I find intriguing. After looking its source, may I ask if there's some LLVM (or thirdparty) documentation (hopefully with examples) that I could follow for learning doing this myself?

Do you know of any C and/or C++ compiler, or static analyzer, or similar tool, that can optimize the source code expressions for speed issuing a source-to-source result, rather than compiled object code?

I suppose that a proper optimization would require to tell the optimizer about the computing cost of each operation, because depending on the device you use, the cost of additions/subtractions/multiplications/divisions/etc... might be different. However, by looking at this source code, I found no traces of the assumed cost for each operation...

Thanks!!

@thvnx
Copy link
Owner

thvnx commented Apr 17, 2020

Hi,

This little project is a work in progress that doesn't progress... it does nothing yet. My goal is to reimplement the work I've done during my PhD: https://hal.archives-ouvertes.fr/hal-01236919.

I don't think there is any documentation for this, you'll have to take a look at the example that you can find in the llvm-project source tree: llvm-project/clang-tools-extra/.

You can find here some tools that can optimize source code expressions (floating-point arithmetic oriented): https://fpbench.org/community.html

@cesss
Copy link
Author

cesss commented Apr 17, 2020

Thanks a lot for your reply, @thvnx ! By looking at the link with optimization tools, it seems like all of them are related to mixed-precision and to optimization as means of finding an optimal precision for the calculation being done.

However, my interest is in the kind of optimizations that compilers usually perform: exchanging operators (ie: turn divisions into multiplications when possible, change multiplications by additions or vice versa, changing multiplications by powers of 2 into shifts in integers, etc...), completely transforming the expression into another one. Granted, some of these optimizations can have a negative impact in accuracy -or positive in some cases-, and some of them can even violate standards compliance, but most compilers let the user decide the level of optimization from safest to most aggressive, from compliant to not-necessarily compliant, etc...

Do you know of any tool capable of doing this at a source code level rather than at a CPU instructions level?

@thvnx
Copy link
Owner

thvnx commented Apr 17, 2020

I don't know if such a tool exists, nevertheless a clang tool can be "quickly" prototyped to do so.

@cesss
Copy link
Author

cesss commented Apr 17, 2020

Thanks a lot! In this moment I tend to believe that what would be needed would be a custom builtin type rather than a source-to-source transformation tool, so I have asked at llvm-dev hoping somebody can help: https://lists.llvm.org/pipermail/llvm-dev/2020-April/141046.html

But I feel like I'm not going to get many replies. It's somewhat strange, because there are C++ classes for emulating 16bit half floats and 128bit "quad" floats, but when you use them, you not only lose the hardware performance from the FP unit in the CPU, but you also lose all arithmetic optimizations... I feel it very strange that nobody seems to have developed a solution for this.

A similar problem could be discussed for matrix algebra: you can overload C++ operators for correctly implement matrix algebra expressions, but then the optimizer is not able to rearrange your expressions for speed, because the C++ standard doesn't let you define a semantic meaning for the operators...

Well, I'm closing this, as this obviously is not an issue about your software :-)

Thanks a lot!

@cesss cesss closed this as completed Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants