This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Help restricting args of an intrinsic function
- From: Syd Polk <spolk at apple dot com>
- To: GCC List <gcc at gcc dot gnu dot org>
- Date: Fri, 30 Jan 2004 16:46:48 -0800
- Subject: Help restricting args of an intrinsic function
I am trying to implement a few PowerPC intrinsics that are supported by
another PowerPC compiler. It is going pretty well in general (thanks to
help by Mike Stump), but now, I have hit a road block.
The intrinsic I am trying to implement is rlwimi. The syntax is:
__rwlimi (rA,rS, SH, MB, ME);
rA is the output register.
rS is the input.
SH is the shift value; MB and ME are mask begin and mask end values.
The problem is that the only valid values SH, MB and ME are constant
integers from 1 to 31 inclusively. I have an instruction pattern which
accepts valid calls like:
r2 = __rlwimi (r, arg, 3, 5, 8);
This is cool. The next step was getting:
r2 = __rlwimi (r, arg, 789, 5, 8);
to correctly flag that 789 was not a valid value. I did that by calling
TREE_CODE on the argument, checking to see if it is INTEGER_CST, and
then using compare_tree_int to see the constant value. This is all
cool.
The problem is this:
const int shift = 3;
r2 = __rlwimi (r, arg, shift, 5, 8);
When I get the tree for the third arg, it is of type NOP_EXPR. I tried
just calling default_conversion() from c-typeck.c as an experiment,
knowing that it is C-specific. However, it still came out a NOP_EXPR.
Our competition handles this case just fine.
This is just one example; there are others even worse:
enum tests {
t1, t2, t3, t4, t5
};
r2 = __rlwimi(r, arg, t3, 5, 8);
or
const int foo = 5;
const int *shiftPtr = &foo;
r2 = __rlwimi (r, arg, *shiftPtr, 5, 8);
etc.
(not to mention Ada or Fortran constructs)
How can I safely:
- Determine if a value is really a compile-time constant?
- Get the value of that constant?
Or, alternatively, is there a hook in the front-end parser that I can
tie into to flag the error at parse time?
Syd Polk
Apple Computer
Technology EPM, Mac OS X Development Tools
+1 408 974-0577