Movatterモバイル変換


[0]ホーム

URL:


Next:, Up:Using the RTL SSA framework to change instructions   [Contents][Index]


13.21.8.1 Changing One RTL SSA Instruction

Before making a change, passes should first use a statement like thefollowing:

auto attempt = crtl->ssa->new_change_attempt ();

Here,attempt is an RAII object that should remain in scopefor the entire change attempt. It automatically frees temporarymemory related to the changes when it goes out of scope.

Next, the pass should create anrtl_ssa::insn_change objectfor the instruction that it wants to change. This object specifiesseveral things:

If a pass was attempting to change all these properties of an instructioninsn, it might do something like this:

rtl_ssa::insn_change change (insn);change.new_defs = …;change.new_uses = …;change.move_range = …;

Thisrtl_ssa::insn_change only describes something that thepassmight do; at this stage, nothing has actually changed.

As noted above, the defaultmove_range requires the instructionto remain where it is. At the other extreme, it is possible to allowthe instruction to move anywhere within its extended basic block,provided that all the new uses and definitions can be performedat the new location. The way to do this is:

change.move_range = insn->ebb ()->insn_range ();

In either case, the next step is to make sure that move range isconsistent with the new uses and definitions. The way to do this is:

if (!rtl_ssa::restrict_movement (change))  return false;

This function tries to limitmove_range to a range of instructionsat whichnew_uses andnew_defs can be correctly performed.It returns true on success or false if no suitable location exists.

The pass should also tentatively change the pattern of the instructionto whatever form the pass wants the instruction to have. This should usethe facilities provided byrecog.cc. For example:

rtl_insn *rtl = insn->rtl ();insn_change_watermark watermark;validate_change (rtl, &PATTERN (rtl), new_pat, 1);

will tentatively replaceinsn’s pattern withnew_pat.

These changes and the construction of thertl_ssa::insn_changecan happen in either order or be interleaved.

After the tentative changes to the instruction are complete,the pass should check whether the new pattern matches a targetinstruction or satisfies the requirements of an inline asm:

if (!rtl_ssa::recog (attempt, change))  return false;

This step might change the instruction pattern further in order tomake it match. It might also add new definitions or restrict the rangeof the move. For example, if the new pattern did not match in its originalform, but could be made to match by adding a clobber of the flagsregister,rtl_ssa::recog will check whether the flags registeris free at an appropriate point. If so, it will add a clobber of theflags register tonew_defs and restrictmove_range tothe locations at which the flags register can be safely clobbered.

Even if the proposed new instruction is valid according tortl_ssa::recog, the change might not be worthwhile.For example, when optimizing for speed, the new instruction mightturn out to be slower than the original one. When optimizing forsize, the new instruction might turn out to be bigger than theoriginal one.

Passes should check for this case usingchange_is_worthwhile.For example:

if (!rtl_ssa::change_is_worthwhile (change))  return false;

If the change passes this test too then the pass can perform the change using:

confirm_change_group ();crtl->ssa->change_insn (change);

Putting all this together, the change has the following form:

auto attempt = crtl->ssa->new_change_attempt ();rtl_ssa::insn_change change (insn);change.new_defs = …;change.new_uses = …;change.move_range = …;if (!rtl_ssa::restrict_movement (change))  return false;insn_change_watermark watermark;// Use validate_change etc. to change INSN's pattern.…if (!rtl_ssa::recog (attempt, change)    || !rtl_ssa::change_is_worthwhile (change))  return false;confirm_change_group ();crtl->ssa->change_insn (change);

Next:Changing Multiple RTL SSA Instructions, Up:Using the RTL SSA framework to change instructions   [Contents][Index]


[8]ページ先頭

©2009-2026 Movatter.jp