[llvm] r374369 - [Alignment][NFC] Use llv::Align in GISelKnownBits

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 10 08:38:22 PDT 2019


Author: gchatelet
Date: Thu Oct 10 08:38:22 2019
New Revision: 374369

URL: http://llvm.org/viewvc/llvm-project?rev=374369&view=rev
Log:
[Alignment][NFC] Use llv::Align in GISelKnownBits

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: hiraditya, llvm-commits

Tags: #llvm

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

Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h
    llvm/trunk/lib/CodeGen/GlobalISel/GISelKnownBits.cpp

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h?rev=374369&r1=374368&r2=374369&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h Thu Oct 10 08:38:22 2019
@@ -63,12 +63,13 @@ public:
   void computeKnownBitsForFrameIndex(Register R, KnownBits &Known,
                                      const APInt &DemandedElts,
                                      unsigned Depth = 0);
-  static unsigned inferAlignmentForFrameIdx(int FrameIdx, int Offset,
-                                            const MachineFunction &MF);
-  static void computeKnownBitsForAlignment(KnownBits &Known, unsigned Align);
+  static Align inferAlignmentForFrameIdx(int FrameIdx, int Offset,
+                                         const MachineFunction &MF);
+  static void computeKnownBitsForAlignment(KnownBits &Known,
+                                           MaybeAlign Alignment);
 
   // Try to infer alignment for MI.
-  static unsigned inferPtrAlignment(const MachineInstr &MI);
+  static MaybeAlign inferPtrAlignment(const MachineInstr &MI);
 
   // Observer API. No-op for non-caching implementation.
   void erasingInstr(MachineInstr &MI) override{};

Modified: llvm/trunk/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/GISelKnownBits.cpp?rev=374369&r1=374368&r2=374369&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/GISelKnownBits.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/GISelKnownBits.cpp Thu Oct 10 08:38:22 2019
@@ -33,19 +33,19 @@ GISelKnownBits::GISelKnownBits(MachineFu
     : MF(MF), MRI(MF.getRegInfo()), TL(*MF.getSubtarget().getTargetLowering()),
       DL(MF.getFunction().getParent()->getDataLayout()) {}
 
-unsigned GISelKnownBits::inferAlignmentForFrameIdx(int FrameIdx, int Offset,
-                                                   const MachineFunction &MF) {
+Align GISelKnownBits::inferAlignmentForFrameIdx(int FrameIdx, int Offset,
+                                                const MachineFunction &MF) {
   const MachineFrameInfo &MFI = MF.getFrameInfo();
-  return MinAlign(Offset, MFI.getObjectAlignment(FrameIdx));
+  return commonAlignment(Align(MFI.getObjectAlignment(FrameIdx)), Offset);
   // TODO: How to handle cases with Base + Offset?
 }
 
-unsigned GISelKnownBits::inferPtrAlignment(const MachineInstr &MI) {
+MaybeAlign GISelKnownBits::inferPtrAlignment(const MachineInstr &MI) {
   if (MI.getOpcode() == TargetOpcode::G_FRAME_INDEX) {
     int FrameIdx = MI.getOperand(1).getIndex();
     return inferAlignmentForFrameIdx(FrameIdx, 0, *MI.getMF());
   }
-  return 0;
+  return None;
 }
 
 void GISelKnownBits::computeKnownBitsForFrameIndex(Register R, KnownBits &Known,
@@ -56,10 +56,10 @@ void GISelKnownBits::computeKnownBitsFor
 }
 
 void GISelKnownBits::computeKnownBitsForAlignment(KnownBits &Known,
-                                                  unsigned Align) {
-  if (Align)
+                                                  MaybeAlign Alignment) {
+  if (Alignment)
     // The low bits are known zero if the pointer is aligned.
-    Known.Zero.setLowBits(Log2_32(Align));
+    Known.Zero.setLowBits(Log2(Alignment));
 }
 
 KnownBits GISelKnownBits::getKnownBits(MachineInstr &MI) {




More information about the llvm-commits mailing list