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