[llvm] r272757 - [PM] Port AlignmentFromAssumptions to the new PM.

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 14 23:18:02 PDT 2016


Author: silvas
Date: Wed Jun 15 01:18:01 2016
New Revision: 272757

URL: http://llvm.org/viewvc/llvm-project?rev=272757&view=rev
Log:
[PM] Port AlignmentFromAssumptions to the new PM.

This uses the "runImpl" pattern to share code between the old and new PM.

Added:
    llvm/trunk/include/llvm/Transforms/Scalar/AlignmentFromAssumptions.h
Modified:
    llvm/trunk/lib/Passes/PassBuilder.cpp
    llvm/trunk/lib/Passes/PassRegistry.def
    llvm/trunk/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
    llvm/trunk/test/Transforms/AlignmentFromAssumptions/simple.ll
    llvm/trunk/test/Transforms/AlignmentFromAssumptions/simple32.ll
    llvm/trunk/test/Transforms/AlignmentFromAssumptions/start-unk.ll

Added: llvm/trunk/include/llvm/Transforms/Scalar/AlignmentFromAssumptions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar/AlignmentFromAssumptions.h?rev=272757&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Scalar/AlignmentFromAssumptions.h (added)
+++ llvm/trunk/include/llvm/Transforms/Scalar/AlignmentFromAssumptions.h Wed Jun 15 01:18:01 2016
@@ -0,0 +1,51 @@
+//===---- AlignmentFromAssumptions.h ----------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a ScalarEvolution-based transformation to set
+// the alignments of load, stores and memory intrinsics based on the truth
+// expressions of assume intrinsics. The primary motivation is to handle
+// complex alignment assumptions that apply to vector loads and stores that
+// appear after vectorization and unrolling.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_SCALAR_ALIGNMENTFROMASSUMPTIONS_H
+#define LLVM_TRANSFORMS_SCALAR_ALIGNMENTFROMASSUMPTIONS_H
+
+#include "llvm/Analysis/ScalarEvolution.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+struct AlignmentFromAssumptionsPass
+    : public PassInfoMixin<AlignmentFromAssumptionsPass> {
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+
+  // Glue for old PM.
+  bool runImpl(Function &F, AssumptionCache &AC, ScalarEvolution *SE_,
+               DominatorTree *DT_);
+
+  // For memory transfers, we need a common alignment for both the source and
+  // destination. If we have a new alignment for only one operand of a transfer
+  // instruction, save it in these maps.  If we reach the other operand through
+  // another assumption later, then we may change the alignment at that point.
+  DenseMap<MemTransferInst *, unsigned> NewDestAlignments, NewSrcAlignments;
+
+  ScalarEvolution *SE = nullptr;
+  DominatorTree *DT = nullptr;
+
+  bool extractAlignmentInfo(CallInst *I, Value *&AAPtr, const SCEV *&AlignSCEV,
+                            const SCEV *&OffSCEV);
+  bool processAssumption(CallInst *I);
+};
+}
+
+#endif // LLVM_TRANSFORMS_SCALAR_ALIGNMENTFROMASSUMPTIONS_H

Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=272757&r1=272756&r2=272757&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Wed Jun 15 01:18:01 2016
@@ -69,6 +69,7 @@
 #include "llvm/Transforms/PGOInstrumentation.h"
 #include "llvm/Transforms/SampleProfile.h"
 #include "llvm/Transforms/Scalar/ADCE.h"
+#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
 #include "llvm/Transforms/Scalar/BDCE.h"
 #include "llvm/Transforms/Scalar/DCE.h"
 #include "llvm/Transforms/Scalar/DeadStoreElimination.h"

Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=272757&r1=272756&r2=272757&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Wed Jun 15 01:18:01 2016
@@ -119,6 +119,7 @@ FUNCTION_ALIAS_ANALYSIS("type-based-aa",
 #endif
 FUNCTION_PASS("aa-eval", AAEvaluator())
 FUNCTION_PASS("adce", ADCEPass())
+FUNCTION_PASS("alignment-from-assumptions", AlignmentFromAssumptionsPass())
 FUNCTION_PASS("bdce", BDCEPass())
 FUNCTION_PASS("dce", DCEPass())
 FUNCTION_PASS("dse", DSEPass())

Modified: llvm/trunk/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp?rev=272757&r1=272756&r2=272757&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp Wed Jun 15 01:18:01 2016
@@ -18,6 +18,7 @@
 
 #define AA_NAME "alignment-from-assumptions"
 #define DEBUG_TYPE AA_NAME
+#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/Statistic.h"
@@ -25,13 +26,11 @@
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/AssumptionCache.h"
 #include "llvm/Analysis/LoopInfo.h"
-#include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/IR/Constant.h"
 #include "llvm/IR/Dominators.h"
 #include "llvm/IR/Instruction.h"
-#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/Debug.h"
@@ -67,18 +66,7 @@ struct AlignmentFromAssumptions : public
     AU.addPreserved<ScalarEvolutionWrapperPass>();
   }
 
-  // For memory transfers, we need a common alignment for both the source and
-  // destination. If we have a new alignment for only one operand of a transfer
-  // instruction, save it in these maps.  If we reach the other operand through
-  // another assumption later, then we may change the alignment at that point.
-  DenseMap<MemTransferInst *, unsigned> NewDestAlignments, NewSrcAlignments;
-
-  ScalarEvolution *SE;
-  DominatorTree *DT;
-
-  bool extractAlignmentInfo(CallInst *I, Value *&AAPtr, const SCEV *&AlignSCEV,
-                            const SCEV *&OffSCEV);
-  bool processAssumption(CallInst *I);
+  AlignmentFromAssumptionsPass Impl;
 };
 }
 
