Skip to content

Commit cc0b60c

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 950bb68 commit cc0b60c

File tree

8 files changed

+131
-0
lines changed

8 files changed

+131
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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_SANDBOXVEC_SANDBOXVECTORIZER_H
9+
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVEC_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+
DenseSet<sandboxir::Value *> Visited;
22+
ScalarEvolution *SE = nullptr;
23+
const DataLayout *DL = nullptr;
24+
TargetTransformInfo *TTI = nullptr;
25+
AliasAnalysis *AA = nullptr;
26+
27+
public:
28+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
29+
30+
bool runImpl(Function &F);
31+
};
32+
33+
} // namespace llvm
34+
35+
#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVEC_SANDBOXVECTORIZER_H

llvm/lib/Passes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ add_llvm_component_library(LLVMPasses
2626
InstCombine
2727
IRPrinter
2828
ObjCARC
29+
SandboxVec
2930
Scalar
3031
Support
3132
Target

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/SandboxVec/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
@@ -1,3 +1,5 @@
1+
add_subdirectory(SandboxVec)
2+
13
add_llvm_component_library(LLVMVectorize
24
LoadStoreVectorizer.cpp
35
LoopIdiomVectorize.cpp
@@ -27,4 +29,5 @@ add_llvm_component_library(LLVMVectorize
2729
Core
2830
Support
2931
TransformUtils
32+
SandboxVec
3033
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
add_llvm_component_library(LLVMSandboxVec
2+
SandboxVectorizer.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms/Vectorize/SandboxVec
6+
7+
DEPENDS
8+
intrinsics_gen
9+
10+
LINK_COMPONENTS
11+
Analysis
12+
Core
13+
SandboxIR
14+
Support
15+
TransformUtils
16+
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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/SandboxVec/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+
SE = &AM.getResult<ScalarEvolutionAnalysis>(F);
25+
DL = &F.getParent()->getDataLayout();
26+
AA = &AM.getResult<AAManager>(F);
27+
28+
bool Changed = runImpl(F);
29+
if (!Changed)
30+
return PreservedAnalyses::all();
31+
32+
PreservedAnalyses PA;
33+
PA.preserveSet<CFGAnalyses>();
34+
return PA;
35+
}
36+
37+
bool SandboxVectorizerPass::runImpl(Function &F) {
38+
if (SBVecDisable)
39+
return false;
40+
41+
// If the target claims to have no vector registers don't attempt
42+
// vectorization.
43+
if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true))) {
44+
LLVM_DEBUG(dbgs() << "SBVec: Target has no vector registers, abort.\n");
45+
return false;
46+
}
47+
48+
// Don't vectorize when the attribute NoImplicitFloat is used.
49+
if (F.hasFnAttribute(Attribute::NoImplicitFloat))
50+
return false;
51+
52+
sandboxir::Context Ctx(F.getContext());
53+
54+
LLVM_DEBUG(dbgs() << "SBVec: Analyzing blocks in " << F.getName() << ".\n");
55+
56+
// Create SandboxIR for `F`.
57+
sandboxir::Function &SBF = *Ctx.createFunction(&F);
58+
59+
// TODO: Initialize SBVec Pass Manager
60+
(void)SBF;
61+
62+
return false;
63+
}
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)