Skip to content

Commit 3a20f1e

Browse files
IDmitryyAnton Sidorenko
authored and
Anton Sidorenko
committed
CMOptimizationsFence implementation
Implementation of CMOptimizationsFence class, which blocks optimizations between modules.
1 parent 20490aa commit 3a20f1e

File tree

11 files changed

+524
-1
lines changed

11 files changed

+524
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2022 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#include "llvm/IR/PassManager.h"
10+
11+
namespace llvm {
12+
13+
class ModulePass;
14+
class PassRegistry;
15+
16+
//-----------------------------------------------------------------------------
17+
// New PM support
18+
//-----------------------------------------------------------------------------
19+
// Optimizations Fence Lowering pass for new PM.
20+
class OptFenceLowering final : public PassInfoMixin<OptFenceLowering> {
21+
public:
22+
OptFenceLowering() = default;
23+
24+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
25+
26+
static StringRef getArgString() { return "OptFenceLowering"; }
27+
};
28+
//-----------------------------------------------------------------------------
29+
// Legacy PM support
30+
//-----------------------------------------------------------------------------
31+
void initializeOptFenceLoweringLegacyPass(PassRegistry &);
32+
33+
ModulePass *createOptFenceLoweringPass();
34+
} // namespace llvm

clang/lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ if(CLANG_ENABLE_STATIC_ANALYZER)
3232
endif()
3333
add_subdirectory(Format)
3434
add_subdirectory(FrontendWrapper)
35+
add_subdirectory(FrontendPasses)

clang/lib/CodeGen/BackendUtil.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ See LICENSE.TXT for details.
1414
============================= end_copyright_notice ===========================*/
1515

1616
#include "clang/CodeGen/BackendUtil.h"
17+
#include "LLVMSPIRVLib.h"
1718
#include "clang/Basic/CodeGenOptions.h"
1819
#include "clang/Basic/Diagnostic.h"
1920
#include "clang/Basic/LangOptions.h"
2021
#include "clang/Basic/TargetOptions.h"
2122
#include "clang/Frontend/FrontendDiagnostic.h"
2223
#include "clang/Frontend/Utils.h"
24+
#include "clang/FrontendPasses/OptFenceLowering.h"
2325
#include "clang/Lex/HeaderSearchOptions.h"
2426
#include "llvm/ADT/SmallSet.h"
2527
#include "llvm/ADT/StringExtras.h"
@@ -72,7 +74,6 @@ See LICENSE.TXT for details.
7274
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
7375
#include "llvm/Transforms/Utils/NameAnonGlobals.h"
7476
#include "llvm/Transforms/Utils/SymbolRewriter.h"
75-
#include "LLVMSPIRVLib.h"
7677
#include <memory>
7778
#include <sstream>
7879
using namespace clang;
@@ -575,6 +576,7 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
575576
PMBuilder.RerollLoops = CodeGenOpts.RerollLoops;
576577

577578
MPM.add(new TargetLibraryInfoWrapperPass(*TLII));
579+
MPM.add(createOptFenceLoweringPass());
578580

579581
if (TM)
580582
TM->adjustPassManager(PMBuilder);

clang/lib/CodeGen/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ add_clang_library(clangCodeGen
117117
clangFrontend
118118
clangLex
119119
clangSerialization
120+
clangPasses
120121
)
121122

122123
target_link_libraries(clangCodeGen PUBLIC LLVMSPIRVLib)
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#=========================== begin_copyright_notice ============================
2+
#
3+
# Copyright (C) 2022 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: MIT
6+
#
7+
#============================ end_copyright_notice =============================
8+
9+
10+
# In a standard Clang+LLVM build, we need to generate intrinsics before
11+
# building codegen. In a standalone build, LLVM is already built and we don't
12+
# need this dependency. Furthermore, LLVM doesn't export it so we can't have
13+
# this dependency.
14+
set(frontendpasses_deps intrinsics_gen)
15+
if (CLANG_BUILT_STANDALONE)
16+
set(frontendpasses_deps)
17+
endif()
18+
19+
20+
set(LLVM_LINK_COMPONENTS
21+
${LLVM_TARGETS_TO_BUILD}
22+
Core
23+
Support
24+
Instrumentation
25+
Passes
26+
TransformUtils
27+
)
28+
29+
add_clang_library(clangPasses
30+
OptFenceLowering.cpp
31+
32+
DEPENDS
33+
${frontendpasses_deps}
34+
)

0 commit comments

Comments
 (0)