Skip to content

Commit 52dca6f

Browse files
authored
[SandboxVec] Boilerplate (#107431)
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 84bf0da commit 52dca6f

File tree

6 files changed

+86
-0
lines changed

6 files changed

+86
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 SV_NAME
16+
17+
PreservedAnalyses SandboxVectorizerPass::run(Function &F,
18+
FunctionAnalysisManager &AM) {
19+
TTI = &AM.getResult<TargetIRAnalysis>(F);
20+
21+
bool Changed = runImpl(F);
22+
if (!Changed)
23+
return PreservedAnalyses::all();
24+
25+
PreservedAnalyses PA;
26+
PA.preserveSet<CFGAnalyses>();
27+
return PA;
28+
}
29+
30+
bool SandboxVectorizerPass::runImpl(Function &F) {
31+
LLVM_DEBUG(dbgs() << "SBVec: Analyzing " << F.getName() << ".\n");
32+
sandboxir::Context Ctx(F.getContext());
33+
// Create SandboxIR for `F`.
34+
sandboxir::Function &SBF = *Ctx.createFunction(&F);
35+
// TODO: Initialize SBVec Pass Manager
36+
(void)SBF;
37+
38+
return false;
39+
}
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)