-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SandboxVec] Add BottomUpVec test flag to build regions from metadata. #111904
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTINSTRUCTIONCOUNTPASS_H | ||
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTINSTRUCTIONCOUNTPASS_H | ||
|
||
#include "llvm/SandboxIR/Pass.h" | ||
#include "llvm/SandboxIR/Region.h" | ||
|
||
namespace llvm::sandboxir { | ||
|
||
/// A Region pass that prints the instruction count for the region to stdout. | ||
/// Used to test -sbvec-passes while we don't have any actual optimization | ||
/// passes. | ||
class PrintInstructionCountPass final : public RegionPass { | ||
public: | ||
PrintInstructionCountPass() : RegionPass("null") {} | ||
bool runOnRegion(Region &R) final { | ||
outs() << "InstructionCount: " << std::distance(R.begin(), R.end()) << "\n"; | ||
return false; | ||
} | ||
}; | ||
|
||
} // namespace llvm::sandboxir | ||
|
||
#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTINSTRUCTIONCOUNTPASS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,55 @@ | |
#include "llvm/Analysis/TargetTransformInfo.h" | ||
#include "llvm/SandboxIR/Constant.h" | ||
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h" | ||
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/NullPass.h" | ||
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintInstructionCountPass.h" | ||
|
||
using namespace llvm; | ||
using namespace llvm::sandboxir; | ||
|
||
namespace llvm { | ||
|
||
#define SV_NAME "sandbox-vectorizer" | ||
#define DEBUG_TYPE SV_NAME | ||
|
||
SandboxVectorizerPass::SandboxVectorizerPass() = default; | ||
static cl::opt<bool> | ||
PrintPassPipeline("sbvec-print-pass-pipeline", cl::init(false), cl::Hidden, | ||
cl::desc("Prints the pass pipeline and returns.")); | ||
|
||
/// A magic string for the default pass pipeline. | ||
static const char *DefaultPipelineMagicStr = "*"; | ||
|
||
static cl::opt<std::string> UserDefinedPassPipeline( | ||
"sbvec-passes", cl::init(DefaultPipelineMagicStr), cl::Hidden, | ||
cl::desc("Comma-separated list of vectorizer passes. If not set " | ||
"we run the predefined pipeline.")); | ||
|
||
static cl::opt<bool> UseRegionsFromMetadata( | ||
"sbvec-use-regions-from-metadata", cl::init(false), cl::Hidden, | ||
cl::desc("Skips bottom-up vectorization, builds regions from metadata " | ||
"already present in the IR and runs the region pass pipeline.")); | ||
|
||
static std::unique_ptr<sandboxir::RegionPass> createRegionPass(StringRef Name) { | ||
#define REGION_PASS(NAME, CREATE_PASS) \ | ||
if (Name == NAME) \ | ||
return std::make_unique<decltype(CREATE_PASS)>(CREATE_PASS); | ||
#include "Passes/PassRegistry.def" | ||
return nullptr; | ||
} | ||
|
||
sandboxir::RegionPassManager createRegionPassManager() { | ||
sandboxir::RegionPassManager RPM("rpm"); | ||
// Create a pipeline to be run on each Region created by BottomUpVec. | ||
if (UserDefinedPassPipeline == DefaultPipelineMagicStr) { | ||
// TODO: Add default passes to RPM. | ||
} else { | ||
// Create the user-defined pipeline. | ||
RPM.setPassPipeline(UserDefinedPassPipeline, createRegionPass); | ||
} | ||
return RPM; | ||
} | ||
|
||
SandboxVectorizerPass::SandboxVectorizerPass() | ||
: RPM(createRegionPassManager()), BottomUpVecPass(&RPM) {} | ||
|
||
SandboxVectorizerPass::SandboxVectorizerPass(SandboxVectorizerPass &&) = | ||
default; | ||
|
@@ -37,6 +79,11 @@ PreservedAnalyses SandboxVectorizerPass::run(Function &F, | |
} | ||
|
||
bool SandboxVectorizerPass::runImpl(Function &LLVMF) { | ||
if (PrintPassPipeline) { | ||
RPM.printPipeline(outs()); | ||
return false; | ||
} | ||
|
||
// If the target claims to have no vector registers early return. | ||
if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true))) { | ||
LLVM_DEBUG(dbgs() << "SBVec: Target has no vector registers, return.\n"); | ||
|
@@ -52,5 +99,16 @@ bool SandboxVectorizerPass::runImpl(Function &LLVMF) { | |
// Create SandboxIR for LLVMF and run BottomUpVec on it. | ||
sandboxir::Context Ctx(LLVMF.getContext()); | ||
sandboxir::Function &F = *Ctx.createFunction(&LLVMF); | ||
return BottomUpVecPass.runOnFunction(F); | ||
if (UseRegionsFromMetadata) { | ||
SmallVector<std::unique_ptr<sandboxir::Region>> Regions = | ||
sandboxir::Region::createRegionsFromMD(F); | ||
for (auto &R : Regions) { | ||
RPM.runOnRegion(*R); | ||
} | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not following the various discussions. Why can't this be another function pass called "TestsFuncPass" which then runs the various regions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can. I'm just having some trouble figuring out what we want. |
||
} else { | ||
return BottomUpVecPass.runOnFunction(F); | ||
} | ||
} | ||
|
||
} // namespace llvm |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
; RUN: opt -disable-output --passes=sandbox-vectorizer \ | ||
; RUN: -sbvec-passes=print-instruction-count \ | ||
; RUN: -sbvec-use-regions-from-metadata %s | FileCheck %s | ||
|
||
define i8 @foo(i8 %v0, i8 %v1) { | ||
%t0 = add i8 %v0, 1, !sandboxvec !0 | ||
aeubanks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
%t1 = add i8 %t0, %v1, !sandboxvec !1 | ||
%t2 = add i8 %t1, %v1, !sandboxvec !1 | ||
ret i8 %t2 | ||
} | ||
|
||
!0 = distinct !{!"sandboxregion"} | ||
!1 = distinct !{!"sandboxregion"} | ||
|
||
; CHECK: InstructionCount: 1 | ||
; CHECK: InstructionCount: 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be a reference?