Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions llvm/include/llvm/SandboxIR/Pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class ScalarEvolution;
namespace sandboxir {

class Function;
class Region;

class Analyses {
AAResults *AA = nullptr;
Expand Down Expand Up @@ -76,15 +75,6 @@ class FunctionPass : public Pass {
virtual bool runOnFunction(Function &F, const Analyses &A) = 0;
};

/// A pass that runs on a sandbox::Region.
class RegionPass : public Pass {
public:
/// \p Name can't contain any spaces or start with '-'.
RegionPass(StringRef Name) : Pass(Name) {}
/// \Returns true if it modifies \p R.
virtual bool runOnRegion(Region &R, const Analyses &A) = 0;
};

} // namespace sandboxir
} // namespace llvm

Expand Down
9 changes: 0 additions & 9 deletions llvm/include/llvm/SandboxIR/PassManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,6 @@ class FunctionPassManager final
bool runOnFunction(Function &F, const Analyses &A) final;
};

class RegionPassManager final : public PassManager<RegionPass, RegionPass> {
public:
RegionPassManager(StringRef Name) : PassManager(Name) {}
RegionPassManager(StringRef Name, StringRef Pipeline,
CreatePassFunc CreatePass)
: PassManager(Name, Pipeline, CreatePass) {}
bool runOnRegion(Region &R, const Analyses &A) final;
};

} // namespace llvm::sandboxir

#endif // LLVM_SANDBOXIR_PASSMANAGER_H
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/SandboxIR/PassManager.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Legality.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Region.h"

