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 28 struct ScalarizerPassOptions { 29 // These options correspond 1:1 to cl::opt options defined in 30 // Scalarizer.cpp. When the cl::opt are specified, they take precedence. 31 // When the cl::opt are not specified, the present optional values allow to 32 // override the cl::opt's default values. 33 std::optional<bool> ScalarizeVariableInsertExtract; 34 std::optional<bool> ScalarizeLoadStore; 35 std::optional<unsigned> ScalarizeMinBits; 36 }; 37 38 class ScalarizerPass : public PassInfoMixin<ScalarizerPass> { 39 ScalarizerPassOptions Options; 40 41 public: 42 ScalarizerPass() = default; 43 ScalarizerPass(const ScalarizerPassOptions &Options) : Options(Options) {} 44 45 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); 46 47 void setScalarizeVariableInsertExtract(bool Value) { 48 Options.ScalarizeVariableInsertExtract = Value; 49 } 50 void setScalarizeLoadStore(bool Value) { Options.ScalarizeLoadStore = Value; } 51 void setScalarizeMinBits(unsigned Value) { Options.ScalarizeMinBits = Value; } 52 }; 53 } 54 55 #endif /* LLVM_TRANSFORMS_SCALAR_SCALARIZER_H */ 56