Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OpenMP] Introduce the OpenMPOpt transformation pass
The OpenMPOpt pass is a CGSCC pass in which OpenMP specific optimizations can reside. The OpenMPOpt pass uses the OpenMPKinds.def file to identify runtime calls and their uses. This allows targeted transformations and eases their implementation. This initial patch deduplicates `__kmpc_global_thread_num` and `omp_get_thread_num` calls. We can also identify arguments that are equivalent to such a call result and use it instead. Later we can determine "gtid" arguments based on the use in kernel functions etc. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D69930
- Loading branch information
Showing
20 changed files
with
594 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===- IPO/OpenMPOpt.h - Collection of OpenMP optimizations -----*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TRANSFORMS_IPO_OPENMP_OPT_H | ||
#define LLVM_TRANSFORMS_IPO_OPENMP_OPT_H | ||
|
||
#include "llvm/Analysis/CGSCCPassManager.h" | ||
#include "llvm/Analysis/LazyCallGraph.h" | ||
#include "llvm/IR/PassManager.h" | ||
|
||
namespace llvm { | ||
|
||
namespace omp { | ||
|
||
/// Helper to remember if the module contains OpenMP (runtime calls), to be used | ||
/// foremost with containsOpenMP. | ||
struct OpenMPInModule { | ||
OpenMPInModule &operator=(bool Found) { | ||
if (Found) | ||
Value = OpenMPInModule::OpenMP::FOUND; | ||
else | ||
Value = OpenMPInModule::OpenMP::NOT_FOUND; | ||
return *this; | ||
} | ||
bool isKnown() { return Value != OpenMP::UNKNOWN; } | ||
operator bool() { return Value != OpenMP::NOT_FOUND; } | ||
|
||
private: | ||
enum class OpenMP { FOUND, NOT_FOUND, UNKNOWN } Value = OpenMP::UNKNOWN; | ||
}; | ||
|
||
/// Helper to determine if \p M contains OpenMP (runtime calls). | ||
bool containsOpenMP(Module &M, OpenMPInModule &OMPInModule); | ||
|
||
} // namespace omp | ||
|
||
/// OpenMP optimizations pass. | ||
class OpenMPOptPass : public PassInfoMixin<OpenMPOptPass> { | ||
/// Helper to remember if the module contains OpenMP (runtime calls). | ||
omp::OpenMPInModule OMPInModule; | ||
|
||
public: | ||
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, | ||
LazyCallGraph &CG, CGSCCUpdateResult &UR); | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_TRANSFORMS_IPO_OPENMP_OPT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.