-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use fmt to format trace and ir (#48)
- Loading branch information
1 parent
b79795f
commit 8b78e3b
Showing
985 changed files
with
9,593 additions
and
5,948 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +0,0 @@ | ||
|
||
#include "nautilus/compiler/ir/IRDumpHandler.hpp" | ||
#include "nautilus/compiler/ir/operations/BranchOperation.hpp" | ||
#include "nautilus/compiler/ir/operations/FunctionOperation.hpp" | ||
#include "nautilus/compiler/ir/operations/IfOperation.hpp" | ||
#include "nautilus/compiler/ir/operations/Operation.hpp" | ||
#include <iostream> | ||
|
||
namespace nautilus::compiler::ir { | ||
|
||
NESIRDumpHandler::~NESIRDumpHandler() = default; | ||
|
||
NESIRDumpHandler::NESIRDumpHandler(std::ostream& out) : out(out) { | ||
} | ||
|
||
std::shared_ptr<NESIRDumpHandler> NESIRDumpHandler::create(std::ostream& out) { | ||
return std::make_shared<NESIRDumpHandler>(out); | ||
} | ||
|
||
const BasicBlock* NESIRDumpHandler::getNextLowerOrEqualLevelBasicBlock(const BasicBlock* thenBlock) { | ||
auto& terminatorOp = thenBlock->getOperations().back(); | ||
if (terminatorOp->getOperationType() == Operation::OperationType::BranchOp) { | ||
auto branchOp = dynamic_cast<BranchOperation*>(terminatorOp.get()); | ||
return getNextLowerOrEqualLevelBasicBlock(branchOp->getNextBlockInvocation().getBlock()); | ||
} else if (terminatorOp->getOperationType() == Operation::OperationType::IfOp) { | ||
auto ifOp = dynamic_cast<IfOperation*>(terminatorOp.get()); | ||
if (ifOp->getFalseBlockInvocation().getBlock() != nullptr) { | ||
return getNextLowerOrEqualLevelBasicBlock(ifOp->getFalseBlockInvocation().getBlock()); | ||
} else { | ||
return getNextLowerOrEqualLevelBasicBlock(ifOp->getTrueBlockInvocation().getBlock()); | ||
} | ||
} else { // ReturnOp todo changed #3234 | ||
return nullptr; | ||
} | ||
} | ||
|
||
void NESIRDumpHandler::dumpHelper(Operation* terminatorOp) { | ||
switch (terminatorOp->getOperationType()) { | ||
case Operation::OperationType::BranchOp: { | ||
auto branchOp = static_cast<BranchOperation*>(terminatorOp); | ||
dumpHelper(branchOp->getNextBlockInvocation().getBlock()); | ||
break; | ||
} | ||
case Operation::OperationType::IfOp: { | ||
auto ifOp = static_cast<IfOperation*>(terminatorOp); | ||
auto lastTerminatorOp = getNextLowerOrEqualLevelBasicBlock(ifOp->getTrueBlockInvocation().getBlock()); | ||
dumpHelper(ifOp->getTrueBlockInvocation().getBlock()); | ||
dumpHelper(ifOp->getFalseBlockInvocation().getBlock()); | ||
if (lastTerminatorOp) { | ||
dumpHelper(lastTerminatorOp); | ||
} | ||
break; | ||
} | ||
case Operation::OperationType::ReturnOp: | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void NESIRDumpHandler::dumpHelper(const BasicBlock* basicBlock) { | ||
if (!visitedBlocks.contains(basicBlock->getIdentifier())) { | ||
// int32_t indent = basicBlock->getScopeLevel() + 1; | ||
visitedBlocks.emplace(basicBlock->getIdentifier()); | ||
out << '\n' << "Block_" << basicBlock->getIdentifier() << '('; | ||
if (basicBlock->getArguments().size() > 0) { | ||
out << basicBlock->getArguments().at(0)->getIdentifier().toString() << ":" << toString(basicBlock->getArguments().at(0)->getStamp()); | ||
for (int i = 1; i < (int) basicBlock->getArguments().size(); ++i) { | ||
out << ", " << basicBlock->getArguments().at(i)->getIdentifier().toString() << ":" << toString(basicBlock->getArguments().at(i)->getStamp()); | ||
} | ||
} | ||
out << "):" << '\n'; | ||
for (auto& operation : basicBlock->getOperations()) { | ||
out << std::string(4, ' ') << operation->toString() << " :" << toString(operation->getStamp()) << std::endl; | ||
} | ||
auto& terminatorOp = basicBlock->getOperations().back(); | ||
dumpHelper(terminatorOp.get()); | ||
} | ||
} | ||
|
||
void NESIRDumpHandler::dump(const std::unique_ptr<FunctionOperation>& funcOp) { | ||
out << funcOp->toString() << " {"; | ||
dumpHelper(funcOp->getFunctionBasicBlock()); | ||
out << "}\n"; | ||
} | ||
|
||
} // namespace nautilus::compiler::ir | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +0,0 @@ | ||
#pragma once | ||
|
||
#include "nautilus/compiler/ir/IRGraph.hpp" | ||
#include "nautilus/compiler/ir/blocks/BasicBlock.hpp" | ||
#include <memory> | ||
#include <unordered_set> | ||
|
||
namespace nautilus::compiler::ir { | ||
|
||
/** | ||
* @brief Converts query plans and pipeline plans to the .nesviz format and dumps them to a file.m | ||
*/ | ||
class NESIRDumpHandler { | ||
|
||
public: | ||
virtual ~NESIRDumpHandler(); | ||
|
||
static std::shared_ptr<NESIRDumpHandler> create(std::ostream& out); | ||
|
||
explicit NESIRDumpHandler(std::ostream& out); | ||
|
||
/** | ||
* @brief Dump the NESIR of the funcOp into the 'out' stringstream. | ||
* @param funcOp: FunctionOperation that exists on the top level of a NESIR module. | ||
*/ | ||
void dump(const std::unique_ptr<FunctionOperation>& funcOp); | ||
|
||
private: | ||
std::ostream& out; | ||
std::unordered_set<std::string> visitedBlocks; // We keep track of visited blocks to avoid multi or infinite | ||
// dumping. | ||
|
||
/** | ||
* @brief Traverses the NESIR to find a BB that is on the same or higher 'blockScopeLevel' compared to the initial | ||
* 'basicBlock'. Note: There is always a 'next block', since we always have a return block at the very end of a | ||
* function. | ||
* @param basicBlock: Initially the block that we want to find the next BB for. Replaced while recursively | ||
* traversing NESIR. | ||
*/ | ||
const BasicBlock* getNextLowerOrEqualLevelBasicBlock(const BasicBlock* basicBlock); | ||
|
||
/** | ||
* @brief Handle dumping terminator operations(LoopOp, BranchOp, IfOp, ReturnOp) to the 'out' stringstream. | ||
* | ||
* @param terminatorOp: Terminator operation that we append to the 'out' stringstream. | ||
* @param scopeLevel: scopeLevel of the BasicBlock that is terminated by the terminator operation. | ||
*/ | ||
void dumpHelper(Operation* terminatorOp); | ||
|
||
/** | ||
* @brief Handle dumping BasicBlocks to the 'out' stringstream. Print all operations, then handle the terminatorOp. | ||
* | ||
* @param basicBlock: The basicBlock that is dumped to the 'out' stringstream. | ||
*/ | ||
void dumpHelper(const BasicBlock* basicBlock); | ||
}; | ||
|
||
} // namespace nautilus::compiler::ir | ||
Oops, something went wrong.