[cfe-dev] link-time optimization

Xi Wang xi.wang at gmail.com
Fri Mar 16 14:50:40 PDT 2012


I am not sure if -O4 enables LTO on windows, but you can try to
replace llvm-link with llvm-ld in your build script.

- xi

On Mar 16, 2012, at 5:31 PM, Jason Sachs wrote:

> I'm experimenting a bit with clang + llvm to get an idea of what it
> can and can't do. It seems to do a very good job with compile-time
> optimization and function inlining; I'm wondering how to enable
> link-time optimization properly, and what its limitations are.
> 
> I have a set of simple files computing the Fibonacci function
> iteratively (attached but with synopsis below; I had to rename a batch
> file to get Google to allow the attachment):
> 
> Foo.cpp:
> 
> int Foo::fib5(int n) {
> 	Bar bar;
> 	if (n <= 0)
> 		return 0;
> 	int p1 = 0;
> 	int p2 = 1;
> 	for (int i = 0; i < n; ++i)
> 	{
> 		int p2new = bar.sum2(p1,p2);
> 		p1 = p2;
> 		p2 = p2new;
> 	}
> 	return p2;
> }
> 
> Bar.cpp:
> 
> int Bar::sum2(int a, int b)
> {
> 	return a+b;
> }
> 
> Obviously there's no way for the compiler compiling each file
> separately to inline the Bar::sum2() function in Foo::fib5(), but I
> was hoping it would be smart enough to inline it at link time. (Alas,
> no.) Is there a way to tell it to create inlined functions at link
> time, even at the cost of code duplication? If so, how? If not, what's
> the limitation?
> 
> I'm compiling with -O4 on a WinXP box and with the prebuilt binaries
> for clang/llvm 2.9 (http://llvm.org/releases/download.html) running
> with mingw-32
> 
> --Jason
> <test2.zip>_______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list