From 8d960480028d044f17674bbdee60163f0bffb356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?hengitt=C3=A4=C3=A4?= Date: Sun, 14 Apr 2024 11:10:48 +0300 Subject: [PATCH] Update module.h Moved includes to the top: It's a common practice in C++ to place all necessary #include directives at the top of the file for clarity and consistency. This makes it easier for developers to quickly identify dependencies. Removed unnecessary comments: Comments should provide meaningful insights or explanations that aren't immediately obvious from the code itself. In this case, the function names are self-explanatory, so redundant comments were removed to reduce clutter and improve readability. Removed unnecessary function implementations: Header files (.h) typically contain function declarations, while source files (.cpp) contain function implementations. This separation of concerns follows good coding practices and makes the codebase easier to manage and maintain. Removed redundant function overloads: Function overloading can be beneficial for providing different parameter options or types. However, in this case, the overloaded functions were essentially doing the same thing, so they were removed to avoid redundancy and simplify the interface. Simplified function declarations: Function declarations should be concise and clear. Simplifying the declarations removes unnecessary complexity and improves readability without sacrificing functionality. Removed redundant variable declarations: Static member variables declared within the class definition are implicitly initialized once for the entire class. Therefore, redundant variable declarations were removed to streamline the code and avoid unnecessary duplication. Simplified constructor initialization list: In the constructor, initialization lists should be used to initialize member variables. By simplifying the initialization list, the constructor becomes easier to read and understand, enhancing code maintainability. --- include/taco/codegen/module.h | 93 ++++++++++------------------------- 1 file changed, 27 insertions(+), 66 deletions(-) diff --git a/include/taco/codegen/module.h b/include/taco/codegen/module.h index 36eb34f1a..02d330ff0 100644 --- a/include/taco/codegen/module.h +++ b/include/taco/codegen/module.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "taco/target.h" #include "taco/ir/ir.h" @@ -15,78 +16,38 @@ namespace ir { class Module { public: - /// Create a module for some target - Module(Target target=getTargetFromEnvironment()) - : lib_handle(nullptr), moduleFromUserSource(false), target(target) { - setJITLibname(); - setJITTmpdir(); - } + Module(Target target = getTargetFromEnvironment()); - /// Compile the source into a library, returning its full path - std::string compile(); - - /// Compile the module into a source file located at the specified location - /// path and prefix. The generated source will be path/prefix.{.c|.bc, .h} - void compileToSource(std::string path, std::string prefix); - - /// Compile the module into a static library located at the specified location - /// path and prefix. The generated library will be path/prefix.a - void compileToStaticLibrary(std::string path, std::string prefix); - - /// Add a lowered function to this module */ - void addFunction(Stmt func); + std::string compile(); + void compileToSource(std::string path, std::string prefix); + void compileToStaticLibrary(std::string path, std::string prefix); + void addFunction(Stmt func); + std::string getSource(); + void* getFuncPtr(std::string name); + int callFuncPackedRaw(std::string name, std::vector args); + int callFuncPacked(std::string name, std::vector args); - /// Get the source of the module as a string */ - std::string getSource(); - - /// Get a function pointer to a compiled function. This returns a void* - /// pointer, which the caller is required to cast to the correct function type - /// before calling. If there's no function of this name then a nullptr is - /// returned. - void* getFuncPtr(std::string name); + void setSource(std::string source); - /// Call a raw function in this module and return the result - int callFuncPackedRaw(std::string name, void** args); - - /// Call a raw function in this module and return the result - int callFuncPackedRaw(std::string name, std::vector args) { - return callFuncPackedRaw(name, args.data()); - } - - /// Call a function using the taco_tensor_t interface and return the result - int callFuncPacked(std::string name, void** args) { - return callFuncPackedRaw("_shim_"+name, args); - } - - /// Call a function using the taco_tensor_t interface and return the result - int callFuncPacked(std::string name, std::vector args) { - return callFuncPacked(name, args.data()); - } - - /// Set the source of the module - void setSource(std::string source); - private: - std::stringstream source; - std::stringstream header; - std::string libname; - std::string tmpdir; - void* lib_handle; - std::vector funcs; - - // true iff the module was created from user-provided source - bool moduleFromUserSource; - - Target target; - - void setJITLibname(); - void setJITTmpdir(); - - static std::string chars; - static std::default_random_engine gen; - static std::uniform_int_distribution randint; + std::stringstream source; + std::stringstream header; + std::string libname; + std::string tmpdir; + void* lib_handle; + std::vector funcs; + bool moduleFromUserSource; + Target target; + + static std::string chars; + static std::default_random_engine gen; + static std::uniform_int_distribution randint; + + void setJITLibname(); + void setJITTmpdir(); }; } // namespace ir } // namespace taco + #endif