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
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file 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
|
|
|
|
|
2006-11-13 23:36:35 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2013-01-09 01:02:19 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstrBundle.h"
|
2010-10-12 18:00:49 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2002-10-28 21:31:48 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2011-06-28 19:10:37 +00:00
|
|
|
class MCInstrDesc;
|
2010-01-13 00:00:24 +00:00
|
|
|
class MDNode;
|
2006-11-27 23:37:22 +00:00
|
|
|
|
2009-05-13 21:33:08 +00:00
|
|
|
namespace RegState {
|
|
|
|
enum {
|
|
|
|
Define = 0x2,
|
|
|
|
Implicit = 0x4,
|
|
|
|
Kill = 0x8,
|
|
|
|
Dead = 0x10,
|
2009-06-30 08:49:04 +00:00
|
|
|
Undef = 0x20,
|
|
|
|
EarlyClobber = 0x40,
|
2010-02-06 02:28:32 +00:00
|
|
|
Debug = 0x80,
|
2012-06-07 04:43:52 +00:00
|
|
|
InternalRead = 0x100,
|
2012-03-04 18:40:30 +00:00
|
|
|
DefineNoRead = Define | Undef,
|
2009-05-13 21:33:08 +00:00
|
|
|
ImplicitDefine = Implicit | Define,
|
|
|
|
ImplicitKill = Implicit | Kill
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2003-01-13 00:18:44 +00:00
|
|
|
class MachineInstrBuilder {
|
2012-12-19 19:19:01 +00:00
|
|
|
MachineFunction *MF;
|
2002-10-28 21:31:48 +00:00
|
|
|
MachineInstr *MI;
|
2003-01-13 00:18:44 +00:00
|
|
|
public:
|
2012-12-19 19:19:01 +00:00
|
|
|
MachineInstrBuilder() : MF(0), MI(0) {}
|
|
|
|
|
|
|
|
/// Create a MachineInstrBuilder for manipulating an existing instruction.
|
|
|
|
/// F must be the machine function that was used to allocate I.
|
|
|
|
MachineInstrBuilder(MachineFunction &F, MachineInstr *I) : MF(&F), MI(I) {}
|
2002-10-28 21:31:48 +00:00
|
|
|
|
|
|
|
/// Allow automatic conversion to the machine instruction we are working on.
|
|
|
|
///
|
|
|
|
operator MachineInstr*() const { return MI; }
|
2011-04-29 05:24:07 +00:00
|
|
|
MachineInstr *operator->() 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
|
2009-05-13 21:33:08 +00:00
|
|
|
MachineInstrBuilder &addReg(unsigned RegNo, unsigned flags = 0,
|
|
|
|
unsigned SubReg = 0) const {
|
|
|
|
assert((flags & 0x1) == 0 &&
|
|
|
|
"Passing in 'true' to addReg is forbidden! Use enums instead.");
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateReg(RegNo,
|
|
|
|
flags & RegState::Define,
|
|
|
|
flags & RegState::Implicit,
|
|
|
|
flags & RegState::Kill,
|
|
|
|
flags & RegState::Dead,
|
|
|
|
flags & RegState::Undef,
|
|
|
|
flags & RegState::EarlyClobber,
|
|
|
|
SubReg,
|
|
|
|
flags & RegState::Debug,
|
|
|
|
flags & RegState::InternalRead));
|
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 {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateImm(Val));
|
2004-02-29 05:06:49 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2002-10-28 21:31:48 +00:00
|
|
|
|
2011-06-24 20:46:11 +00:00
|
|
|
const MachineInstrBuilder &addCImm(const ConstantInt *Val) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateCImm(Val));
|
2011-06-24 20:46:11 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2008-09-12 18:08:03 +00:00
|
|
|
const MachineInstrBuilder &addFPImm(const ConstantFP *Val) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateFPImm(Val));
|
2008-08-26 23:19:23 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-06-25 01:16:22 +00:00
|
|
|
const MachineInstrBuilder &addMBB(MachineBasicBlock *MBB,
|
|
|
|
unsigned char TargetFlags = 0) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateMBB(MBB, TargetFlags));
|
2002-12-15 08:01:02 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2002-12-25 05:01:18 +00:00
|
|
|
|
2011-05-17 18:29:21 +00:00
|
|
|
const MachineInstrBuilder &addFrameIndex(int Idx) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateFI(Idx));
|
2002-12-25 05:01:18 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2003-01-13 00:18:44 +00:00
|
|
|
|
2006-02-25 09:54:52 +00:00
|
|
|
const MachineInstrBuilder &addConstantPoolIndex(unsigned Idx,
|
2009-06-25 01:16:22 +00:00
|
|
|
int Offset = 0,
|
|
|
|
unsigned char TargetFlags = 0) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateCPI(Idx, Offset, TargetFlags));
|
2003-01-13 00:18:44 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-08-07 18:56:39 +00:00
|
|
|
const MachineInstrBuilder &addTargetIndex(unsigned Idx, int64_t Offset = 0,
|
|
|
|
unsigned char TargetFlags = 0) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateTargetIndex(Idx, Offset,
|
|
|
|
TargetFlags));
|
2012-08-07 18:56:39 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-06-25 01:16:22 +00:00
|
|
|
const MachineInstrBuilder &addJumpTableIndex(unsigned Idx,
|
|
|
|
unsigned char TargetFlags = 0) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateJTI(Idx, TargetFlags));
|
2006-04-24 06:42:15 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
const MachineInstrBuilder &addGlobalAddress(const GlobalValue *GV,
|
2009-06-25 01:16:22 +00:00
|
|
|
int64_t Offset = 0,
|
|
|
|
unsigned char TargetFlags = 0) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateGA(GV, Offset, TargetFlags));
|
2003-01-13 00:18:44 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
Teach DAGCombine to fold constant offsets into GlobalAddress nodes,
and add a TargetLowering hook for it to use to determine when this
is legal (i.e. not in PIC mode, etc.)
This allows instruction selection to emit folded constant offsets
in more cases, such as the included testcase, eliminating the need
for explicit arithmetic instructions.
This eliminates the need for the C++ code in X86ISelDAGToDAG.cpp
that attempted to achieve the same effect, but wasn't as effective.
Also, fix handling of offsets in GlobalAddressSDNodes in several
places, including changing GlobalAddressSDNode's offset from
int to int64_t.
The Mips, Alpha, Sparc, and CellSPU targets appear to be
unaware of GlobalAddress offsets currently, so set the hook to
false on those targets.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-10-18 02:06:02 +00:00
|
|
|
const MachineInstrBuilder &addExternalSymbol(const char *FnName,
|
2009-06-25 01:16:22 +00:00
|
|
|
unsigned char TargetFlags = 0) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateES(FnName, TargetFlags));
|
2003-01-13 00:18:44 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2008-12-03 18:11:40 +00:00
|
|
|
|
2012-12-20 18:08:09 +00:00
|
|
|
const MachineInstrBuilder &addBlockAddress(const BlockAddress *BA,
|
|
|
|
int64_t Offset = 0,
|
|
|
|
unsigned char TargetFlags = 0) const {
|
|
|
|
MI->addOperand(*MF, MachineOperand::CreateBA(BA, Offset, TargetFlags));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-01-16 19:22:00 +00:00
|
|
|
const MachineInstrBuilder &addRegMask(const uint32_t *Mask) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateRegMask(Mask));
|
2012-01-16 19:22:00 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-09-25 20:36:54 +00:00
|
|
|
const MachineInstrBuilder &addMemOperand(MachineMemOperand *MMO) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addMemOperand(*MF, MMO);
|
2008-12-03 18:11:40 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2009-02-18 05:45:50 +00:00
|
|
|
|
2010-10-12 18:00:49 +00:00
|
|
|
const MachineInstrBuilder &setMemRefs(MachineInstr::mmo_iterator b,
|
|
|
|
MachineInstr::mmo_iterator e) const {
|
|
|
|
MI->setMemRefs(b, e);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-18 05:45:50 +00:00
|
|
|
const MachineInstrBuilder &addOperand(const MachineOperand &MO) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MO);
|
2009-02-18 05:45:50 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2010-01-13 00:00:24 +00:00
|
|
|
|
2010-02-26 19:39:56 +00:00
|
|
|
const MachineInstrBuilder &addMetadata(const MDNode *MD) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateMetadata(MD));
|
2010-01-13 00:00:24 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2010-03-13 08:16:25 +00:00
|
|
|
|
|
|
|
const MachineInstrBuilder &addSym(MCSymbol *Sym) const {
|
2012-12-19 22:35:46 +00:00
|
|
|
MI->addOperand(*MF, MachineOperand::CreateMCSymbol(Sym));
|
2010-03-13 08:16:25 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2010-10-12 18:00:49 +00:00
|
|
|
|
2011-03-05 18:43:20 +00:00
|
|
|
const MachineInstrBuilder &setMIFlags(unsigned Flags) const {
|
|
|
|
MI->setFlags(Flags);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MachineInstrBuilder &setMIFlag(MachineInstr::MIFlag Flag) const {
|
|
|
|
MI->setFlag(Flag);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-10-12 18:00:49 +00:00
|
|
|
// Add a displacement from an existing MachineOperand with an added offset.
|
2012-10-11 00:15:48 +00:00
|
|
|
const MachineInstrBuilder &addDisp(const MachineOperand &Disp, int64_t off,
|
|
|
|
unsigned char TargetFlags = 0) const {
|
2010-10-12 18:00:49 +00:00
|
|
|
switch (Disp.getType()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unhandled operand type in addDisp()");
|
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
return addImm(Disp.getImm() + off);
|
2012-10-11 00:15:48 +00:00
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
|
|
|
// If caller specifies new TargetFlags then use it, otherwise the
|
|
|
|
// default behavior is to copy the target flags from the existing
|
|
|
|
// MachineOperand. This means if the caller wants to clear the
|
|
|
|
// target flags it needs to do so explicitly.
|
|
|
|
if (TargetFlags)
|
|
|
|
return addGlobalAddress(Disp.getGlobal(), Disp.getOffset() + off,
|
|
|
|
TargetFlags);
|
|
|
|
return addGlobalAddress(Disp.getGlobal(), Disp.getOffset() + off,
|
|
|
|
Disp.getTargetFlags());
|
|
|
|
}
|
2010-10-12 18:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-20 22:54:02 +00:00
|
|
|
|
|
|
|
/// Copy all the implicit operands from OtherMI onto this one.
|
|
|
|
const MachineInstrBuilder ©ImplicitOps(const MachineInstr *OtherMI) {
|
|
|
|
MI->copyImplicitOps(*MF, OtherMI);
|
|
|
|
return *this;
|
|
|
|
}
|
2002-10-28 21:31:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// BuildMI - Builder interface. Specify how to create the initial instruction
|
2006-11-27 23:37:22 +00:00
|
|
|
/// itself.
|
2002-10-28 21:31:48 +00:00
|
|
|
///
|
2009-02-03 00:55:04 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineFunction &MF,
|
|
|
|
DebugLoc DL,
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &MCID) {
|
2012-12-19 19:19:01 +00:00
|
|
|
return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, DL));
|
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
|
2006-11-27 23:37:22 +00:00
|
|
|
/// destination virtual register.
|
2002-12-13 09:33:06 +00:00
|
|
|
///
|
2009-02-03 00:55:04 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineFunction &MF,
|
|
|
|
DebugLoc DL,
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &MCID,
|
2009-02-03 00:55:04 +00:00
|
|
|
unsigned DestReg) {
|
2012-12-19 19:19:01 +00:00
|
|
|
return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, DL))
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(DestReg, RegState::Define);
|
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.
|
|
|
|
///
|
2009-02-03 00:55:04 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
DebugLoc DL,
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &MCID,
|
2009-02-03 00:55:04 +00:00
|
|
|
unsigned DestReg) {
|
2012-12-19 19:19:01 +00:00
|
|
|
MachineFunction &MF = *BB.getParent();
|
|
|
|
MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
|
2004-02-29 04:55:28 +00:00
|
|
|
BB.insert(I, MI);
|
2012-12-19 19:19:01 +00:00
|
|
|
return MachineInstrBuilder(MF, MI).addReg(DestReg, RegState::Define);
|
2004-02-29 04:55:28 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
|
|
|
|
MachineBasicBlock::instr_iterator I,
|
|
|
|
DebugLoc DL,
|
|
|
|
const MCInstrDesc &MCID,
|
|
|
|
unsigned DestReg) {
|
2012-12-19 19:19:01 +00:00
|
|
|
MachineFunction &MF = *BB.getParent();
|
|
|
|
MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
|
2011-12-14 02:11:42 +00:00
|
|
|
BB.insert(I, MI);
|
2012-12-19 19:19:01 +00:00
|
|
|
return MachineInstrBuilder(MF, MI).addReg(DestReg, RegState::Define);
|
2011-12-14 02:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
|
|
|
|
MachineInstr *I,
|
|
|
|
DebugLoc DL,
|
|
|
|
const MCInstrDesc &MCID,
|
|
|
|
unsigned DestReg) {
|
|
|
|
if (I->isInsideBundle()) {
|
|
|
|
MachineBasicBlock::instr_iterator MII = I;
|
|
|
|
return BuildMI(BB, MII, DL, MCID, DestReg);
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineBasicBlock::iterator MII = I;
|
|
|
|
return BuildMI(BB, MII, DL, MCID, DestReg);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
///
|
2009-02-03 00:55:04 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
DebugLoc DL,
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &MCID) {
|
2012-12-19 19:19:01 +00:00
|
|
|
MachineFunction &MF = *BB.getParent();
|
|
|
|
MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
|
2004-02-29 04:55:28 +00:00
|
|
|
BB.insert(I, MI);
|
2012-12-19 19:19:01 +00:00
|
|
|
return MachineInstrBuilder(MF, MI);
|
2004-02-29 04:55:28 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
|
|
|
|
MachineBasicBlock::instr_iterator I,
|
|
|
|
DebugLoc DL,
|
|
|
|
const MCInstrDesc &MCID) {
|
2012-12-19 19:19:01 +00:00
|
|
|
MachineFunction &MF = *BB.getParent();
|
|
|
|
MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
|
2011-12-14 02:11:42 +00:00
|
|
|
BB.insert(I, MI);
|
2012-12-19 19:19:01 +00:00
|
|
|
return MachineInstrBuilder(MF, MI);
|
2011-12-14 02:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
|
|
|
|
MachineInstr *I,
|
|
|
|
DebugLoc DL,
|
|
|
|
const MCInstrDesc &MCID) {
|
|
|
|
if (I->isInsideBundle()) {
|
|
|
|
MachineBasicBlock::instr_iterator MII = I;
|
|
|
|
return BuildMI(BB, MII, DL, MCID);
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineBasicBlock::iterator MII = I;
|
|
|
|
return BuildMI(BB, MII, DL, MCID);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
///
|
2009-02-03 00:55:04 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB,
|
|
|
|
DebugLoc DL,
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &MCID) {
|
|
|
|
return BuildMI(*BB, BB->end(), DL, MCID);
|
2009-02-03 00:55:04 +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
|
2009-09-20 04:03:25 +00:00
|
|
|
/// operand as a destination virtual register.
|
2002-10-30 01:48:41 +00:00
|
|
|
///
|
2009-02-03 00:55:04 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB,
|
|
|
|
DebugLoc DL,
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &MCID,
|
2009-02-03 00:55:04 +00:00
|
|
|
unsigned DestReg) {
|
2011-06-28 19:10:37 +00:00
|
|
|
return BuildMI(*BB, BB->end(), DL, MCID, DestReg);
|
2009-02-03 00:55:04 +00:00
|
|
|
}
|
2002-10-30 01:48:41 +00:00
|
|
|
|
2009-05-13 21:33:08 +00:00
|
|
|
inline unsigned getDefRegState(bool B) {
|
|
|
|
return B ? RegState::Define : 0;
|
|
|
|
}
|
|
|
|
inline unsigned getImplRegState(bool B) {
|
|
|
|
return B ? RegState::Implicit : 0;
|
|
|
|
}
|
|
|
|
inline unsigned getKillRegState(bool B) {
|
|
|
|
return B ? RegState::Kill : 0;
|
|
|
|
}
|
|
|
|
inline unsigned getDeadRegState(bool B) {
|
|
|
|
return B ? RegState::Dead : 0;
|
|
|
|
}
|
2009-06-30 08:49:04 +00:00
|
|
|
inline unsigned getUndefRegState(bool B) {
|
|
|
|
return B ? RegState::Undef : 0;
|
|
|
|
}
|
2012-06-07 04:43:52 +00:00
|
|
|
inline unsigned getInternalReadRegState(bool B) {
|
|
|
|
return B ? RegState::InternalRead : 0;
|
|
|
|
}
|
2012-12-20 18:08:09 +00:00
|
|
|
inline unsigned getDebugRegState(bool B) {
|
|
|
|
return B ? RegState::Debug : 0;
|
|
|
|
}
|
2009-05-13 21:33:08 +00:00
|
|
|
|
2012-12-07 04:23:35 +00:00
|
|
|
|
|
|
|
/// Helper class for constructing bundles of MachineInstrs.
|
|
|
|
///
|
|
|
|
/// MIBundleBuilder can create a bundle from scratch by inserting new
|
|
|
|
/// MachineInstrs one at a time, or it can create a bundle from a sequence of
|
|
|
|
/// existing MachineInstrs in a basic block.
|
|
|
|
class MIBundleBuilder {
|
|
|
|
MachineBasicBlock &MBB;
|
|
|
|
MachineBasicBlock::instr_iterator Begin;
|
|
|
|
MachineBasicBlock::instr_iterator End;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Create an MIBundleBuilder that inserts instructions into a new bundle in
|
|
|
|
/// BB above the bundle or instruction at Pos.
|
|
|
|
MIBundleBuilder(MachineBasicBlock &BB,
|
|
|
|
MachineBasicBlock::iterator Pos)
|
|
|
|
: MBB(BB), Begin(Pos.getInstrIterator()), End(Begin) {}
|
|
|
|
|
|
|
|
/// Create a bundle from the sequence of instructions between B and E.
|
|
|
|
MIBundleBuilder(MachineBasicBlock &BB,
|
|
|
|
MachineBasicBlock::iterator B,
|
|
|
|
MachineBasicBlock::iterator E)
|
|
|
|
: MBB(BB), Begin(B.getInstrIterator()), End(E.getInstrIterator()) {
|
|
|
|
assert(B != E && "No instructions to bundle");
|
|
|
|
++B;
|
|
|
|
while (B != E) {
|
|
|
|
MachineInstr *MI = B;
|
|
|
|
++B;
|
|
|
|
MI->bundleWithPred();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-13 00:59:36 +00:00
|
|
|
/// Create an MIBundleBuilder representing an existing instruction or bundle
|
|
|
|
/// that has MI as its head.
|
|
|
|
explicit MIBundleBuilder(MachineInstr *MI)
|
2013-01-09 01:02:19 +00:00
|
|
|
: MBB(*MI->getParent()), Begin(MI), End(getBundleEnd(MI)) {}
|
2012-12-13 00:59:36 +00:00
|
|
|
|
|
|
|
/// Return a reference to the basic block containing this bundle.
|
|
|
|
MachineBasicBlock &getMBB() const { return MBB; }
|
|
|
|
|
2012-12-07 04:23:35 +00:00
|
|
|
/// Return true if no instructions have been inserted in this bundle yet.
|
|
|
|
/// Empty bundles aren't representable in a MachineBasicBlock.
|
|
|
|
bool empty() const { return Begin == End; }
|
|
|
|
|
|
|
|
/// Return an iterator to the first bundled instruction.
|
|
|
|
MachineBasicBlock::instr_iterator begin() const { return Begin; }
|
|
|
|
|
|
|
|
/// Return an iterator beyond the last bundled instruction.
|
|
|
|
MachineBasicBlock::instr_iterator end() const { return End; }
|
|
|
|
|
2012-12-13 00:59:36 +00:00
|
|
|
/// Insert MI into this bundle before I which must point to an instruction in
|
|
|
|
/// the bundle, or end().
|
|
|
|
MIBundleBuilder &insert(MachineBasicBlock::instr_iterator I,
|
|
|
|
MachineInstr *MI) {
|
|
|
|
MBB.insert(I, MI);
|
|
|
|
if (I == Begin) {
|
|
|
|
if (!empty())
|
|
|
|
MI->bundleWithSucc();
|
|
|
|
Begin = MI;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
if (I == End) {
|
|
|
|
MI->bundleWithPred();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
// MI was inserted in the middle of the bundle, so its neighbors' flags are
|
|
|
|
// already fine. Update MI's bundle flags manually.
|
|
|
|
MI->setFlag(MachineInstr::BundledPred);
|
|
|
|
MI->setFlag(MachineInstr::BundledSucc);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-12-07 04:23:35 +00:00
|
|
|
/// Insert MI into MBB by prepending it to the instructions in the bundle.
|
|
|
|
/// MI will become the first instruction in the bundle.
|
|
|
|
MIBundleBuilder &prepend(MachineInstr *MI) {
|
2012-12-13 00:59:36 +00:00
|
|
|
return insert(begin(), MI);
|
2012-12-07 04:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Insert MI into MBB by appending it to the instructions in the bundle.
|
|
|
|
/// MI will become the last instruction in the bundle.
|
|
|
|
MIBundleBuilder &append(MachineInstr *MI) {
|
2012-12-13 00:59:36 +00:00
|
|
|
return insert(end(), MI);
|
2012-12-07 04:23:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-10-28 21:31:48 +00:00
|
|
|
#endif
|