Skip to content

Commit

Permalink
cleanup llvm compilation pass (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrulich authored Sep 12, 2024
1 parent 73c9028 commit c4acd69
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 39 deletions.
1 change: 0 additions & 1 deletion nautilus/include/nautilus/std/cmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ val<float> log10f(val<float> x);
val<float> log2(val<float> x);
val<double> log2(val<double> x);


/**
* @brief natural logarithm (to base e) of 1 plus the given number (ln(1+x))
*
Expand Down
8 changes: 4 additions & 4 deletions nautilus/src/nautilus/api/std/cmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ val<int8_t> abs(val<int8_t> x) {
return invoke<>(
+[](int8_t x) -> int8_t { return std::abs(x); }, x);
}
val<int16_t > abs(val<int16_t > x) {
val<int16_t> abs(val<int16_t> x) {
return invoke<>(
+[](int16_t x) -> int16_t { return std::abs(x); }, x);
}
val<int32_t > abs(val<int32_t > x) {
val<int32_t> abs(val<int32_t> x) {
return invoke<>(
+[](int32_t x) -> int32_t { return std::abs(x); }, x);
}
Expand Down Expand Up @@ -633,11 +633,11 @@ val<double> log10(val<double> x) {

val<float> log2(val<float> x) {
return invoke<>(
+[](float x) { return std::log2(x); }, x);
+[](float x) { return std::log2(x); }, x);
}
val<double> log2(val<double> x) {
return invoke<>(
+[](double x) { return std::log2(x); }, x);
+[](double x) { return std::log2(x); }, x);
}

#if defined(_LIBCPP_VERSION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ std::unique_ptr<Executable> MLIRCompilationBackend::compile(const std::shared_pt

// 2.b Take the MLIR module from the MLIRLoweringProvider and apply lowering
// and optimization passes.
if (mlir::MLIRPassManager::lowerAndOptimizeMLIRModule(mlirModule, {}, {})) {
if (mlir::MLIRPassManager::lowerAndOptimizeMLIRModule(mlirModule, {})) {
throw RuntimeException("Could not lower and optimize MLIR module.");
}

Expand Down
28 changes: 3 additions & 25 deletions nautilus/src/nautilus/compiler/backends/mlir/MLIRPassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ namespace nautilus::compiler::mlir {

using namespace ::mlir;

/**
* @brief Takes a LoweringPass Enum and returns the corresponding mlir lowering
* pass.
*
* @param loweringPass: Used to get the correct mlir lowering pass.
* @return std::unique_ptr<mlir::Pass>: MLIR lowering pass corresponding to
* supplied Enum.
*/
std::unique_ptr<mlir::Pass> getMLIRLoweringPass(MLIRPassManager::LoweringPass loweringPass) {
switch (loweringPass) {
case MLIRPassManager::LoweringPass::LLVM:
return mlir::createConvertControlFlowToLLVMPass();
}
throw NotImplementedException("pass is not supported");
}

/**
* @brief Takes a OptimizationPass Enum and returns the corresponding mlir
* optimization pass.
Expand All @@ -44,7 +28,7 @@ std::unique_ptr<mlir::Pass> getMLIROptimizationPass(MLIRPassManager::Optimizatio
throw NotImplementedException("pass is not supported");
}

int MLIRPassManager::lowerAndOptimizeMLIRModule(mlir::OwningOpRef<mlir::ModuleOp>& module, const std::vector<LoweringPass>& loweringPasses, const std::vector<OptimizationPass>& optimizationPasses) {
int MLIRPassManager::lowerAndOptimizeMLIRModule(mlir::OwningOpRef<mlir::ModuleOp>& module, const std::vector<OptimizationPass>& optimizationPasses) {
mlir::PassManager passManager(module->getContext());

// Apply optimization passes.
Expand All @@ -56,14 +40,8 @@ int MLIRPassManager::lowerAndOptimizeMLIRModule(mlir::OwningOpRef<mlir::ModuleOp
passManager.addPass(mlir::createInlinerPass());
}
// Apply lowering passes.
if (!loweringPasses.empty()) {
for (auto loweringPass : loweringPasses) {
passManager.addPass(getMLIRLoweringPass(loweringPass));
}
} else {
passManager.addPass(mlir::createConvertFuncToLLVMPass());
passManager.addPass(mlir::createConvertControlFlowToLLVMPass());
}
passManager.addPass(mlir::createConvertFuncToLLVMPass());
passManager.addPass(mlir::createConvertControlFlowToLLVMPass());

// Run passes.
if (mlir::failed(passManager.run(*module))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ namespace nautilus::compiler::mlir {
// and applies configured lowering & optimization passes to it.
class MLIRPassManager {
public:
enum class LoweringPass : uint8_t { LLVM };
enum class OptimizationPass : uint8_t { Inline };

MLIRPassManager(); // Disable default constructor
~MLIRPassManager(); // Disable default destructor

static int lowerAndOptimizeMLIRModule(::mlir::OwningOpRef<::mlir::ModuleOp>& module,
const std::vector<LoweringPass>& loweringPasses,
const std::vector<OptimizationPass>& optimizationPasses);
static int lowerAndOptimizeMLIRModule(::mlir::OwningOpRef<::mlir::ModuleOp>& module, const std::vector<OptimizationPass>& optimizationPasses);
};
} // namespace nautilus::compiler::mlir
3 changes: 2 additions & 1 deletion nautilus/src/nautilus/compiler/ir/IRGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

namespace nautilus::compiler::ir {

IRGraph::IRGraph(const compiler::CompilationUnitID& id) : id(id) {}
IRGraph::IRGraph(const compiler::CompilationUnitID& id) : id(id) {
}

std::unique_ptr<FunctionOperation>& IRGraph::addRootOperation(std::unique_ptr<FunctionOperation> root) {
this->rootOperation = std::move(root);
Expand Down
3 changes: 2 additions & 1 deletion nautilus/src/nautilus/tracing/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace nautilus::tracing {

Block::Block(uint16_t blockId) : blockId(blockId), type(Type::Default) {}
Block::Block(uint16_t blockId) : blockId(blockId), type(Type::Default) {
}

operation_identifier Block::addOperation(nautilus::tracing::TraceOperation&& operation) {
uint16_t operationIndex = operations.size();
Expand Down
3 changes: 2 additions & 1 deletion nautilus/src/nautilus/tracing/Snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace nautilus::tracing {
Snapshot::Snapshot(Tag* tag, uint64_t staticValueHash) : staticValueHash(staticValueHash), tag(tag) {
}

Snapshot::Snapshot() : staticValueHash(), tag() {}
Snapshot::Snapshot() : staticValueHash(), tag() {
}

bool Snapshot::operator==(const nautilus::tracing::Snapshot& rhs) const {
return staticValueHash == rhs.staticValueHash && tag == rhs.tag;
Expand Down
3 changes: 2 additions & 1 deletion nautilus/src/nautilus/tracing/TraceOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ std::ostream& operator<<(std::ostream& os, const FunctionCall& call) {
return os;
}

BlockRef::BlockRef(uint16_t block) : block(block) {}
BlockRef::BlockRef(uint16_t block) : block(block) {
}

std::ostream& operator<<(std::ostream& os, const BlockRef& ref) {
os << "B" << ref.block << "(";
Expand Down

0 comments on commit c4acd69

Please sign in to comment.