This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Split off MLIRExecutionEngineUtils to fix libMLIR.so build (PR54242)
ClosedPublic

Authored by nikic on May 9 2022, 2:09 AM.

Details

Summary

Building libMLIR.so currently fails with:

/usr/bin/ld: /tmp/ccNzulEA.ltrans39.ltrans.o: in function `(anonymous namespace)::SerializeToHsacoPass::optimizeLlvm(llvm::Module&, llvm::TargetMachine&)':
/builddir/build/BUILD/llvm-project-15.0.0.src/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp:328: undefined reference to `mlir::makeOptimizingTransformer(unsigned int, unsigned int, llvm::TargetMachine*)'

This is because MLIRGPUTransforms depends on MLIRExecutionEngine in https://github.com/llvm/llvm-project/blob/61bb2e4ea82fc5499a271d70d4537383d1942208/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp#L328, but MLIRExecutionEngine is marked as excluded from libMLIR.so.

However, this code doesn't require the full execution engine: It only performs middle-end optimization, and does not need any of the JIT/codegen infrastructure. As such, split off a separate library MLIRExecutionEngineUtils, which only contains that part and is not excluded from libMLIR.so.

Fixes https://github.com/llvm/llvm-project/issues/54242.

Diff Detail

Event Timeline

nikic created this revision.May 9 2022, 2:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2022, 2:09 AM
nikic requested review of this revision.May 9 2022, 2:09 AM
nikic edited the summary of this revision. (Show Details)May 9 2022, 2:09 AM
mehdi_amini requested changes to this revision.May 9 2022, 7:23 AM

We should resolve the discussion in the tracking bug first I think: https://github.com/llvm/llvm-project/issues/54242#issuecomment-1063520117

This revision now requires changes to proceed.May 9 2022, 7:23 AM
nikic updated this revision to Diff 428084.May 9 2022, 7:49 AM

Split off MLIRExecutionEngineUtils and only include that in libMLIR.so. This avoids embedding the JIT/MC/etc layer into libMLIR.so.

nikic added a comment.May 9 2022, 7:53 AM

Does this general approach seem reasonable? I based this off what bazel does.

If we don't want to include this in libMLIR.so either, then I think the only alternative is to revert https://github.com/llvm/llvm-project/commit/bd22554af06e1f16dc9ff12eac8987f0ceebe8c1 due to the layering violation.

Thanks someone for having the bandwidth to factor makeOptimizingTransformer into a separate library so that "the utility function that lets us invoke LLVM" doesn't require pulling in the entire JIT.

mehdi_amini accepted this revision.May 9 2022, 9:44 AM

LGTM, but please update the title and description.

This revision is now accepted and ready to land.May 9 2022, 9:44 AM
nikic retitled this revision from [MLIR] Don't exclude MLIRExecutionEngine from libMLIR.so to [MLIR] Split off MLIRExecutionEngineUtils to fix libMLIR.so build (PR54242).May 10 2022, 1:15 AM
nikic edited the summary of this revision. (Show Details)