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/Constant.h" 12 #include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h" 13 14 using namespace llvm; 15 16 #define SV_NAME "sandbox-vectorizer" 17 #define DEBUG_TYPE SV_NAME 18 19 SandboxVectorizerPass::SandboxVectorizerPass() = default; 20 21 SandboxVectorizerPass::SandboxVectorizerPass(SandboxVectorizerPass &&) = 22 default; 23 24 SandboxVectorizerPass::~SandboxVectorizerPass() = default; 25 26 PreservedAnalyses SandboxVectorizerPass::run(Function &F, 27 FunctionAnalysisManager &AM) { 28 TTI = &AM.getResult<TargetIRAnalysis>(F); 29 30 bool Changed = runImpl(F); 31 if (!Changed) 32 return PreservedAnalyses::all(); 33 34 PreservedAnalyses PA; 35 PA.preserveSet<CFGAnalyses>(); 36 return PA; 37 } 38 39 bool SandboxVectorizerPass::runImpl(Function &LLVMF) { 40 // If the target claims to have no vector registers early return. 41 if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true))) { 42 LLVM_DEBUG(dbgs() << "SBVec: Target has no vector registers, return.\n"); 43 return false; 44 } 45 LLVM_DEBUG(dbgs() << "SBVec: Analyzing " << LLVMF.getName() << ".\n"); 46 // Early return if the attribute NoImplicitFloat is used. 47 if (LLVMF.hasFnAttribute(Attribute::NoImplicitFloat)) { 48 LLVM_DEBUG(dbgs() << "SBVec: NoImplicitFloat attribute, return.\n"); 49 return false; 50 } 51 52 // Create SandboxIR for LLVMF and run BottomUpVec on it. 53 sandboxir::Context Ctx(LLVMF.getContext()); 54 sandboxir::Function &F = *Ctx.createFunction(&LLVMF); 55 return BottomUpVecPass.runOnFunction(F); 56 } 57