Skip to content

Commit 81d60f6

Browse files
committed
[SandboxVec] Boilerplate
This patch implements the new pass and registers it with the pass manager. For context, this is a vectorizer that operates on Sandbox IR, which is a transactional IR on top of LLVM IR.
1 parent 4d819da commit 81d60f6

File tree

6 files changed

+107
-0
lines changed

6 files changed

+107
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===- SandboxVectorizer.h --------------------------------------*- C++ -*-===//
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+
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SANDBOXVECTORIZER_H
9+
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SANDBOXVECTORIZER_H
10+
11+
#include "llvm/Analysis/AliasAnalysis.h"
12+
#include "llvm/Analysis/ScalarEvolution.h"
13+
#include "llvm/Analysis/TargetTransformInfo.h"
14+
#include "llvm/IR/DataLayout.h"
15+
#include "llvm/IR/PassManager.h"
16+
#include "llvm/SandboxIR/SandboxIR.h"
17+
18+
namespace llvm {
19+
20+
class SandboxVectorizerPass : public PassInfoMixin<SandboxVectorizerPass> {
21+
TargetTransformInfo *TTI = nullptr;
22+
23+
public:
24+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
25+
26+
bool runImpl(Function &F);
27+
};
28+
29+
} // namespace llvm
30+
31+
#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SANDBOXVECTORIZER_H

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
#include "llvm/Transforms/Vectorize/LoopIdiomVectorize.h"
322322
#include "llvm/Transforms/Vectorize/LoopVectorize.h"
323323
#include "llvm/Transforms/Vectorize/SLPVectorizer.h"
324+
#include "llvm/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.h"
324325
#include "llvm/Transforms/Vectorize/VectorCombine.h"
325326
#include <optional>
326327

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ FUNCTION_PASS("reassociate", ReassociatePass())
453453
FUNCTION_PASS("redundant-dbg-inst-elim", RedundantDbgInstEliminationPass())
454454
FUNCTION_PASS("reg2mem", RegToMemPass())
455455
FUNCTION_PASS("safe-stack", SafeStackPass(TM))
456+
FUNCTION_PASS("sandbox-vectorizer", SandboxVectorizerPass())
456457
FUNCTION_PASS("scalarize-masked-mem-intrin", ScalarizeMaskedMemIntrinPass())
457458
FUNCTION_PASS("scalarizer", ScalarizerPass())
458459
FUNCTION_PASS("sccp", SCCPPass())

llvm/lib/Transforms/Vectorize/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_llvm_component_library(LLVMVectorize
33
LoopIdiomVectorize.cpp
44
LoopVectorizationLegality.cpp
55
LoopVectorize.cpp
6+
SandboxVectorizer/SandboxVectorizer.cpp
67
SLPVectorizer.cpp
78
Vectorize.cpp
89
VectorCombine.cpp
@@ -18,6 +19,7 @@ add_llvm_component_library(LLVMVectorize
1819
ADDITIONAL_HEADER_DIRS
1920
${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms
2021
${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms/Vectorize
22+
${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms/Vectorize/SandboxVectorizer
2123

2224
DEPENDS
2325
intrinsics_gen
@@ -27,4 +29,5 @@ add_llvm_component_library(LLVMVectorize
2729
Core
2830
Support
2931
TransformUtils
32+
SandboxIR
3033
)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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/Support/CommandLine.h"
11+
12+
using namespace llvm;
13+
14+
#define SV_NAME "sandbox-vectorizer"
15+
#define DEBUG_TYPE "SBVec"
16+
17+
cl::opt<bool>
18+
SBVecDisable("sbvec-disable", cl::init(false), cl::Hidden,
19+
cl::desc("Disable the Sandbox Vectorization passes"));
20+
21+
PreservedAnalyses SandboxVectorizerPass::run(Function &F,
22+
FunctionAnalysisManager &AM) {
23+
TTI = &AM.getResult<TargetIRAnalysis>(F);
24+
25+
bool Changed = runImpl(F);
26+
if (!Changed)
27+
return PreservedAnalyses::all();
28+
29+
PreservedAnalyses PA;
30+
PA.preserveSet<CFGAnalyses>();
31+
return PA;
32+
}
33+
34+
bool SandboxVectorizerPass::runImpl(Function &F) {
35+
if (SBVecDisable)
36+
return false;
37+
38+
// If the target claims to have no vector registers don't attempt
39+
// vectorization.
40+
if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true))) {
41+
LLVM_DEBUG(dbgs() << "SBVec: Target has no vector registers, abort.\n");
42+
return false;
43+
}
44+
45+
// Don't vectorize when the attribute NoImplicitFloat is used.
46+
if (F.hasFnAttribute(Attribute::NoImplicitFloat))
47+
return false;
48+
49+
sandboxir::Context Ctx(F.getContext());
50+
51+
LLVM_DEBUG(dbgs() << "SBVec: Analyzing blocks in " << F.getName() << ".\n");
52+
53+
// Create SandboxIR for `F`.
54+
sandboxir::Function &SBF = *Ctx.createFunction(&F);
55+
56+
// TODO: Initialize SBVec Pass Manager
57+
(void)SBF;
58+
59+
return false;
60+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes=sandbox-vectorizer %s -S | FileCheck %s
3+
4+
; This test checks that the pass was registered with the pass manager.
5+
; TODO: Remove this test once actual tests land.
6+
define void @boilerplate() {
7+
; CHECK-LABEL: define void @boilerplate() {
8+
; CHECK-NEXT: ret void
9+
;
10+
ret void
11+
}

0 commit comments

Comments
 (0)