@@ -209,9 +197,10 @@ static unsigned getNewAlignment(const SC
   return 0;
 }
 
-bool AlignmentFromAssumptions::extractAlignmentInfo(CallInst *I,
-                                 Value *&AAPtr, const SCEV *&AlignSCEV,
-                                 const SCEV *&OffSCEV) {
+bool AlignmentFromAssumptionsPass::extractAlignmentInfo(CallInst *I,
+                                                        Value *&AAPtr,
+                                                        const SCEV *&AlignSCEV,
+                                                        const SCEV *&OffSCEV) {
   // An alignment assume must be a statement about the least-significant
   // bits of the pointer being zero, possibly with some offset.
   ICmpInst *ICI = dyn_cast<ICmpInst>(I->getArgOperand(0));
@@ -302,7 +291,7 @@ bool AlignmentFromAssumptions::extractAl
   return true;
 }
 
-bool AlignmentFromAssumptions::processAssumption(CallInst *ACall) {
+bool AlignmentFromAssumptionsPass::processAssumption(CallInst *ACall) {
   Value *AAPtr;
   const SCEV *AlignSCEV, *OffSCEV;
   if (!extractAlignmentInfo(ACall, AAPtr, AlignSCEV, OffSCEV))
@@ -414,14 +403,23 @@ bool AlignmentFromAssumptions::runOnFunc
   if (skipFunction(F))
     return false;
 
-  bool Changed = false;
   auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
-  SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
-  DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+  ScalarEvolution *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
+  DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+
+  return Impl.runImpl(F, AC, SE, DT);
+}
+
+bool AlignmentFromAssumptionsPass::runImpl(Function &F, AssumptionCache &AC,
+                                           ScalarEvolution *SE_,
+                                           DominatorTree *DT_) {
+  SE = SE_;
+  DT = DT_;
 
   NewDestAlignments.clear();
   NewSrcAlignments.clear();
 
+  bool Changed = false;
   for (auto &AssumeVH : AC.assumptions())
     if (AssumeVH)
       Changed |= processAssumption(cast<CallInst>(AssumeVH));
@@ -429,3 +427,20 @@ bool AlignmentFromAssumptions::runOnFunc
   return Changed;
 }
 
+PreservedAnalyses
+AlignmentFromAssumptionsPass::run(Function &F, FunctionAnalysisManager &AM) {
+
+  AssumptionCache &AC = AM.getResult<AssumptionAnalysis>(F);
+  ScalarEvolution &SE = AM.getResult<ScalarEvolutionAnalysis>(F);
+  DominatorTree &DT = AM.getResult<DominatorTreeAnalysis>(F);
+  bool Changed = runImpl(F, AC, &SE, &DT);
+  if (!Changed)
+    return PreservedAnalyses::all();
+  PreservedAnalyses PA;
+  PA.preserve<AAManager>();
+  PA.preserve<ScalarEvolutionAnalysis>();
+  PA.preserve<GlobalsAA>();
+  PA.preserve<LoopAnalysis>();
+  PA.preserve<DominatorTreeAnalysis>();
+  return PA;
+}

Modified: llvm/trunk/test/Transforms/AlignmentFromAssumptions/simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/AlignmentFromAssumptions/simple.ll?rev=272757&r1=272756&r2=272757&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/AlignmentFromAssumptions/simple.ll (original)
+++ llvm/trunk/test/Transforms/AlignmentFromAssumptions/simple.ll Wed Jun 15 01:18:01 2016
@@ -1,5 +1,6 @@
 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
 ; RUN: opt < %s -alignment-from-assumptions -S | FileCheck %s
+; RUN: opt < %s -passes=alignment-from-assumptions -S | FileCheck %s
 
 define i32 @foo(i32* nocapture %a) nounwind uwtable readonly {
 entry:

Modified: llvm/trunk/test/Transforms/AlignmentFromAssumptions/simple32.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/AlignmentFromAssumptions/simple32.ll?rev=272757&r1=272756&r2=272757&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/AlignmentFromAssumptions/simple32.ll (original)
+++ llvm/trunk/test/Transforms/AlignmentFromAssumptions/simple32.ll Wed Jun 15 01:18:01 2016
@@ -1,5 +1,6 @@
 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64"
 ; RUN: opt < %s -alignment-from-assumptions -S | FileCheck %s
+; RUN: opt < %s -passes=alignment-from-assumptions -S | FileCheck %s
 
 define i32 @foo(i32* nocapture %a) nounwind uwtable readonly {
 entry:

Modified: llvm/trunk/test/Transforms/AlignmentFromAssumptions/start-unk.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/AlignmentFromAssumptions/start-unk.ll?rev=272757&r1=272756&r2=272757&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/AlignmentFromAssumptions/start-unk.ll (original)
+++ llvm/trunk/test/Transforms/AlignmentFromAssumptions/start-unk.ll Wed Jun 15 01:18:01 2016
@@ -1,4 +1,5 @@
 ; RUN: opt -alignment-from-assumptions -S < %s | FileCheck %s
+; RUN: opt -passes=alignment-from-assumptions -S < %s | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 




More information about the llvm-commits mailing list