[Alignment][NFC] GlobalIsel Utils inferAlignFromPtrInfo
authorGuillaume Chatelet <gchatelet@google.com>
Mon, 30 Mar 2020 18:55:41 +0000 (18:55 +0000)
committerGuillaume Chatelet <gchatelet@google.com>
Tue, 31 Mar 2020 06:58:57 +0000 (06:58 +0000)
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: rovka, hiraditya, volkan, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77079

llvm/include/llvm/CodeGen/GlobalISel/Utils.h
llvm/lib/CodeGen/GlobalISel/Utils.cpp

index c30f4db..54079ff 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/CodeGen/Register.h"
+#include "llvm/Support/Alignment.h"
 #include "llvm/Support/LowLevelTypeImpl.h"
 #include "llvm/Support/MachineValueType.h"
 
@@ -181,8 +182,13 @@ inline bool isKnownNeverSNaN(Register Val, const MachineRegisterInfo &MRI) {
   return isKnownNeverNaN(Val, MRI, true);
 }
 
-unsigned inferAlignmentFromPtrInfo(MachineFunction &MF,
-                                   const MachinePointerInfo &MPO);
+Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO);
+
+/// FIXME: Remove once the transition to Align is over.
+inline unsigned inferAlignmentFromPtrInfo(MachineFunction &MF,
+                                          const MachinePointerInfo &MPO) {
+  return inferAlignFromPtrInfo(MF, MPO).value();
+}
 
 /// Return the least common multiple type of \p Ty0 and \p Ty1, by changing
 /// the number of vector elements or scalar bitwidth. The intent is a
index 27b346d..d248a2f 100644 (file)
@@ -457,15 +457,16 @@ bool llvm::isKnownNeverNaN(Register Val, const MachineRegisterInfo &MRI,
   return false;
 }
 
-unsigned llvm::inferAlignmentFromPtrInfo(MachineFunction &MF,
-                                         const MachinePointerInfo &MPO) {
+Align llvm::inferAlignFromPtrInfo(MachineFunction &MF,
+                                  const MachinePointerInfo &MPO) {
   auto PSV = MPO.V.dyn_cast<const PseudoSourceValue *>();
   if (auto FSPV = dyn_cast_or_null<FixedStackPseudoSourceValue>(PSV)) {
     MachineFrameInfo &MFI = MF.getFrameInfo();
-    return MinAlign(MFI.getObjectAlignment(FSPV->getFrameIndex()), MPO.Offset);
+    return commonAlignment(MFI.getObjectAlign(FSPV->getFrameIndex()),
+                           MPO.Offset);
   }
 
-  return 1;
+  return Align(1);
 }
 
 Optional<APInt> llvm::ConstantFoldExtOp(unsigned Opcode, const unsigned Op1,