Index: include/llvm/Transforms/Scalar/Scalarizer.h =================================================================== --- /dev/null +++ include/llvm/Transforms/Scalar/Scalarizer.h @@ -0,0 +1,30 @@ +//===- Scalarizer.h --- Scalarize vector operations -----------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This pass converts vector operations into scalar operations, in order +// to expose optimization opportunities on the individual scalar operations. +// It is mainly intended for targets that do not have vector units, but it +// may also be useful for revectorizing code to different vector widths. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TRANSFORMS_SCALAR_SCALARIZER_H +#define LLVM_TRANSFORMS_SCALAR_SCALARIZER_H + +#include "llvm/IR/PassManager.h" + +namespace llvm { + +class ScalarizerPass : public PassInfoMixin { +public: + PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); +}; +} + +#endif /* LLVM_TRANSFORMS_SCALAR_SCALARIZER_H */ Index: lib/Passes/PassBuilder.cpp =================================================================== --- lib/Passes/PassBuilder.cpp +++ lib/Passes/PassBuilder.cpp @@ -139,6 +139,7 @@ #include "llvm/Transforms/Scalar/RewriteStatepointsForGC.h" #include "llvm/Transforms/Scalar/SCCP.h" #include "llvm/Transforms/Scalar/SROA.h" +#include "llvm/Transforms/Scalar/Scalarizer.h" #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h" #include "llvm/Transforms/Scalar/SimplifyCFG.h" #include "llvm/Transforms/Scalar/Sink.h" Index: lib/Passes/PassRegistry.def =================================================================== --- lib/Passes/PassRegistry.def +++ lib/Passes/PassRegistry.def @@ -205,6 +205,7 @@ FUNCTION_PASS("print", RegionInfoPrinterPass(dbgs())) FUNCTION_PASS("print", ScalarEvolutionPrinterPass(dbgs())) FUNCTION_PASS("reassociate", ReassociatePass()) +FUNCTION_PASS("scalarizer", ScalarizerPass()) FUNCTION_PASS("sccp", SCCPPass()) FUNCTION_PASS("simplify-cfg", SimplifyCFGPass()) FUNCTION_PASS("sink", SinkingPass()) Index: lib/Transforms/Scalar/Scalarizer.cpp =================================================================== --- lib/Transforms/Scalar/Scalarizer.cpp +++ lib/Transforms/Scalar/Scalarizer.cpp @@ -40,6 +40,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/Options.h" #include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Scalar/Scalarizer.h" #include #include #include @@ -155,6 +156,7 @@ class Scalarizer : public FunctionPass, public InstVisitor { + friend class llvm::ScalarizerPass; public: static char ID; @@ -164,6 +166,7 @@ bool doInitialization(Module &M) override; bool runOnFunction(Function &F) override; + bool doTransform(Function &F); void getAnalysisUsage(AnalysisUsage& AU) const override { AU.addRequired(); @@ -298,11 +301,14 @@ } bool Scalarizer::runOnFunction(Function &F) { + DT = &getAnalysis().getDomTree(); + return doTransform(F); +} + +bool Scalarizer::doTransform(Function &F) { if (skipFunction(F)) return false; - DT = &getAnalysis().getDomTree(); - assert(Gathered.empty() && Scattered.empty()); // To ensure we replace gathered components correctly we need to do an ordered @@ -842,3 +848,13 @@ FunctionPass *llvm::createScalarizerPass() { return new Scalarizer(); } + +PreservedAnalyses ScalarizerPass::run(Function &F, FunctionAnalysisManager &AM) { + Scalarizer Impl; + (void)Impl.doInitialization(*F.getParent()); + Impl.DT = &AM.getResult(F); + bool Modified = Impl.doTransform(F); + PreservedAnalyses PA; + PA.preserve(); + return Modified ? PA : PreservedAnalyses::all(); +} Index: test/Transforms/Scalarizer/basic.ll =================================================================== --- test/Transforms/Scalarizer/basic.ll +++ test/Transforms/Scalarizer/basic.ll @@ -1,4 +1,5 @@ ; RUN: opt %s -scalarizer -scalarize-load-store -dce -S | FileCheck %s +; RUN: opt %s -passes='function(scalarizer,dce)' -scalarize-load-store -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" declare <4 x float> @ext(<4 x float>)