allocation_order_begin takes non-const reference for MachineFunction

Hi!

Could someone tell me the reason why allocation_order_begin method of TargetRegisterClass class takes a non-const reference to MachineFunction? I can’t imagine why this method will change function and didn’t find any override within llvm source which uses non-const methods of the MF parameter.

Just run into compiler error because I passed a const reference to the method.

Best regards,

Tony.

Hi Tony,

It doesn't look right to me either. The "begin" and "end" methods which
allocation_order_begin should return a const_iterator instead of an
iterator. Those methods are "const". And, yes, the MachineFunction
reference isn't even used so at the very least it could be const (if not
removed). However, I'm not an expert in this area of the code. Chris or
someone else will have to look at this and provide a determination.

Reid.

Thanks, Reid.

I’ve found that some overrides of allocation_order_begin() calls MachineFunction getInfo method. this method is not const. However, I think there could be default const implementation (const_cast of non-const method) and then allocation_order_begin() could be const.

That sounds reasonable to me. There should probably also be a const version of the getInfo method. If you'd be willing to put together a patch, we can get it fixed.

Thanks,

-Chris

I’m willing :slight_smile: I don’t know how to do it.
What’s “to put together a patch”? :slight_smile:

In your local CVS tree, change the methods to be const, and adjust any code that is neccesary for that to work. Once that is done, from the top level, type 'cvs diff -u >& patch.txt' and attach patch.txt to an email.

If you're using sh instead of csh, use 'cvs diff -u 2>&1 > patch.txt'.

Thanks,

-Chris

Ok, I’m in process. Do I need to checkout the latest llvm source, first?

I updated last right after the 1.8 release.

That would be advisable, there have been many commits since then.

Reid.

Ok, I'm in process. Do I need to checkout the latest llvm source, first?

yes, please check out cvs head. See the getting started guide for info

-Chris

I updated last right after the 1.8 release.

-Chris

Hi Chris,

> I'm willing :slight_smile: I don't know how to do it. What's "to put together a
> patch"? :slight_smile:

In your local CVS tree, change the methods to be const, and adjust any
code that is neccesary for that to work. Once that is done, from the
top level, type 'cvs diff -u >& patch.txt' and attach patch.txt to an
email.

If you're using sh instead of csh, use 'cvs diff -u 2>&1 > patch.txt'.

The sh equivalent of that csh is

    cvs diff -u >patch.txt 2>&1

The first duplicates stderr onto stdout and then changes stdout to be
patch.txt leaving stderr to go to wherever stdout used to go. The
second changes stdout to be patch.txt and then duplicates stderr to go
there too. This flexibility is one of sh's advantages over csh. :wink:

Cheers,

Ralph.

Thanks, Ralph, this line worked well :slight_smile:

Here it is, my first patch to LLVM :slight_smile:

I’ve changed all allocation_order_begin() and allocation_order_end() methods to take const MachineFunction &MF as a parameter. I also added const version of MachineFunction::getInfo() method. And I changed three static hasFP() functions to take const reference to MachineFunction.

While doing this I’ve found that some methods of MachineFunction are const but return non-const pointers to MachineFunction internal info. Is that all right?

Thanks,

Tony.

P.S. I’ve updated llvm from CVS about 20 hour ago.

patch.zip (5.6 KB)

Thanks, Ralph, this line worked well :slight_smile:
Here it is, my first patch to LLVM :slight_smile:

I've changed all allocation_order_begin() and allocation_order_end() methods
to take const MachineFunction &MF as a parameter. I also added const version
of MachineFunction::getInfo<Ty>() method. And I changed three static hasFP()
functions to take const reference to MachineFunction.

Looks great, applied:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20060814/036832.html
...
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20060814/036839.html

While doing this I've found that some methods of MachineFunction are const
but return non-const pointers to MachineFunction internal info. Is that all
right?

Which ones specifically?

-Chris

While doing this I’ve found that some methods of MachineFunction are const
but return non-const pointers to MachineFunction internal info. Is that all
right?

Which ones specifically?

-Chris

Probable candidates are:
getSSARegMap, getFrameInfo, getJumpTableInfo, getConstantPool, isPhysRegUsed, getBlockNumbered.

They are const but return non-const pointers to object’s internal data. Though I don’t know if making two versions of each methods will be useful or it’ll just make code bigger and compilation a bit longer :slight_smile:

isPhysRegUsed should be constified I suppose.

And btw comment to addToMMBNumbering method is a bit old (refers to getNextMMBNumber, which doesn’t exist already).

Dear guys,

    my llvm-gcc does not compile stdlib.h correctly. I found this
explanation
here: http://llvm.cs.uiuc.edu/bugs/show_bug.cgi?id=567
    Indeed, I am running Mac OS 10.4. Do I have to rebuild my gcc
front-end from source, or there is a script in the LLVM website that could
help me?

Best regards,

Fernando

Rebuilding llvm-gcc4 from source should work fine. Please see the
directions in the file README.LLVM at the top level src directory. You
can check llvm-gcc4 out from Subversion with the command:

svn co svn://anonsvn.opensource.apple.com/svn/llvm/trunk llvm-gcc4

Reid.

Rebuilding llvm-gcc4 from source should work fine. Please see the
directions in the file README.LLVM at the top level src directory. You
can check llvm-gcc4 out from Subversion with the command:

Dear guys,

    I've rebuild my llvm-gcc3 (not llvm-gcc4) from source, and now it can
find stdlib.c and all the other sources, but I am having some other
problems with the new libraries.
1) If I try: llvm-gcc source.c -o source; llc -f source.bc -o ch.s ;
gcc ch.s -o exec,
    I end up getting this error from gcc:
/usr/bin/ld: Undefined symbols:
___main
collect2: ld returned 1 exit status
    If I fix this, by replacing ___main by main manually, the program
seg-faults.

It used to work fine with the cfrontend that came together with llvm. Do
you
guys know what can be happening?

2) If I try: llvm-g++ source.cpp -o source ; source
I get this error:
ERROR: Program used external function '__llvm_eh_add_uncaught_exception'
which could not be resolved!
Abort

Could some one help me fixing this? Do I have to use llvm-gcc4?

All the best,

Fernando

Try adding -lcrtend to the gcc link line. You need to link in the LLVM
runtime stuff.

Reid.

Thank you, Reid,

    I tried llvm-gcc -lcrtend ary3.c -o ary3, but I get

gccld: warning: Cannot find library 'crtend'
gccld: warning: Cannot find library 'c'

I have the libraries in my llvm directory:
llvm/runtime/GCCLibraries/crtend

Well, how do I link this to the LLVM runtime stuff? Before building from
the source, I had copied all the .h from my old gcc 4.0 to
llvm/cfrontend/and_so_forth... and I was able to compile .c all right. The
problem was the .cpp.

Thanks a lot,

Fernando

Thank you, Reid,
   I tried llvm-gcc -lcrtend ary3.c -o ary3, but I get
gccld: warning: Cannot find library 'crtend'
gccld: warning: Cannot find library 'c'

I have the libraries in my llvm directory:
llvm/runtime/GCCLibraries/crtend

Well, how do I link this to the LLVM runtime stuff? Before building from
the source, I had copied all the .h from my old gcc 4.0 to
llvm/cfrontend/and_so_forth... and I was able to compile .c all right. The
problem was the .cpp.

You need to follow the directions here:
http://llvm.org/docs/CFEBuildInstrs.html#llvm-gcc3-instructions

In particular, you must run the install-bytecode target, as instructed.

-Chris

Try adding -lcrtend to the gcc link line. You need to link in the LLVM
runtime stuff.

Reid.

    I've rebuild my llvm-gcc3 (not llvm-gcc4) from source, and now it can
find stdlib.c and all the other sources, but I am having some other
problems with the new libraries.
1) If I try: llvm-gcc source.c -o source; llc -f source.bc -o ch.s ;
gcc ch.s -o exec,
    I end up getting this error from gcc:
/usr/bin/ld: Undefined symbols:
___main
collect2: ld returned 1 exit status
    If I fix this, by replacing ___main by main manually, the program
seg-faults.

It used to work fine with the cfrontend that came together with llvm. Do
you
guys know what can be happening?

2) If I try: llvm-g++ source.cpp -o source ; source
I get this error:
ERROR: Program used external function '__llvm_eh_add_uncaught_exception'
which could not be resolved!
Abort

Could some one help me fixing this? Do I have to use llvm-gcc4?

_______________________________________________
LLVM Developers mailing list
LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-Chris