Skip to content

Commit c4f4a6b

Browse files
committed
ExpandFp: Require RuntimeLibcallsInfo analysis
Not sure I'm doing the new pass manager handling correctly. I do not like needing to manually check if the cached module pass is available and manually erroring in every pass.
1 parent 833269e commit c4f4a6b

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

llvm/lib/CodeGen/ExpandFp.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/SmallVector.h"
1919
#include "llvm/Analysis/AssumptionCache.h"
2020
#include "llvm/Analysis/GlobalsModRef.h"
21+
#include "llvm/Analysis/RuntimeLibcallInfo.h"
2122
#include "llvm/Analysis/SimplifyQuery.h"
2223
#include "llvm/Analysis/ValueTracking.h"
2324
#include "llvm/CodeGen/ISDOpcodes.h"
@@ -1092,6 +1093,8 @@ class ExpandFpLegacyPass : public FunctionPass {
10921093
auto *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
10931094
auto *TLI = TM->getSubtargetImpl(F)->getTargetLowering();
10941095
AssumptionCache *AC = nullptr;
1096+
const RTLIB::RuntimeLibcallsInfo *Libcalls =
1097+
&getAnalysis<RuntimeLibraryInfoWrapper>().getRTLCI(*F.getParent());
10951098

10961099
if (OptLevel != CodeGenOptLevel::None && !F.hasOptNone())
10971100
AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
@@ -1104,6 +1107,7 @@ class ExpandFpLegacyPass : public FunctionPass {
11041107
AU.addRequired<AssumptionCacheTracker>();
11051108
AU.addPreserved<AAResultsWrapperPass>();
11061109
AU.addPreserved<GlobalsAAWrapperPass>();
1110+
AU.addRequired<RuntimeLibraryInfoWrapper>();
11071111
}
11081112
};
11091113
} // namespace
@@ -1126,13 +1130,23 @@ PreservedAnalyses ExpandFpPass::run(Function &F, FunctionAnalysisManager &FAM) {
11261130
AssumptionCache *AC = nullptr;
11271131
if (OptLevel != CodeGenOptLevel::None)
11281132
AC = &FAM.getResult<AssumptionAnalysis>(F);
1133+
1134+
auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
1135+
const RTLIB::RuntimeLibcallsInfo *Libcalls =
1136+
MAMProxy.getCachedResult<RuntimeLibraryAnalysis>(*F.getParent());
1137+
if (!Libcalls) {
1138+
F.getContext().emitError("'runtime-libcall-info' analysis required");
1139+
return PreservedAnalyses::all();
1140+
}
1141+
11291142
return runImpl(F, TLI, AC) ? PreservedAnalyses::none()
11301143
: PreservedAnalyses::all();
11311144
}
11321145

11331146
char ExpandFpLegacyPass::ID = 0;
11341147
INITIALIZE_PASS_BEGIN(ExpandFpLegacyPass, "expand-fp",
11351148
"Expand certain fp instructions", false, false)
1149+
INITIALIZE_PASS_DEPENDENCY(RuntimeLibraryInfoWrapper)
11361150
INITIALIZE_PASS_END(ExpandFpLegacyPass, "expand-fp", "Expand fp", false, false)
11371151

11381152
FunctionPass *llvm::createExpandFpPass(CodeGenOptLevel OptLevel) {

llvm/test/Transforms/ExpandFp/AMDGPU/frem-inf.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: opt -mtriple=amdgcn -passes="expand-fp<O0>" %s -S -o - | FileCheck --check-prefixes CHECK %s
2-
; RUN: opt -mtriple=amdgcn -passes="expand-fp<O1>" %s -S -o - | FileCheck --check-prefixes CHECK,OPT1 %s
1+
; RUN: opt -mtriple=amdgcn -passes="require<runtime-libcall-info>,expand-fp<O0>" %s -S -o - | FileCheck --check-prefixes CHECK %s
2+
; RUN: opt -mtriple=amdgcn -passes="require<runtime-libcall-info>,expand-fp<O1>" %s -S -o - | FileCheck --check-prefixes CHECK,OPT1 %s
33

44
; Check the handling of potentially infinite numerators in the frem
55
; expansion at different optimization levels and with different

llvm/test/Transforms/ExpandFp/AMDGPU/frem.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -mtriple=amdgcn -passes="expand-fp<O1>" %s -S -o - | FileCheck %s
2+
; RUN: opt -mtriple=amdgcn -passes="require<runtime-libcall-info>,expand-fp<O1>" %s -S -o - | FileCheck %s
33

44
define amdgpu_kernel void @frem_f16(ptr addrspace(1) %out, ptr addrspace(1) %in1,
55
; CHECK-LABEL: define amdgpu_kernel void @frem_f16(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; RUN: not opt -mtriple=amdgcn -passes=expand-fp -disable-output %s 2>&1 | FileCheck %s
2+
3+
; CHECK: 'runtime-libcall-info' analysis required
4+
define void @empty() {
5+
ret void
6+
}

llvm/test/Transforms/ExpandFp/AMDGPU/pass-parameters.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
; RUN: opt -mtriple=amdgcn -passes="expand-fp<O0>" %s -S -o /dev/null
2-
; RUN: opt -mtriple=amdgcn -passes="expand-fp<O1>" %s -S -o /dev/null
3-
; RUN: opt -mtriple=amdgcn -passes="expand-fp<O2>" %s -S -o /dev/null
4-
; RUN: opt -mtriple=amdgcn -passes="expand-fp<O3>" %s -S -o /dev/null
1+
; RUN: opt -mtriple=amdgcn -passes="require<runtime-libcall-info>,expand-fp<O0>" -disable-output %s
2+
; RUN: opt -mtriple=amdgcn -passes="require<runtime-libcall-info>,expand-fp<O1>" -disable-output %s
3+
; RUN: opt -mtriple=amdgcn -passes="require<runtime-libcall-info>,expand-fp<O2>" -disable-output %s
4+
; RUN: opt -mtriple=amdgcn -passes="require<runtime-libcall-info>,expand-fp<O3>" -disable-output %s
55

66
; RUN: not opt -mtriple=amdgcn -passes="expand-fp<O4>" %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=TOO-LARGE %s
77
; TOO-LARGE: {{.*}}invalid optimization level for expand-fp pass: 4

0 commit comments

Comments
 (0)