X86 merge is complete, eliminate unused code
[oota-llvm.git] / include / llvm / CodeGen / MInstBuilder.h
1 //===-- CodeGen/MInstBuilder.h - Simplify creation of MInstcn's -*- C++ -*-===//
2 //
3 // This file exposes a function named BuildMInst that is useful for dramatically
4 // simplifying how MInstruction's are created.  Instead of using code like this:
5 //
6 //   M = new MInstruction(BB, X86::ADDrr32, DestReg);
7 //   M->addOperand(Arg0Reg, MOperand::Register);
8 //   M->addOperand(Arg1Reg, MOperand::Register);
9 //
10 // we can now use code like this:
11 //
12 //   M = BuildMInst(BB, X86::ADDrr8, DestReg).addReg(Arg0Reg).addReg(Arg1Reg);
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_MINSTBUILDER_H
17 #define LLVM_CODEGEN_MINSTBUILDER_H
18
19 #include "llvm/CodeGen/MInstruction.h"
20
21 struct MInstructionBuilder { 
22   MInstruction *MI;
23
24   MInstructionBuilder(MInstruction *mi) : MI(mi) {}
25
26   /// Allow automatic conversion to the machine instruction we are working on.
27   ///
28   operator MInstruction*() const { return MI; }
29
30   /// addReg - Add a new register operand...
31   ///
32   MInstructionBuilder &addReg(unsigned RegNo) {
33     MI->addOperand(RegNo, MOperand::Register);
34     return *this;
35   }
36
37   /// addSImm - Add a new sign extended immediate operand...
38   ///
39   MInstructionBuilder &addSImm(int Val) {
40     MI->addOperand(Val, MOperand::SignExtImmediate);
41     return *this;
42   }
43
44   /// addZImm - Add a new zero extended immediate operand...
45   ///
46   MInstructionBuilder &addZImm(unsigned Val) {
47     MI->addOperand(Val, MOperand::ZeroExtImmediate);
48     return *this;
49   }
50
51   /// addPCDisp - Add a PC Relative Displacement operand...
52   ///
53   MInstructionBuilder &addPCDisp(int Disp) {
54     MI->addOperand(Disp, MOperand::PCRelativeDisp);
55     return *this;
56   }
57 };
58
59 /// BuildMInst - Builder interface.  Specify how to create the initial
60 /// instruction itself.
61 ///
62 inline MInstructionBuilder BuildMInst(unsigned Opcode, unsigned DestReg = 0) {
63   return MInstructionBuilder(new MInstruction(Opcode, DestReg));
64 }
65
66 inline MInstructionBuilder BuildMInst(MBasicBlock *BB, unsigned Opcode,
67                                unsigned DestReg = 0) {
68   return MInstructionBuilder(new MInstruction(BB, Opcode, DestReg));
69 }
70                                 
71 #endif