[llvm-commits] [LLVM] SwitchInst PATCH: Changes in semantics and usage.

Stepan Dyatkovskiy STPWORLD at narod.ru
Tue Jan 24 02:41:40 PST 2012


Hi all. I think, that we need re-factor SwitchInst, since current SwitchInst state blocks any further development in PR1255 direction ("Should enhance LLVM switch instruction to take case ranges"). Please find the attached patch for review.  I quoted my first post notes for this patch:

[post]
I refactored SwitchInst a little bit. The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.

What was done:

1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
[/post]

Thanks!
-Stepan.

23.01.2012, 13:10, "Stepan Dyatkovskiy" <STPWORLD at narod.ru>:
> Hi all.
> I also updated serializing of SwitchInst in BitcodeWriter. Done the same like in other files - replaced low level operands usage with SwitchInst analogues.
> Please find the updated patch in attachment for review.
>
> -Stepan.
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
A non-text attachment was scrubbed...
Name: si-cleanup.patch
Type: application/octet-stream
Size: 40746 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120124/0208b592/attachment.obj>


More information about the llvm-commits mailing list