Skip to content

Commit 5452445

Browse files
committed
format and tests
Signed-off-by: Sidorov, Dmitry <[email protected]>
1 parent edaf76b commit 5452445

File tree

5 files changed

+43
-21
lines changed

5 files changed

+43
-21
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
20712071
// -foffload-fp32-prec-div JIT
20722072
Args.AddLastArg(BeArgs, options::OPT_foffload_fp32_prec_div);
20732073
// -foffload-fp32-prec-sqrt JIT
2074-
Args.AddLastArg(BeArgs, options::OPT_OPT_foffload_fp32_prec_sqrt);
2074+
Args.AddLastArg(BeArgs, options::OPT_foffload_fp32_prec_sqrt);
20752075
}
20762076
if (IsGen) {
20772077
for (auto [DeviceName, BackendArgStr] : PerDeviceArgs) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Test SYCL -foffload-fp32-prec-div
2+
3+
// RUN: %clang -### -fsycl --offload-new-driver \
4+
// RUN: -fsycl-targets=spir64_gen -foffload-fp32-prec-div %s 2>&1 \
5+
// RUN: | FileCheck -check-prefix=AOT %s
6+
7+
// RUN: %clang -### -fsycl --offload-new-driver \
8+
// RUN: -foffload-fp32-prec-div %s 2>&1 \
9+
// RUN: | FileCheck -check-prefix=JIT %s
10+
11+
// AOT: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spir64_gen-unknown-unknown,arch={{.*}},kind=sycl,compile-opts=-options -ze-fp32-correctly-rounded-divide-sqrt{{.*}}"
12+
13+
// JIT: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spir64-unknown-unknown,arch={{.*}} -foffload-fp32-prec-div"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Test SYCL -foffload-fp32-prec-sqrt
2+
3+
// RUN: %clang -### -fsycl --offload-new-driver \
4+
// RUN: -fsycl-targets=spir64_gen -foffload-fp32-prec-sqrt %s 2>&1 \
5+
// RUN: | FileCheck -check-prefix=AOT %s
6+
7+
// RUN: %clang -### -fsycl --offload-new-driver \
8+
// RUN: -foffload-fp32-prec-sqrt %s 2>&1 \
9+
// RUN: | FileCheck -check-prefix=JIT %s
10+
11+
// AOT: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spir64_gen-unknown-unknown,arch={{.*}},kind=sycl,compile-opts=-options -ze-fp32-correctly-rounded-divide-sqrt{{.*}}"
12+
13+
// JIT: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spir64-unknown-unknown,arch={{.*}} -foffload-fp32-prec-sqrt"

llvm/lib/SYCLLowerIR/SYCLSqrtFDivMaxErrorCleanUp.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#include "llvm/SYCLLowerIR/SYCLSqrtFDivMaxErrorCleanUp.h"
1818

1919
#include "llvm/ADT/SmallSet.h"
20-
#include "llvm/IR/Module.h"
21-
#include "llvm/IR/IntrinsicInst.h"
2220
#include "llvm/IR/IRBuilder.h"
21+
#include "llvm/IR/IntrinsicInst.h"
22+
#include "llvm/IR/Module.h"
2323

2424
using namespace llvm;
2525

@@ -29,8 +29,7 @@ static constexpr char FDIV_ERROR[] = "2.5";
2929
} // namespace
3030

