Hi, I'm currently trying to modify LLVM to include runtime checks into X86 binaries. I've looked into some of the possibilities during the phases happening in LLVM and have the impression that inserting runtime checks during selection would be great, since lots of optimizations are already done and I can work directly with X86 instructions. I've read through the documentation for code generation (http://www.llvm.org/docs/CodeGenerator.html) and am unsure if I understand it correctly, because I have trouble figuring out what actually to do in the code to accomplish my aim. There are the tablegen generated functions and custom C++ code (I guess that will be X86DAGToDAGISel::Select(SDValue)) that deal with selection. The runtime checks I want to add concern indirect jumps. So for example for all calls that jump to register values like call eax I want to insert a check ... (some test) ...# perform test jne error_label # jump if test fails call eax # otherwise execute original call So the check is a sequence of instructions before the call instruction. Is it possible to do that at the selection level? If yes, could you give a simple example or some hint how it would be done? I only find examples where exactly one instruction is emitted (and/or returned). Do you think it's the right approach or is there a better place? I'd really appreciate your help. Artjom Kochtchi -- View this message in context: http://www.nabble.com/Selection-of-multiple-instructions-tp24395706p24395706.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On Jul 8, 2009, at 10:16 AM, Artjom Kochtchi wrote:> > Hi, > > I'm currently trying to modify LLVM to include runtime checks into X86 > binaries. I've looked into some of the possibilities during the phases > happening in LLVM and have the impression that inserting runtime > checks > during selection would be great, since lots of optimizations are > already > done and I can work directly with X86 instructions. > > I've read through the documentation for code generation > (http://www.llvm.org/docs/CodeGenerator.html) and am unsure if I > understand > it correctly, because I have trouble figuring out what actually to > do in the > code to accomplish my aim. > > There are the tablegen generated functions and custom C++ code (I > guess that > will be X86DAGToDAGISel::Select(SDValue)) that deal with selection. > > The runtime checks I want to add concern indirect jumps. So for > example for > all calls that jump to register values like > > call eax > > I want to insert a check > > ... (some test) ...# perform test > jne error_label # jump if test fails > call eax # otherwise execute original call > > So the check is a sequence of instructions before the call > instruction. > > Is it possible to do that at the selection level? If yes, could you > give a > simple example or some hint how it would be done? I only find > examples where > exactly one instruction is emitted (and/or returned).It's not. It requires updating CFG. I'd do this as a separate pass. Another possibility is to use the usesCustomDAGSchedInserter hack. That is, isel to a pseudo instruction and expand it to a series of instructions and update cfg at scheduling time. Look for the usesCustomDAGSchedInserter in X86InstrInfo.td and EmitInstrWithCustomInserter in X86ISelLowering.cpp. Evan> > Do you think it's the right approach or is there a better place? > > I'd really appreciate your help. > Artjom Kochtchi > -- > View this message in context: http://www.nabble.com/Selection-of-multiple-instructions-tp24395706p24395706.html > Sent from the LLVM - Dev mailing list archive at Nabble.com. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Evan Cheng-2 wrote:> > It's not. It requires updating CFG. I'd do this as a separate pass. > Another possibility is to use the usesCustomDAGSchedInserter hack.I've looked into this and it appears that a pass is probably better because I want to add the check to every indirect call/jump/branch instruction which -- using the hack -- would lead to rather many pseudo instructions. In the runtime check I need to access the address of the jump target. That's why it probably needs to happen after instruction selection. So is it the right spot to put the pass between selection and scheduling (so the register or memory locations that during runtime will contain the jump target is already known)? Do I just create a PassManager, put my pass in and run it or is there another approach to run passes at more or less arbitrary places? Examples on that are rather sparse... Artjom -- View this message in context: http://www.nabble.com/Selection-of-multiple-instructions-tp24395706p24412862.html Sent from the LLVM - Dev mailing list archive at Nabble.com.