Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrulich committed Oct 15, 2024
1 parent 59855bd commit f65b1d7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@ void MLIRLoweringProvider::generateMLIR(ir::ProxyCallOperation* proxyCallOp, Val
if (theModule.lookupSymbol<mlir::LLVM::LLVMFuncOp>(proxyCallOp->getFunctionSymbol())) {
functionRef = mlir::SymbolRefAttr::get(context, proxyCallOp->getFunctionSymbol());
} else {
functionRef = insertExternalFunction(proxyCallOp->getFunctionSymbol(), proxyCallOp->getFunctionPtr(),
getMLIRType(proxyCallOp->getStamp()),
getMLIRType(proxyCallOp->getInputArguments()));
functionRef =
insertExternalFunction(proxyCallOp->getFunctionSymbol(), proxyCallOp->getFunctionPtr(),
getMLIRType(proxyCallOp->getStamp()), getMLIRType(proxyCallOp->getInputArguments()));
}

std::vector<mlir::Value> functionArgs;
Expand Down
20 changes: 10 additions & 10 deletions nautilus/src/nautilus/compiler/ir/IRGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ struct formatter<nautilus::compiler::ir::IRGraph> : formatter<std::string_view>

template <>
struct formatter<nautilus::compiler::ir::OperationIdentifier> : formatter<std::string_view> {
static auto format(const nautilus::compiler::ir::OperationIdentifier& op,
format_context& ctx) -> format_context::iterator {
static auto format(const nautilus::compiler::ir::OperationIdentifier& op, format_context& ctx)
-> format_context::iterator {
auto out = ctx.out();
fmt::format_to(out, "${}", op.getId());
return out;
Expand All @@ -130,8 +130,8 @@ struct formatter<nautilus::compiler::ir::OperationIdentifier> : formatter<std::s

template <>
struct formatter<nautilus::compiler::ir::BasicBlockInvocation> : formatter<std::string_view> {
static auto format(const nautilus::compiler::ir::BasicBlockInvocation& op,
format_context& ctx) -> format_context::iterator {
static auto format(const nautilus::compiler::ir::BasicBlockInvocation& op, format_context& ctx)
-> format_context::iterator {
auto out = ctx.out();
fmt::format_to(out, "Block_{}(", op.getBlock()->getIdentifier());
const auto& args = op.getArguments();
Expand All @@ -158,8 +158,8 @@ struct formatter<nautilus::compiler::ir::IfOperation> : formatter<std::string_vi

template <>
struct formatter<nautilus::compiler::ir::ProxyCallOperation> : formatter<std::string_view> {
static auto format(const nautilus::compiler::ir::ProxyCallOperation& op,
format_context& ctx) -> format_context::iterator {
static auto format(const nautilus::compiler::ir::ProxyCallOperation& op, format_context& ctx)
-> format_context::iterator {
auto out = ctx.out();

if (op.getStamp() != nautilus::Type::v) {
Expand Down Expand Up @@ -239,8 +239,8 @@ struct formatter<nautilus::compiler::ir::Operation> : formatter<std::string_view

template <>
struct formatter<nautilus::compiler::ir::BasicBlock> : formatter<std::string_view> {
static auto format(const nautilus::compiler::ir::BasicBlock& block,
format_context& ctx) -> format_context::iterator {
static auto format(const nautilus::compiler::ir::BasicBlock& block, format_context& ctx)
-> format_context::iterator {
auto out = ctx.out();
fmt::format_to(out, "\nBlock_{}(", block.getIdentifier());
const auto& args = block.getArguments();
Expand All @@ -261,8 +261,8 @@ struct formatter<nautilus::compiler::ir::BasicBlock> : formatter<std::string_vie

template <>
struct formatter<nautilus::compiler::ir::FunctionOperation> : formatter<std::string_view> {
static auto format(const nautilus::compiler::ir::FunctionOperation& func,
format_context& ctx) -> format_context::iterator {
static auto format(const nautilus::compiler::ir::FunctionOperation& func, format_context& ctx)
-> format_context::iterator {
auto out = ctx.out();
fmt::format_to(out, "{}(", func.getName());
for (const auto& arg : func.getInputArgNames()) {
Expand Down
63 changes: 40 additions & 23 deletions nautilus/src/nautilus/compiler/ir/util/GraphVizUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template <>
struct formatter<nautilus::compiler::ir::Operation> : formatter<std::string_view> {
static auto format(const nautilus::compiler::ir::Operation& c, format_context& ctx) -> format_context::iterator;
};
}
} // namespace fmt

namespace nautilus::compiler::ir {
/*
Expand Down Expand Up @@ -59,24 +59,27 @@ digraph G {
*/

const std::string WHITE_ICE = "#d7ede7";
//const std::string CRUISE = "#b8ddd1";
// const std::string CRUISE = "#b8ddd1";
const std::string KEPPEL = "#3cb4a4";
const std::string CARISSMA = "#e98693";
const std::string AMARANTH = "#da2d4f";
const std::string BLACK = "#1a1919";
//const std::string WHITE = "#ffffff";
// const std::string WHITE = "#ffffff";
const std::string DUST = "#f9f9f9";
const std::string BIG_STONE = "#343d46";
//const std::string ICE_STONE = "#b3bbc3";
// const std::string ICE_STONE = "#b3bbc3";
const std::string ORANGE = "#ffa500";
//const std::string LIGHT_BLUE = "#ccccff";
// const std::string LIGHT_BLUE = "#ccccff";
const std::string LIGHT_PURPLE = "#c39bd3";
const std::string LIGHT_YELLOW = "#ffffde";
const std::string DARK_YELLOW = "#aaaa33";
const std::map<std::string, std::string> EDGE_COLORS = {{"info", BIG_STONE}, {"control", AMARANTH}, {"loop", AMARANTH}, {"data", KEPPEL}, {"other", BLACK}};
const std::map<std::string, std::pair<std::string, std::string>> NODE_COLORS = {{"info", {DUST, BLACK}}, {"input", {WHITE_ICE, BLACK}}, {"control", {CARISSMA, BLACK}}, {"memory", {LIGHT_PURPLE, BLACK}},
{"call", {AMARANTH, "white"}}, {"alloc", {AMARANTH, "white"}}, {"sync", {AMARANTH, "white"}}, {"virtual", {BIG_STONE, "white"}},
{"guard", {ORANGE, BLACK}}, {"calc", {KEPPEL, BLACK}}, {"other", {DUST, BLACK}}};
const std::map<std::string, std::string> EDGE_COLORS = {
{"info", BIG_STONE}, {"control", AMARANTH}, {"loop", AMARANTH}, {"data", KEPPEL}, {"other", BLACK}};
const std::map<std::string, std::pair<std::string, std::string>> NODE_COLORS = {
{"info", {DUST, BLACK}}, {"input", {WHITE_ICE, BLACK}}, {"control", {CARISSMA, BLACK}},
{"memory", {LIGHT_PURPLE, BLACK}}, {"call", {AMARANTH, "white"}}, {"alloc", {AMARANTH, "white"}},
{"sync", {AMARANTH, "white"}}, {"virtual", {BIG_STONE, "white"}}, {"guard", {ORANGE, BLACK}},
{"calc", {KEPPEL, BLACK}}, {"other", {DUST, BLACK}}};

std::string urlEncode(const std::string& value) {
std::ostringstream encoded;
Expand Down Expand Up @@ -112,7 +115,8 @@ std::string write_attrs(const std::map<std::string, std::string>& attrs) {

class GraphvizWriter {
public:
GraphvizWriter(std::ostream& stream) : stream(stream) {}
GraphvizWriter(std::ostream& stream) : stream(stream) {
}
void end_graph() {
stream << "}" << std::endl;
}
Expand All @@ -121,7 +125,9 @@ class GraphvizWriter {
stream << " graph " << write_attrs(attrs) << ";" << std::endl;
}

void write_block_argument_edges([[maybe_unused]] const std::shared_ptr<IRGraph>& graph, const BasicBlockInvocation& bi, [[maybe_unused]] bool hideIntermediateBlockArguments) {
void write_block_argument_edges([[maybe_unused]] const std::shared_ptr<IRGraph>& graph,
const BasicBlockInvocation& bi,
[[maybe_unused]] bool hideIntermediateBlockArguments) {
auto targetBlock = bi.getBlock();
auto preBlocks = getPredecessorBlocks(graph, targetBlock);
// if (hideIntermediateBlockArguments && preBlocks.size() == 1){
Expand All @@ -135,34 +141,41 @@ class GraphvizWriter {
}
}

std::vector<std::tuple<BasicBlock*, BasicBlockInvocation*>> getPredecessorBlocks(const std::shared_ptr<IRGraph>& graph, const BasicBlock* targetBlock) {
std::vector<std::tuple<BasicBlock*, BasicBlockInvocation*>>
getPredecessorBlocks(const std::shared_ptr<IRGraph>& graph, const BasicBlock* targetBlock) {
std::vector<std::tuple<BasicBlock*, BasicBlockInvocation*>> predeccessor;
for (const auto& block : graph->getRootOperation().getBasicBlocks()) {
auto& op = block->getOperations().back();
if (op->getOperationType() == Operation::OperationType::IfOp) {
auto ifOp = as<IfOperation>(op);
if (ifOp->getFalseBlockInvocation().getBlock() == targetBlock) {
auto tup = std::make_tuple<BasicBlock*, BasicBlockInvocation*>(block.get(), &ifOp->getFalseBlockInvocation());
auto tup = std::make_tuple<BasicBlock*, BasicBlockInvocation*>(block.get(),
&ifOp->getFalseBlockInvocation());
predeccessor.emplace_back(tup);
}
if (ifOp->getTrueBlockInvocation().getBlock() == targetBlock) {
auto tup = std::make_tuple<BasicBlock*, BasicBlockInvocation*>(block.get(), &ifOp->getTrueBlockInvocation());
auto tup = std::make_tuple<BasicBlock*, BasicBlockInvocation*>(block.get(),
&ifOp->getTrueBlockInvocation());
predeccessor.emplace_back(tup);
}
} else if (op->getOperationType() == Operation::OperationType::BranchOp) {
auto branchOp = as<BranchOperation>(op);
if (branchOp->getNextBlockInvocation().getBlock() == targetBlock) {
auto tup = std::make_tuple<BasicBlock*, BasicBlockInvocation*>(block.get(), &branchOp->getNextBlockInvocation());
auto tup = std::make_tuple<BasicBlock*, BasicBlockInvocation*>(block.get(),
&branchOp->getNextBlockInvocation());
predeccessor.emplace_back(tup);
}
}
}
return predeccessor;
}

std::string getFromInput([[maybe_unused]] const std::shared_ptr<IRGraph>& graph, [[maybe_unused]] const BasicBlock* block, Operation* input, bool hideIntermediateBlockArguments) {
std::string getFromInput([[maybe_unused]] const std::shared_ptr<IRGraph>& graph,
[[maybe_unused]] const BasicBlock* block, Operation* input,
bool hideIntermediateBlockArguments) {

if (hideIntermediateBlockArguments && input->getOperationType() == Operation::OperationType::BasicBlockArgument) {
if (hideIntermediateBlockArguments &&
input->getOperationType() == Operation::OperationType::BasicBlockArgument) {
[[maybe_unused]] const auto* arg = as<const BasicBlockArgument>(input);
size_t index = 0;
for (size_t i = 0; i < block->getArguments().size(); i++) {
Expand Down Expand Up @@ -208,7 +221,8 @@ class GraphvizWriter {
}
}

void getBlockArgumentMap(const BasicBlock* block, std::set<const BasicBlock*>& visitedBlocks, std::map<Operation*, std::vector<Operation*>>& map) {
void getBlockArgumentMap(const BasicBlock* block, std::set<const BasicBlock*>& visitedBlocks,
std::map<Operation*, std::vector<Operation*>>& map) {
if (visitedBlocks.contains(block)) {
return;
}
Expand Down Expand Up @@ -251,7 +265,8 @@ class GraphvizWriter {
write_block_argument_edges(graph, ifOp->getFalseBlockInvocation(), hideIntermediateBlockArguments);
} else if (op->getOperationType() == Operation::OperationType::BranchOp) {
[[maybe_unused]] auto branchOp = as<BranchOperation>(op);
write_block_argument_edges(graph, branchOp->getNextBlockInvocation(), hideIntermediateBlockArguments);
write_block_argument_edges(graph, branchOp->getNextBlockInvocation(),
hideIntermediateBlockArguments);
}
}
}
Expand Down Expand Up @@ -294,7 +309,8 @@ class GraphvizWriter {
}
}

void write_edge(const std::string& from, const std::string& to, const std::string type, const std::string& label = "") {
void write_edge(const std::string& from, const std::string& to, const std::string type,
const std::string& label = "") {
std::map<std::string, std::string> attrs;
attrs["label"] = label; // Example label
attrs["fontname"] = "arial";
Expand All @@ -318,7 +334,8 @@ class GraphvizWriter {
write_edges(graph, true);
end_graph();
}
void write_node(const std::string& indent, const std::string& label, const std::string& id, const std::string type) {
void write_node(const std::string& indent, const std::string& label, const std::string& id,
const std::string type) {
std::map<std::string, std::string> attrs;
attrs["label"] = label;
attrs["shape"] = "rectangle"; // Example shape
Expand All @@ -334,8 +351,8 @@ class GraphvizWriter {
stream << indent << "node" << id << " " << write_attrs(attrs) << ";" << std::endl;
}

void write_node_for_op(const std::string& indent, const std::string& block, Operation* node) {
std::string id = block +"_" +std::to_string(nodeIdMap.size());
void write_node_for_op(const std::string& indent, const std::string& block, Operation* node) {
std::string id = block + "_" + std::to_string(nodeIdMap.size());
nodeIdMap[node] = id;

write_node(indent, getNodeLabelForOp(node), id, getNodeTypeForOp(node->getOperationType()));
Expand Down
8 changes: 4 additions & 4 deletions nautilus/src/nautilus/tracing/ExecutionTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ auto formatter<nautilus::tracing::ExecutionTrace>::format(const nautilus::tracin
return out;
}

auto formatter<nautilus::tracing::Block>::format(const nautilus::tracing::Block& block,
format_context& ctx) -> format_context::iterator {
auto formatter<nautilus::tracing::Block>::format(const nautilus::tracing::Block& block, format_context& ctx)
-> format_context::iterator {
auto out = ctx.out();
fmt::format_to(out, "(");
for (size_t i = 0; i < block.arguments.size(); i++) {
Expand All @@ -306,8 +306,8 @@ auto formatter<nautilus::tracing::Block>::format(const nautilus::tracing::Block&

template <>
struct formatter<nautilus::tracing::TypedValueRef> : formatter<std::string_view> {
static auto format(const nautilus::tracing::TypedValueRef& typeValRef,
format_context& ctx) -> format_context::iterator {
static auto format(const nautilus::tracing::TypedValueRef& typeValRef, format_context& ctx)
-> format_context::iterator {
auto out = ctx.out();
fmt::format_to(out, "${}", typeValRef.ref);
return out;
Expand Down
16 changes: 9 additions & 7 deletions nautilus/src/nautilus/tracing/tag/TagRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TagRecorder::TagRecorder(TagAddress startAddress) : startAddress(startAddress) {
// check if gnu backtrace is available.
#if defined(BACKWARD_HAS_BACKTRACE) & !defined(HOST_IS_MUSL)
TagVector TagRecorder::createBaseTag() {
void* tagBuffer[MAX_TAG_SIZE];
void* tagBuffer[MAX_TAG_SIZE];
int size = backtrace(tagBuffer, MAX_TAG_SIZE);
std::vector<TagAddress> addresses;
for (int i = 0; i < size; i++) {
Expand Down Expand Up @@ -106,16 +106,18 @@ Tag* TagRecorder::createReferenceTag() {

template <size_t StackSize>
__attribute__((noinline)) void* get_addr(size_t index) {
return [&]<std::size_t... ints>(std::index_sequence<ints...>) __attribute__((noinline)) {
void* addr = nullptr;
(void)((index == ints && (void(addr = __builtin_extract_return_addr(__builtin_return_address(ints + 2))), true)) || ...);
return addr;
}(std::make_index_sequence<StackSize>{});
return [&]<std::size_t... ints>(std::index_sequence<ints...>) __attribute__((noinline)) {
void* addr = nullptr;
(void) ((index == ints &&
(void(addr = __builtin_extract_return_addr(__builtin_return_address(ints + 2))), true)) ||
...);
return addr;
}
(std::make_index_sequence<StackSize> {});
}

static void* getReturnAddress(uint32_t offset) {
return get_addr<TagRecorder::MAX_TAG_SIZE>(offset);
}


} // namespace nautilus::tracing

0 comments on commit f65b1d7

Please sign in to comment.