PageRenderTime 240ms CodeModel.GetById 120ms app.highlight 8ms RepoModel.GetById 111ms app.codeStats 0ms

/JIT/opcodes/control.h

http://unladen-swallow.googlecode.com/
C++ Header | 100 lines | 62 code | 17 blank | 21 comment | 0 complexity | 72ff68917c8fa700098be9ef2d9cf585 MD5 | raw file
  1// -*- C++ -*-
  2#ifndef OPCODE_CONTROL_H_
  3#define OPCODE_CONTROL_H_
  4
  5#ifndef __cplusplus
  6#error This header expects to be included only in C++ source
  7#endif
  8
  9#include "llvm/Support/IRBuilder.h"
 10#include "llvm/Support/TargetFolder.h"
 11
 12namespace llvm {
 13    class BasicBlock;
 14    class Value;
 15}
 16
 17namespace py {
 18
 19class LlvmFunctionBuilder;
 20class LlvmFunctionState;
 21
 22// This class contains most control flow opcodes.
 23// break and continue can be found in OpcodeLoop.
 24class OpcodeControl
 25{
 26public:
 27    OpcodeControl(LlvmFunctionBuilder *fbuilder);
 28
 29    void RAISE_VARARGS_ZERO();
 30    void RAISE_VARARGS_ONE();
 31    void RAISE_VARARGS_TWO();
 32    void RAISE_VARARGS_THREE();
 33
 34    void RETURN_VALUE();
 35    void YIELD_VALUE();
 36
 37    void JUMP_FORWARD(llvm::BasicBlock *target, llvm::BasicBlock *fallthrough) {
 38        this->JUMP_ABSOLUTE(target, fallthrough);
 39    }
 40    void JUMP_ABSOLUTE(llvm::BasicBlock *target, llvm::BasicBlock *fallthrough);
 41
 42    void POP_JUMP_IF_FALSE(unsigned target_idx,
 43                           unsigned fallthrough_idx,
 44                           llvm::BasicBlock *target,
 45                           llvm::BasicBlock *fallthrough);
 46    void POP_JUMP_IF_TRUE(unsigned target_idx,
 47                          unsigned fallthrough_idx,
 48                          llvm::BasicBlock *target,
 49                          llvm::BasicBlock *fallthrough);
 50    void JUMP_IF_FALSE_OR_POP(unsigned target_idx,
 51                              unsigned fallthrough_idx,
 52                              llvm::BasicBlock *target,
 53                              llvm::BasicBlock *fallthrough);
 54    void JUMP_IF_TRUE_OR_POP(unsigned target_idx,
 55                             unsigned fallthrough_idx,
 56                             llvm::BasicBlock *target,
 57                             llvm::BasicBlock *fallthrough);
 58
 59private:
 60    typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
 61
 62    // Set exception information and jump to exception handling. The
 63    // arguments can be Value*'s representing NULL to implement the
 64    // four forms of the 'raise' statement. Steals all references.
 65    void DoRaise(llvm::Value *exc_type, llvm::Value *exc_inst,
 66                 llvm::Value *exc_tb);
 67
 68    // Helper function for the POP_JUMP_IF_{TRUE,FALSE} and
 69    // JUMP_IF_{TRUE,FALSE}_OR_POP, used for omitting untake branches.
 70    // If sufficient data is availble, we made decide to omit one side of a
 71    // conditional branch, replacing that code with a jump to the interpreter.
 72    // If sufficient data is available:
 73    //      - set true_block or false_block to a bail-to-interpreter block.
 74    //      - set bail_idx and bail_block to handle bailing.
 75    // If sufficient data is available or we decide not to optimize:
 76    //      - leave true_block and false_block alone.
 77    //      - bail_idx will be 0, bail_block will be NULL.
 78    //
 79    // Out parameters: true_block, false_block, bail_idx, bail_block.
 80    void GetPyCondBranchBailBlock(unsigned true_idx,
 81                                  llvm::BasicBlock **true_block,
 82                                  unsigned false_idx,
 83                                  llvm::BasicBlock **false_block,
 84                                  unsigned *bail_idx,
 85                                  llvm::BasicBlock **bail_block);
 86
 87    // Helper function for the POP_JUMP_IF_{TRUE,FALSE} and
 88    // JUMP_IF_{TRUE,FALSE}_OR_POP. Fill in the bail block for these opcodes
 89    // that was obtained from GetPyCondBranchBailBlock().
 90    void FillPyCondBranchBailBlock(llvm::BasicBlock *bail_to,
 91                                   unsigned bail_idx);
 92
 93    LlvmFunctionBuilder *fbuilder_;
 94    LlvmFunctionState *state_;
 95    BuilderT &builder_;
 96};
 97
 98}
 99
100#endif /* OPCODE_CONTROL_H_ */