How to get the TargetTransformInfo in InstructionCombining.cpp?

I’m creating my own algorithm in InstructionCombining.cpp and I need to get the TargetTransformInfo to complete it.

The solution I get TargetTransformInfo is that moving the TargetTransformInfo &TTI; from private to public in InstCombiner.h file. And then I can get the TTI in InstrutionCombining.cpp.

But I think that is not a good way to do that. I only want to do some changes in InstructionCombining.cpp without others.

How do I get TargetTransformInfo in InstructionCombining.cpp ?

AFAIK InstCombine is intentionally kept target-indepdent and does not provide access to TTI.

Except some generic interfaces to combine target specific intrinsics I guess

That is correct, see also the comment in llvm-project/InstCombiner.h at 8d5c8d57c637d898094af323d1888ea5a3364f8c · llvm/llvm-project · GitHub