Skip to content

Commit 0f6c18e

Browse files
authored
[SandboxVec] Replace hard-coded context save() with transaction-save pass (#127690)
This patch implements a small region pass that saves the context's state. The patch is now used in the default pipeline to save the context state instead of the hard-coded call to Context::save(). The concept behind this is that the passes themselves should not have to do the actual saving/restoring of the IR state, because that would make it challenging to reorder them in the pipeline. Having separate save/restore passes makes the transformation passes more composable as parts of arbitrary pipelines.
1 parent db5bc8e commit 0f6c18e

File tree

15 files changed

+61
-12
lines changed

15 files changed

+61
-12
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===- TransactionSave.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+
//
9+
// This is a region pass that simply calls Context::save() to save the IR state.
10+
//
11+
12+
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_TRANSACTIONSAVE_H
13+
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_TRANSACTIONSAVE_H
14+
15+
#include "llvm/SandboxIR/Pass.h"
16+
#include "llvm/SandboxIR/Region.h"
17+
18+
namespace llvm::sandboxir {
19+
20+
class TransactionSave : public RegionPass {
21+
public:
22+
TransactionSave() : RegionPass("tr-save") {}
23+
bool runOnRegion(Region &Rgn, const Analyses &A) final;
24+
};
25+
26+
} // namespace llvm::sandboxir
27+
28+
#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_TRANSACTIONSAVE_H

llvm/lib/Transforms/Vectorize/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_llvm_component_library(LLVMVectorize
1111
SandboxVectorizer/Passes/RegionsFromMetadata.cpp
1212
SandboxVectorizer/Passes/SeedCollection.cpp
1313
SandboxVectorizer/Passes/TransactionAcceptOrRevert.cpp
14+
SandboxVectorizer/Passes/TransactionSave.cpp
1415
SandboxVectorizer/SandboxVectorizer.cpp
1516
SandboxVectorizer/SandboxVectorizerPassBuilder.cpp
1617
SandboxVectorizer/Scheduler.cpp

llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
REGION_PASS("null", ::llvm::sandboxir::NullPass)
2121
REGION_PASS("print-instruction-count", ::llvm::sandboxir::PrintInstructionCount)
22+
REGION_PASS("tr-save", ::llvm::sandboxir::TransactionSave)
2223
REGION_PASS("tr-accept", ::llvm::sandboxir::TransactionAlwaysAccept)
2324
REGION_PASS("tr-accept-or-revert", ::llvm::sandboxir::TransactionAcceptOrRevert)
2425
REGION_PASS("bottom-up-vec", ::llvm::sandboxir::BottomUpVec)

llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ bool SeedCollection::runOnFunction(Function &F, const Analyses &A) {
8282
// Create a region containing the seed slice.
8383
auto &Ctx = F.getContext();
8484
Region Rgn(Ctx, A.getTTI());
85-
// TODO: Replace save() with a save pass in the pass pipeline.
86-
Ctx.save();
8785
Rgn.setAux(SeedSlice);
8886
// Run the region pass pipeline.
8987
Change |= RPM.runOnRegion(Rgn, A);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===- TransactionSave.cpp - Save the IR state ----------------------------===//
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/Passes/TransactionSave.h"
10+
#include "llvm/Support/CommandLine.h"
11+
#include "llvm/Support/InstructionCost.h"
12+
13+
namespace llvm::sandboxir {
14+
15+
bool TransactionSave::runOnRegion(Region &Rgn, const Analyses &A) {
16+
Rgn.getContext().save();
17+
return false;
18+
}
19+
20+
} // namespace llvm::sandboxir

llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ SandboxVectorizerPass::SandboxVectorizerPass() : FPM("fpm") {
3636
// - Bottom-up Vectorizer pass that starts from a seed
3737
// - Accept or revert IR state pass
3838
FPM.setPassPipeline(
39-
"seed-collection<bottom-up-vec,tr-accept-or-revert>",
39+
"seed-collection<tr-save,bottom-up-vec,tr-accept-or-revert>",
4040
sandboxir::SandboxVectorizerPassBuilder::createFunctionPass);
4141
} else {
4242
// Create the user-defined pipeline.

llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.h"
88
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAcceptOrRevert.h"
99
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAlwaysAccept.h"
10+
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionSave.h"
1011

1112
namespace llvm::sandboxir {
1213

llvm/test/Transforms/SandboxVectorizer/bottomup_basic.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<bottom-up-vec,tr-accept>" %s -S | FileCheck %s
2+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" %s -S | FileCheck %s
33

44
define void @store_load(ptr %ptr) {
55
; CHECK-LABEL: define void @store_load(

llvm/test/Transforms/SandboxVectorizer/bottomup_seed_slice.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<bottom-up-vec,tr-accept>" %s -S | FileCheck %s
2+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" %s -S | FileCheck %s
33

44

55
declare void @foo()

llvm/test/Transforms/SandboxVectorizer/bottomup_seed_slice_pow2.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2=false -sbvec-passes="seed-collection<bottom-up-vec,tr-accept>" %s -S | FileCheck %s --check-prefix=POW2
3-
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2=true -sbvec-passes="seed-collection<bottom-up-vec,tr-accept>" %s -S | FileCheck %s --check-prefix=NON-POW2
2+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2=false -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" %s -S | FileCheck %s --check-prefix=POW2
3+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2=true -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" %s -S | FileCheck %s --check-prefix=NON-POW2
44

55
define void @pow2(ptr %ptr, float %val) {
66
; POW2-LABEL: define void @pow2(

llvm/test/Transforms/SandboxVectorizer/cross_bbs.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<bottom-up-vec,tr-accept>" %s -S | FileCheck %s
2+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" %s -S | FileCheck %s
33

44
define void @cross_bbs(ptr %ptr) {
55
; CHECK-LABEL: define void @cross_bbs(

llvm/test/Transforms/SandboxVectorizer/pack.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<bottom-up-vec,tr-accept>" %s -S | FileCheck %s
2+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" %s -S | FileCheck %s
33

44
define void @pack_constants(ptr %ptr) {
55
; CHECK-LABEL: define void @pack_constants(

llvm/test/Transforms/SandboxVectorizer/repeated_instrs.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<bottom-up-vec,tr-accept>" %s -S | FileCheck %s
2+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" %s -S | FileCheck %s
33

44
define i32 @repeated_splat(ptr %ptr, i32 %v) #0 {
55
; CHECK-LABEL: define i32 @repeated_splat(

llvm/test/Transforms/SandboxVectorizer/scheduler.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<bottom-up-vec,tr-accept>" %s -S | FileCheck %s
2+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" %s -S | FileCheck %s
33

44
; This used to crash because the newly added pack instructions would not update
55
; the DAG and scheduler, leading to def-after-use.

llvm/test/Transforms/SandboxVectorizer/special_opcodes.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<bottom-up-vec,tr-accept>" %s -S | FileCheck %s
2+
; RUN: opt -passes=sandbox-vectorizer -sbvec-vec-reg-bits=1024 -sbvec-allow-non-pow2 -sbvec-passes="seed-collection<tr-save,bottom-up-vec,tr-accept>" %s -S | FileCheck %s
33

44
; This file includes tests for opcodes that need special checks.
55

0 commit comments

Comments
 (0)