-
Notifications
You must be signed in to change notification settings - Fork 15.3k
CodeGen: Add LibcallLoweringInfo analysis pass #168622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: users/arsenm/codegen/move-libcall-lowering-config-subtarget
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,12 +9,16 @@ | |
| #ifndef LLVM_CODEGEN_LIBCALLLOWERINGINFO_H | ||
| #define LLVM_CODEGEN_LIBCALLLOWERINGINFO_H | ||
|
|
||
| #include "llvm/ADT/DenseMap.h" | ||
| #include "llvm/IR/RuntimeLibcalls.h" | ||
| #include "llvm/Pass.h" | ||
|
|
||
| namespace llvm { | ||
|
|
||
| class TargetSubtargetInfo; | ||
| class TargetMachine; | ||
|
|
||
| /// Tracks which library functions to use for a particular subtarget. | ||
| class LibcallLoweringInfo { | ||
| private: | ||
| const RTLIB::RuntimeLibcallsInfo &RTLCI; | ||
|
|
@@ -73,6 +77,70 @@ class LibcallLoweringInfo { | |
| } | ||
| }; | ||
|
|
||
| /// Record a mapping from subtarget to LibcallLoweringInfo. | ||
| class LibcallLoweringModuleAnalysisResult { | ||
| private: | ||
| using LibcallLoweringMap = | ||
| DenseMap<const TargetSubtargetInfo *, LibcallLoweringInfo>; | ||
| mutable LibcallLoweringMap LoweringMap; | ||
| const RTLIB::RuntimeLibcallsInfo *RTLCI = nullptr; | ||
|
|
||
| public: | ||
| LibcallLoweringModuleAnalysisResult() = default; | ||
| LibcallLoweringModuleAnalysisResult(RTLIB::RuntimeLibcallsInfo &RTLCI) | ||
| : RTLCI(&RTLCI) {} | ||
|
|
||
| void init(const RTLIB::RuntimeLibcallsInfo *RT) { RTLCI = RT; } | ||
|
|
||
| void clear() { | ||
| RTLCI = nullptr; | ||
| LoweringMap.clear(); | ||
| } | ||
|
|
||
| LLVM_ABI bool invalidate(Module &, const PreservedAnalyses &, | ||
| ModuleAnalysisManager::Invalidator &); | ||
|
|
||
| const LibcallLoweringInfo & | ||
| getLibcallLowering(const TargetSubtargetInfo &Subtarget) const { | ||
| return LoweringMap.try_emplace(&Subtarget, *RTLCI, Subtarget).first->second; | ||
| } | ||
| }; | ||
|
|
||
| class LibcallLoweringModuleAnalysis | ||
| : public AnalysisInfoMixin<LibcallLoweringModuleAnalysis> { | ||
| private: | ||
| friend AnalysisInfoMixin<LibcallLoweringModuleAnalysis>; | ||
| LLVM_ABI static AnalysisKey Key; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private members shouldn't be LLVM_ABI |
||
|
|
||
| LibcallLoweringModuleAnalysisResult LibcallLoweringMap; | ||
|
|
||
| public: | ||
| using Result = LibcallLoweringModuleAnalysisResult; | ||
|
|
||
| LLVM_ABI Result run(Module &M, ModuleAnalysisManager &); | ||
| }; | ||
|
|
||
| class LLVM_ABI LibcallLoweringInfoWrapper : public ImmutablePass { | ||
| LibcallLoweringModuleAnalysisResult Result; | ||
|
|
||
| public: | ||
| static char ID; | ||
| LibcallLoweringInfoWrapper(); | ||
|
|
||
| const LibcallLoweringInfo & | ||
| getLibcallLowering(const TargetSubtargetInfo &Subtarget) const { | ||
| return Result.getLibcallLowering(Subtarget); | ||
| } | ||
|
|
||
| const LibcallLoweringModuleAnalysisResult &getResult() const { | ||
| return Result; | ||
| } | ||
|
|
||
| bool doInitialization(Module &M) override; | ||
| void getAnalysisUsage(AnalysisUsage &AU) const override; | ||
| void releaseMemory() override; | ||
| }; | ||
|
|
||
| } // end namespace llvm | ||
|
|
||
| #endif // LLVM_CODEGEN_LIBCALLLOWERINGINFO_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -991,7 +991,7 @@ static void addToWorklist(Instruction &I, | |
| } | ||
|
|
||
| static bool runImpl(Function &F, const TargetLowering &TLI, | ||
| AssumptionCache *AC) { | ||
| const LibcallLoweringInfo &Libcalls, AssumptionCache *AC) { | ||
| SmallVector<Instruction *, 4> Worklist; | ||
|
|
||
| unsigned MaxLegalFpConvertBitWidth = | ||
|
|
@@ -1090,12 +1090,17 @@ class ExpandFpLegacyPass : public FunctionPass { | |
|
|
||
| bool runOnFunction(Function &F) override { | ||
| auto *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>(); | ||
| auto *TLI = TM->getSubtargetImpl(F)->getTargetLowering(); | ||
| const TargetSubtargetInfo *Subtarget = TM->getSubtargetImpl(F); | ||
| auto *TLI = Subtarget->getTargetLowering(); | ||
| AssumptionCache *AC = nullptr; | ||
|
|
||
| const LibcallLoweringInfo &Libcalls = | ||
| getAnalysis<LibcallLoweringInfoWrapper>().getLibcallLowering( | ||
| *Subtarget); | ||
|
|
||
| if (OptLevel != CodeGenOptLevel::None && !F.hasOptNone()) | ||
| AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); | ||
| return runImpl(F, *TLI, AC); | ||
| return runImpl(F, *TLI, Libcalls, AC); | ||
| } | ||
|
|
||
| void getAnalysisUsage(AnalysisUsage &AU) const override { | ||
|
|
@@ -1104,6 +1109,7 @@ class ExpandFpLegacyPass : public FunctionPass { | |
| AU.addRequired<AssumptionCacheTracker>(); | ||
| AU.addPreserved<AAResultsWrapperPass>(); | ||
| AU.addPreserved<GlobalsAAWrapperPass>(); | ||
| AU.addRequired<LibcallLoweringInfoWrapper>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be added as |
||
| } | ||
| }; | ||
| } // namespace | ||
|
|
@@ -1126,8 +1132,23 @@ PreservedAnalyses ExpandFpPass::run(Function &F, FunctionAnalysisManager &FAM) { | |
| AssumptionCache *AC = nullptr; | ||
| if (OptLevel != CodeGenOptLevel::None) | ||
| AC = &FAM.getResult<AssumptionAnalysis>(F); | ||
| return runImpl(F, TLI, AC) ? PreservedAnalyses::none() | ||
| : PreservedAnalyses::all(); | ||
|
|
||
| auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F); | ||
|
|
||
| const LibcallLoweringModuleAnalysisResult *LibcallLowering = | ||
| MAMProxy.getCachedResult<LibcallLoweringModuleAnalysis>(*F.getParent()); | ||
|
|
||
| if (!LibcallLowering) { | ||
| F.getContext().emitError("'" + LibcallLoweringModuleAnalysis::name() + | ||
| "' analysis required"); | ||
| return PreservedAnalyses::all(); | ||
| } | ||
|
|
||
| const LibcallLoweringInfo &Libcalls = | ||
| LibcallLowering->getLibcallLowering(*STI); | ||
|
|
||
| return runImpl(F, TLI, Libcalls, AC) ? PreservedAnalyses::none() | ||
| : PreservedAnalyses::all(); | ||
| } | ||
|
|
||
| char ExpandFpLegacyPass::ID = 0; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the default values required? AFAICS they are always explicitly specified