tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] kumasento commented on a change in pull request #4847: Return empty CSourceModule when no lowered_funcs exists in Relay mod
Date Mon, 02 Mar 2020 19:33:54 GMT
kumasento commented on a change in pull request #4847: Return empty CSourceModule when no lowered_funcs
exists in Relay mod
URL: https://github.com/apache/incubator-tvm/pull/4847#discussion_r386604910
 
 

 ##########
 File path: src/target/llvm/llvm_module.cc
 ##########
 @@ -356,6 +356,40 @@ TVM_REGISTER_GLOBAL("codegen.build_llvm")
     *rv = runtime::Module(n);
   });
 
+TVM_REGISTER_GLOBAL("codegen.LLVMModuleCreate")
+.set_body([](TVMArgs args, TVMRetValue *rv) {
+  auto n = make_object<LLVMModuleNode>();
+
+  // parse target triple from the first argument
+  auto target = args[0].operator std::string();
+  std::string triple, mcpu, mattr;
+  llvm::TargetOptions opt;
+  ParseLLVMTargetOptions(target, &triple, &mcpu, &mattr, &opt);
+
+  // create a default data layout
+  auto tm = GetLLVMTargetMachine(target);
+  llvm::DataLayout layout(tm->createDataLayout());
+
+  // initialize an IR code snippet from a simple template
+  std::string ir_str;
+  ir_str += "target triple = \"" + triple + "\"\n";
+  ir_str += "target datalayout = \"" + layout.getStringRepresentation() + "\"";
+
+  // use parseIR to create a LLVM Module.
+  auto ctx = std::make_shared<llvm::LLVMContext>();
+  llvm::SMDiagnostic err;
+  auto mem_buf = llvm::MemoryBuffer::getMemBuffer(ir_str);
+  auto module = llvm::parseIR(mem_buf->getMemBufferRef(), err, *ctx);
 
 Review comment:
   @FrozenGene Thank you very much! It looks much better. I've updated my PR accordingly.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message