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:
|
2014-04-14 00:51:57 +00:00
|
|
|
MachineInstrBuilder() : MF(nullptr), MI(nullptr) {}
|
2012-12-19 19:19:01 +00:00
|
|
|
|
|
|
|
/// 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
|
|
|
|
2014-10-31 23:19:46 +00:00
|
|
|
/// If conversion operators fail, use this method to get the MachineInstr
|
|
|
|
/// explicitly.
|
|
|
|
MachineInstr *getInstr() const { return MI; }
|
|
|
|
|
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));
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
assert((MI->isDebugValue() ? MI->getDebugVariable().Verify() : true) &&
|
|
|
|
"first MDNode argument of a DBG_VALUE not a DIVariable");
|
2010-01-13 00:00:24 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2014-03-07 06:08:31 +00:00
|
|
|
|
|
|
|
const MachineInstrBuilder &addCFIIndex(unsigned CFIIndex) const {
|
|
|
|
MI->addOperand(*MF, MachineOperand::CreateCFIIndex(CFIIndex));
|
|
|
|
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
|
|
|
|
2013-07-09 20:28:37 +00:00
|
|
|
/// BuildMI - This version of the builder builds a DBG_VALUE intrinsic
|
|
|
|
/// for either a value in a register or a register-indirect+offset
|
|
|
|
/// address. The convention is that a DBG_VALUE is indirect iff the
|
|
|
|
/// second operand is an immediate.
|
|
|
|
///
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
inline MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL,
|
|
|
|
const MCInstrDesc &MCID, bool IsIndirect,
|
|
|
|
unsigned Reg, unsigned Offset,
|
|
|
|
const MDNode *Variable, const MDNode *Expr) {
|
|
|
|
assert(DIVariable(Variable).Verify() && "not a DIVariable");
|
|
|
|
assert(DIExpression(Expr).Verify() && "not a DIExpression");
|
2013-07-09 20:28:37 +00:00
|
|
|
if (IsIndirect)
|
|
|
|
return BuildMI(MF, DL, MCID)
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
.addReg(Reg, RegState::Debug)
|
|
|
|
.addImm(Offset)
|
|
|
|
.addMetadata(Variable)
|
|
|
|
.addMetadata(Expr);
|
2013-07-09 20:28:37 +00:00
|
|
|
else {
|
|
|
|
assert(Offset == 0 && "A direct address cannot have an offset.");
|
|
|
|
return BuildMI(MF, DL, MCID)
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
.addReg(Reg, RegState::Debug)
|
|
|
|
.addReg(0U, RegState::Debug)
|
|
|
|
.addMetadata(Variable)
|
|
|
|
.addMetadata(Expr);
|
2013-07-09 20:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// BuildMI - This version of the builder builds a DBG_VALUE intrinsic
|
|
|
|
/// for either a value in a register or a register-indirect+offset
|
|
|
|
/// address and inserts it at position I.
|
|
|
|
///
|
|
|
|
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
MachineBasicBlock::iterator I, DebugLoc DL,
|
|
|
|
const MCInstrDesc &MCID, bool IsIndirect,
|
|
|
|
unsigned Reg, unsigned Offset,
|
|
|
|
const MDNode *Variable, const MDNode *Expr) {
|
|
|
|
assert(DIVariable(Variable).Verify() && "not a DIVariable");
|
|
|
|
assert(DIExpression(Expr).Verify() && "not a DIExpression");
|
2013-07-09 20:28:37 +00:00
|
|
|
MachineFunction &MF = *BB.getParent();
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
MachineInstr *MI =
|
|
|
|
BuildMI(MF, DL, MCID, IsIndirect, Reg, Offset, Variable, Expr);
|
2013-07-09 20:28:37 +00:00
|
|
|
BB.insert(I, MI);
|
|
|
|
return MachineInstrBuilder(MF, MI);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|