MLIR lowering

I don’t know if this is the right place to post this, but I’m new to MLIR. I’m trying to lower a MobileNet V1 model to LLVM IR. Here are the steps I’ve followed so far:

(1) Translate from model.pbtxt to tf_executor Dialect
tf-mlir-translate – --graphdef-to-mlir ${PWD}/mobilenetv1_graph.pbtxt -o ${PWD}/mobilenet.mlir

(2) tf_executor Dialect → tf Dialect (get add-func.mlir):
tf-opt -tf-executor-to-functional-conversion mobilenet.mlir -o add-func.mlir

for now every thing is working fine but when I want:
(3) tf Dialect → mhlo Dialect
tf-opt --tf-to-hlo-pipeline add-func.mlir -o add-mhlo.mlir

I get the following output:
module attributes {tf.versions = {bad_consumers = , min_consumer = 12 : i32, producer = 1395 : i32}} {
func.func @main() {

Can someone help me understand what might be causing this issue?

I can’t see your code exactly, but when I run a pass and the entire IR disappears, it usually means that the values were determined to be “dead” (unused) and deleted by the canonicalizer pass.

Perhaps your input mlir model should return the final computed value from main, to avoid that? It might also help to post a link to the mlir code just before the pass that breaks things.


Thank you for your response this the mlir code just before the pass that breaks things

Yes, it looks like your main function returns nothing, and the functions defined within are marked private and not called. So a canonicalizer would delete them as unused. I am not familiar with the pipelines you’re calling, but I imagine you could continue if your IR used the functions and returned a value from main.


ah, sorry, I see the private internal function is called, but still nothing is returned or used at the end, so I think that’s why it’s pruned.