Marcello Maggioni
2013-Sep-21 11:43 UTC
[LLVMdev] Inserting a custom switch instruction implementation in backend
Hi, in implementing a backend for a target we work on, I ended up needing to lower the switch instruction in a very specific way that is quite different from the standard llvm way with the decision trees. The custom implementation wants to get rid of the decision blocks that llvm generates between the actual cases basic blocks and the switch root block. What I do currently is basically deleting these blocks manually and moving all the successors (updating the PHIs) to the switch root block and splicing the instructions in the decision blocks into the switch root block manually and then proceed to the removal of these blocks. This seems to work fine, but is a solution that I not like very much. I would prefer being able to lower the switch instructions in my own way directly instead of having to let llvm do it its own way and "morph" the result into my own. There is a clean way to custom lower the switch instruction in the backend without substituting the entire SelectionDAGBuilder? Cheers, Marcello
Anton Korobeynikov
2013-Sep-21 16:59 UTC
[LLVMdev] Inserting a custom switch instruction implementation in backend
Hello Probably the easiest way for you is to lower switch instructions via IR-to-IR pass in the way you want. On Sat, Sep 21, 2013 at 3:43 PM, Marcello Maggioni <marcello at codeplay.com> wrote:> Hi, > > in implementing a backend for a target we work on, I ended up needing to > lower the switch instruction in a very specific way that is quite different > from the standard llvm way with the decision trees. > > The custom implementation wants to get rid of the decision blocks that llvm > generates between the actual cases basic blocks and the switch root block. > What I do currently is basically deleting these blocks manually and moving > all the successors (updating the PHIs) to the switch root block and splicing > the instructions in the decision blocks into the switch root block manually > and then proceed to the removal of these blocks. > > This seems to work fine, but is a solution that I not like very much. I > would prefer being able to lower the switch instructions in my own way > directly instead of having to let llvm do it its own way and "morph" the > result into my own. > > There is a clean way to custom lower the switch instruction in the backend > without substituting the entire SelectionDAGBuilder? > > Cheers, > Marcello > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Marcello Maggioni
2013-Sep-21 19:30 UTC
[LLVMdev] Inserting a custom switch instruction implementation in backend
I see, the only problem is that I would really enjoy the model of having one basic-block with multiple successors in my lowering and to my understanding the only terminators that support multiple successors are switch and indirectbr. What I would need is really having a single basic block with multiple successors that then I can handle in the backend (that handles the switch in a very special and custom way for this target). Switch of course is the source of my problem and using indirectbr to avoid the switch lowering is still a kind of a hack (because it is not actually an indirectbr, because I have no address involved ...). The only other way I see is removing the switch and lowering manually to a tree of nodes that then I would recognize and remove in the backend, but it is not actually very different from what I'm doing just now. I don't know if there is a cleaner way of handling the switch instruction customly in LLVM at the moment ... Marcello Il 21/09/2013 17:59, Anton Korobeynikov ha scritto:> Hello > > Probably the easiest way for you is to lower switch instructions via > IR-to-IR pass in the way you want. > > On Sat, Sep 21, 2013 at 3:43 PM, Marcello Maggioni > <marcello at codeplay.com> wrote: >> Hi, >> >> in implementing a backend for a target we work on, I ended up needing to >> lower the switch instruction in a very specific way that is quite different >> from the standard llvm way with the decision trees. >> >> The custom implementation wants to get rid of the decision blocks that llvm >> generates between the actual cases basic blocks and the switch root block. >> What I do currently is basically deleting these blocks manually and moving >> all the successors (updating the PHIs) to the switch root block and splicing >> the instructions in the decision blocks into the switch root block manually >> and then proceed to the removal of these blocks. >> >> This seems to work fine, but is a solution that I not like very much. I >> would prefer being able to lower the switch instructions in my own way >> directly instead of having to let llvm do it its own way and "morph" the >> result into my own. >> >> There is a clean way to custom lower the switch instruction in the backend >> without substituting the entire SelectionDAGBuilder? >> >> Cheers, >> Marcello >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
Hal Finkel
2013-Sep-21 22:28 UTC
[LLVMdev] Inserting a custom switch instruction implementation in backend
----- Original Message -----> Hello > > Probably the easiest way for you is to lower switch instructions via > IR-to-IR pass in the way you want.In case it helps, lib/Transforms/Utils/LowerSwitch.cpp does generic switch lowering. You might be able to use that as a base for what you need to do. -Hal> > On Sat, Sep 21, 2013 at 3:43 PM, Marcello Maggioni > <marcello at codeplay.com> wrote: > > Hi, > > > > in implementing a backend for a target we work on, I ended up > > needing to > > lower the switch instruction in a very specific way that is quite > > different > > from the standard llvm way with the decision trees. > > > > The custom implementation wants to get rid of the decision blocks > > that llvm > > generates between the actual cases basic blocks and the switch root > > block. > > What I do currently is basically deleting these blocks manually and > > moving > > all the successors (updating the PHIs) to the switch root block and > > splicing > > the instructions in the decision blocks into the switch root block > > manually > > and then proceed to the removal of these blocks. > > > > This seems to work fine, but is a solution that I not like very > > much. I > > would prefer being able to lower the switch instructions in my own > > way > > directly instead of having to let llvm do it its own way and > > "morph" the > > result into my own. > > > > There is a clean way to custom lower the switch instruction in the > > backend > > without substituting the entire SelectionDAGBuilder? > > > > Cheers, > > Marcello > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > > -- > With best regards, Anton Korobeynikov > Faculty of Mathematics and Mechanics, Saint Petersburg State > University > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Hal Finkel Assistant Computational Scientist Leadership Computing Facility Argonne National Laboratory
Possibly Parallel Threads
- [LLVMdev] Inserting a custom switch instruction implementation in backend
- [LLVMdev] Inserting a custom switch instruction implementation in backend
- [LLVMdev] Predication on SIMD architectures and LLVM
- [LLVMdev] Is it safe to insert instructions in batches into BBs?
- [LLVMdev] Predication on SIMD architectures and LLVM