[llvm] r358617 - Add a getSizeInBits() accessor to MachineMemOperand. NFC.
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 17 15:21:06 PDT 2019
Author: aemerson
Date: Wed Apr 17 15:21:05 2019
New Revision: 358617
URL: http://llvm.org/viewvc/llvm-project?rev=358617&view=rev
Log:
Add a getSizeInBits() accessor to MachineMemOperand. NFC.
Cleans up a bunch of places where we do getSize() * 8.
Differential Revision: https://reviews.llvm.org/D60799
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h
llvm/trunk/include/llvm/CodeGen/MachineMemOperand.h
llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h
llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/trunk/lib/CodeGen/MachineVerifier.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h?rev=358617&r1=358616&r2=358617&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h Wed Apr 17 15:21:05 2019
@@ -437,15 +437,15 @@ bool InstructionSelector::executeMatchTa
unsigned Size = MRI.getType(MO.getReg()).getSizeInBits();
if (MatcherOpcode == GIM_CheckMemorySizeEqualToLLT &&
- MMO->getSize() * 8 != Size) {
+ MMO->getSizeInBits() != Size) {
if (handleReject() == RejectAndGiveUp)
return false;
} else if (MatcherOpcode == GIM_CheckMemorySizeLessThanLLT &&
- MMO->getSize() * 8 >= Size) {
+ MMO->getSizeInBits() >= Size) {
if (handleReject() == RejectAndGiveUp)
return false;
} else if (MatcherOpcode == GIM_CheckMemorySizeGreaterThanLLT &&
- MMO->getSize() * 8 <= Size)
+ MMO->getSizeInBits() <= Size)
if (handleReject() == RejectAndGiveUp)
return false;
Modified: llvm/trunk/include/llvm/CodeGen/MachineMemOperand.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineMemOperand.h?rev=358617&r1=358616&r2=358617&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineMemOperand.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineMemOperand.h Wed Apr 17 15:21:05 2019
@@ -220,6 +220,9 @@ public:
/// Return the size in bytes of the memory reference.
uint64_t getSize() const { return Size; }
+ /// Return the size in bits of the memory reference.
+ uint64_t getSizeInBits() const { return Size * 8; }
+
/// Return the minimum known alignment in bytes of the actual memory
/// reference.
uint64_t getAlignment() const;
Modified: llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h?rev=358617&r1=358616&r2=358617&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h (original)
+++ llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h Wed Apr 17 15:21:05 2019
@@ -111,6 +111,12 @@ public:
return getScalarSizeInBits() * getNumElements();
}
+ /// Returns the total size of the type in bytes, i.e. number of whole bytes
+ /// needed to represent the size in bits. Must only be called on sized types.
+ unsigned getSizeInBytes() const {
+ return (getSizeInBits() + 7) / 8;
+ }
+
LLT getScalarType() const {
return isVector() ? getElementType() : *this;
}
Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp?rev=358617&r1=358616&r2=358617&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp Wed Apr 17 15:21:05 2019
@@ -603,7 +603,7 @@ LegalizerHelper::LegalizeResult Legalize
unsigned TmpReg = MRI.createGenericVirtualRegister(NarrowTy);
auto &MMO = **MI.memoperands_begin();
- if (MMO.getSize() * 8 == NarrowSize) {
+ if (MMO.getSizeInBits() == NarrowSize) {
MIRBuilder.buildLoad(TmpReg, PtrReg, MMO);
} else {
unsigned ExtLoad = ZExt ? TargetOpcode::G_ZEXTLOAD
@@ -1483,7 +1483,7 @@ LegalizerHelper::lower(MachineInstr &MI,
LLT DstTy = MRI.getType(DstReg);
auto &MMO = **MI.memoperands_begin();
- if (DstTy.getSizeInBits() == MMO.getSize() /* in bytes */ * 8) {
+ if (DstTy.getSizeInBits() == MMO.getSizeInBits()) {
if (MI.getOpcode() == TargetOpcode::G_LOAD) {
// This load needs splitting into power of 2 sized loads.
if (DstTy.isVector())
@@ -1540,8 +1540,8 @@ LegalizerHelper::lower(MachineInstr &MI,
}
if (DstTy.isScalar()) {
- unsigned TmpReg = MRI.createGenericVirtualRegister(
- LLT::scalar(MMO.getSize() /* in bytes */ * 8));
+ unsigned TmpReg =
+ MRI.createGenericVirtualRegister(LLT::scalar(MMO.getSizeInBits()));
MIRBuilder.buildLoad(TmpReg, PtrReg, MMO);
switch (MI.getOpcode()) {
default:
@@ -1573,7 +1573,7 @@ LegalizerHelper::lower(MachineInstr &MI,
unsigned PtrReg = MI.getOperand(1).getReg();
LLT SrcTy = MRI.getType(SrcReg);
MachineMemOperand &MMO = **MI.memoperands_begin();
- if (SrcTy.getSizeInBits() != MMO.getSize() /* in bytes */ * 8)
+ if (SrcTy.getSizeInBits() != MMO.getSizeInBits())
return UnableToLegalize;
if (SrcTy.isVector())
return UnableToLegalize;
Modified: llvm/trunk/lib/CodeGen/MachineVerifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineVerifier.cpp?rev=358617&r1=358616&r2=358617&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineVerifier.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineVerifier.cpp Wed Apr 17 15:21:05 2019
@@ -1022,13 +1022,13 @@ void MachineVerifier::verifyPreISelGener
const MachineMemOperand &MMO = **MI->memoperands_begin();
if (MI->getOpcode() == TargetOpcode::G_ZEXTLOAD ||
MI->getOpcode() == TargetOpcode::G_SEXTLOAD) {
- if (MMO.getSize() * 8 >= ValTy.getSizeInBits())
+ if (MMO.getSizeInBits() >= ValTy.getSizeInBits())
report("Generic extload must have a narrower memory type", MI);
} else if (MI->getOpcode() == TargetOpcode::G_LOAD) {
- if (MMO.getSize() > (ValTy.getSizeInBits() + 7) / 8)
+ if (MMO.getSize() > ValTy.getSizeInBytes())
report("load memory size cannot exceed result size", MI);
} else if (MI->getOpcode() == TargetOpcode::G_STORE) {
- if ((ValTy.getSizeInBits() + 7) / 8 < MMO.getSize())
+ if (ValTy.getSizeInBytes() < MMO.getSize())
report("store memory size cannot exceed value size", MI);
}
}
More information about the llvm-commits
mailing list