2002-10-28 22:31:48 +01:00
|
|
|
//===-- CodeGen/MachineInstBuilder.h - Simplify creation of MIs -*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// This file exposes a function named BuildMI, which is useful for dramatically
|
|
|
|
// simplifying how MachineInstr's are created. Instead of using code like this:
|
|
|
|
//
|
|
|
|
// M = new MachineInstr(X86::ADDrr32);
|
|
|
|
// M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, argVal1);
|
|
|
|
// M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, argVal2);
|
|
|
|
//
|
|
|
|
// we can now use code like this:
|
|
|
|
//
|
2002-10-28 22:43:42 +01:00
|
|
|
// M = BuildMI(X86::ADDrr8, 2).addReg(argVal1).addReg(argVal2);
|
2002-10-28 22:31:48 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINEINSTRBUILDER_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEINSTRBUILDER_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
|
2002-11-17 22:56:10 +01:00
|
|
|
struct MachineInstrBuilder {
|
2002-10-28 22:31:48 +01:00
|
|
|
MachineInstr *MI;
|
|
|
|
|
|
|
|
MachineInstrBuilder(MachineInstr *mi) : MI(mi) {}
|
|
|
|
|
|
|
|
/// Allow automatic conversion to the machine instruction we are working on.
|
|
|
|
///
|
|
|
|
operator MachineInstr*() const { return MI; }
|
|
|
|
|
2002-10-28 22:43:42 +01:00
|
|
|
/// addReg - Add a new virtual register operand...
|
2002-10-28 22:31:48 +01:00
|
|
|
///
|
2002-11-17 22:56:10 +01:00
|
|
|
const MachineInstrBuilder &addReg(int RegNo,
|
|
|
|
MOTy::UseType Ty = MOTy::Use) const {
|
|
|
|
MI->addRegOperand(RegNo, Ty);
|
2002-10-28 22:31:48 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2002-11-14 23:32:30 +01:00
|
|
|
/// addReg - Add an LLVM value that is to be used as a register...
|
2002-10-28 22:43:42 +01:00
|
|
|
///
|
2002-11-17 22:56:10 +01:00
|
|
|
const MachineInstrBuilder &addReg(Value *V,
|
|
|
|
MOTy::UseType Ty = MOTy::Use) const {
|
|
|
|
MI->addRegOperand(V, Ty);
|
2002-10-28 22:31:48 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2002-11-14 23:32:30 +01:00
|
|
|
/// addClobber - Assert that this MI is going to clobber a specific
|
|
|
|
/// register. Useful for instructions that always clobber certain hard regs.
|
|
|
|
/// (Same as addReg(RegNo, true) but shorter and more obvious).
|
|
|
|
///
|
2002-11-17 22:02:42 +01:00
|
|
|
const MachineInstrBuilder &addClobber(int RegNo) const {
|
2002-11-14 23:32:30 +01:00
|
|
|
MI->addRegOperand(RegNo, true);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2002-10-28 22:43:42 +01:00
|
|
|
/// addPCDisp - Add an LLVM value to be treated as a PC relative
|
|
|
|
/// displacement...
|
|
|
|
///
|
2002-11-17 22:02:42 +01:00
|
|
|
const MachineInstrBuilder &addPCDisp(Value *V) const {
|
2002-10-28 22:31:48 +01:00
|
|
|
MI->addPCDispOperand(V);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2002-10-28 22:43:42 +01:00
|
|
|
/// addMReg - Add a machine register operand...
|
|
|
|
///
|
2002-11-17 22:56:10 +01:00
|
|
|
const MachineInstrBuilder &addMReg(int Reg,
|
|
|
|
MOTy::UseType Ty = MOTy::Use) const {
|
|
|
|
MI->addMachineRegOperand(Reg, Ty);
|
2002-10-28 22:31:48 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addSImm - Add a new sign extended immediate operand...
|
|
|
|
///
|
2002-11-17 22:02:42 +01:00
|
|
|
const MachineInstrBuilder &addSImm(int64_t val) const {
|
2002-10-28 22:31:48 +01:00
|
|
|
MI->addSignExtImmOperand(val);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addZImm - Add a new zero extended immediate operand...
|
|
|
|
///
|
2002-11-17 22:02:42 +01:00
|
|
|
const MachineInstrBuilder &addZImm(int64_t Val) const {
|
2002-10-28 22:31:48 +01:00
|
|
|
MI->addZeroExtImmOperand(Val);
|
|
|
|
return *this;
|
|
|
|
}
|
2002-12-15 09:01:02 +01:00
|
|
|
|
|
|
|
const MachineInstrBuilder &addMBB(MachineBasicBlock *MBB) const {
|
|
|
|
MI->addMachineBasicBlockOperand(MBB);
|
|
|
|
return *this;
|
|
|
|
}
|
2002-10-28 22:31:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// BuildMI - Builder interface. Specify how to create the initial instruction
|
2002-10-30 02:48:41 +01:00
|
|
|
/// itself. NumOperands is the number of operands to the machine instruction to
|
|
|
|
/// allow for memory efficient representation of machine instructions.
|
2002-10-28 22:31:48 +01:00
|
|
|
///
|
|
|
|
inline MachineInstrBuilder BuildMI(MachineOpCode Opcode, unsigned NumOperands) {
|
|
|
|
return MachineInstrBuilder(new MachineInstr(Opcode, NumOperands, true, true));
|
|
|
|
}
|
|
|
|
|
2002-12-13 10:33:06 +01:00
|
|
|
/// BuildMI - This version of the builder also sets up the first "operand" as a
|
|
|
|
/// destination virtual register. NumOperands is the number of additional add*
|
|
|
|
/// calls that are expected, it does not include the destination register.
|
|
|
|
///
|
|
|
|
inline MachineInstrBuilder BuildMI(MachineOpCode Opcode, unsigned NumOperands,
|
|
|
|
unsigned DestReg) {
|
|
|
|
return MachineInstrBuilder(new MachineInstr(Opcode, NumOperands+1,
|
|
|
|
true, true)).addReg(DestReg, MOTy::Def);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-30 02:48:41 +01:00
|
|
|
/// BuildMI - This version of the builder inserts the built MachineInstr into
|
|
|
|
/// the specified MachineBasicBlock.
|
|
|
|
///
|
2002-10-30 00:18:23 +01:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, MachineOpCode Opcode,
|
|
|
|
unsigned NumOperands) {
|
|
|
|
return MachineInstrBuilder(new MachineInstr(BB, Opcode, NumOperands));
|
2002-10-28 22:31:48 +01:00
|
|
|
}
|
2002-10-30 00:18:23 +01:00
|
|
|
|
2002-10-30 02:48:41 +01:00
|
|
|
/// BuildMI - This version of the builder inserts the built MachineInstr into
|
|
|
|
/// the specified MachineBasicBlock, and also sets up the first "operand" as a
|
|
|
|
/// destination virtual register. NumOperands is the number of additional add*
|
|
|
|
/// calls that are expected, it does not include the destination register.
|
|
|
|
///
|
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, MachineOpCode Opcode,
|
|
|
|
unsigned NumOperands, unsigned DestReg) {
|
|
|
|
return MachineInstrBuilder(new MachineInstr(BB, Opcode,
|
|
|
|
NumOperands+1)).addReg(DestReg,
|
2002-11-17 22:56:10 +01:00
|
|
|
MOTy::Def);
|
2002-10-30 02:48:41 +01:00
|
|
|
}
|
|
|
|
|
2002-10-28 22:31:48 +01:00
|
|
|
#endif
|