1 //===- Legality.cpp -------------------------------------------------------===// 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 #include "llvm/Transforms/Vectorize/SandboxVectorizer/Legality.h" 10 #include "llvm/SandboxIR/Instruction.h" 11 #include "llvm/SandboxIR/Utils.h" 12 #include "llvm/SandboxIR/Value.h" 13 #include "llvm/Support/Debug.h" 14 15 namespace llvm::sandboxir { 16 17 #define DEBUG_TYPE "SBVec:Legality" 18 19 #ifndef NDEBUG 20 void LegalityResult::dump() const { 21 print(dbgs()); 22 dbgs() << "\n"; 23 } 24 #endif // NDEBUG 25 26 std::optional<ResultReason> 27 LegalityAnalysis::notVectorizableBasedOnOpcodesAndTypes( 28 ArrayRef<Value *> Bndl) { 29 // TODO: Unimplemented. 30 return std::nullopt; 31 } 32 33 #ifndef NDEBUG 34 static void dumpBndl(ArrayRef<Value *> Bndl) { 35 for (auto *V : Bndl) 36 dbgs() << *V << "\n"; 37 } 38 #endif // NDEBUG 39 40 const LegalityResult &LegalityAnalysis::canVectorize(ArrayRef<Value *> Bndl) { 41 // If Bndl contains values other than instructions, we need to Pack. 42 if (any_of(Bndl, [](auto *V) { return !isa<Instruction>(V); })) { 43 LLVM_DEBUG(dbgs() << "Not vectorizing: Not Instructions:\n"; 44 dumpBndl(Bndl);); 45 return createLegalityResult<Pack>(ResultReason::NotInstructions); 46 } 47 48 if (auto ReasonOpt = notVectorizableBasedOnOpcodesAndTypes(Bndl)) 49 return createLegalityResult<Pack>(*ReasonOpt); 50 51 // TODO: Check for existing vectors containing values in Bndl. 52 53 // TODO: Check with scheduler. 54 55 return createLegalityResult<Widen>(); 56 } 57 } // namespace llvm::sandboxir 58