3131
PreservedAnalyses
32-
SYCLSqrtFDivMaxErrorCleanUpPass::run(Module &M,
33-
ModuleAnalysisManager &MAM) {
32+
SYCLSqrtFDivMaxErrorCleanUpPass::run(Module &M, ModuleAnalysisManager &MAM) {
3433
SmallVector<IntrinsicInst *, 16> WorkListSqrt;
3534
SmallVector<IntrinsicInst *, 16> WorkListFDiv;
3635

@@ -48,22 +47,22 @@ SYCLSqrtFDivMaxErrorCleanUpPass::run(Module &M,
4847

4948
for (auto *Use : F.users()) {
5049
auto *II = cast<IntrinsicInst>(Use);
51-
if (II && II->getCalledFunction()->getName().
52-
starts_with("llvm.fpbuiltin")) {
50+
if (II &&
51+
II->getCalledFunction()->getName().starts_with("llvm.fpbuiltin")) {
5352
// llvm.fpbuiltin.* intrinsics should always have fpbuiltin-max-error
5453
// attribute, but it's not a concern of the pass, so just do an early
5554
// exit here if the attribute is not attached.
5655
if (!II->getAttributes().hasFnAttr("fpbuiltin-max-error"))
5756
return PreservedAnalyses::none();
58-
StringRef MaxError = II->getAttributes().getFnAttr(
59-
"fpbuiltin-max-error").getValueAsString();
57+
StringRef MaxError = II->getAttributes()
58+
.getFnAttr("fpbuiltin-max-error")
59+
.getValueAsString();
6060

6161
if (ID == llvm::Intrinsic::fpbuiltin_sqrt) {
6262
if (MaxError != SQRT_ERROR)
6363
return PreservedAnalyses::none();
6464
WorkListSqrt.push_back(II);
65-
}
66-
else if (ID == llvm::Intrinsic::fpbuiltin_fdiv) {
65+
} else if (ID == llvm::Intrinsic::fpbuiltin_fdiv) {
6766
if (MaxError != FDIV_ERROR)
6867
return PreservedAnalyses::none();
6968
WorkListFDiv.push_back(II);
@@ -113,9 +112,9 @@ SYCLSqrtFDivMaxErrorCleanUpPass::run(Module &M,
113112
Type *Ty = Sqrt->getType();
114113
AttributeList Attrs = Sqrt->getAttributes();
115114
Function *NewSqrtF =
116-
Intrinsic::getDeclaration(&M, llvm::Intrinsic::sqrt, Ty);
117-
auto *NewSqrt = Builder.CreateCall(NewSqrtF, { Sqrt->getOperand(0) },
118-
Sqrt->getName());
115+
Intrinsic::getDeclaration(&M, llvm::Intrinsic::sqrt, Ty);
116+
auto *NewSqrt =
117+
Builder.CreateCall(NewSqrtF, {Sqrt->getOperand(0)}, Sqrt->getName());
119118

120119
// Copy FP flags, metadata and attributes. Replace old call with a new call.
121120
Attrs = Attrs.removeFnAttribute(Sqrt->getContext(), "fpbuiltin-max-error");
@@ -134,9 +133,8 @@ SYCLSqrtFDivMaxErrorCleanUpPass::run(Module &M,
134133
DeclToRemove.insert(FDiv->getCalledFunction());
135134
IRBuilder Builder(FDiv);
136135
Builder.SetInsertPoint(FDiv);
137-
Instruction *NewFDiv =
138-
cast<Instruction>(Builder.CreateFDiv(
139-
FDiv->getOperand(0), FDiv->getOperand(1), FDiv->getName()));
136+
Instruction *NewFDiv = cast<Instruction>(Builder.CreateFDiv(
137+
FDiv->getOperand(0), FDiv->getOperand(1), FDiv->getName()));
140138

141139
// Copy FP flags and metadata. Replace old call with a new instruction.
142140
cast<Instruction>(NewFDiv)->copyMetadata(*FDiv);

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,14 @@ static void appendCompileOptionsFromImage(std::string &CompileOpts,
447447
OptPos = CompileOpts.find(TargetRegisterAllocMode);
448448
}
449449
static const char *FP32PrecDiv = "-foffload-fp32-prec-div";
450-
if (auto Pos = CompileOpts.find(FP32PrecDiv);
451-
Pos != std::string::npos) {
450+
if (auto Pos = CompileOpts.find(FP32PrecDiv); Pos != std::string::npos) {
452451
const char *BackendOption = nullptr;
453452
PlatformImpl->getBackendOption(FP32PrecDiv, &BackendOption);
454453
auto OptLen = strlen(FP32PrecDiv);
455454
CompileOpts.replace(Pos, OptLen, BackendOption);
456455
}
457456
static const char *FP32PrecSqrt = "-foffload-fp32-prec-sqrt";
458-
if (auto Pos = CompileOpts.find(FP32PrecSqrt);
459-
Pos != std::string::npos) {
457+
if (auto Pos = CompileOpts.find(FP32PrecSqrt); Pos != std::string::npos) {
460458
const char *BackendOption = nullptr;
461459
PlatformImpl->getBackendOption(FP32PrecSqrt, &BackendOption);
462460
auto OptLen = strlen(FP32PrecSqrt);

0 commit comments

Comments
 (0)