Skip to content

Commit

Permalink
use fmt instead of sstream
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrulich committed Sep 22, 2024
1 parent c159832 commit ace90dc
Show file tree
Hide file tree
Showing 956 changed files with 348 additions and 8,713 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ void BCLoweringProvider::RegisterProvider::freeRegister() {

std::tuple<Code, RegisterFile> BCLoweringProvider::LoweringContext::process() {
defaultRegisterFile.fill(0);
auto functionOperation = ir->getRootOperation();
const auto& functionOperation = ir->getRootOperation();
RegisterFrame rootFrame;
auto functionBasicBlock = functionOperation->getFunctionBasicBlock();
for (auto i = 0ull; i < functionBasicBlock->getArguments().size(); i++) {
auto& argument = functionBasicBlock->getArguments()[i];
const auto& functionBasicBlock = functionOperation.getFunctionBasicBlock();
for (auto i = 0ull; i < functionBasicBlock.getArguments().size(); i++) {
auto& argument = functionBasicBlock.getArguments()[i];
auto argumentRegister = registerProvider.allocRegister();
rootFrame.setValue(argument->getIdentifier(), argumentRegister);
program.arguments.emplace_back(argumentRegister);
}
this->process(functionBasicBlock, rootFrame);
this->process(&functionBasicBlock, rootFrame);
// NES_INFO("Allocated Registers: " <<
// this->registerProvider.allocRegister());
return std::make_tuple(program, defaultRegisterFile);
Expand Down Expand Up @@ -944,7 +944,7 @@ void BCLoweringProvider::LoweringContext::process(ir::ShiftOperation* shiftOpera
program.blocks[block].code.emplace_back(oc);
}

void BCLoweringProvider::LoweringContext::process(ir::BasicBlockInvocation& bi, short block, RegisterFrame& parentFrame) {
void BCLoweringProvider::LoweringContext::process(const ir::BasicBlockInvocation& bi, short block, RegisterFrame& parentFrame) {
auto blockInputArguments = bi.getArguments();
auto& blockTargetArguments = bi.getBlock()->getArguments();
std::vector<short> tempArgs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class BCLoweringProvider {

void process(ir::BranchOperation* opt, short block, RegisterFrame& frame);

void process(ir::BasicBlockInvocation& opt, short block, RegisterFrame& frame);
void process(const ir::BasicBlockInvocation& opt, short block, RegisterFrame& frame);

void process(ir::LoadOperation* opt, short block, RegisterFrame& frame);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ std::string CPPLoweringProvider::LoweringContext::getType(const Type& stamp) {

std::stringstream CPPLoweringProvider::LoweringContext::process() {

auto functionOperation = ir->getRootOperation();
const auto& functionOperation = ir->getRootOperation();
RegisterFrame rootFrame;
std::vector<std::string> arguments;
auto functionBasicBlock = functionOperation->getFunctionBasicBlock();
for (auto i = 0ull; i < functionBasicBlock->getArguments().size(); i++) {
auto argument = functionBasicBlock->getArguments()[i].get();
const auto& functionBasicBlock = functionOperation.getFunctionBasicBlock();
for (auto i = 0ull; i < functionBasicBlock.getArguments().size(); i++) {
auto argument = functionBasicBlock.getArguments()[i].get();
auto var = getVariable(argument->getIdentifier());
rootFrame.setValue(argument->getIdentifier(), var);
arguments.emplace_back(getType(argument->getStamp()) + " " + var);
}
this->process(functionBasicBlock, rootFrame);
this->process(&functionBasicBlock, rootFrame);

std::stringstream pipelineCode;
pipelineCode << "\n";
Expand Down Expand Up @@ -179,7 +179,7 @@ void CPPLoweringProvider::LoweringContext::process(ir::StoreOperation* storeOp,
blocks[blockIndex] << "*reinterpret_cast<" << type << "*>(" << address << ") = " << value << ";\n";
}

void CPPLoweringProvider::LoweringContext::process(ir::BasicBlockInvocation& bi, short blockIndex, RegisterFrame& parentFrame) {
void CPPLoweringProvider::LoweringContext::process(const ir::BasicBlockInvocation& bi, short blockIndex, RegisterFrame& parentFrame) {
auto blockInputArguments = bi.getArguments();
auto& blockTargetArguments = bi.getBlock()->getArguments();
blocks[blockIndex] << "// prepare block arguments\n";
Expand All @@ -197,8 +197,7 @@ void CPPLoweringProvider::LoweringContext::process(ir::BasicBlockInvocation& bi,
blockArguments << getType(blockTargetArguments[i]->getStamp()) << " " << var << ";\n";
}

blocks[blockIndex] << parentFrame.getValue(blockTargetArgument) << " = "
<< "temp_" << i << ";\n";
blocks[blockIndex] << parentFrame.getValue(blockTargetArgument) << " = " << "temp_" << i << ";\n";
}
blocks[blockIndex] << "}\n";
}
Expand Down Expand Up @@ -351,8 +350,7 @@ void CPPLoweringProvider::LoweringContext::process(const std::unique_ptr<ir::Ope
return;
}
default: {
throw NotImplementedException("Operation is not implemented:" + opt->toString());
return;
throw NotImplementedException("Operation is not implemented");
}
}
}
Expand All @@ -373,8 +371,7 @@ void CPPLoweringProvider::LoweringContext::process(ir::ProxyCallOperation* opt,
argTypes << getType(arg->getStamp());
}
if (!functionNames.contains(opt->getFunctionSymbol())) {
functions << "auto f_" << opt->getFunctionSymbol() << " = "
<< "(" << returnType << "(*)(" << argTypes.str() << "))" << opt->getFunctionPtr() << ";\n";
functions << "auto f_" << opt->getFunctionSymbol() << " = " << "(" << returnType << "(*)(" << argTypes.str() << "))" << opt->getFunctionPtr() << ";\n";
functionNames.emplace(opt->getFunctionSymbol());
}
if (opt->getStamp() != Type::v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CPPLoweringProvider {

std::string process(const ir::BasicBlock*, RegisterFrame& frame);

void process(ir::BasicBlockInvocation& opt, short block, RegisterFrame& frame);
void process(const ir::BasicBlockInvocation& opt, short block, RegisterFrame& frame);

void process(const std::unique_ptr<ir::Operation>& operation, short block, RegisterFrame& frame);

Expand Down Expand Up @@ -97,13 +97,11 @@ class CPPLoweringProvider {
blockArguments << getType(constValue->getStamp()) << " " << var << ";\n";
frame.setValue(constValue->getIdentifier(), var);

blocks[blockIndex] << var << " = (" << getType(constValue->getStamp()) << ")" << constValue->getValue()
<< ";\n";
blocks[blockIndex] << var << " = (" << getType(constValue->getStamp()) << ")" << constValue->getValue() << ";\n";
}

template <class Type>
void processBinary(const std::unique_ptr<ir::Operation>& o, const std::string& operation, short blockIndex,
RegisterFrame& frame) {
void processBinary(const std::unique_ptr<ir::Operation>& o, const std::string& operation, short blockIndex, RegisterFrame& frame) {
auto op = static_cast<Type*>(o.get());
auto leftInput = frame.getValue(op->getLeftInput()->getIdentifier());
auto rightInput = frame.getValue(op->getRightInput()->getIdentifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void MLIRLoweringProvider::generateMLIR(const ir::BasicBlock* basicBlock, ValueF
void MLIRLoweringProvider::generateMLIR(const std::unique_ptr<ir::Operation>& operation, ValueFrame& frame) {
switch (operation->getOperationType()) {
case ir::Operation::OperationType::FunctionOp:
generateMLIR(as<ir::FunctionOperation>(operation), frame);
//generateMLIR(as<ir::FunctionOperation>(operation), frame);
break;
case ir::Operation::OperationType::ConstIntOp:
generateMLIR(as<ir::ConstIntOperation>(operation), frame);
Expand Down Expand Up @@ -356,23 +356,23 @@ void MLIRLoweringProvider::generateMLIR(ir::AndOperation* andOperation, ValueFra
);
}

void MLIRLoweringProvider::generateMLIR(ir::FunctionOperation* functionOp, ValueFrame& frame) {
void MLIRLoweringProvider::generateMLIR(const ir::FunctionOperation& functionOp, ValueFrame& frame) {
// Generate execute function. Set input/output types and get its entry block.
llvm::SmallVector<mlir::Type> inputTypes(0);
for (auto& inputArg : functionOp->getFunctionBasicBlock()->getArguments()) {
for (auto& inputArg : functionOp.getFunctionBasicBlock().getArguments()) {
inputTypes.emplace_back(getMLIRType(inputArg->getStamp()));
}
llvm::SmallVector<mlir::Type> outputTypes(1, getMLIRType(functionOp->getOutputArg()));
llvm::SmallVector<mlir::Type> outputTypes(1, getMLIRType(functionOp.getOutputArg()));
;
auto functionInOutTypes = builder->getFunctionType(inputTypes, outputTypes);
auto loc = getNameLoc("EntryPoint");
auto mlirFunction = builder->create<mlir::func::FuncOp>(loc, functionOp->getName(), functionInOutTypes);
auto mlirFunction = builder->create<mlir::func::FuncOp>(loc, functionOp.getName(), functionInOutTypes);

// Avoid function name mangling.
mlirFunction->setAttr("llvm.emit_c_interface", mlir::UnitAttr::get(context));
if (isUnsignedInteger(functionOp->getStamp())) {
if (isUnsignedInteger(functionOp.getStamp())) {
mlirFunction.setResultAttr(0, "llvm.zeroext", mlir::UnitAttr::get(context));
} else if (isSignedInteger(functionOp->getStamp())) {
} else if (isSignedInteger(functionOp.getStamp())) {
mlirFunction.setResultAttr(0, "llvm.signext", mlir::UnitAttr::get(context));
}
// mlirFunction.setArgAttr(0, "llvm.signext", mlir::UnitAttr::get(context));
Expand All @@ -395,14 +395,14 @@ void MLIRLoweringProvider::generateMLIR(ir::FunctionOperation* functionOp, Value

// Store references to function args in the valueMap map.
auto valueMapIterator = mlirFunction.args_begin();
for (int i = 0; i < (int) functionOp->getFunctionBasicBlock()->getArguments().size(); ++i) {
frame.setValue(functionOp->getFunctionBasicBlock()->getArguments().at(i)->getIdentifier(), valueMapIterator[i]
for (int i = 0; i < (int) functionOp.getFunctionBasicBlock().getArguments().size(); ++i) {
frame.setValue(functionOp.getFunctionBasicBlock().getArguments().at(i)->getIdentifier(), valueMapIterator[i]

);
}

// Generate MLIR for operations in function body (BasicBlock).
generateMLIR(functionOp->getFunctionBasicBlock(), frame);
generateMLIR(&functionOp.getFunctionBasicBlock(), frame);

theModule.push_back(mlirFunction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class MLIRLoweringProvider {
*/
void generateMLIR(const std::unique_ptr<ir::Operation>& operation, ValueFrame& frame);

void generateMLIR(ir::FunctionOperation* funcOp, ValueFrame& frame);
void generateMLIR(const ir::FunctionOperation& funcOp, ValueFrame& frame);

void generateMLIR(ir::ConstIntOperation* constIntOp, ValueFrame& frame);

Expand Down Expand Up @@ -147,9 +147,7 @@ class MLIRLoweringProvider {
* @param varArgs: Include variable arguments.
* @return FlatSymbolRefAttr: Reference to function used in CallOps.
*/
::mlir::FlatSymbolRefAttr insertExternalFunction(const std::string& name, void* functionPtr,
::mlir::Type resultType, std::vector<::mlir::Type> argTypes,
bool varArgs);
::mlir::FlatSymbolRefAttr insertExternalFunction(const std::string& name, void* functionPtr, ::mlir::Type resultType, std::vector<::mlir::Type> argTypes, bool varArgs);

/**
* @brief Generates a Name(d)Loc(ation) that is attached to the operation.
Expand Down
2 changes: 1 addition & 1 deletion nautilus/src/nautilus/compiler/ir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ add_subdirectory(operations)
add_subdirectory(phases)
#add_subdirectory(Types)

add_source_files(nautilus IRGraph.cpp IRDumpHandler.cpp)
add_source_files(nautilus IRGraph.cpp)
92 changes: 0 additions & 92 deletions nautilus/src/nautilus/compiler/ir/IRDumpHandler.cpp

This file was deleted.

60 changes: 0 additions & 60 deletions nautilus/src/nautilus/compiler/ir/IRDumpHandler.hpp

This file was deleted.

Loading

0 comments on commit ace90dc

Please sign in to comment.