On Jul 1, 2006, at 12:54 AM, kernel coder wrote:
I'm having trouble in understanding the term sequnce in an insn
chain.get_insns() actually returns the current instruction.
I'd recommend reading the code:
/* Emission of insns (adding them to the doubly-linked list). */
/* Return the first insn of the current sequence or current
function. */
rtx
get_insns (void)
{
return first_insn;
}
/* Specify a new insn as the first in the chain. */
void
set_first_insn (rtx insn)
{
gcc_assert (!PREV_INSN (insn));
first_insn = insn;
}
/* Return the last insn emitted in current sequence or current
function. */
rtx
get_last_insn (void)
{
return last_insn;
}
/* Specify a new insn as the last in the chain. */
void
set_last_insn (rtx insn)
{
gcc_assert (!NEXT_INSN (insn));
last_insn = insn;
}
It can help form a basis from which you can build your understanding
of the code.
What does the term "sequence" mean,as the name suggests it must be
a sequence of
instructions
Ok, so you know what it means...
Another way would be to read the code. If you read the code:
push_topmost_sequence (void)
{
struct sequence_stack *stack, *top = NULL;
start_sequence ();
for (stack = seq_stack; stack; stack = stack->next)
top = stack;
first_insn = top->first;
and then first_insn:
#define first_insn (cfun->emit->x_first_insn)
and then if you find x_first_insn:
/* The ends of the doubly-linked chain of rtl for the current
function.
Both are reset to null at the start of rtl generation for the
function.
start_sequence saves both of these on `sequence_stack' and then
starts
a new, nested sequence of insns. */
rtx x_first_insn;
rtx x_last_insn;
and then you can read the comments. The term doubly linked list
should help understand the term sequence. Also, if you read the
code, the code can also help understand the term sequence, just M-
grep sequence *.c and read it all. And lastly, to understand the
term sequence you can google("sequence") and read how it is used, as
our use of the term is no different that every other use of the term.
but in an instruction chain,a single element will be an instruction,
Unless you have a reference to a member of a container and you can
find the container from the reference. I'd recommend some books on
data structures and programming if your unfamiliar with data structures.
When push_topmost_sequence is called ,it should push a sequence of
instructions ,but an element of insn chain is a single
instruction,then which sequence will be pushed.
See above. In addition, another way to understand the code would be
to set a breakpoint on whatever you're interested in and single step
it in your favorite debugger. You can then see what it does, how it
does it, what data structures are in play, the comments around that
code and so on.
Suppose following is a sequnce of instructions.
1) entry_insns = get_insns ();
2) push_topmost_sequence ();
3) emit_insn_after (entry_insns, get_insns ());
4) pop_topmost_sequence ();
In 1) current insn is saved in entry_insns. what is happening in In
2).Is sequence differnet from insn in an insn chain ,any example will
be helpful.
If you read the comments in the code:
/* Put the insns after the NOTE that starts the function.
If this is inside a start_sequence, make the outer-level insn
chain current, so the code is placed at the start of the
function. */
push_topmost_sequence ();
emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
pop_topmost_sequence ();
return temp;
and:
/* Put the insns after the NOTE that starts the function. If this
is inside a start_sequence, make the outer-level insn chain
current, so
the code is placed at the start of the function. */
push_topmost_sequence ();
emit_insn_after (seq, entry_of_function ());
pop_topmost_sequence ();
do they help clarify things?
But does get_insns() also increaments the current instruction pointer.
Is is documented to do that? Is there code in the function to do
that? Hint, here is everything you need to answer those questions:
/* Return the first insn of the current sequence or current
function. */
rtx
get_insns (void)
{
return first_insn;
}
If you don't use emacs, I'd recommend it. If you don't know about
M-., I'd recommend reading up on it, to use it, just go the the call
of the function your interested in, such s get_insns and then hit
M-., and then presto, you're there. Just be sure to do a make TAGS
once. You can then read up on what it is and does.
Now again which sequnce is being poped out in 4).
In the idiom:
push
pop
the pop, pops the thing on top the stack, in the above case, it would
be the thing just pushed. If you don't understand that, I'd
recommend an intro to CS type book, then a dara structures book, and
algorithms book, then an advanced data structures book. We can't
help with this sort of background.
Asking on this list those questions that can be answered by google,
CS books, the code, comments in the code and the documentation is
generally off-topic.