This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Problems Forcing Global Register Allocation
- To: gcc-help at gcc dot gnu dot org
- Subject: Problems Forcing Global Register Allocation
- From: Brendan Younger <dyounger at facstaff dot wisc dot edu>
- Date: Wed, 3 Jan 2001 15:32:42 -0600
Hi,
I'm having a bit of trouble forcing gcc use a specific register for a
global variable. I use the syntax:
register int foo asm ("r1");
but this doesn't work perfectly. For instance, it will only compile using
the -traditional-cpp option and only if the register I use is r1 or r2
(general purpose registers on the PowerPC). These registers, however, are
clobbered after any function call. I can't not assign a specific register
since it then complains that no register was assigned. I'm using Mac OS X
Public Beta and compiling with "cc," Apple's port of gcc 2.95.x. Specific
things I've tried and their error codes are below:
register int foo asm ("r13"); //the first register that is preserved by
callees
compiling with the -traditional-cpp option, I get:
error: global register variable follows a function definition
register int foo asm ("r1");
compiling with the -traditional-cpp option, I get:
error: global register variable follows a function definition
warning: call-clobbered register used for global register variable
register int foo asm ("r1");
compiling without -traditional-cpp
error: illegal external declaration, missing ";" after foo
now, I was looking in the system.framework headers and they have mappings
of the PPC registers to other register names, like so:
#define a5 r4
substituting these names does no good since it produces an error to this
effect, "not a valid register assignment"
if anyone could please help, I'm compiling in Project Builder as a Standard
Tool (a standard UNIX console app). Also, I believe my problem lies
somewhere with the __ASSEMBLER__ macro. All the architecture-dependent
headers in the system framework have #ifdef __ASSEMBLER__ in them. Also,
in desperation I tried making the register one of gcc's virtual ones like
"%0" and that crashes my program with a bad memory access. Please help.
Brendan Younger