Skip to content

Commit

Permalink
[DAPHNE-daphne-eu#830] Fix anonymous namespace issue when compiling w…
Browse files Browse the repository at this point in the history
…ith Clang

When compiling with clang, there is a issue at runtime (LLVM complaining about anonymous namespaces not allowed in various places). These are hereby replaced with a non-anonymous namespace. For the lack of creativity these are all called "file_local".
  • Loading branch information
corepointer committed Oct 4, 2024
1 parent 30408cb commit 675dc0c
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 50 deletions.
8 changes: 4 additions & 4 deletions src/compiler/lowering/AggAllOpLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class SumAllOpLowering : public OpConversionPattern<daphne::AllAggSumOp> {
}
};

namespace {
namespace file_local {
/**
* @brief Lowers the daphne::AggAll operator to a set of affine loops and
* performs the aggregation on a MemRef which is created from the input
Expand All @@ -198,9 +198,9 @@ struct AggAllLoweringPass : public mlir::PassWrapper<AggAllLoweringPass, mlir::O
}
void runOnOperation() final;
};
} // end anonymous namespace
} // end file_local namespace

void AggAllLoweringPass::runOnOperation() {
void file_local::AggAllLoweringPass::runOnOperation() {
mlir::ConversionTarget target(getContext());
mlir::RewritePatternSet patterns(&getContext());
LowerToLLVMOptions llvmOptions(&getContext());
Expand Down Expand Up @@ -236,5 +236,5 @@ void AggAllLoweringPass::runOnOperation() {
}

std::unique_ptr<mlir::Pass> mlir::daphne::createAggAllOpLoweringPass() {
return std::make_unique<AggAllLoweringPass>();
return std::make_unique<file_local::AggAllLoweringPass>();
}
8 changes: 4 additions & 4 deletions src/compiler/lowering/DaphneOptPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class IntegerModOpt : public mlir::OpConversionPattern<mlir::daphne::EwModOp> {
}
};

namespace {
namespace file_local {
/**
* @brief This pass transforms operations (currently limited to the EwModOp) in
* the DaphneDialect to a different set of operations also from the
Expand All @@ -64,9 +64,9 @@ struct DenseMatrixOptPass : public mlir::PassWrapper<DenseMatrixOptPass, mlir::O
"also from the DaphneDialect.";
}
};
} // end anonymous namespace
} // end file_local namespace

void DenseMatrixOptPass::runOnOperation() {
void file_local::DenseMatrixOptPass::runOnOperation() {
mlir::ConversionTarget target(getContext());
mlir::RewritePatternSet patterns(&getContext());
mlir::LowerToLLVMOptions llvmOptions(&getContext());
Expand All @@ -89,4 +89,4 @@ void DenseMatrixOptPass::runOnOperation() {
}
}

std::unique_ptr<mlir::Pass> mlir::daphne::createDaphneOptPass() { return std::make_unique<DenseMatrixOptPass>(); }
std::unique_ptr<mlir::Pass> mlir::daphne::createDaphneOptPass() { return std::make_unique<file_local::DenseMatrixOptPass>(); }
8 changes: 4 additions & 4 deletions src/compiler/lowering/DistributeComputationsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

using namespace mlir;

namespace {
namespace file_local {
struct Distribute : public OpInterfaceConversionPattern<daphne::Distributable> {
using OpInterfaceConversionPattern::OpInterfaceConversionPattern;

Expand Down Expand Up @@ -71,13 +71,13 @@ struct DistributeComputationsPass : public PassWrapper<DistributeComputationsPas
StringRef getArgument() const final { return "distribute-computation"; }
StringRef getDescription() const final { return "TODO"; }
};
} // namespace
} // file_local namespace

bool onlyMatrixOperands(Operation *op) {
return llvm::all_of(op->getOperandTypes(), [](Type t) { return llvm::isa<daphne::MatrixType>(t); });
}

void DistributeComputationsPass::runOnOperation() {
void file_local::DistributeComputationsPass::runOnOperation() {
auto module = getOperation();

RewritePatternSet patterns(&getContext());
Expand Down Expand Up @@ -105,5 +105,5 @@ void DistributeComputationsPass::runOnOperation() {
}

std::unique_ptr<Pass> daphne::createDistributeComputationsPass() {
return std::make_unique<DistributeComputationsPass>();
return std::make_unique<file_local::DistributeComputationsPass>();
}
8 changes: 4 additions & 4 deletions src/compiler/lowering/EwOpsLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ using DivOpLowering = BinaryOpLowering<mlir::daphne::EwDivOp, mlir::arith::DivSI
using PowOpLowering = BinaryOpLowering<mlir::daphne::EwPowOp, mlir::math::PowFOp, mlir::math::PowFOp>;
// clang-format on

namespace {
namespace file_local {
/**
* @brief This pass lowers element-wise operations to affine loop
* structures and arithmetic operations.
Expand All @@ -223,7 +223,7 @@ struct EwOpLoweringPass : public mlir::PassWrapper<EwOpLoweringPass, mlir::Opera
"structures and arithmetic operations.";
}
};
} // end anonymous namespace
} // end file_local namespace

void populateLowerEwOpConversionPatterns(mlir::LLVMTypeConverter &typeConverter, mlir::RewritePatternSet &patterns) {
// clang-format off
Expand All @@ -238,7 +238,7 @@ void populateLowerEwOpConversionPatterns(mlir::LLVMTypeConverter &typeConverter,
// clang-format on
}

void EwOpLoweringPass::runOnOperation() {
void file_local::EwOpLoweringPass::runOnOperation() {
mlir::ConversionTarget target(getContext());
mlir::RewritePatternSet patterns(&getContext());
mlir::LowerToLLVMOptions llvmOptions(&getContext());
Expand Down Expand Up @@ -286,4 +286,4 @@ void EwOpLoweringPass::runOnOperation() {
signalPassFailure();
}

std::unique_ptr<mlir::Pass> mlir::daphne::createEwOpLoweringPass() { return std::make_unique<EwOpLoweringPass>(); }
std::unique_ptr<mlir::Pass> mlir::daphne::createEwOpLoweringPass() { return std::make_unique<file_local::EwOpLoweringPass>(); }
8 changes: 4 additions & 4 deletions src/compiler/lowering/LowerToLLVMPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ class GenericCallOpLowering : public OpConversionPattern<daphne::GenericCallOp>
}
};

namespace {
namespace file_local {
struct DaphneLowerToLLVMPass : public PassWrapper<DaphneLowerToLLVMPass, OperationPass<ModuleOp>> {
explicit DaphneLowerToLLVMPass(const DaphneUserConfig &cfg) : cfg(cfg) {}
const DaphneUserConfig &cfg;
Expand All @@ -889,9 +889,9 @@ struct DaphneLowerToLLVMPass : public PassWrapper<DaphneLowerToLLVMPass, Operati
}
void runOnOperation() final;
};
} // end anonymous namespace
} // end file_local namespace

void DaphneLowerToLLVMPass::runOnOperation() {
void file_local::DaphneLowerToLLVMPass::runOnOperation() {
auto module = getOperation();

RewritePatternSet patterns(&getContext());
Expand Down Expand Up @@ -950,5 +950,5 @@ void DaphneLowerToLLVMPass::runOnOperation() {
}

std::unique_ptr<Pass> daphne::createLowerToLLVMPass(const DaphneUserConfig &cfg) {
return std::make_unique<DaphneLowerToLLVMPass>(cfg);
return std::make_unique<file_local::DaphneLowerToLLVMPass>(cfg);
}
8 changes: 4 additions & 4 deletions src/compiler/lowering/MapOpLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class InlineMapOpLowering : public mlir::OpConversionPattern<mlir::daphne::MapOp
}
};

namespace {
namespace file_local {
/**
* @brief The MapOpLoweringPass rewrites the daphne::MapOp operator
* to a set of perfectly nested affine loops and inserts for each element a call
Expand All @@ -107,9 +107,9 @@ struct MapOpLoweringPass : public mlir::PassWrapper<MapOpLoweringPass, mlir::Ope
"UDF.";
}
};
} // end anonymous namespace
} // end file_local namespace

void MapOpLoweringPass::runOnOperation() {
void file_local::MapOpLoweringPass::runOnOperation() {
mlir::ConversionTarget target(getContext());
mlir::RewritePatternSet patterns(&getContext());
mlir::LowerToLLVMOptions llvmOptions(&getContext());
Expand All @@ -127,4 +127,4 @@ void MapOpLoweringPass::runOnOperation() {
}
}

std::unique_ptr<mlir::Pass> mlir::daphne::createMapOpLoweringPass() { return std::make_unique<MapOpLoweringPass>(); }
std::unique_ptr<mlir::Pass> mlir::daphne::createMapOpLoweringPass() { return std::make_unique<file_local::MapOpLoweringPass>(); }
10 changes: 5 additions & 5 deletions src/compiler/lowering/MatMulOpLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ class MatMulLowering : public OpConversionPattern<daphne::MatMulOp> {
}
};

namespace {
namespace file_local {
/**
* @brief The MatMulLoweringPass rewrites the MatMulOp from the DaphneDialect
* to a affine loop structure implementing a multi tiled loop structure.
Expand Down Expand Up @@ -663,9 +663,9 @@ struct MatMulLoweringPass : public impl::MatMulOpLoweringPassBase<MatMulLowering
return sizes;
}
};
} // end anonymous namespace
} // end file_local namespace

void MatMulLoweringPass::runOnOperation() {
void file_local::MatMulLoweringPass::runOnOperation() {
auto module = getOperation();
mlir::ConversionTarget target(getContext());
mlir::RewritePatternSet patterns(&getContext());
Expand Down Expand Up @@ -725,13 +725,13 @@ std::unique_ptr<OperationPass<ModuleOp>> mlir::daphne::createMatMulOpLoweringPas
bool matmul_tile, int matmul_vec_size_bits, std::vector<unsigned> matmul_fixed_tile_sizes,
bool matmul_use_fixed_tile_sizes, int matmul_unroll_factor, int matmul_unroll_jam_factor,
int matmul_num_vec_registers, bool matmul_invert_loops) {
return std::make_unique<MatMulLoweringPass>(
return std::make_unique<file_local::MatMulLoweringPass>(
matmul_tile, matmul_vec_size_bits, matmul_fixed_tile_sizes, matmul_use_fixed_tile_sizes, matmul_unroll_factor,
matmul_unroll_jam_factor, matmul_num_vec_registers, matmul_invert_loops);
}

// This is used by daphne-opt and automatically inserts the options provided on
// the command line into the pass.
std::unique_ptr<OperationPass<ModuleOp>> mlir::daphne::createMatMulOpLoweringPass() {
return std::make_unique<MatMulLoweringPass>();
return std::make_unique<file_local::MatMulLoweringPass>();
}
8 changes: 4 additions & 4 deletions src/compiler/lowering/ModOpLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class EwModOpLowering : public mlir::OpConversionPattern<mlir::daphne::EwModOp>
}
};

namespace {
namespace file_local {
/**
* @brief Performs an integer mod optimization on the EwModOp operator by
* lowering to an affine loop structure and performing the mod op on values
Expand All @@ -153,9 +153,9 @@ struct ModOpLoweringPass : public mlir::PassWrapper<ModOpLoweringPass, mlir::Ope
"and performing the mod op on values loaded from a MemRef.";
}
};
} // end anonymous namespace
} // end file_local namespace

void ModOpLoweringPass::runOnOperation() {
void file_local::ModOpLoweringPass::runOnOperation() {
mlir::ConversionTarget target(getContext());
mlir::RewritePatternSet patterns(&getContext());
mlir::LowerToLLVMOptions llvmOptions(&getContext());
Expand Down Expand Up @@ -184,4 +184,4 @@ void ModOpLoweringPass::runOnOperation() {
}
}

std::unique_ptr<mlir::Pass> mlir::daphne::createModOpLoweringPass() { return std::make_unique<ModOpLoweringPass>(); }
std::unique_ptr<mlir::Pass> mlir::daphne::createModOpLoweringPass() { return std::make_unique<file_local::ModOpLoweringPass>(); }
6 changes: 3 additions & 3 deletions src/compiler/lowering/PhyOperatorSelectionPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ class MatMulOpLowering : public OpConversionPattern<daphne::MatMulOp> {
}
};

namespace {
namespace file_local {
struct PhyOperatorSelectionPass : public PassWrapper<PhyOperatorSelectionPass, OperationPass<ModuleOp>> {
explicit PhyOperatorSelectionPass() {}
void runOnOperation() final;
};
} // end anonymous namespace

void PhyOperatorSelectionPass::runOnOperation() {
void file_local::PhyOperatorSelectionPass::runOnOperation() {
auto module = getOperation();

ConversionTarget target(getContext());
Expand Down Expand Up @@ -108,4 +108,4 @@ void PhyOperatorSelectionPass::runOnOperation() {
signalPassFailure();
}

std::unique_ptr<Pass> daphne::createPhyOperatorSelectionPass() { return std::make_unique<PhyOperatorSelectionPass>(); }
std::unique_ptr<Pass> daphne::createPhyOperatorSelectionPass() { return std::make_unique<file_local::PhyOperatorSelectionPass>(); }
6 changes: 3 additions & 3 deletions src/compiler/lowering/RewriteSqlOpPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

using namespace mlir;

namespace {
namespace file_local {

std::unordered_map<std::string, mlir::Value> tables;
struct SqlReplacement : public RewritePattern {
Expand Down Expand Up @@ -83,7 +83,7 @@ struct RewriteSqlOpPass : public PassWrapper<RewriteSqlOpPass, OperationPass<Mod
};
} // namespace

void RewriteSqlOpPass::runOnOperation() {
void file_local::RewriteSqlOpPass::runOnOperation() {
auto module = getOperation();

RewritePatternSet patterns(&getContext());
Expand All @@ -98,4 +98,4 @@ void RewriteSqlOpPass::runOnOperation() {
signalPassFailure();
}

std::unique_ptr<Pass> daphne::createRewriteSqlOpPass() { return std::make_unique<RewriteSqlOpPass>(); }
std::unique_ptr<Pass> daphne::createRewriteSqlOpPass() { return std::make_unique<file_local::RewriteSqlOpPass>(); }
11 changes: 7 additions & 4 deletions src/compiler/lowering/RewriteToCallKernelOpPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <utility>
Expand Down Expand Up @@ -504,6 +503,7 @@ class DistributedPipelineKernelReplacement : public OpConversionPattern<daphne::

public:
using OpConversionPattern::OpConversionPattern;

DistributedPipelineKernelReplacement(MLIRContext *mctx, Value dctx, const DaphneUserConfig &userConfig,
std::unordered_map<std::string, bool> &usedLibPaths,
PatternBenefit benefit = 2)
Expand Down Expand Up @@ -584,7 +584,9 @@ class DistributedPipelineKernelReplacement : public OpConversionPattern<daphne::
return success();
}
};
} // namespace

namespace file_local {
struct RewriteToCallKernelOpPass : public PassWrapper<RewriteToCallKernelOpPass, OperationPass<func::FuncOp>> {
const DaphneUserConfig &userConfig;
std::unordered_map<std::string, bool> &usedLibPaths;
Expand All @@ -594,9 +596,9 @@ struct RewriteToCallKernelOpPass : public PassWrapper<RewriteToCallKernelOpPass,

void runOnOperation() final;
};
} // namespace
} // namespace file_local

void RewriteToCallKernelOpPass::runOnOperation() {
void file_local::RewriteToCallKernelOpPass::runOnOperation() {
func::FuncOp func = getOperation();

RewritePatternSet patterns(&getContext());
Expand Down Expand Up @@ -628,5 +630,6 @@ void RewriteToCallKernelOpPass::runOnOperation() {

std::unique_ptr<Pass> daphne::createRewriteToCallKernelOpPass(const DaphneUserConfig &cfg,
std::unordered_map<std::string, bool> &usedLibPaths) {
return std::make_unique<RewriteToCallKernelOpPass>(cfg, usedLibPaths);
return std::make_unique<file_local::RewriteToCallKernelOpPass>(
cfg, usedLibPaths);
}
6 changes: 3 additions & 3 deletions src/compiler/lowering/SpecializeGenericFunctionsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

using namespace mlir;

namespace {
namespace file_local {

/**
* @brief Checks if the function is untyped, i.e., if at least one of the inputs
Expand Down Expand Up @@ -433,7 +433,7 @@ class SpecializeGenericFunctionsPass : public PassWrapper<SpecializeGenericFunct
* Finally we delete all the template functions such that the MLIR code can be
* verified for correct input and output types.
*/
void SpecializeGenericFunctionsPass::runOnOperation() {
void file_local::SpecializeGenericFunctionsPass::runOnOperation() {
auto module = getOperation();

module.walk([&](func::FuncOp funcOp) { functions.insert({funcOp.getSymName().str(), funcOp}); });
Expand Down Expand Up @@ -469,5 +469,5 @@ void SpecializeGenericFunctionsPass::runOnOperation() {
}

std::unique_ptr<Pass> daphne::createSpecializeGenericFunctionsPass(const DaphneUserConfig &cfg) {
return std::make_unique<SpecializeGenericFunctionsPass>(cfg);
return std::make_unique<file_local::SpecializeGenericFunctionsPass>(cfg);
}
8 changes: 4 additions & 4 deletions src/compiler/lowering/VectorizeComputationsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

using namespace mlir;

namespace {
namespace file_local {
/**
* @brief Recursive function checking if the given value is transitively
* dependant on the operation `op`.
Expand Down Expand Up @@ -182,9 +182,9 @@ void movePipelineInterleavedOperations(Block::iterator pipelinePosition,
struct VectorizeComputationsPass : public PassWrapper<VectorizeComputationsPass, OperationPass<func::FuncOp>> {
void runOnOperation() final;
};
} // namespace
} // file_local namespace

void VectorizeComputationsPass::runOnOperation() {
void file_local::VectorizeComputationsPass::runOnOperation() {
auto func = getOperation();
// TODO: fuse pipelines that have the matching inputs, even if no output of
// the one pipeline is used by the other.
Expand Down Expand Up @@ -405,5 +405,5 @@ void VectorizeComputationsPass::runOnOperation() {
}

std::unique_ptr<Pass> daphne::createVectorizeComputationsPass() {
return std::make_unique<VectorizeComputationsPass>();
return std::make_unique<file_local::VectorizeComputationsPass>();
}

0 comments on commit 675dc0c

Please sign in to comment.