Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTINSTRUCTIONCOUNTPASS_H
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTINSTRUCTIONCOUNTPASS_H

#include "llvm/SandboxIR/Pass.h"

namespace llvm::sandboxir {

class Region;

/// 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
Expand Up @@ -10,15 +10,22 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/SandboxIR/Function.h"
#include "llvm/SandboxIR/Instruction.h"
#include "llvm/SandboxIR/Region.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/NullPass.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintInstructionCountPass.h"

namespace llvm::sandboxir {

static cl::opt<bool>
PrintPassPipeline("sbvec-print-pass-pipeline", cl::init(false), cl::Hidden,
cl::desc("Prints the pass pipeline and returns."));

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."));

/// A magic string for the default pass pipeline.
static const char *DefaultPipelineMagicStr = "*";

Expand Down Expand Up @@ -86,6 +93,14 @@ bool BottomUpVec::runOnFunction(Function &F) {
RPM.printPipeline(outs());
return false;
}
if (UseRegionsFromMetadata) {
SmallVector<std::unique_ptr<Region>> Regions =
Region::createRegionsFromMD(F);
for (auto &R : Regions) {
RPM.runOnRegion(*R);
}
return false;
}

Change = false;
// TODO: Start from innermost BBs first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
#endif

REGION_PASS("null", NullPass())
REGION_PASS("print-instruction-count", PrintInstructionCountPass())

#undef REGION_PASS
16 changes: 16 additions & 0 deletions llvm/test/Transforms/SandboxVectorizer/regions-from-metadata.ll
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
%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
Loading