LoopsToGPU: use PassRegistration with constructor

PassRegistration with an optional constructor was introduced after the
LoopsToGPUPass, which resorted to deriving one pass from another as a means of
accepting options supplied as command-line arguments. Use PassRegistration with
constructor instead of defining a derived pass for LoopsToGPU.  Also rename the
pass to better reflect its current nature.

PiperOrigin-RevId: 257786923
This commit is contained in:
Alex Zinenko
2019-07-12 05:36:55 -07:00
committed by jpienaar
parent f20f347fdb
commit 2178467dca

View File

@@ -41,8 +41,8 @@ namespace {
// A pass that traverses top-level loops in the function and converts them to
// GPU launch operations. Nested launches are not allowed, so this does not
// walk the function recursively to avoid considering nested loops.
struct AffineForGPUMapper : public FunctionPass<AffineForGPUMapper> {
AffineForGPUMapper(unsigned numBlockDims, unsigned numThreadDims)
struct ForLoopMapper : public FunctionPass<ForLoopMapper> {
ForLoopMapper(unsigned numBlockDims, unsigned numThreadDims)
: numBlockDims(numBlockDims), numThreadDims(numThreadDims) {}
void runOnFunction() override {
@@ -63,18 +63,15 @@ struct AffineForGPUMapper : public FunctionPass<AffineForGPUMapper> {
unsigned numBlockDims;
unsigned numThreadDims;
};
struct AffineForGPUMapperCLI : public AffineForGPUMapper {
AffineForGPUMapperCLI()
: AffineForGPUMapper(clNumBlockDims.getValue(),
clNumThreadDims.getValue()) {}
};
} // namespace
FunctionPassBase *mlir::createSimpleLoopsToGPUPass(unsigned numBlockDims,
unsigned numThreadDims) {
return new AffineForGPUMapper(numBlockDims, numThreadDims);
return new ForLoopMapper(numBlockDims, numThreadDims);
}
static PassRegistration<AffineForGPUMapperCLI>
registration(PASS_NAME, "Convert top-level loops to GPU kernels");
static PassRegistration<ForLoopMapper>
registration(PASS_NAME, "Convert top-level loops to GPU kernels", [] {
return new ForLoopMapper(clNumBlockDims.getValue(),
clNumThreadDims.getValue());
});