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 static void dumpBndl(ArrayRef<Value *> Bndl) { 34 for (auto *V : Bndl) 35 dbgs() << *V << "\n"; 36 } 37 38 const LegalityResult &LegalityAnalysis::canVectorize(ArrayRef<Value *> Bndl) { 39 // If Bndl contains values other than instructions, we need to Pack. 40 if (any_of(Bndl, [](auto *V) { return !isa<Instruction>(V); })) { 41 LLVM_DEBUG(dbgs() << "Not vectorizing: Not Instructions:\n"; 42 dumpBndl(Bndl);); 43 return createLegalityResult<Pack>(ResultReason::NotInstructions); 44 } 45 46 if (auto ReasonOpt = notVectorizableBasedOnOpcodesAndTypes(Bndl)) 47 return createLegalityResult<Pack>(*ReasonOpt); 48 49 // TODO: Check for existing vectors containing values in Bndl. 50 51 // TODO: Check with scheduler. 52 53 return createLegalityResult<Widen>(); 54 } 55 } // namespace llvm::sandboxir 56