2002-10-28 21:31:48 +00:00
|
|
|
//===-- CodeGen/MachineInstBuilder.h - Simplify creation of MIs -*- C++ -*-===//
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-28 21:31:48 +00:00
|
|
|
//
|
|
|
|
// This file exposes a function named BuildMI, which is useful for dramatically
|
2006-05-04 17:02:51 +00:00
|
|
|
// simplifying how MachineInstr's are created. It allows use of code like this:
|
2002-10-28 21:31:48 +00:00
|
|
|
//
|
2002-10-28 21:43:42 +00:00
|
|
|
// M = BuildMI(X86::ADDrr8, 2).addReg(argVal1).addReg(argVal2);
|
2002-10-28 21:31:48 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINEINSTRBUILDER_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEINSTRBUILDER_H
|
|
|
|
|
2004-02-29 04:55:28 +00:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2006-11-13 23:36:35 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2002-10-28 21:31:48 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2003-01-13 00:18:44 +00:00
|
|
|
class MachineInstrBuilder {
|
2002-10-28 21:31:48 +00:00
|
|
|
MachineInstr *MI;
|
2003-01-13 00:18:44 +00:00
|
|
|
public:
|
2002-10-28 21:31:48 +00:00
|
|
|
MachineInstrBuilder(MachineInstr *mi) : MI(mi) {}
|
|
|
|
|
|
|
|
/// Allow automatic conversion to the machine instruction we are working on.
|
|
|
|
///
|
|
|
|
operator MachineInstr*() const { return MI; }
|
2004-04-01 04:03:10 +00:00
|
|
|
operator MachineBasicBlock::iterator() const { return MI; }
|
2002-10-28 21:31:48 +00:00
|
|
|
|
2002-10-28 21:43:42 +00:00
|
|
|
/// addReg - Add a new virtual register operand...
|
2002-10-28 21:31:48 +00:00
|
|
|
///
|
2006-11-13 23:36:35 +00:00
|
|
|
const
|
|
|
|
MachineInstrBuilder &addReg(int RegNo, bool isDef = false, bool isImp = false,
|
|
|
|
bool isKill = false, bool isDead = false) const {
|
2006-11-10 08:32:14 +00:00
|
|
|
MI->addRegOperand(RegNo, isDef, isImp);
|
2002-10-28 21:31:48 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-02-29 05:06:49 +00:00
|
|
|
/// addImm - Add a new immediate operand.
|
|
|
|
///
|
2006-05-04 18:05:43 +00:00
|
|
|
const MachineInstrBuilder &addImm(int64_t Val) const {
|
|
|
|
MI->addImmOperand(Val);
|
2004-02-29 05:06:49 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2002-10-28 21:31:48 +00:00
|
|
|
|
2002-12-15 08:01:02 +00:00
|
|
|
const MachineInstrBuilder &addMBB(MachineBasicBlock *MBB) const {
|
|
|
|
MI->addMachineBasicBlockOperand(MBB);
|
|
|
|
return *this;
|
|
|
|
}
|
2002-12-25 05:01:18 +00:00
|
|
|
|
|
|
|
const MachineInstrBuilder &addFrameIndex(unsigned Idx) const {
|
|
|
|
MI->addFrameIndexOperand(Idx);
|
|
|
|
return *this;
|
|
|
|
}
|
2003-01-13 00:18:44 +00:00
|
|
|
|
2006-02-25 09:54:52 +00:00
|
|
|
const MachineInstrBuilder &addConstantPoolIndex(unsigned Idx,
|
|
|
|
int Offset = 0) const {
|
|
|
|
MI->addConstantPoolIndexOperand(Idx, Offset);
|
2003-01-13 00:18:44 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2006-04-24 06:42:15 +00:00
|
|
|
const MachineInstrBuilder &addJumpTableIndex(unsigned Idx) const {
|
|
|
|
MI->addJumpTableIndexOperand(Idx);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2003-01-13 00:18:44 +00:00
|
|
|
const MachineInstrBuilder &addGlobalAddress(GlobalValue *GV,
|
2006-02-25 09:54:52 +00:00
|
|
|
int Offset = 0) const {
|
2006-05-04 01:15:02 +00:00
|
|
|
MI->addGlobalAddressOperand(GV, Offset);
|
2003-01-13 00:18:44 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2006-05-04 01:15:02 +00:00
|
|
|
const MachineInstrBuilder &addExternalSymbol(const char *FnName) const{
|
|
|
|
MI->addExternalSymbolOperand(FnName);
|
2003-01-13 00:18:44 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2002-10-28 21:31:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// BuildMI - Builder interface. Specify how to create the initial instruction
|
2002-10-30 01:48:41 +00:00
|
|
|
/// itself. NumOperands is the number of operands to the machine instruction to
|
|
|
|
/// allow for memory efficient representation of machine instructions.
|
2002-10-28 21:31:48 +00:00
|
|
|
///
|
2006-11-13 23:36:35 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(const TargetInstrInfo &TII, int Opcode,
|
|
|
|
unsigned NumOperands) {
|
|
|
|
return MachineInstrBuilder(new MachineInstr(TII, Opcode, NumOperands));
|
2002-10-28 21:31:48 +00:00
|
|
|
}
|
|
|
|
|
2004-05-23 05:04:00 +00:00
|
|
|
/// BuildMI - This version of the builder sets up the first operand as a
|
2002-12-13 09:33:06 +00:00
|
|
|
/// destination virtual register. NumOperands is the number of additional add*
|
2004-05-23 05:04:00 +00:00
|
|
|
/// calls that are expected, not including the destination register.
|
2002-12-13 09:33:06 +00:00
|
|
|
///
|
2006-11-13 23:36:35 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(const TargetInstrInfo &TII, int Opcode,
|
|
|
|
unsigned NumOperands, unsigned DestReg) {
|
|
|
|
return MachineInstrBuilder(new MachineInstr(TII, Opcode, NumOperands+1))
|
2006-09-05 02:31:13 +00:00
|
|
|
.addReg(DestReg, true);
|
2002-12-13 09:33:06 +00:00
|
|
|
}
|
|
|
|
|
2004-05-23 05:04:00 +00:00
|
|
|
/// BuildMI - This version of the builder inserts the newly-built
|
|
|
|
/// instruction before the given position in the given MachineBasicBlock, and
|
|
|
|
/// sets up the first operand as a destination virtual register.
|
|
|
|
/// NumOperands is the number of additional add* calls that are expected,
|
|
|
|
/// not including the destination register.
|
|
|
|
///
|
2004-02-29 04:55:28 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
int Opcode, unsigned NumOperands,
|
|
|
|
unsigned DestReg) {
|
2006-11-13 23:36:35 +00:00
|
|
|
MachineInstr *MI = new MachineInstr(*BB.getParent()->getTarget().
|
|
|
|
getInstrInfo(), Opcode, NumOperands+1);
|
2004-02-29 04:55:28 +00:00
|
|
|
BB.insert(I, MI);
|
2006-09-05 02:31:13 +00:00
|
|
|
return MachineInstrBuilder(MI).addReg(DestReg, true);
|
2004-02-29 04:55:28 +00:00
|
|
|
}
|
|
|
|
|
2004-05-23 05:04:00 +00:00
|
|
|
/// BuildMI - This version of the builder inserts the newly-built
|
|
|
|
/// instruction before the given position in the given MachineBasicBlock, and
|
|
|
|
/// does NOT take a destination register.
|
|
|
|
///
|
2004-02-29 04:55:28 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
int Opcode, unsigned NumOperands) {
|
2006-11-13 23:36:35 +00:00
|
|
|
MachineInstr *MI = new MachineInstr(*BB.getParent()->getTarget().
|
|
|
|
getInstrInfo(), Opcode, NumOperands);
|
2004-02-29 04:55:28 +00:00
|
|
|
BB.insert(I, MI);
|
|
|
|
return MachineInstrBuilder(MI);
|
|
|
|
}
|
|
|
|
|
2004-05-23 05:04:00 +00:00
|
|
|
/// BuildMI - This version of the builder inserts the newly-built
|
|
|
|
/// instruction at the end of the given MachineBasicBlock, and does NOT take a
|
|
|
|
/// destination register.
|
2002-10-30 01:48:41 +00:00
|
|
|
///
|
2003-06-03 15:41:45 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, int Opcode,
|
2002-10-29 23:18:23 +00:00
|
|
|
unsigned NumOperands) {
|
2004-02-29 04:55:28 +00:00
|
|
|
return BuildMI(*BB, BB->end(), Opcode, NumOperands);
|
2002-10-28 21:31:48 +00:00
|
|
|
}
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2004-05-23 05:04:00 +00:00
|
|
|
/// BuildMI - This version of the builder inserts the newly-built
|
|
|
|
/// instruction at the end of the given MachineBasicBlock, and sets up the first
|
|
|
|
/// operand as a destination virtual register. NumOperands is the number of
|
|
|
|
/// additional add* calls that are expected, not including the destination
|
|
|
|
/// register.
|
2002-10-30 01:48:41 +00:00
|
|
|
///
|
2003-06-03 15:41:45 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, int Opcode,
|
2002-10-30 01:48:41 +00:00
|
|
|
unsigned NumOperands, unsigned DestReg) {
|
2004-02-29 04:55:28 +00:00
|
|
|
return BuildMI(*BB, BB->end(), Opcode, NumOperands, DestReg);
|
2002-10-30 01:48:41 +00:00
|
|
|
}
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-10-28 21:31:48 +00:00
|
|
|
#endif
|