2017-11-29 01:58:43 +08:00
|
|
|
//===- lib/CodeGen/MachineOperand.cpp -------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-11-29 01:58:43 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2017-11-29 03:23:39 +08:00
|
|
|
/// \file Methods common to all machine operands.
|
2017-11-29 01:58:43 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2020-01-18 08:04:02 +08:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2018-03-15 05:52:13 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2017-11-29 01:58:43 +08:00
|
|
|
#include "llvm/Analysis/Loads.h"
|
2018-08-21 04:37:57 +08:00
|
|
|
#include "llvm/Analysis/MemoryLocation.h"
|
2020-01-09 12:02:37 +08:00
|
|
|
#include "llvm/CodeGen/MIRFormatter.h"
|
2017-11-29 01:58:43 +08:00
|
|
|
#include "llvm/CodeGen/MIRPrinter.h"
|
2017-12-16 00:33:45 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2017-12-13 18:30:59 +08:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2017-11-29 01:58:43 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-12-13 18:30:51 +08:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2017-11-29 01:58:43 +08:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
2018-04-30 22:59:11 +08:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2017-11-29 01:58:43 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
2017-12-14 18:02:58 +08:00
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
2020-06-24 20:17:44 +08:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2017-11-29 01:58:43 +08:00
|
|
|
#include "llvm/IR/ModuleSlotTracker.h"
|
2019-04-12 14:16:33 +08:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2017-12-07 18:40:31 +08:00
|
|
|
#include "llvm/Target/TargetIntrinsicInfo.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2017-11-29 01:58:43 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
static cl::opt<int>
|
|
|
|
PrintRegMaskNumRegs("print-regmask-num-regs",
|
|
|
|
cl::desc("Number of registers to limit to when "
|
|
|
|
"printing regmask operands in IR dumps. "
|
|
|
|
"unlimited = -1"),
|
|
|
|
cl::init(32), cl::Hidden);
|
|
|
|
|
2017-12-06 19:55:42 +08:00
|
|
|
static const MachineFunction *getMFIfAvailable(const MachineOperand &MO) {
|
|
|
|
if (const MachineInstr *MI = MO.getParent())
|
|
|
|
if (const MachineBasicBlock *MBB = MI->getParent())
|
|
|
|
if (const MachineFunction *MF = MBB->getParent())
|
|
|
|
return MF;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
static MachineFunction *getMFIfAvailable(MachineOperand &MO) {
|
|
|
|
return const_cast<MachineFunction *>(
|
|
|
|
getMFIfAvailable(const_cast<const MachineOperand &>(MO)));
|
|
|
|
}
|
|
|
|
|
2019-08-06 11:59:31 +08:00
|
|
|
void MachineOperand::setReg(Register Reg) {
|
2017-11-29 01:58:43 +08:00
|
|
|
if (getReg() == Reg)
|
|
|
|
return; // No change.
|
|
|
|
|
[MachineOperand][Target] MachineOperand::isRenamable semantics changes
Summary:
Add a target option AllowRegisterRenaming that is used to opt in to
post-register-allocation renaming of registers. This is set to 0 by
default, which causes the hasExtraSrcRegAllocReq/hasExtraDstRegAllocReq
fields of all opcodes to be set to 1, causing
MachineOperand::isRenamable to always return false.
Set the AllowRegisterRenaming flag to 1 for all in-tree targets that
have lit tests that were effected by enabling COPY forwarding in
MachineCopyPropagation (AArch64, AMDGPU, ARM, Hexagon, Mips, PowerPC,
RISCV, Sparc, SystemZ and X86).
Add some more comments describing the semantics of the
MachineOperand::isRenamable function and how it is set and maintained.
Change isRenamable to check the operand's opcode
hasExtraSrcRegAllocReq/hasExtraDstRegAllocReq bit directly instead of
relying on it being consistently reflected in the IsRenamable bit
setting.
Clear the IsRenamable bit when changing an operand's register value.
Remove target code that was clearing the IsRenamable bit when changing
registers/opcodes now that this is done conservatively by default.
Change setting of hasExtraSrcRegAllocReq in AMDGPU target to be done in
one place covering all opcodes that have constant pipe read limit
restrictions.
Reviewers: qcolombet, MatzeB
Subscribers: aemerson, arsenm, jyknight, mcrosier, sdardis, nhaehnle, javed.absar, tpr, arichardson, kristof.beyls, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, jordy.potman.lists, apazos, sabuasal, niosHD, escha, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D43042
llvm-svn: 325931
2018-02-24 02:25:08 +08:00
|
|
|
// Clear the IsRenamable bit to keep it conservatively correct.
|
|
|
|
IsRenamable = false;
|
|
|
|
|
2017-11-29 01:58:43 +08:00
|
|
|
// Otherwise, we have to change the register. If this operand is embedded
|
|
|
|
// into a machine function, we need to update the old and new register's
|
|
|
|
// use/def lists.
|
2017-12-06 19:55:42 +08:00
|
|
|
if (MachineFunction *MF = getMFIfAvailable(*this)) {
|
|
|
|
MachineRegisterInfo &MRI = MF->getRegInfo();
|
|
|
|
MRI.removeRegOperandFromUseList(this);
|
|
|
|
SmallContents.RegNo = Reg;
|
|
|
|
MRI.addRegOperandToUseList(this);
|
|
|
|
return;
|
2017-12-06 19:57:53 +08:00
|
|
|
}
|
2017-11-29 01:58:43 +08:00
|
|
|
|
|
|
|
// Otherwise, just change the register, no problem. :)
|
|
|
|
SmallContents.RegNo = Reg;
|
|
|
|
}
|
|
|
|
|
2019-08-06 11:59:31 +08:00
|
|
|
void MachineOperand::substVirtReg(Register Reg, unsigned SubIdx,
|
2017-11-29 01:58:43 +08:00
|
|
|
const TargetRegisterInfo &TRI) {
|
2019-08-06 11:59:31 +08:00
|
|
|
assert(Reg.isVirtual());
|
2017-11-29 01:58:43 +08:00
|
|
|
if (SubIdx && getSubReg())
|
|
|
|
SubIdx = TRI.composeSubRegIndices(SubIdx, getSubReg());
|
|
|
|
setReg(Reg);
|
|
|
|
if (SubIdx)
|
|
|
|
setSubReg(SubIdx);
|
|
|
|
}
|
|
|
|
|
2019-08-06 11:59:31 +08:00
|
|
|
void MachineOperand::substPhysReg(MCRegister Reg, const TargetRegisterInfo &TRI) {
|
|
|
|
assert(Reg.isPhysical());
|
2017-11-29 01:58:43 +08:00
|
|
|
if (getSubReg()) {
|
|
|
|
Reg = TRI.getSubReg(Reg, getSubReg());
|
|
|
|
// Note that getSubReg() may return 0 if the sub-register doesn't exist.
|
|
|
|
// That won't happen in legal code.
|
|
|
|
setSubReg(0);
|
|
|
|
if (isDef())
|
|
|
|
setIsUndef(false);
|
|
|
|
}
|
|
|
|
setReg(Reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Change a def to a use, or a use to a def.
|
|
|
|
void MachineOperand::setIsDef(bool Val) {
|
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
|
|
|
assert((!Val || !isDebug()) && "Marking a debug operation as def");
|
|
|
|
if (IsDef == Val)
|
|
|
|
return;
|
2017-12-13 01:53:59 +08:00
|
|
|
assert(!IsDeadOrKill && "Changing def/use with dead/kill set not supported");
|
2017-11-29 01:58:43 +08:00
|
|
|
// MRI may keep uses and defs in different list positions.
|
2017-12-06 19:55:42 +08:00
|
|
|
if (MachineFunction *MF = getMFIfAvailable(*this)) {
|
|
|
|
MachineRegisterInfo &MRI = MF->getRegInfo();
|
|
|
|
MRI.removeRegOperandFromUseList(this);
|
|
|
|
IsDef = Val;
|
|
|
|
MRI.addRegOperandToUseList(this);
|
|
|
|
return;
|
|
|
|
}
|
2017-11-29 01:58:43 +08:00
|
|
|
IsDef = Val;
|
|
|
|
}
|
|
|
|
|
2017-12-13 01:53:59 +08:00
|
|
|
bool MachineOperand::isRenamable() const {
|
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2019-08-02 07:27:28 +08:00
|
|
|
assert(Register::isPhysicalRegister(getReg()) &&
|
2017-12-13 01:53:59 +08:00
|
|
|
"isRenamable should only be checked on physical registers");
|
[MachineOperand][Target] MachineOperand::isRenamable semantics changes
Summary:
Add a target option AllowRegisterRenaming that is used to opt in to
post-register-allocation renaming of registers. This is set to 0 by
default, which causes the hasExtraSrcRegAllocReq/hasExtraDstRegAllocReq
fields of all opcodes to be set to 1, causing
MachineOperand::isRenamable to always return false.
Set the AllowRegisterRenaming flag to 1 for all in-tree targets that
have lit tests that were effected by enabling COPY forwarding in
MachineCopyPropagation (AArch64, AMDGPU, ARM, Hexagon, Mips, PowerPC,
RISCV, Sparc, SystemZ and X86).
Add some more comments describing the semantics of the
MachineOperand::isRenamable function and how it is set and maintained.
Change isRenamable to check the operand's opcode
hasExtraSrcRegAllocReq/hasExtraDstRegAllocReq bit directly instead of
relying on it being consistently reflected in the IsRenamable bit
setting.
Clear the IsRenamable bit when changing an operand's register value.
Remove target code that was clearing the IsRenamable bit when changing
registers/opcodes now that this is done conservatively by default.
Change setting of hasExtraSrcRegAllocReq in AMDGPU target to be done in
one place covering all opcodes that have constant pipe read limit
restrictions.
Reviewers: qcolombet, MatzeB
Subscribers: aemerson, arsenm, jyknight, mcrosier, sdardis, nhaehnle, javed.absar, tpr, arichardson, kristof.beyls, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, jordy.potman.lists, apazos, sabuasal, niosHD, escha, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D43042
llvm-svn: 325931
2018-02-24 02:25:08 +08:00
|
|
|
if (!IsRenamable)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const MachineInstr *MI = getParent();
|
|
|
|
if (!MI)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (isDef())
|
|
|
|
return !MI->hasExtraDefRegAllocReq(MachineInstr::IgnoreBundle);
|
|
|
|
|
|
|
|
assert(isUse() && "Reg is not def or use");
|
|
|
|
return !MI->hasExtraSrcRegAllocReq(MachineInstr::IgnoreBundle);
|
2017-12-13 01:53:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MachineOperand::setIsRenamable(bool Val) {
|
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2019-08-02 07:27:28 +08:00
|
|
|
assert(Register::isPhysicalRegister(getReg()) &&
|
2017-12-13 01:53:59 +08:00
|
|
|
"setIsRenamable should only be called on physical registers");
|
|
|
|
IsRenamable = Val;
|
|
|
|
}
|
|
|
|
|
2017-11-29 01:58:43 +08:00
|
|
|
// If this operand is currently a register operand, and if this is in a
|
|
|
|
// function, deregister the operand from the register's use/def list.
|
|
|
|
void MachineOperand::removeRegFromUses() {
|
|
|
|
if (!isReg() || !isOnRegUseList())
|
|
|
|
return;
|
|
|
|
|
2017-12-06 19:55:42 +08:00
|
|
|
if (MachineFunction *MF = getMFIfAvailable(*this))
|
|
|
|
MF->getRegInfo().removeRegOperandFromUseList(this);
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ChangeToImmediate - Replace this operand with a new immediate operand of
|
|
|
|
/// the specified value. If an operand is known to be an immediate already,
|
|
|
|
/// the setImm method should be used.
|
|
|
|
void MachineOperand::ChangeToImmediate(int64_t ImmVal) {
|
|
|
|
assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
|
|
|
|
|
|
|
|
removeRegFromUses();
|
|
|
|
|
|
|
|
OpKind = MO_Immediate;
|
|
|
|
Contents.ImmVal = ImmVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineOperand::ChangeToFPImmediate(const ConstantFP *FPImm) {
|
|
|
|
assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
|
|
|
|
|
|
|
|
removeRegFromUses();
|
|
|
|
|
|
|
|
OpKind = MO_FPImmediate;
|
|
|
|
Contents.CFP = FPImm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineOperand::ChangeToES(const char *SymName,
|
2019-08-01 04:14:09 +08:00
|
|
|
unsigned TargetFlags) {
|
2017-11-29 01:58:43 +08:00
|
|
|
assert((!isReg() || !isTied()) &&
|
|
|
|
"Cannot change a tied operand into an external symbol");
|
|
|
|
|
|
|
|
removeRegFromUses();
|
|
|
|
|
|
|
|
OpKind = MO_ExternalSymbol;
|
|
|
|
Contents.OffsetedInfo.Val.SymbolName = SymName;
|
|
|
|
setOffset(0); // Offset is always 0.
|
|
|
|
setTargetFlags(TargetFlags);
|
|
|
|
}
|
|
|
|
|
2019-05-16 01:48:10 +08:00
|
|
|
void MachineOperand::ChangeToGA(const GlobalValue *GV, int64_t Offset,
|
2019-08-01 04:14:09 +08:00
|
|
|
unsigned TargetFlags) {
|
2019-05-16 01:48:10 +08:00
|
|
|
assert((!isReg() || !isTied()) &&
|
|
|
|
"Cannot change a tied operand into a global address");
|
|
|
|
|
|
|
|
removeRegFromUses();
|
|
|
|
|
|
|
|
OpKind = MO_GlobalAddress;
|
|
|
|
Contents.OffsetedInfo.Val.GV = GV;
|
|
|
|
setOffset(Offset);
|
|
|
|
setTargetFlags(TargetFlags);
|
|
|
|
}
|
|
|
|
|
2017-11-29 01:58:43 +08:00
|
|
|
void MachineOperand::ChangeToMCSymbol(MCSymbol *Sym) {
|
|
|
|
assert((!isReg() || !isTied()) &&
|
|
|
|
"Cannot change a tied operand into an MCSymbol");
|
|
|
|
|
|
|
|
removeRegFromUses();
|
|
|
|
|
|
|
|
OpKind = MO_MCSymbol;
|
|
|
|
Contents.Sym = Sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineOperand::ChangeToFrameIndex(int Idx) {
|
|
|
|
assert((!isReg() || !isTied()) &&
|
|
|
|
"Cannot change a tied operand into a FrameIndex");
|
|
|
|
|
|
|
|
removeRegFromUses();
|
|
|
|
|
|
|
|
OpKind = MO_FrameIndex;
|
|
|
|
setIndex(Idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineOperand::ChangeToTargetIndex(unsigned Idx, int64_t Offset,
|
2019-08-01 04:14:09 +08:00
|
|
|
unsigned TargetFlags) {
|
2017-11-29 01:58:43 +08:00
|
|
|
assert((!isReg() || !isTied()) &&
|
|
|
|
"Cannot change a tied operand into a FrameIndex");
|
|
|
|
|
|
|
|
removeRegFromUses();
|
|
|
|
|
|
|
|
OpKind = MO_TargetIndex;
|
|
|
|
setIndex(Idx);
|
|
|
|
setOffset(Offset);
|
|
|
|
setTargetFlags(TargetFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ChangeToRegister - Replace this operand with a new register operand of
|
|
|
|
/// the specified value. If an operand is known to be an register already,
|
|
|
|
/// the setReg method should be used.
|
2019-08-06 11:59:31 +08:00
|
|
|
void MachineOperand::ChangeToRegister(Register Reg, bool isDef, bool isImp,
|
2017-11-29 01:58:43 +08:00
|
|
|
bool isKill, bool isDead, bool isUndef,
|
|
|
|
bool isDebug) {
|
|
|
|
MachineRegisterInfo *RegInfo = nullptr;
|
2017-12-06 19:55:42 +08:00
|
|
|
if (MachineFunction *MF = getMFIfAvailable(*this))
|
|
|
|
RegInfo = &MF->getRegInfo();
|
2017-11-29 01:58:43 +08:00
|
|
|
// If this operand is already a register operand, remove it from the
|
|
|
|
// register's use/def lists.
|
|
|
|
bool WasReg = isReg();
|
|
|
|
if (RegInfo && WasReg)
|
|
|
|
RegInfo->removeRegOperandFromUseList(this);
|
|
|
|
|
|
|
|
// Change this to a register and set the reg#.
|
2017-12-13 01:53:59 +08:00
|
|
|
assert(!(isDead && !isDef) && "Dead flag on non-def");
|
|
|
|
assert(!(isKill && isDef) && "Kill flag on def");
|
2017-11-29 01:58:43 +08:00
|
|
|
OpKind = MO_Register;
|
|
|
|
SmallContents.RegNo = Reg;
|
|
|
|
SubReg_TargetFlags = 0;
|
|
|
|
IsDef = isDef;
|
|
|
|
IsImp = isImp;
|
2017-12-13 01:53:59 +08:00
|
|
|
IsDeadOrKill = isKill | isDead;
|
|
|
|
IsRenamable = false;
|
2017-11-29 01:58:43 +08:00
|
|
|
IsUndef = isUndef;
|
|
|
|
IsInternalRead = false;
|
|
|
|
IsEarlyClobber = false;
|
|
|
|
IsDebug = isDebug;
|
|
|
|
// Ensure isOnRegUseList() returns false.
|
|
|
|
Contents.Reg.Prev = nullptr;
|
|
|
|
// Preserve the tie when the operand was already a register.
|
|
|
|
if (!WasReg)
|
|
|
|
TiedTo = 0;
|
|
|
|
|
|
|
|
// If this operand is embedded in a function, add the operand to the
|
|
|
|
// register's use/def list.
|
|
|
|
if (RegInfo)
|
|
|
|
RegInfo->addRegOperandToUseList(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isIdenticalTo - Return true if this operand is identical to the specified
|
|
|
|
/// operand. Note that this should stay in sync with the hash_value overload
|
|
|
|
/// below.
|
|
|
|
bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
|
|
|
|
if (getType() != Other.getType() ||
|
|
|
|
getTargetFlags() != Other.getTargetFlags())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (getType()) {
|
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
return getReg() == Other.getReg() && isDef() == Other.isDef() &&
|
|
|
|
getSubReg() == Other.getSubReg();
|
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
return getImm() == Other.getImm();
|
|
|
|
case MachineOperand::MO_CImmediate:
|
|
|
|
return getCImm() == Other.getCImm();
|
|
|
|
case MachineOperand::MO_FPImmediate:
|
|
|
|
return getFPImm() == Other.getFPImm();
|
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
return getMBB() == Other.getMBB();
|
|
|
|
case MachineOperand::MO_FrameIndex:
|
|
|
|
return getIndex() == Other.getIndex();
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
case MachineOperand::MO_TargetIndex:
|
|
|
|
return getIndex() == Other.getIndex() && getOffset() == Other.getOffset();
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
return getIndex() == Other.getIndex();
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset();
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
return strcmp(getSymbolName(), Other.getSymbolName()) == 0 &&
|
|
|
|
getOffset() == Other.getOffset();
|
|
|
|
case MachineOperand::MO_BlockAddress:
|
|
|
|
return getBlockAddress() == Other.getBlockAddress() &&
|
|
|
|
getOffset() == Other.getOffset();
|
|
|
|
case MachineOperand::MO_RegisterMask:
|
|
|
|
case MachineOperand::MO_RegisterLiveOut: {
|
|
|
|
// Shallow compare of the two RegMasks
|
|
|
|
const uint32_t *RegMask = getRegMask();
|
|
|
|
const uint32_t *OtherRegMask = Other.getRegMask();
|
|
|
|
if (RegMask == OtherRegMask)
|
|
|
|
return true;
|
|
|
|
|
2017-12-06 19:55:42 +08:00
|
|
|
if (const MachineFunction *MF = getMFIfAvailable(*this)) {
|
|
|
|
// Calculate the size of the RegMask
|
|
|
|
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
|
|
|
|
unsigned RegMaskSize = (TRI->getNumRegs() + 31) / 32;
|
2017-11-29 01:58:43 +08:00
|
|
|
|
2017-12-06 19:55:42 +08:00
|
|
|
// Deep compare of the two RegMasks
|
|
|
|
return std::equal(RegMask, RegMask + RegMaskSize, OtherRegMask);
|
|
|
|
}
|
|
|
|
// We don't know the size of the RegMask, so we can't deep compare the two
|
|
|
|
// reg masks.
|
|
|
|
return false;
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
case MachineOperand::MO_MCSymbol:
|
|
|
|
return getMCSymbol() == Other.getMCSymbol();
|
|
|
|
case MachineOperand::MO_CFIIndex:
|
|
|
|
return getCFIIndex() == Other.getCFIIndex();
|
|
|
|
case MachineOperand::MO_Metadata:
|
|
|
|
return getMetadata() == Other.getMetadata();
|
|
|
|
case MachineOperand::MO_IntrinsicID:
|
|
|
|
return getIntrinsicID() == Other.getIntrinsicID();
|
|
|
|
case MachineOperand::MO_Predicate:
|
|
|
|
return getPredicate() == Other.getPredicate();
|
2019-08-13 23:34:38 +08:00
|
|
|
case MachineOperand::MO_ShuffleMask:
|
|
|
|
return getShuffleMask() == Other.getShuffleMask();
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
llvm_unreachable("Invalid machine operand type");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: this must stay exactly in sync with isIdenticalTo above.
|
|
|
|
hash_code llvm::hash_value(const MachineOperand &MO) {
|
|
|
|
switch (MO.getType()) {
|
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
// Register operands don't have target flags.
|
2019-06-24 23:50:29 +08:00
|
|
|
return hash_combine(MO.getType(), (unsigned)MO.getReg(), MO.getSubReg(), MO.isDef());
|
2017-11-29 01:58:43 +08:00
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getImm());
|
|
|
|
case MachineOperand::MO_CImmediate:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCImm());
|
|
|
|
case MachineOperand::MO_FPImmediate:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getFPImm());
|
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMBB());
|
|
|
|
case MachineOperand::MO_FrameIndex:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex());
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
case MachineOperand::MO_TargetIndex:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex(),
|
|
|
|
MO.getOffset());
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex());
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getOffset(),
|
2019-06-01 08:08:54 +08:00
|
|
|
StringRef(MO.getSymbolName()));
|
2017-11-29 01:58:43 +08:00
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getGlobal(),
|
|
|
|
MO.getOffset());
|
|
|
|
case MachineOperand::MO_BlockAddress:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getBlockAddress(),
|
|
|
|
MO.getOffset());
|
|
|
|
case MachineOperand::MO_RegisterMask:
|
|
|
|
case MachineOperand::MO_RegisterLiveOut:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getRegMask());
|
|
|
|
case MachineOperand::MO_Metadata:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMetadata());
|
|
|
|
case MachineOperand::MO_MCSymbol:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMCSymbol());
|
|
|
|
case MachineOperand::MO_CFIIndex:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCFIIndex());
|
|
|
|
case MachineOperand::MO_IntrinsicID:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIntrinsicID());
|
|
|
|
case MachineOperand::MO_Predicate:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getPredicate());
|
2019-08-13 23:34:38 +08:00
|
|
|
case MachineOperand::MO_ShuffleMask:
|
|
|
|
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getShuffleMask());
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
llvm_unreachable("Invalid machine operand type");
|
|
|
|
}
|
|
|
|
|
2017-12-07 18:40:31 +08:00
|
|
|
// Try to crawl up to the machine function and get TRI and IntrinsicInfo from
|
|
|
|
// it.
|
|
|
|
static void tryToGetTargetInfo(const MachineOperand &MO,
|
|
|
|
const TargetRegisterInfo *&TRI,
|
|
|
|
const TargetIntrinsicInfo *&IntrinsicInfo) {
|
2017-12-07 22:32:15 +08:00
|
|
|
if (const MachineFunction *MF = getMFIfAvailable(MO)) {
|
|
|
|
TRI = MF->getSubtarget().getRegisterInfo();
|
|
|
|
IntrinsicInfo = MF->getTarget().getIntrinsicInfo();
|
2017-12-07 18:40:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:30:51 +08:00
|
|
|
static const char *getTargetIndexName(const MachineFunction &MF, int Index) {
|
|
|
|
const auto *TII = MF.getSubtarget().getInstrInfo();
|
|
|
|
assert(TII && "expected instruction info");
|
|
|
|
auto Indices = TII->getSerializableTargetIndices();
|
|
|
|
auto Found = find_if(Indices, [&](const std::pair<int, const char *> &I) {
|
|
|
|
return I.first == Index;
|
|
|
|
});
|
|
|
|
if (Found != Indices.end())
|
|
|
|
return Found->second;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-14 18:03:09 +08:00
|
|
|
static const char *getTargetFlagName(const TargetInstrInfo *TII, unsigned TF) {
|
|
|
|
auto Flags = TII->getSerializableDirectMachineOperandTargetFlags();
|
|
|
|
for (const auto &I : Flags) {
|
|
|
|
if (I.first == TF) {
|
|
|
|
return I.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-20 00:51:52 +08:00
|
|
|
static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
if (!TRI) {
|
|
|
|
OS << "%dwarfreg." << DwarfReg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
MCRegisterInfo: Merge getLLVMRegNum and getLLVMRegNumFromEH
Summary:
The functions different in two ways:
- getLLVMRegNum could return both "eh" and "other" dwarf register
numbers, while getLLVMRegNumFromEH only returned the "eh" number.
- getLLVMRegNum asserted if the register was not found, while the second
function returned -1.
The second distinction was pretty important, but it was very hard to
infer that from the function name. Aditionally, for the use case of
dumping dwarf expressions, we needed a function which can work with both
kinds of number, but does not assert.
This patch solves both of these issues by merging the two functions into
one, returning an Optional<unsigned> value. While the same thing could
be achieved by adding an "IsEH" argument to the (renamed)
getLLVMRegNumFromEH function, it seemed better to avoid the confusion of
two functions and put the choice of asserting into the hands of the
caller -- if he checks the Optional value, he can safely process
"untrusted" input, and if he blindly dereferences the Optional, he gets
the assertion.
I've updated all call sites to the new API, choosing between the two
options according to the function they were calling originally, except
that I've updated the usage in DWARFExpression.cpp to use the "safe"
method instead, and added a test case which would have previously
triggered an assertion failure when processing (incorrect?) dwarf
expressions.
Reviewers: dsanders, arsenm, JDevlieghere
Subscribers: wdng, aprantl, javed.absar, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67154
llvm-svn: 372710
2019-09-24 17:31:02 +08:00
|
|
|
if (Optional<unsigned> Reg = TRI->getLLVMRegNum(DwarfReg, true))
|
|
|
|
OS << printReg(*Reg, TRI);
|
|
|
|
else
|
2017-12-20 00:51:52 +08:00
|
|
|
OS << "<badreg>";
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:47:14 +08:00
|
|
|
static void printIRBlockReference(raw_ostream &OS, const BasicBlock &BB,
|
|
|
|
ModuleSlotTracker &MST) {
|
|
|
|
OS << "%ir-block.";
|
|
|
|
if (BB.hasName()) {
|
|
|
|
printLLVMNameWithoutPrefix(OS, BB.getName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Optional<int> Slot;
|
|
|
|
if (const Function *F = BB.getParent()) {
|
|
|
|
if (F == MST.getCurrentFunction()) {
|
|
|
|
Slot = MST.getLocalSlot(&BB);
|
|
|
|
} else if (const Module *M = F->getParent()) {
|
|
|
|
ModuleSlotTracker CustomMST(M, /*ShouldInitializeAllMetadata=*/false);
|
|
|
|
CustomMST.incorporateFunction(*F);
|
|
|
|
Slot = CustomMST.getLocalSlot(&BB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Slot)
|
|
|
|
MachineOperand::printIRSlotNumber(OS, *Slot);
|
|
|
|
else
|
|
|
|
OS << "<unknown>";
|
|
|
|
}
|
|
|
|
|
2018-03-15 05:52:13 +08:00
|
|
|
static void printSyncScope(raw_ostream &OS, const LLVMContext &Context,
|
|
|
|
SyncScope::ID SSID,
|
|
|
|
SmallVectorImpl<StringRef> &SSNs) {
|
|
|
|
switch (SSID) {
|
|
|
|
case SyncScope::System:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (SSNs.empty())
|
|
|
|
Context.getSyncScopeNames(SSNs);
|
|
|
|
|
|
|
|
OS << "syncscope(\"";
|
2018-06-01 01:01:42 +08:00
|
|
|
printEscapedString(SSNs[SSID], OS);
|
2018-03-15 05:52:13 +08:00
|
|
|
OS << "\") ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *getTargetMMOFlagName(const TargetInstrInfo &TII,
|
|
|
|
unsigned TMMOFlag) {
|
|
|
|
auto Flags = TII.getSerializableMachineMemOperandTargetFlags();
|
|
|
|
for (const auto &I : Flags) {
|
|
|
|
if (I.first == TMMOFlag) {
|
|
|
|
return I.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printFrameIndex(raw_ostream& OS, int FrameIndex, bool IsFixed,
|
|
|
|
const MachineFrameInfo *MFI) {
|
|
|
|
StringRef Name;
|
|
|
|
if (MFI) {
|
|
|
|
IsFixed = MFI->isFixedObjectIndex(FrameIndex);
|
|
|
|
if (const AllocaInst *Alloca = MFI->getObjectAllocation(FrameIndex))
|
|
|
|
if (Alloca->hasName())
|
|
|
|
Name = Alloca->getName();
|
|
|
|
if (IsFixed)
|
|
|
|
FrameIndex -= MFI->getObjectIndexBegin();
|
|
|
|
}
|
|
|
|
MachineOperand::printStackObjectReference(OS, FrameIndex, IsFixed, Name);
|
|
|
|
}
|
|
|
|
|
2018-01-16 18:53:11 +08:00
|
|
|
void MachineOperand::printSubRegIdx(raw_ostream &OS, uint64_t Index,
|
2017-12-09 06:53:21 +08:00
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
OS << "%subreg.";
|
|
|
|
if (TRI)
|
|
|
|
OS << TRI->getSubRegIndexName(Index);
|
|
|
|
else
|
|
|
|
OS << Index;
|
|
|
|
}
|
|
|
|
|
2017-12-14 18:03:09 +08:00
|
|
|
void MachineOperand::printTargetFlags(raw_ostream &OS,
|
|
|
|
const MachineOperand &Op) {
|
|
|
|
if (!Op.getTargetFlags())
|
|
|
|
return;
|
|
|
|
const MachineFunction *MF = getMFIfAvailable(Op);
|
|
|
|
if (!MF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto *TII = MF->getSubtarget().getInstrInfo();
|
|
|
|
assert(TII && "expected instruction info");
|
|
|
|
auto Flags = TII->decomposeMachineOperandsTargetFlags(Op.getTargetFlags());
|
|
|
|
OS << "target-flags(";
|
|
|
|
const bool HasDirectFlags = Flags.first;
|
|
|
|
const bool HasBitmaskFlags = Flags.second;
|
|
|
|
if (!HasDirectFlags && !HasBitmaskFlags) {
|
|
|
|
OS << "<unknown>) ";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (HasDirectFlags) {
|
|
|
|
if (const auto *Name = getTargetFlagName(TII, Flags.first))
|
|
|
|
OS << Name;
|
|
|
|
else
|
|
|
|
OS << "<unknown target flag>";
|
|
|
|
}
|
|
|
|
if (!HasBitmaskFlags) {
|
|
|
|
OS << ") ";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool IsCommaNeeded = HasDirectFlags;
|
|
|
|
unsigned BitMask = Flags.second;
|
|
|
|
auto BitMasks = TII->getSerializableBitmaskMachineOperandTargetFlags();
|
|
|
|
for (const auto &Mask : BitMasks) {
|
|
|
|
// Check if the flag's bitmask has the bits of the current mask set.
|
|
|
|
if ((BitMask & Mask.first) == Mask.first) {
|
|
|
|
if (IsCommaNeeded)
|
|
|
|
OS << ", ";
|
|
|
|
IsCommaNeeded = true;
|
|
|
|
OS << Mask.second;
|
|
|
|
// Clear the bits which were serialized from the flag's bitmask.
|
|
|
|
BitMask &= ~(Mask.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (BitMask) {
|
|
|
|
// When the resulting flag's bitmask isn't zero, we know that we didn't
|
|
|
|
// serialize all of the bit flags.
|
|
|
|
if (IsCommaNeeded)
|
|
|
|
OS << ", ";
|
|
|
|
OS << "<unknown bitmask target flag>";
|
|
|
|
}
|
|
|
|
OS << ") ";
|
|
|
|
}
|
|
|
|
|
2017-12-15 23:17:18 +08:00
|
|
|
void MachineOperand::printSymbol(raw_ostream &OS, MCSymbol &Sym) {
|
|
|
|
OS << "<mcsymbol " << Sym << ">";
|
|
|
|
}
|
|
|
|
|
2017-12-16 00:33:45 +08:00
|
|
|
void MachineOperand::printStackObjectReference(raw_ostream &OS,
|
|
|
|
unsigned FrameIndex,
|
|
|
|
bool IsFixed, StringRef Name) {
|
|
|
|
if (IsFixed) {
|
|
|
|
OS << "%fixed-stack." << FrameIndex;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "%stack." << FrameIndex;
|
|
|
|
if (!Name.empty())
|
|
|
|
OS << '.' << Name;
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:46:55 +08:00
|
|
|
void MachineOperand::printOperandOffset(raw_ostream &OS, int64_t Offset) {
|
|
|
|
if (Offset == 0)
|
|
|
|
return;
|
|
|
|
if (Offset < 0) {
|
|
|
|
OS << " - " << -Offset;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
OS << " + " << Offset;
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:47:14 +08:00
|
|
|
void MachineOperand::printIRSlotNumber(raw_ostream &OS, int Slot) {
|
|
|
|
if (Slot == -1)
|
|
|
|
OS << "<badref>";
|
|
|
|
else
|
|
|
|
OS << Slot;
|
|
|
|
}
|
|
|
|
|
2017-12-20 00:51:52 +08:00
|
|
|
static void printCFI(raw_ostream &OS, const MCCFIInstruction &CFI,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
switch (CFI.getOperation()) {
|
|
|
|
case MCCFIInstruction::OpSameValue:
|
|
|
|
OS << "same_value ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpRememberState:
|
|
|
|
OS << "remember_state ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpRestoreState:
|
|
|
|
OS << "restore_state ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpOffset:
|
|
|
|
OS << "offset ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
OS << ", " << CFI.getOffset();
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpDefCfaRegister:
|
|
|
|
OS << "def_cfa_register ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpDefCfaOffset:
|
|
|
|
OS << "def_cfa_offset ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
OS << CFI.getOffset();
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpDefCfa:
|
|
|
|
OS << "def_cfa ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
OS << ", " << CFI.getOffset();
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpRelOffset:
|
|
|
|
OS << "rel_offset ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
OS << ", " << CFI.getOffset();
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpAdjustCfaOffset:
|
|
|
|
OS << "adjust_cfa_offset ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
OS << CFI.getOffset();
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpRestore:
|
|
|
|
OS << "restore ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpEscape: {
|
|
|
|
OS << "escape ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
if (!CFI.getValues().empty()) {
|
|
|
|
size_t e = CFI.getValues().size() - 1;
|
|
|
|
for (size_t i = 0; i < e; ++i)
|
|
|
|
OS << format("0x%02x", uint8_t(CFI.getValues()[i])) << ", ";
|
|
|
|
OS << format("0x%02x", uint8_t(CFI.getValues()[e])) << ", ";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MCCFIInstruction::OpUndefined:
|
|
|
|
OS << "undefined ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpRegister:
|
|
|
|
OS << "register ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
OS << ", ";
|
|
|
|
printCFIRegister(CFI.getRegister2(), OS, TRI);
|
|
|
|
break;
|
|
|
|
case MCCFIInstruction::OpWindowSave:
|
|
|
|
OS << "window_save ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
break;
|
2018-12-18 18:37:42 +08:00
|
|
|
case MCCFIInstruction::OpNegateRAState:
|
|
|
|
OS << "negate_ra_sign_state ";
|
|
|
|
if (MCSymbol *Label = CFI.getLabel())
|
|
|
|
MachineOperand::printSymbol(OS, *Label);
|
|
|
|
break;
|
2017-12-20 00:51:52 +08:00
|
|
|
default:
|
|
|
|
// TODO: Print the other CFI Operations.
|
|
|
|
OS << "<unserializable cfi directive>";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-29 01:58:43 +08:00
|
|
|
void MachineOperand::print(raw_ostream &OS, const TargetRegisterInfo *TRI,
|
|
|
|
const TargetIntrinsicInfo *IntrinsicInfo) const {
|
2018-05-08 06:31:12 +08:00
|
|
|
print(OS, LLT{}, TRI, IntrinsicInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineOperand::print(raw_ostream &OS, LLT TypeToPrint,
|
|
|
|
const TargetRegisterInfo *TRI,
|
|
|
|
const TargetIntrinsicInfo *IntrinsicInfo) const {
|
2017-12-07 18:40:31 +08:00
|
|
|
tryToGetTargetInfo(*this, TRI, IntrinsicInfo);
|
2017-11-29 01:58:43 +08:00
|
|
|
ModuleSlotTracker DummyMST(nullptr);
|
2020-01-09 12:02:37 +08:00
|
|
|
print(OS, DummyMST, TypeToPrint, None, /*PrintDef=*/false,
|
|
|
|
/*IsStandalone=*/true,
|
2017-12-07 18:40:31 +08:00
|
|
|
/*ShouldPrintRegisterTies=*/true,
|
|
|
|
/*TiedOperandIdx=*/0, TRI, IntrinsicInfo);
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
|
2020-01-09 12:02:37 +08:00
|
|
|
LLT TypeToPrint, Optional<unsigned> OpIdx, bool PrintDef,
|
|
|
|
bool IsStandalone, bool ShouldPrintRegisterTies,
|
2017-12-07 18:40:31 +08:00
|
|
|
unsigned TiedOperandIdx,
|
2017-11-29 01:58:43 +08:00
|
|
|
const TargetRegisterInfo *TRI,
|
|
|
|
const TargetIntrinsicInfo *IntrinsicInfo) const {
|
2017-12-14 18:03:09 +08:00
|
|
|
printTargetFlags(OS, *this);
|
2017-11-29 01:58:43 +08:00
|
|
|
switch (getType()) {
|
2017-12-07 18:40:31 +08:00
|
|
|
case MachineOperand::MO_Register: {
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register Reg = getReg();
|
2017-12-07 18:40:31 +08:00
|
|
|
if (isImplicit())
|
|
|
|
OS << (isDef() ? "implicit-def " : "implicit ");
|
|
|
|
else if (PrintDef && isDef())
|
|
|
|
// Print the 'def' flag only when the operand is defined after '='.
|
|
|
|
OS << "def ";
|
|
|
|
if (isInternalRead())
|
|
|
|
OS << "internal ";
|
|
|
|
if (isDead())
|
|
|
|
OS << "dead ";
|
|
|
|
if (isKill())
|
|
|
|
OS << "killed ";
|
|
|
|
if (isUndef())
|
|
|
|
OS << "undef ";
|
|
|
|
if (isEarlyClobber())
|
|
|
|
OS << "early-clobber ";
|
2019-08-02 07:27:28 +08:00
|
|
|
if (Register::isPhysicalRegister(getReg()) && isRenamable())
|
2017-12-13 01:53:59 +08:00
|
|
|
OS << "renamable ";
|
2018-10-31 07:28:27 +08:00
|
|
|
// isDebug() is exactly true for register operands of a DBG_VALUE. So we
|
|
|
|
// simply infer it when parsing and do not need to print it.
|
2018-03-31 02:15:54 +08:00
|
|
|
|
|
|
|
const MachineRegisterInfo *MRI = nullptr;
|
2019-08-02 07:27:28 +08:00
|
|
|
if (Register::isVirtualRegister(Reg)) {
|
2018-03-31 02:15:54 +08:00
|
|
|
if (const MachineFunction *MF = getMFIfAvailable(*this)) {
|
|
|
|
MRI = &MF->getRegInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << printReg(Reg, TRI, 0, MRI);
|
2017-12-07 18:40:31 +08:00
|
|
|
// Print the sub register.
|
|
|
|
if (unsigned SubReg = getSubReg()) {
|
|
|
|
if (TRI)
|
|
|
|
OS << '.' << TRI->getSubRegIndexName(SubReg);
|
|
|
|
else
|
|
|
|
OS << ".subreg" << SubReg;
|
|
|
|
}
|
|
|
|
// Print the register class / bank.
|
2019-08-02 07:27:28 +08:00
|
|
|
if (Register::isVirtualRegister(Reg)) {
|
2017-12-07 22:32:15 +08:00
|
|
|
if (const MachineFunction *MF = getMFIfAvailable(*this)) {
|
|
|
|
const MachineRegisterInfo &MRI = MF->getRegInfo();
|
2018-01-19 02:05:15 +08:00
|
|
|
if (IsStandalone || !PrintDef || MRI.def_empty(Reg)) {
|
2017-12-07 22:32:15 +08:00
|
|
|
OS << ':';
|
|
|
|
OS << printRegClassOrBank(Reg, MRI, TRI);
|
2017-12-07 18:40:31 +08:00
|
|
|
}
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-07 18:40:31 +08:00
|
|
|
// Print ties.
|
|
|
|
if (ShouldPrintRegisterTies && isTied() && !isDef())
|
|
|
|
OS << "(tied-def " << TiedOperandIdx << ")";
|
|
|
|
// Print types.
|
|
|
|
if (TypeToPrint.isValid())
|
|
|
|
OS << '(' << TypeToPrint << ')';
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-07 18:40:31 +08:00
|
|
|
}
|
2020-01-09 12:02:37 +08:00
|
|
|
case MachineOperand::MO_Immediate: {
|
|
|
|
const MIRFormatter *Formatter = nullptr;
|
2020-01-10 18:18:11 +08:00
|
|
|
if (const MachineFunction *MF = getMFIfAvailable(*this)) {
|
|
|
|
const auto *TII = MF->getSubtarget().getInstrInfo();
|
|
|
|
assert(TII && "expected instruction info");
|
|
|
|
Formatter = TII->getMIRFormatter();
|
|
|
|
}
|
2020-01-09 12:02:37 +08:00
|
|
|
if (Formatter)
|
|
|
|
Formatter->printImm(OS, *getParent(), OpIdx, getImm());
|
|
|
|
else
|
|
|
|
OS << getImm();
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2020-01-09 12:02:37 +08:00
|
|
|
}
|
2017-11-29 01:58:43 +08:00
|
|
|
case MachineOperand::MO_CImmediate:
|
2017-12-08 19:40:06 +08:00
|
|
|
getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_FPImmediate:
|
2017-12-20 05:47:00 +08:00
|
|
|
getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2017-12-05 01:18:51 +08:00
|
|
|
OS << printMBBReference(*getMBB());
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-16 00:33:45 +08:00
|
|
|
case MachineOperand::MO_FrameIndex: {
|
|
|
|
int FrameIndex = getIndex();
|
|
|
|
bool IsFixed = false;
|
2018-03-15 05:52:13 +08:00
|
|
|
const MachineFrameInfo *MFI = nullptr;
|
|
|
|
if (const MachineFunction *MF = getMFIfAvailable(*this))
|
|
|
|
MFI = &MF->getFrameInfo();
|
|
|
|
printFrameIndex(OS, FrameIndex, IsFixed, MFI);
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-16 00:33:45 +08:00
|
|
|
}
|
2017-11-29 01:58:43 +08:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2017-12-13 18:30:45 +08:00
|
|
|
OS << "%const." << getIndex();
|
2017-12-20 05:46:55 +08:00
|
|
|
printOperandOffset(OS, getOffset());
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-13 18:30:51 +08:00
|
|
|
case MachineOperand::MO_TargetIndex: {
|
|
|
|
OS << "target-index(";
|
|
|
|
const char *Name = "<unknown>";
|
|
|
|
if (const MachineFunction *MF = getMFIfAvailable(*this))
|
|
|
|
if (const auto *TargetIndexName = getTargetIndexName(*MF, getIndex()))
|
|
|
|
Name = TargetIndexName;
|
|
|
|
OS << Name << ')';
|
2017-12-20 05:46:55 +08:00
|
|
|
printOperandOffset(OS, getOffset());
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-13 18:30:51 +08:00
|
|
|
}
|
2017-11-29 01:58:43 +08:00
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
2017-12-13 18:30:59 +08:00
|
|
|
OS << printJumpTableEntryReference(getIndex());
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
|
2017-12-20 05:46:55 +08:00
|
|
|
printOperandOffset(OS, getOffset());
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-14 18:02:58 +08:00
|
|
|
case MachineOperand::MO_ExternalSymbol: {
|
|
|
|
StringRef Name = getSymbolName();
|
2018-01-10 08:56:48 +08:00
|
|
|
OS << '&';
|
2017-12-14 18:02:58 +08:00
|
|
|
if (Name.empty()) {
|
|
|
|
OS << "\"\"";
|
|
|
|
} else {
|
|
|
|
printLLVMNameWithoutPrefix(OS, Name);
|
|
|
|
}
|
2017-12-20 05:46:55 +08:00
|
|
|
printOperandOffset(OS, getOffset());
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-14 18:02:58 +08:00
|
|
|
}
|
2017-12-20 05:47:14 +08:00
|
|
|
case MachineOperand::MO_BlockAddress: {
|
|
|
|
OS << "blockaddress(";
|
|
|
|
getBlockAddress()->getFunction()->printAsOperand(OS, /*PrintType=*/false,
|
|
|
|
MST);
|
|
|
|
OS << ", ";
|
|
|
|
printIRBlockReference(OS, *getBlockAddress()->getBasicBlock(), MST);
|
|
|
|
OS << ')';
|
|
|
|
MachineOperand::printOperandOffset(OS, getOffset());
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-20 05:47:14 +08:00
|
|
|
}
|
2017-11-29 01:58:43 +08:00
|
|
|
case MachineOperand::MO_RegisterMask: {
|
|
|
|
OS << "<regmask";
|
2017-12-07 18:40:31 +08:00
|
|
|
if (TRI) {
|
|
|
|
unsigned NumRegsInMask = 0;
|
|
|
|
unsigned NumRegsEmitted = 0;
|
|
|
|
for (unsigned i = 0; i < TRI->getNumRegs(); ++i) {
|
|
|
|
unsigned MaskWord = i / 32;
|
|
|
|
unsigned MaskBit = i % 32;
|
|
|
|
if (getRegMask()[MaskWord] & (1 << MaskBit)) {
|
|
|
|
if (PrintRegMaskNumRegs < 0 ||
|
|
|
|
NumRegsEmitted <= static_cast<unsigned>(PrintRegMaskNumRegs)) {
|
|
|
|
OS << " " << printReg(i, TRI);
|
|
|
|
NumRegsEmitted++;
|
|
|
|
}
|
|
|
|
NumRegsInMask++;
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-07 18:40:31 +08:00
|
|
|
if (NumRegsEmitted != NumRegsInMask)
|
|
|
|
OS << " and " << (NumRegsInMask - NumRegsEmitted) << " more...";
|
|
|
|
} else {
|
|
|
|
OS << " ...";
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
OS << ">";
|
|
|
|
break;
|
|
|
|
}
|
2017-12-14 18:03:14 +08:00
|
|
|
case MachineOperand::MO_RegisterLiveOut: {
|
|
|
|
const uint32_t *RegMask = getRegLiveOut();
|
|
|
|
OS << "liveout(";
|
|
|
|
if (!TRI) {
|
|
|
|
OS << "<unknown>";
|
|
|
|
} else {
|
|
|
|
bool IsCommaNeeded = false;
|
|
|
|
for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) {
|
|
|
|
if (RegMask[Reg / 32] & (1U << (Reg % 32))) {
|
|
|
|
if (IsCommaNeeded)
|
|
|
|
OS << ", ";
|
|
|
|
OS << printReg(Reg, TRI);
|
|
|
|
IsCommaNeeded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OS << ")";
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-14 18:03:14 +08:00
|
|
|
}
|
2017-11-29 01:58:43 +08:00
|
|
|
case MachineOperand::MO_Metadata:
|
|
|
|
getMetadata()->printAsOperand(OS, MST);
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_MCSymbol:
|
2017-12-15 23:17:18 +08:00
|
|
|
printSymbol(OS, *getMCSymbol());
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-20 00:51:52 +08:00
|
|
|
case MachineOperand::MO_CFIIndex: {
|
|
|
|
if (const MachineFunction *MF = getMFIfAvailable(*this))
|
|
|
|
printCFI(OS, MF->getFrameInstructions()[getCFIIndex()], TRI);
|
|
|
|
else
|
|
|
|
OS << "<cfi directive>";
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
2017-12-20 00:51:52 +08:00
|
|
|
}
|
2017-11-29 01:58:43 +08:00
|
|
|
case MachineOperand::MO_IntrinsicID: {
|
|
|
|
Intrinsic::ID ID = getIntrinsicID();
|
|
|
|
if (ID < Intrinsic::num_intrinsics)
|
2017-12-20 05:47:05 +08:00
|
|
|
OS << "intrinsic(@" << Intrinsic::getName(ID, None) << ')';
|
2017-11-29 01:58:43 +08:00
|
|
|
else if (IntrinsicInfo)
|
2017-12-20 05:47:05 +08:00
|
|
|
OS << "intrinsic(@" << IntrinsicInfo->getName(ID) << ')';
|
2017-11-29 01:58:43 +08:00
|
|
|
else
|
2017-12-20 05:47:05 +08:00
|
|
|
OS << "intrinsic(" << ID << ')';
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MachineOperand::MO_Predicate: {
|
|
|
|
auto Pred = static_cast<CmpInst::Predicate>(getPredicate());
|
2017-12-20 05:47:10 +08:00
|
|
|
OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred("
|
|
|
|
<< CmpInst::getPredicateName(Pred) << ')';
|
2017-11-29 01:58:43 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-08-13 23:34:38 +08:00
|
|
|
case MachineOperand::MO_ShuffleMask:
|
|
|
|
OS << "shufflemask(";
|
2020-01-14 07:32:45 +08:00
|
|
|
ArrayRef<int> Mask = getShuffleMask();
|
2019-08-13 23:34:38 +08:00
|
|
|
StringRef Separator;
|
2020-01-14 07:32:45 +08:00
|
|
|
for (int Elt : Mask) {
|
|
|
|
if (Elt == -1)
|
|
|
|
OS << Separator << "undef";
|
|
|
|
else
|
|
|
|
OS << Separator << Elt;
|
2019-08-13 23:34:38 +08:00
|
|
|
Separator = ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << ')';
|
|
|
|
break;
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
|
|
|
LLVM_DUMP_METHOD void MachineOperand::dump() const { dbgs() << *this << '\n'; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineMemOperand Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// getAddrSpace - Return the LLVM IR address space number that this pointer
|
|
|
|
/// points into.
|
2017-12-03 06:13:22 +08:00
|
|
|
unsigned MachinePointerInfo::getAddrSpace() const { return AddrSpace; }
|
2017-11-29 01:58:43 +08:00
|
|
|
|
|
|
|
/// isDereferenceable - Return true if V is always dereferenceable for
|
|
|
|
/// Offset + Size byte.
|
|
|
|
bool MachinePointerInfo::isDereferenceable(unsigned Size, LLVMContext &C,
|
|
|
|
const DataLayout &DL) const {
|
|
|
|
if (!V.is<const Value *>())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const Value *BasePtr = V.get<const Value *>();
|
|
|
|
if (BasePtr == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return isDereferenceableAndAlignedPointer(
|
[Alignment][NFC] Deprecate Align::None()
Summary:
This is a follow up on https://reviews.llvm.org/D71473#inline-647262.
There's a caveat here that `Align(1)` relies on the compiler understanding of `Log2_64` implementation to produce good code. One could use `Align()` as a replacement but I believe it is less clear that the alignment is one in that case.
Reviewers: xbolva00, courbet, bollu
Subscribers: arsenm, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, hiraditya, kbarton, jrtc27, atanasyan, jsji, Jim, kerbowa, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D73099
2020-01-21 22:00:04 +08:00
|
|
|
BasePtr, Align(1), APInt(DL.getPointerSizeInBits(), Offset + Size), DL);
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getConstantPool - Return a MachinePointerInfo record that refers to the
|
|
|
|
/// constant pool.
|
|
|
|
MachinePointerInfo MachinePointerInfo::getConstantPool(MachineFunction &MF) {
|
|
|
|
return MachinePointerInfo(MF.getPSVManager().getConstantPool());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getFixedStack - Return a MachinePointerInfo record that refers to the
|
|
|
|
/// the specified FrameIndex.
|
|
|
|
MachinePointerInfo MachinePointerInfo::getFixedStack(MachineFunction &MF,
|
|
|
|
int FI, int64_t Offset) {
|
|
|
|
return MachinePointerInfo(MF.getPSVManager().getFixedStack(FI), Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
MachinePointerInfo MachinePointerInfo::getJumpTable(MachineFunction &MF) {
|
|
|
|
return MachinePointerInfo(MF.getPSVManager().getJumpTable());
|
|
|
|
}
|
|
|
|
|
|
|
|
MachinePointerInfo MachinePointerInfo::getGOT(MachineFunction &MF) {
|
|
|
|
return MachinePointerInfo(MF.getPSVManager().getGOT());
|
|
|
|
}
|
|
|
|
|
|
|
|
MachinePointerInfo MachinePointerInfo::getStack(MachineFunction &MF,
|
|
|
|
int64_t Offset, uint8_t ID) {
|
|
|
|
return MachinePointerInfo(MF.getPSVManager().getStack(), Offset, ID);
|
|
|
|
}
|
|
|
|
|
2017-12-03 06:13:22 +08:00
|
|
|
MachinePointerInfo MachinePointerInfo::getUnknownStack(MachineFunction &MF) {
|
|
|
|
return MachinePointerInfo(MF.getDataLayout().getAllocaAddrSpace());
|
|
|
|
}
|
|
|
|
|
2017-11-29 01:58:43 +08:00
|
|
|
MachineMemOperand::MachineMemOperand(MachinePointerInfo ptrinfo, Flags f,
|
2020-03-30 17:38:44 +08:00
|
|
|
uint64_t s, Align a,
|
2017-11-29 01:58:43 +08:00
|
|
|
const AAMDNodes &AAInfo,
|
|
|
|
const MDNode *Ranges, SyncScope::ID SSID,
|
|
|
|
AtomicOrdering Ordering,
|
|
|
|
AtomicOrdering FailureOrdering)
|
2020-03-26 23:58:11 +08:00
|
|
|
: PtrInfo(ptrinfo), Size(s), FlagVals(f), BaseAlign(a), AAInfo(AAInfo),
|
|
|
|
Ranges(Ranges) {
|
2017-11-29 01:58:43 +08:00
|
|
|
assert((PtrInfo.V.isNull() || PtrInfo.V.is<const PseudoSourceValue *>() ||
|
|
|
|
isa<PointerType>(PtrInfo.V.get<const Value *>()->getType())) &&
|
|
|
|
"invalid pointer value");
|
|
|
|
assert((isLoad() || isStore()) && "Not a load/store!");
|
|
|
|
|
|
|
|
AtomicInfo.SSID = static_cast<unsigned>(SSID);
|
|
|
|
assert(getSyncScopeID() == SSID && "Value truncated");
|
|
|
|
AtomicInfo.Ordering = static_cast<unsigned>(Ordering);
|
|
|
|
assert(getOrdering() == Ordering && "Value truncated");
|
|
|
|
AtomicInfo.FailureOrdering = static_cast<unsigned>(FailureOrdering);
|
|
|
|
assert(getFailureOrdering() == FailureOrdering && "Value truncated");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Profile - Gather unique data for the object.
|
|
|
|
///
|
|
|
|
void MachineMemOperand::Profile(FoldingSetNodeID &ID) const {
|
|
|
|
ID.AddInteger(getOffset());
|
|
|
|
ID.AddInteger(Size);
|
|
|
|
ID.AddPointer(getOpaqueValue());
|
|
|
|
ID.AddInteger(getFlags());
|
[Alignment][NFC] MachineMemOperand::getAlign/getBaseAlign
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: arsenm, dschuff, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, hiraditya, aheejin, kbarton, jrtc27, atanasyan, jfb, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76925
2020-03-27 21:51:59 +08:00
|
|
|
ID.AddInteger(getBaseAlign().value());
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MachineMemOperand::refineAlignment(const MachineMemOperand *MMO) {
|
|
|
|
// The Value and Offset may differ due to CSE. But the flags and size
|
|
|
|
// should be the same.
|
|
|
|
assert(MMO->getFlags() == getFlags() && "Flags mismatch!");
|
|
|
|
assert(MMO->getSize() == getSize() && "Size mismatch!");
|
|
|
|
|
[Alignment][NFC] MachineMemOperand::getAlign/getBaseAlign
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: arsenm, dschuff, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, hiraditya, aheejin, kbarton, jrtc27, atanasyan, jfb, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76925
2020-03-27 21:51:59 +08:00
|
|
|
if (MMO->getBaseAlign() >= getBaseAlign()) {
|
2017-11-29 01:58:43 +08:00
|
|
|
// Update the alignment value.
|
[Alignment][NFC] MachineMemOperand::getAlign/getBaseAlign
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: arsenm, dschuff, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, hiraditya, aheejin, kbarton, jrtc27, atanasyan, jfb, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76925
2020-03-27 21:51:59 +08:00
|
|
|
BaseAlign = MMO->getBaseAlign();
|
2017-11-29 01:58:43 +08:00
|
|
|
// Also update the base and offset, because the new alignment may
|
|
|
|
// not be applicable with the old ones.
|
|
|
|
PtrInfo = MMO->PtrInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getAlignment - Return the minimum known alignment in bytes of the
|
|
|
|
/// actual memory reference.
|
[Alignment][NFC] MachineMemOperand::getAlign/getBaseAlign
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: arsenm, dschuff, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, hiraditya, aheejin, kbarton, jrtc27, atanasyan, jfb, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76925
2020-03-27 21:51:59 +08:00
|
|
|
uint64_t MachineMemOperand::getAlignment() const { return getAlign().value(); }
|
|
|
|
|
|
|
|
/// getAlign - Return the minimum known alignment in bytes of the
|
|
|
|
/// actual memory reference.
|
|
|
|
Align MachineMemOperand::getAlign() const {
|
|
|
|
return commonAlignment(getBaseAlign(), getOffset());
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
|
|
|
|
2018-03-15 05:52:13 +08:00
|
|
|
void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
|
|
|
|
SmallVectorImpl<StringRef> &SSNs,
|
|
|
|
const LLVMContext &Context,
|
|
|
|
const MachineFrameInfo *MFI,
|
2020-01-10 18:18:11 +08:00
|
|
|
const TargetInstrInfo *TII) const {
|
2018-03-15 05:52:13 +08:00
|
|
|
OS << '(';
|
2017-11-29 01:58:43 +08:00
|
|
|
if (isVolatile())
|
2018-03-15 05:52:13 +08:00
|
|
|
OS << "volatile ";
|
|
|
|
if (isNonTemporal())
|
|
|
|
OS << "non-temporal ";
|
|
|
|
if (isDereferenceable())
|
|
|
|
OS << "dereferenceable ";
|
|
|
|
if (isInvariant())
|
|
|
|
OS << "invariant ";
|
|
|
|
if (getFlags() & MachineMemOperand::MOTargetFlag1)
|
|
|
|
OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag1)
|
|
|
|
<< "\" ";
|
|
|
|
if (getFlags() & MachineMemOperand::MOTargetFlag2)
|
|
|
|
OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag2)
|
|
|
|
<< "\" ";
|
|
|
|
if (getFlags() & MachineMemOperand::MOTargetFlag3)
|
|
|
|
OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag3)
|
|
|
|
<< "\" ";
|
|
|
|
|
|
|
|
assert((isLoad() || isStore()) &&
|
|
|
|
"machine memory operand must be a load or store (or both)");
|
2017-11-29 01:58:43 +08:00
|
|
|
if (isLoad())
|
2018-03-15 05:52:13 +08:00
|
|
|
OS << "load ";
|
2017-11-29 01:58:43 +08:00
|
|
|
if (isStore())
|
2018-03-15 05:52:13 +08:00
|
|
|
OS << "store ";
|
2017-11-29 01:58:43 +08:00
|
|
|
|
2018-03-15 05:52:13 +08:00
|
|
|
printSyncScope(OS, Context, getSyncScopeID(), SSNs);
|
2017-11-29 01:58:43 +08:00
|
|
|
|
2018-03-15 05:52:13 +08:00
|
|
|
if (getOrdering() != AtomicOrdering::NotAtomic)
|
|
|
|
OS << toIRString(getOrdering()) << ' ';
|
|
|
|
if (getFailureOrdering() != AtomicOrdering::NotAtomic)
|
|
|
|
OS << toIRString(getFailureOrdering()) << ' ';
|
2017-11-29 01:58:43 +08:00
|
|
|
|
2018-08-21 04:37:57 +08:00
|
|
|
if (getSize() == MemoryLocation::UnknownSize)
|
|
|
|
OS << "unknown-size";
|
|
|
|
else
|
|
|
|
OS << getSize();
|
|
|
|
|
2018-03-15 05:52:13 +08:00
|
|
|
if (const Value *Val = getValue()) {
|
|
|
|
OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
|
2020-01-09 12:02:37 +08:00
|
|
|
MIRFormatter::printIRValue(OS, *Val, MST);
|
2018-03-15 05:52:13 +08:00
|
|
|
} else if (const PseudoSourceValue *PVal = getPseudoValue()) {
|
|
|
|
OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
|
|
|
|
assert(PVal && "Expected a pseudo source value");
|
|
|
|
switch (PVal->kind()) {
|
|
|
|
case PseudoSourceValue::Stack:
|
|
|
|
OS << "stack";
|
|
|
|
break;
|
|
|
|
case PseudoSourceValue::GOT:
|
|
|
|
OS << "got";
|
|
|
|
break;
|
|
|
|
case PseudoSourceValue::JumpTable:
|
|
|
|
OS << "jump-table";
|
|
|
|
break;
|
|
|
|
case PseudoSourceValue::ConstantPool:
|
|
|
|
OS << "constant-pool";
|
|
|
|
break;
|
|
|
|
case PseudoSourceValue::FixedStack: {
|
|
|
|
int FrameIndex = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex();
|
|
|
|
bool IsFixed = true;
|
|
|
|
printFrameIndex(OS, FrameIndex, IsFixed, MFI);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PseudoSourceValue::GlobalValueCallEntry:
|
|
|
|
OS << "call-entry ";
|
|
|
|
cast<GlobalValuePseudoSourceValue>(PVal)->getValue()->printAsOperand(
|
|
|
|
OS, /*PrintType=*/false, MST);
|
|
|
|
break;
|
|
|
|
case PseudoSourceValue::ExternalSymbolCallEntry:
|
|
|
|
OS << "call-entry &";
|
|
|
|
printLLVMNameWithoutPrefix(
|
|
|
|
OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
|
|
|
|
break;
|
2020-01-09 12:02:37 +08:00
|
|
|
default: {
|
2020-01-10 18:18:11 +08:00
|
|
|
const MIRFormatter *Formatter = TII->getMIRFormatter();
|
2018-03-28 05:14:04 +08:00
|
|
|
// FIXME: This is not necessarily the correct MIR serialization format for
|
|
|
|
// a custom pseudo source value, but at least it allows
|
|
|
|
// -print-machineinstrs to work on a target with custom pseudo source
|
|
|
|
// values.
|
2020-01-09 12:02:37 +08:00
|
|
|
OS << "custom \"";
|
2020-01-10 18:18:11 +08:00
|
|
|
Formatter->printCustomPseudoSourceValue(OS, MST, *PVal);
|
2020-01-09 12:02:37 +08:00
|
|
|
OS << '\"';
|
2018-03-15 05:52:13 +08:00
|
|
|
break;
|
|
|
|
}
|
2020-01-09 12:02:37 +08:00
|
|
|
}
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
2018-03-15 05:52:13 +08:00
|
|
|
MachineOperand::printOperandOffset(OS, getOffset());
|
[Alignment][NFC] MachineMemOperand::getAlign/getBaseAlign
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: arsenm, dschuff, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, hiraditya, aheejin, kbarton, jrtc27, atanasyan, jfb, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76925
2020-03-27 21:51:59 +08:00
|
|
|
if (getBaseAlign() != getSize())
|
|
|
|
OS << ", align " << getBaseAlign().value();
|
2018-03-15 05:52:13 +08:00
|
|
|
auto AAInfo = getAAInfo();
|
|
|
|
if (AAInfo.TBAA) {
|
|
|
|
OS << ", !tbaa ";
|
|
|
|
AAInfo.TBAA->printAsOperand(OS, MST);
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
2018-03-15 05:52:13 +08:00
|
|
|
if (AAInfo.Scope) {
|
|
|
|
OS << ", !alias.scope ";
|
|
|
|
AAInfo.Scope->printAsOperand(OS, MST);
|
|
|
|
}
|
|
|
|
if (AAInfo.NoAlias) {
|
|
|
|
OS << ", !noalias ";
|
|
|
|
AAInfo.NoAlias->printAsOperand(OS, MST);
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|
2018-03-15 05:52:13 +08:00
|
|
|
if (getRanges()) {
|
|
|
|
OS << ", !range ";
|
|
|
|
getRanges()->printAsOperand(OS, MST);
|
|
|
|
}
|
|
|
|
// FIXME: Implement addrspace printing/parsing in MIR.
|
|
|
|
// For now, print this even though parsing it is not available in MIR.
|
|
|
|
if (unsigned AS = getAddrSpace())
|
|
|
|
OS << ", addrspace " << AS;
|
2017-11-29 01:58:43 +08:00
|
|
|
|
2018-03-15 05:52:13 +08:00
|
|
|
OS << ')';
|
2017-11-29 01:58:43 +08:00
|
|
|
}
|