Vasileios Porpodas 1540f772c7 Reapply "[SandboxVec][Legality] Reject non-instructions (#113190)"
This reverts commit eb9f4756bc3daaa4b19f4f46521dc05180814de4.
2024-10-25 12:55:58 -07:00

58 lines
1.7 KiB
C++

//===- Legality.cpp -------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Legality.h"
#include "llvm/SandboxIR/Instruction.h"
#include "llvm/SandboxIR/Utils.h"
#include "llvm/SandboxIR/Value.h"
#include "llvm/Support/Debug.h"
namespace llvm::sandboxir {
#define DEBUG_TYPE "SBVec:Legality"
#ifndef NDEBUG
void LegalityResult::dump() const {
print(dbgs());
dbgs() << "\n";
}
#endif // NDEBUG
std::optional<ResultReason>
LegalityAnalysis::notVectorizableBasedOnOpcodesAndTypes(
ArrayRef<Value *> Bndl) {
// TODO: Unimplemented.
return std::nullopt;
}
#ifndef NDEBUG
static void dumpBndl(ArrayRef<Value *> Bndl) {
for (auto *V : Bndl)
dbgs() << *V << "\n";
}
#endif // NDEBUG
const LegalityResult &LegalityAnalysis::canVectorize(ArrayRef<Value *> Bndl) {
// If Bndl contains values other than instructions, we need to Pack.
if (any_of(Bndl, [](auto *V) { return !isa<Instruction>(V); })) {
LLVM_DEBUG(dbgs() << "Not vectorizing: Not Instructions:\n";
dumpBndl(Bndl););
return createLegalityResult<Pack>(ResultReason::NotInstructions);
}
if (auto ReasonOpt = notVectorizableBasedOnOpcodesAndTypes(Bndl))
return createLegalityResult<Pack>(*ReasonOpt);
// TODO: Check for existing vectors containing values in Bndl.
// TODO: Check with scheduler.
return createLegalityResult<Widen>();
}
} // namespace llvm::sandboxir