Skip to content

Commit 37cb495

Browse files
authored
[SYCL][Fusion] Enable -Werror for fusion library (intel#12830)
Treat warnings as errors, and fix the last remaining warnings in the fusion library. --------- Signed-off-by: Julian Oppermann <[email protected]>
1 parent 527416a commit 37cb495

File tree

9 files changed

+70
-32
lines changed

9 files changed

+70
-32
lines changed

sycl-fusion/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ set(SYCL_JIT_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
99
# directories, similar to how clang/CMakeLists.txt does it.
1010
set(LLVM_SPIRV_INCLUDE_DIRS "${LLVM_MAIN_SRC_DIR}/../llvm-spirv/include")
1111

12+
# Set library-wide warning options.
13+
set(SYCL_FUSION_WARNING_FLAGS -Wall -Wextra)
14+
15+
option(SYCL_FUSION_ENABLE_WERROR "Treat all warnings as errors in SYCL kernel fusion library" ON)
16+
if(SYCL_FUSION_ENABLE_WERROR)
17+
list(APPEND SYCL_FUSION_WARNING_FLAGS -Werror)
18+
endif(SYCL_FUSION_ENABLE_WERROR)
19+
1220
if(WIN32)
1321
message(WARNING "Kernel fusion not yet supported on Windows")
1422
else(WIN32)

sycl-fusion/common/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ add_llvm_library(sycl-fusion-common
55
Support
66
)
77

8+
target_compile_options(sycl-fusion-common PRIVATE ${SYCL_FUSION_WARNING_FLAGS})
9+
10+
# Mark LLVM headers as system headers to ignore warnigns in them. This
11+
# classification remains intact even if the same path is added as a normal
12+
# include path in GCC and Clang.
13+
target_include_directories(sycl-fusion-common
14+
SYSTEM PRIVATE
15+
${LLVM_MAIN_INCLUDE_DIR}
16+
)
817
target_include_directories(sycl-fusion-common
918
PUBLIC
1019
${CMAKE_CURRENT_SOURCE_DIR}/include

sycl-fusion/jit-compiler/CMakeLists.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,23 @@ add_llvm_library(sycl-fusion
2929
${LLVM_TARGETS_TO_BUILD}
3030
)
3131

32+
target_compile_options(sycl-fusion PRIVATE ${SYCL_FUSION_WARNING_FLAGS})
33+
34+
# Mark LLVM and SPIR-V headers as system headers to ignore warnigns in them.
35+
# This classification remains intact even if the same paths are added as normal
36+
# include paths in GCC and Clang.
37+
target_include_directories(sycl-fusion
38+
SYSTEM PRIVATE
39+
${LLVM_MAIN_INCLUDE_DIR}
40+
${LLVM_SPIRV_INCLUDE_DIRS}
41+
)
3242
target_include_directories(sycl-fusion
3343
PUBLIC
3444
$<INSTALL_INTERFACE:include>
3545
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
3646
$<BUILD_INTERFACE:${SYCL_JIT_BASE_DIR}/common/include>
3747
PRIVATE
3848
${CMAKE_CURRENT_SOURCE_DIR}/lib
39-
${LLVM_SPIRV_INCLUDE_DIRS}
4049
)
4150

4251
find_package(Threads REQUIRED)

sycl-fusion/jit-compiler/lib/fusion/FusionHelper.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,13 @@ Expected<std::unique_ptr<Module>> helper::FusionHelper::addFusedKernel(
169169

170170
const auto S = [&]() -> StringRef {
171171
switch (Info.Intern) {
172-
default:
173-
case jit_compiler::Internalization::None:
174-
llvm_unreachable(
175-
"Only a valid internalization kind should be used");
176172
case jit_compiler::Internalization::Local:
177173
return LocalInternalizationStr;
178174
case jit_compiler::Internalization::Private:
179175
return PrivateInternalizationStr;
176+
default:
177+
llvm_unreachable(
178+
"Only a valid internalization kind should be used");
180179
}
181180
}();
182181
EmplaceBackIntern(Info, S);

sycl-fusion/passes/CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ add_llvm_library(SYCLKernelFusion MODULE
1414
intrinsics_gen
1515
)
1616

17+
target_compile_options(SYCLKernelFusion PRIVATE ${SYCL_FUSION_WARNING_FLAGS})
18+
19+
# Mark LLVM headers as system headers to ignore warnigns in them. This
20+
# classification remains intact even if the same path is added as a normal
21+
# include path in GCC and Clang.
22+
target_include_directories(SYCLKernelFusion
23+
SYSTEM PRIVATE
24+
${LLVM_MAIN_INCLUDE_DIR}
25+
)
1726
target_include_directories(SYCLKernelFusion
1827
PUBLIC
1928
${CMAKE_CURRENT_SOURCE_DIR}
@@ -57,6 +66,15 @@ add_llvm_library(SYCLKernelFusionPasses
5766
TargetParser
5867
)
5968

69+
target_compile_options(SYCLKernelFusionPasses PRIVATE ${SYCL_FUSION_WARNING_FLAGS})
70+
71+
# Mark LLVM headers as system headers to ignore warnigns in them. This
72+
# classification remains intact even if the same path is added as a normal
73+
# include path in GCC and Clang.
74+
target_include_directories(SYCLKernelFusionPasses
75+
SYSTEM PRIVATE
76+
${LLVM_MAIN_INCLUDE_DIR}
77+
)
6078
target_include_directories(SYCLKernelFusionPasses
6179
PUBLIC
6280
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>

sycl-fusion/passes/internalization/Internalization.cpp

+11-14
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct SYCLInternalizerImpl {
5454
TargetFusionInfo TargetInfo;
5555

5656
/// Implements internalization the pass run.
57-
PreservedAnalyses operator()(Module &M, ModuleAnalysisManager &AM) const;
57+
PreservedAnalyses operator()(Module &M) const;
5858

5959
///
6060
/// Update a value to be promoted in a function.
@@ -71,8 +71,8 @@ struct SYCLInternalizerImpl {
7171
void promoteValue(Value *Val, const PromotionInfo &PromInfo,
7272
bool InAggregate) const;
7373

74-
void promoteGEPI(GetElementPtrInst *GEPI, const Value *Val,
75-
const PromotionInfo &PromInfo, bool InAggregate) const;
74+
void promoteGEPI(GetElementPtrInst *GEPI, const PromotionInfo &PromInfo,
75+
bool InAggregate) const;
7676

7777
void promoteCall(CallBase *C, const Value *Val,
7878
const PromotionInfo &PromInfo) const;
@@ -103,8 +103,8 @@ struct SYCLInternalizerImpl {
103103
///
104104
/// Check that the operand of a GEP can be promoted to its users, and
105105
/// propagate whether it represents a pointer into an aggregate object.
106-
Error canPromoteGEP(GetElementPtrInst *GEPI, const Value *Val,
107-
const PromotionInfo &PromInfo, bool InAggregate) const;
106+
Error canPromoteGEP(GetElementPtrInst *GEPI, const PromotionInfo &PromInfo,
107+
bool InAggregate) const;
108108

109109
///
110110
/// Check if operand to a function call can be promoted.
@@ -356,7 +356,6 @@ static int getGEPKind(GetElementPtrInst *GEPI, const PromotionInfo &PromInfo) {
356356
}
357357

358358
Error SYCLInternalizerImpl::canPromoteGEP(GetElementPtrInst *GEPI,
359-
const Value *Val,
360359
const PromotionInfo &PromInfo,
361360
bool InAggregate) const {
362361
if (cast<PointerType>(GEPI->getType())->getAddressSpace() == AS) {
@@ -405,7 +404,7 @@ Error SYCLInternalizerImpl::canPromoteValue(Value *Val,
405404
}
406405
break;
407406
case Instruction::GetElementPtr:
408-
if (auto Err = canPromoteGEP(cast<GetElementPtrInst>(I), Val, PromInfo,
407+
if (auto Err = canPromoteGEP(cast<GetElementPtrInst>(I), PromInfo,
409408
InAggregate)) {
410409
return Err;
411410
}
@@ -488,7 +487,6 @@ void SYCLInternalizerImpl::promoteCall(CallBase *C, const Value *Val,
488487
}
489488

490489
void SYCLInternalizerImpl::promoteGEPI(GetElementPtrInst *GEPI,
491-
const Value *Val,
492490
const PromotionInfo &PromInfo,
493491
bool InAggregate) const {
494492
// Not PointerType is unreachable. Other case is caught in caller.
@@ -523,7 +521,7 @@ void SYCLInternalizerImpl::promoteValue(Value *Val,
523521
promoteCall(cast<CallBase>(I), Val, PromInfo);
524522
break;
525523
case Instruction::GetElementPtr:
526-
promoteGEPI(cast<GetElementPtrInst>(I), Val, PromInfo, InAggregate);
524+
promoteGEPI(cast<GetElementPtrInst>(I), PromInfo, InAggregate);
527525
break;
528526
case Instruction::Load:
529527
case Instruction::Store:
@@ -637,8 +635,7 @@ Function *SYCLInternalizerImpl::promoteFunctionArgs(
637635
return NewF;
638636
}
639637

640-
PreservedAnalyses
641-
SYCLInternalizerImpl::operator()(Module &M, ModuleAnalysisManager &AM) const {
638+
PreservedAnalyses SYCLInternalizerImpl::operator()(Module &M) const {
642639
bool Changed{false};
643640
SmallVector<Function *> ToUpdate;
644641
for (auto &F : M) {
@@ -729,10 +726,10 @@ PreservedAnalyses llvm::SYCLInternalizer::run(Module &M,
729726
TargetFusionInfo TFI{&M};
730727
// Private promotion
731728
const PreservedAnalyses Tmp = SYCLInternalizerImpl{
732-
TFI.getPrivateAddressSpace(), PrivatePromotion, true, TFI}(M, AM);
729+
TFI.getPrivateAddressSpace(), PrivatePromotion, true, TFI}(M);
733730
// Local promotion
734-
PreservedAnalyses Res = SYCLInternalizerImpl{
735-
TFI.getLocalAddressSpace(), LocalPromotion, false, TFI}(M, AM);
731+
PreservedAnalyses Res = SYCLInternalizerImpl{TFI.getLocalAddressSpace(),
732+
LocalPromotion, false, TFI}(M);
736733

737734
Res.intersect(Tmp);
738735

sycl-fusion/passes/kernel-fusion/SYCLKernelFusion.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ static bool needsGuard(const jit_compiler::NDRange &SrcNDRange,
198198
static FusionInsertPoints addGuard(IRBuilderBase &Builder,
199199
const TargetFusionInfo &TargetInfo,
200200
const jit_compiler::NDRange &SrcNDRange,
201-
const jit_compiler::NDRange &FusedNDRange,
202-
bool IsLast) {
201+
const jit_compiler::NDRange &FusedNDRange) {
203202
// Guard:
204203

205204
// entry:
@@ -240,8 +239,7 @@ static Expected<CallInst *> createFusionCall(
240239
const jit_compiler::NDRange &FusedNDRange, bool IsLast,
241240
jit_compiler::BarrierFlags BarriersFlags, jit_compiler::Remapper &Remapper,
242241
bool ShouldRemap, TargetFusionInfo &TargetInfo) {
243-
const auto IPs =
244-
addGuard(Builder, TargetInfo, SrcNDRange, FusedNDRange, IsLast);
242+
const auto IPs = addGuard(Builder, TargetInfo, SrcNDRange, FusedNDRange);
245243

246244
if (ShouldRemap) {
247245
auto FOrErr = Remapper.remapBuiltins(F, SrcNDRange, FusedNDRange);

sycl-fusion/passes/syclcp/SYCLCP.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static Expected<SmallVector<ConstantInfo>> getCPFromMD(Function *F) {
6363
///
6464
/// Returns a constant of the given scalar type and value.
6565
static Expected<Constant *> getConstantValue(const unsigned char **ValPtr,
66-
Type *Ty, bool ByVal) {
66+
Type *Ty) {
6767
if (Ty->isIntegerTy()) {
6868
unsigned NumBytes = Ty->getIntegerBitWidth() / 8;
6969
uint64_t IntValue = 0;
@@ -99,7 +99,7 @@ static Error initializeAggregateConstant(const unsigned char **ValPtr,
9999
ArrayRef<Value *> Indices) {
100100
if (CurrentTy->isIntegerTy() || CurrentTy->isFloatTy() ||
101101
CurrentTy->isDoubleTy()) {
102-
Expected<Value *> CVal = getConstantValue(ValPtr, CurrentTy, false);
102+
Expected<Value *> CVal = getConstantValue(ValPtr, CurrentTy);
103103
if (auto E = CVal.takeError()) {
104104
return E;
105105
}
@@ -185,8 +185,7 @@ static bool propagateConstants(Function *F, ArrayRef<ConstantInfo> Constants) {
185185
}
186186
CVal = AggVal.get();
187187
} else {
188-
Expected<Constant *> ScalarVal =
189-
getConstantValue(&ValPtr, ArgTy, Arg->hasByValAttr());
188+
Expected<Constant *> ScalarVal = getConstantValue(&ValPtr, ArgTy);
190189
if (auto E = ScalarVal.takeError()) {
191190
handleAllErrors(std::move(E), [](const StringError &SE) {
192191
FUSION_DEBUG(llvm::dbgs() << SE.message() << "\n");

sycl-fusion/passes/target/TargetFusionInfo.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ class SPIRVTargetFusionInfo : public TargetFusionInfoImpl {
408408
}
409409

410410
Function *createRemapperFunction(
411-
const Remapper &R, BuiltinKind K, StringRef OrigName, Module *M,
412-
const jit_compiler::NDRange &SrcNDRange,
411+
const Remapper &R, BuiltinKind K, [[maybe_unused]] StringRef OrigName,
412+
Module *M, const jit_compiler::NDRange &SrcNDRange,
413413
const jit_compiler::NDRange &FusedNDRange) const override {
414414
const auto Name = Remapper::getFunctionName(K, SrcNDRange, FusedNDRange);
415415
assert(!M->getFunction(Name) && "Function name should be unique");
@@ -551,7 +551,7 @@ class NVPTXAMDGCNTargetFusionInfoBase : public TargetFusionInfoImpl {
551551
uint32_t Idx) const = 0;
552552

553553
Value *getGlobalIDWithoutOffset(IRBuilderBase &Builder,
554-
const NDRange &FusedNDRange,
554+
[[maybe_unused]] const NDRange &FusedNDRange,
555555
uint32_t Idx) const override {
556556
// Construct (or reuse) a helper function to query the global ID.
557557
std::string GetGlobalIDName =
@@ -687,8 +687,9 @@ class NVPTXAMDGCNTargetFusionInfoBase : public TargetFusionInfoImpl {
687687
switch (K) {
688688
case BuiltinKind::NumWorkGroupsRemapper:
689689
case BuiltinKind::GroupIDRemapper:
690-
return WrapValInFunc(
691-
[&](uint32_t Idx) { return Builder.getInt32(R.getDefaultValue(K)); });
690+
return WrapValInFunc([&]([[maybe_unused]] uint32_t Idx) {
691+
return Builder.getInt32(R.getDefaultValue(K));
692+
});
692693
case BuiltinKind::LocalSizeRemapper:
693694
case BuiltinKind::GlobalSizeRemapper: /* only AMDGCN */
694695
return WrapValInFunc([&](uint32_t Idx) {

0 commit comments

Comments
 (0)