1 //===- Scalarizer.h --- Scalarize vector operations -----------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 /// \file 10 /// This pass converts vector operations into scalar operations (or, optionally, 11 /// operations on smaller vector widths), in order to expose optimization 12 /// opportunities on the individual scalar operations. 13 /// It is mainly intended for targets that do not have vector units, but it 14 /// may also be useful for revectorizing code to different vector widths. 15 // 16 //===----------------------------------------------------------------------===// 17 18 #ifndef LLVM_TRANSFORMS_SCALAR_SCALARIZER_H 19 #define LLVM_TRANSFORMS_SCALAR_SCALARIZER_H 20 21 #include "llvm/IR/PassManager.h" 22 #include <optional> 23 24 namespace llvm { 25 26 class Function; 27 class FunctionPass; 28 29 struct ScalarizerPassOptions { 30 /// Instruct the scalarizer pass to attempt to keep values of a minimum number 31 /// of bits. 32 33 /// Split vectors larger than this size into fragments, where each fragment is 34 /// either a vector no larger than this size or a scalar. 35 /// 36 /// Instructions with operands or results of different sizes that would be 37 /// split into a different number of fragments are currently left as-is. 38 unsigned ScalarizeMinBits = 0; 39 40 /// Allow the scalarizer pass to scalarize insertelement/extractelement with 41 /// variable index. 42 bool ScalarizeVariableInsertExtract = true; 43 44 /// Allow the scalarizer pass to scalarize loads and store 45 /// 46 /// This is disabled by default because having separate loads and stores makes 47 /// it more likely that the -combiner-alias-analysis limits will be reached. 48 bool ScalarizeLoadStore = false; 49 }; 50 51 class ScalarizerPass : public PassInfoMixin<ScalarizerPass> { 52 ScalarizerPassOptions Options; 53 54 public: 55 ScalarizerPass() = default; 56 ScalarizerPass(const ScalarizerPassOptions &Options) : Options(Options) {} 57 58 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); 59 60 void setScalarizeVariableInsertExtract(bool Value) { 61 Options.ScalarizeVariableInsertExtract = Value; 62 } 63 void setScalarizeLoadStore(bool Value) { Options.ScalarizeLoadStore = Value; } 64 void setScalarizeMinBits(unsigned Value) { Options.ScalarizeMinBits = Value; } 65 }; 66 67 /// Create a legacy pass manager instance of the Scalarizer pass 68 FunctionPass *createScalarizerPass( 69 const ScalarizerPassOptions &Options = ScalarizerPassOptions()); 70 } 71 72 #endif /* LLVM_TRANSFORMS_SCALAR_SCALARIZER_H */ 73