xref: /llvm-project/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp (revision c1c42518c1356e78a10bf252a4a5a643b2bb9efd)
1 //===- SandboxVectorizer.cpp - Vectorizer based on Sandbox IR -------------===//
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/SandboxVectorizer.h"
10 #include "llvm/Analysis/TargetTransformInfo.h"
11 #include "llvm/SandboxIR/SandboxIR.h"
12 
13 using namespace llvm;
14 
15 #define SV_NAME "sandbox-vectorizer"
16 #define DEBUG_TYPE SV_NAME
17 
18 PreservedAnalyses SandboxVectorizerPass::run(Function &F,
19                                              FunctionAnalysisManager &AM) {
20   TTI = &AM.getResult<TargetIRAnalysis>(F);
21 
22   bool Changed = runImpl(F);
23   if (!Changed)
24     return PreservedAnalyses::all();
25 
26   PreservedAnalyses PA;
27   PA.preserveSet<CFGAnalyses>();
28   return PA;
29 }
30 
31 bool SandboxVectorizerPass::runImpl(Function &F) {
32   // If the target claims to have no vector registers early return.
33   if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true))) {
34     LLVM_DEBUG(dbgs() << "SBVec: Target has no vector registers, return.\n");
35     return false;
36   }
37   LLVM_DEBUG(dbgs() << "SBVec: Analyzing " << F.getName() << ".\n");
38   // Early return if the attribute NoImplicitFloat is used.
39   if (F.hasFnAttribute(Attribute::NoImplicitFloat)) {
40     LLVM_DEBUG(dbgs() << "SBVec: NoImplicitFloat attribute, return.\n");
41     return false;
42   }
43 
44   sandboxir::Context Ctx(F.getContext());
45   // Create SandboxIR for `F`.
46   sandboxir::Function &SBF = *Ctx.createFunction(&F);
47   // TODO: Initialize SBVec Pass Manager
48   (void)SBF;
49 
50   return false;
51 }
52