namespace llvm::sandboxir {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_NULLPASS_H
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_NULLPASS_H

#include "llvm/SandboxIR/Pass.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Region.h"

namespace llvm::sandboxir {

class Region;

/// A Region pass that does nothing, for use as a placeholder in tests.
class NullPass final : public RegionPass {
public:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTINSTRUCTIONCOUNT_H
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTINSTRUCTIONCOUNT_H

#include "llvm/SandboxIR/Pass.h"
#include "llvm/SandboxIR/Region.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Region.h"

namespace llvm::sandboxir {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/SandboxIR/Pass.h"
#include "llvm/SandboxIR/PassManager.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Region.h"

namespace llvm::sandboxir {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/SandboxIR/Instruction.h"
#include "llvm/SandboxIR/Pass.h"
#include "llvm/SandboxIR/PassManager.h"
#include "llvm/Support/raw_ostream.h"

namespace llvm::sandboxir {
Expand Down Expand Up @@ -107,6 +109,25 @@ class Region {
#endif
};

/// A pass that runs on a Region.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declaring the RegionPass class in Region.h is a bit strange. Wouldn't it make more sense to move Pass.* to the vectorizer too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including things like FunctionPass that operate on non-vectorizer-specific SandboxIR concepts like Function? I guess the question is whether we believe SandboxVectorizer is the only user that will create SandboxIR sub-pass pipelines or they can be useful elsewhere.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as it is not vectorizer specific, I would move it into SandboxIR ( also for modularity).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the Region-related stuff is currently already in SandboxIR, so "move it into SandboxIR" is just dropping this PR (which is, of course, an option). Or were you talking about something different?

class RegionPass : public Pass {
public:
/// \p Name can't contain any spaces or start with '-'.
RegionPass(StringRef Name) : Pass(Name) {}
/// \Returns true if it modifies \p R.
virtual bool runOnRegion(Region &R, const Analyses &A) = 0;
};

/// A PassManager for passes that operate on Regions.
class RegionPassManager final : public PassManager<RegionPass, RegionPass> {
public:
RegionPassManager(StringRef Name) : PassManager(Name) {}
RegionPassManager(StringRef Name, StringRef Pipeline,
CreatePassFunc CreatePass)
: PassManager(Name, Pipeline, CreatePass) {}
bool runOnRegion(Region &R, const Analyses &A) final;
};

} // namespace llvm::sandboxir

#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_REGION_H
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "llvm/ADT/StringRef.h"
#include "llvm/SandboxIR/Pass.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Region.h"

#include <memory>

Expand Down
1 change: 0 additions & 1 deletion llvm/lib/SandboxIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ add_llvm_component_library(LLVMSandboxIR
Module.cpp
Pass.cpp
PassManager.cpp
Region.cpp
Tracker.cpp
Type.cpp
User.cpp
Expand Down
10 changes: 0 additions & 10 deletions llvm/lib/SandboxIR/PassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,4 @@ bool FunctionPassManager::runOnFunction(Function &F, const Analyses &A) {
return Change;
}

bool RegionPassManager::runOnRegion(Region &R, const Analyses &A) {
bool Change = false;
for (auto &Pass : Passes) {
Change |= Pass->runOnRegion(R, A);
// TODO: run the verifier.
}
// TODO: Check ChangeAll against hashes before/after.
return Change;
}

} // namespace llvm::sandboxir
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Vectorize/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_llvm_component_library(LLVMVectorize
SandboxVectorizer/Legality.cpp
SandboxVectorizer/Passes/BottomUpVec.cpp
SandboxVectorizer/Passes/RegionsFromMetadata.cpp
SandboxVectorizer/Region.cpp
SandboxVectorizer/SandboxVectorizer.cpp
SandboxVectorizer/SandboxVectorizerPassBuilder.cpp
SandboxVectorizer/Scheduler.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromMetadata.h"

#include "llvm/SandboxIR/Region.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Region.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.h"

namespace llvm::sandboxir {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "llvm/SandboxIR/Region.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Region.h"
#include "llvm/SandboxIR/Function.h"

namespace llvm::sandboxir {
Expand Down Expand Up @@ -81,4 +81,14 @@ SmallVector<std::unique_ptr<Region>> Region::createRegionsFromMD(Function &F) {
return Regions;
}

bool RegionPassManager::runOnRegion(Region &R, const Analyses &A) {
bool Change = false;
for (auto &Pass : Passes) {
Change |= Pass->runOnRegion(R, A);
// TODO: run the verifier.
}
// TODO: Check ChangeAll against hashes before/after.
return Change;
}

} // namespace llvm::sandboxir
1 change: 0 additions & 1 deletion llvm/unittests/SandboxIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(LLVM_LINK_COMPONENTS
add_llvm_unittest(SandboxIRTests
IntrinsicInstTest.cpp
PassTest.cpp
RegionTest.cpp
OperatorTest.cpp
SandboxIRTest.cpp
TrackerTest.cpp
Expand Down
122 changes: 0 additions & 122 deletions llvm/unittests/SandboxIR/PassTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "llvm/SandboxIR/Context.h"
#include "llvm/SandboxIR/Function.h"
#include "llvm/SandboxIR/PassManager.h"
#include "llvm/SandboxIR/Region.h"
#include "llvm/Support/SourceMgr.h"
#include "gtest/gtest.h"

Expand Down Expand Up @@ -87,68 +86,6 @@ define void @foo() {
#endif
}

TEST_F(PassTest, RegionPass) {
auto *F = parseFunction(R"IR(
define i8 @foo(i8 %v0, i8 %v1) {
%t0 = add i8 %v0, 1
%t1 = add i8 %t0, %v1, !sandboxvec !0
%t2 = add i8 %t1, %v1, !sandboxvec !0
ret i8 %t1
}

!0 = distinct !{!"sandboxregion"}
)IR",
"foo");

class TestPass final : public RegionPass {
unsigned &InstCount;

public:
TestPass(unsigned &InstCount)
: RegionPass("test-pass"), InstCount(InstCount) {}
bool runOnRegion(Region &R, const Analyses &A) final {
for ([[maybe_unused]] auto &Inst : R) {
++InstCount;
}
return false;
}
};
unsigned InstCount = 0;
TestPass TPass(InstCount);
// Check getName(),
EXPECT_EQ(TPass.getName(), "test-pass");
// Check runOnRegion();
llvm::SmallVector<std::unique_ptr<Region>> Regions =
Region::createRegionsFromMD(*F);
ASSERT_EQ(Regions.size(), 1u);
TPass.runOnRegion(*Regions[0], Analyses::emptyForTesting());
EXPECT_EQ(InstCount, 2u);
#ifndef NDEBUG
{
// Check print().
std::string Buff;
llvm::raw_string_ostream SS(Buff);
TPass.print(SS);
EXPECT_EQ(Buff, "test-pass");
}
{
// Check operator<<().
std::string Buff;
llvm::raw_string_ostream SS(Buff);
SS << TPass;
EXPECT_EQ(Buff, "test-pass");
}
// Check pass name assertions.
class TestNamePass final : public RegionPass {
public:
TestNamePass(llvm::StringRef Name) : RegionPass(Name) {}
bool runOnRegion(Region &F, const Analyses &A) { return false; }
};
EXPECT_DEATH(TestNamePass("white space"), ".*whitespace.*");
EXPECT_DEATH(TestNamePass("-dash"), ".*start with.*");
#endif
}

TEST_F(PassTest, FunctionPassManager) {
auto *F = parseFunction(R"IR(
define void @foo() {
Expand Down Expand Up @@ -197,65 +134,6 @@ define void @foo() {
#endif // NDEBUG
}

TEST_F(PassTest, RegionPassManager) {
auto *F = parseFunction(R"IR(
define i8 @foo(i8 %v0, i8 %v1) {
%t0 = add i8 %v0, 1
%t1 = add i8 %t0, %v1, !sandboxvec !0
%t2 = add i8 %t1, %v1, !sandboxvec !0
ret i8 %t1
}

!0 = distinct !{!"sandboxregion"}
)IR",
"foo");

class TestPass1 final : public RegionPass {
unsigned &InstCount;

public:
TestPass1(unsigned &InstCount)
: RegionPass("test-pass1"), InstCount(InstCount) {}
bool runOnRegion(Region &R, const Analyses &A) final {
for ([[maybe_unused]] auto &Inst : R)
++InstCount;
return false;
}
};
class TestPass2 final : public RegionPass {
unsigned &InstCount;

public:
TestPass2(unsigned &InstCount)
: RegionPass("test-pass2"), InstCount(InstCount) {}
bool runOnRegion(Region &R, const Analyses &A) final {
for ([[maybe_unused]] auto &Inst : R)
++InstCount;
return false;
}
};
unsigned InstCount1 = 0;
unsigned InstCount2 = 0;

RegionPassManager RPM("test-rpm");
RPM.addPass(std::make_unique<TestPass1>(InstCount1));
RPM.addPass(std::make_unique<TestPass2>(InstCount2));
// Check runOnRegion().
llvm::SmallVector<std::unique_ptr<Region>> Regions =
Region::createRegionsFromMD(*F);
ASSERT_EQ(Regions.size(), 1u);
RPM.runOnRegion(*Regions[0], Analyses::emptyForTesting());
EXPECT_EQ(InstCount1, 2u);
EXPECT_EQ(InstCount2, 2u);
#ifndef NDEBUG
// Check dump().
std::string Buff;
llvm::raw_string_ostream SS(Buff);
RPM.print(SS);
EXPECT_EQ(Buff, "test-rpm(test-pass1,test-pass2)");
#endif // NDEBUG
}

TEST_F(PassTest, SetPassPipeline) {
auto *F = parseFunction(R"IR(
define void @f() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ add_llvm_unittest(SandboxVectorizerTests
DependencyGraphTest.cpp
IntervalTest.cpp
LegalityTest.cpp
RegionTest.cpp
SchedulerTest.cpp
SeedCollectorTest.cpp
SeedCollectorTest.cpp
VecUtilsTest.cpp
)
Loading
Loading