Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
kbobrovs committed Jun 7, 2022
1 parent d77bf6e commit c6710c5
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 74 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void initializeStripSymbolsPass(PassRegistry&);
void initializeStructurizeCFGLegacyPassPass(PassRegistry &);
void initializeSYCLLowerWGScopeLegacyPassPass(PassRegistry &);
void initializeSYCLLowerESIMDLegacyPassPass(PassRegistry &);
void initializeSYCLLowerESIMDKernelPropsLegacyPassPass(PassRegistry&);
void initializeSYCLLowerESIMDKernelPropsLegacyPassPass(PassRegistry &);
void initializeSYCLLowerInvokeSimdLegacyPassPass(PassRegistry &);
void initializeSYCLMutatePrintfAddrspaceLegacyPassPass(PassRegistry &);
void initializeSPIRITTAnnotationsLegacyPassPass(PassRegistry &);
Expand Down
23 changes: 13 additions & 10 deletions llvm/include/llvm/SYCLLowerIR/ESIMD/ESIMDUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ namespace esimd {

constexpr char ATTR_DOUBLE_GRF[] = "esimd-double-grf";

using CallGraphNodeAction = std::function<void(Function*)>;
void traverseCallgraphUp(llvm::Function* F, CallGraphNodeAction NodeF, bool ErrorOnNonCallUse);

// Traverses call graph starting from given function up the call chain applying given action
// to each function met on the way. If \c ErrorOnNonCallUse parameter is true, then no
// functions' uses are allowed except calls. Otherwise, any function where use of the
// current one happened is added to the call graph as if the use was a call.
using CallGraphNodeAction = std::function<void(Function *)>;
void traverseCallgraphUp(llvm::Function *F, CallGraphNodeAction NodeF,
bool ErrorOnNonCallUse);

// Traverses call graph starting from given function up the call chain applying
// given action to each function met on the way. If \c ErrorOnNonCallUse
// parameter is true, then no functions' uses are allowed except calls.
// Otherwise, any function where use of the current one happened is added to the
// call graph as if the use was a call.
template <class CallGraphNodeActionF>
void traverseCallgraphUp(Function* F, CallGraphNodeActionF ActionF, bool ErrorOnNonCallUse = true) {
traverseCallgraphUp(F, CallGraphNodeAction{ ActionF }, ErrorOnNonCallUse);
void traverseCallgraphUp(Function *F, CallGraphNodeActionF ActionF,
bool ErrorOnNonCallUse = true) {
traverseCallgraphUp(F, CallGraphNodeAction{ActionF}, ErrorOnNonCallUse);
}

// Tells whether given function is a ESIMD kernel.
bool isESIMDKernel(const Function& F);
bool isESIMDKernel(const Function &F);

} // namespace esimd
} // namespace llvm
5 changes: 3 additions & 2 deletions llvm/include/llvm/SYCLLowerIR/ESIMD/LowerESIMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ ModulePass *createESIMDLowerVecArgPass();
void initializeESIMDLowerVecArgLegacyPassPass(PassRegistry &);

// Lowers calls to __esimd_set_kernel_properties
class SYCLLowerESIMDKernelPropsPass : public PassInfoMixin<SYCLLowerESIMDKernelPropsPass> {
class SYCLLowerESIMDKernelPropsPass
: public PassInfoMixin<SYCLLowerESIMDKernelPropsPass> {
public:
PreservedAnalyses run(Module& M, ModuleAnalysisManager&);
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
};

} // namespace llvm
Expand Down
22 changes: 11 additions & 11 deletions llvm/lib/SYCLLowerIR/ESIMD/ESIMDUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
namespace llvm {
namespace esimd {

void traverseCallgraphUp(llvm::Function* F, CallGraphNodeAction ActionF, bool ErrorOnNonCallUse) {
SmallPtrSet<Function*, 32> FunctionsVisited;
SmallVector<Function*, 32> Worklist{ F };
void traverseCallgraphUp(llvm::Function *F, CallGraphNodeAction ActionF,
bool ErrorOnNonCallUse) {
SmallPtrSet<Function *, 32> FunctionsVisited;
SmallVector<Function *, 32> Worklist{F};

while (!Worklist.empty()) {
Function* CurF = Worklist.pop_back_val();
Function *CurF = Worklist.pop_back_val();
FunctionsVisited.insert(CurF);
// Apply the action function.
ActionF(CurF);
Expand All @@ -26,12 +27,12 @@ void traverseCallgraphUp(llvm::Function* F, CallGraphNodeAction ActionF, bool Er
if (ErrorOnNonCallUse) {
// ... non-call is an error - report
llvm::report_fatal_error(
llvm::Twine(__FILE__ " ") +
"Function use other than call detected while traversing call\n"
"graph up to a kernel");
llvm::Twine(__FILE__ " ") +
"Function use other than call detected while traversing call\n"
"graph up to a kernel");
} else {
// ... non-call is OK - add using function to the worklist
if (auto* I = dyn_cast<Instruction>(FCall)) {
if (auto *I = dyn_cast<Instruction>(FCall)) {
auto UseF = I->getFunction();

if (!FunctionsVisited.count(UseF)) {
Expand All @@ -50,11 +51,10 @@ void traverseCallgraphUp(llvm::Function* F, CallGraphNodeAction ActionF, bool Er
}
}

bool isESIMDKernel(const Function& F) {
bool isESIMDKernel(const Function &F) {
return (F.getCallingConv() == CallingConv::SPIR_KERNEL) &&
(F.getMetadata("sycl_explicit_simd") != nullptr);
(F.getMetadata("sycl_explicit_simd") != nullptr);
}

} // namespace esimd
} // namespace llvm

8 changes: 5 additions & 3 deletions llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// values of integer template parameters they were instantiated with.
//===----------------------------------------------------------------------===//

#include "llvm/SYCLLowerIR/ESIMD/ESIMDUtils.h"
#include "llvm/SYCLLowerIR/ESIMD/LowerESIMD.h"
#include "llvm/SYCLLowerIR/ESIMD/ESIMDUtils.h"

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
Expand Down Expand Up @@ -72,7 +72,8 @@ class SYCLLowerESIMDLegacyPass : public ModulePass {

char SYCLLowerESIMDLegacyPass::ID = 0;
INITIALIZE_PASS(SYCLLowerESIMDLegacyPass, "LowerESIMD",
"Lower constructs specific to the 'explicit SIMD' extension", false, false)
"Lower constructs specific to the 'explicit SIMD' extension",
false, false)

// Public interface to the SYCLLowerESIMDPass.
ModulePass *llvm::createSYCLLowerESIMDPass() {
Expand Down Expand Up @@ -1760,7 +1761,8 @@ size_t SYCLLowerESIMDPass::runOnFunction(Function &F,
ToErase.push_back(CI);
continue;
}
assert(!Name.startswith("__esimd_set_kernel_properties") && "__esimd_set_kernel_properties must have been lowered");
assert(!Name.startswith("__esimd_set_kernel_properties") &&
"__esimd_set_kernel_properties must have been lowered");

if (Name.empty() || !Name.startswith(ESIMD_INTRIN_PREF1))
continue;
Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/SYCLLowerIR/ESIMD/LowerESIMDKernelProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// function attributes and adds those attributes to all kernels which can
// potentially call this intrinsic.

#include "llvm/SYCLLowerIR/ESIMD/LowerESIMD.h"
#include "llvm/SYCLLowerIR/ESIMD/ESIMDUtils.h"
#include "llvm/SYCLLowerIR/ESIMD/LowerESIMD.h"

#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/IR/Instructions.h"
Expand All @@ -24,7 +24,8 @@ using namespace llvm;

namespace {

constexpr char SET_KERNEL_PROPS_FUNC_NAME[] = "_Z29__esimd_set_kernel_propertiesi";
constexpr char SET_KERNEL_PROPS_FUNC_NAME[] =
"_Z29__esimd_set_kernel_propertiesi";

// Kernel property identifiers. Should match ones in
// sycl/include/sycl/ext/intel/experimental/esimd/kernel_properties.hpp
Expand All @@ -36,8 +37,8 @@ void processSetKernelPropertiesCall(CallInst &CI) {

if (!isa<ConstantInt>(ArgV)) {
llvm::report_fatal_error(
llvm::Twine(__FILE__ " ") +
"integral constant is expected for set_kernel_properties");
llvm::Twine(__FILE__ " ") +
"integral constant is expected for set_kernel_properties");
}
uint64_t PropID = cast<llvm::ConstantInt>(ArgV)->getZExtValue();

Expand All @@ -57,9 +58,9 @@ void processSetKernelPropertiesCall(CallInst &CI) {
} // namespace

namespace llvm {
PreservedAnalyses SYCLLowerESIMDKernelPropsPass::run(Module &M,
ModuleAnalysisManager &MAM) {
Function* F = M.getFunction(SET_KERNEL_PROPS_FUNC_NAME);
PreservedAnalyses
SYCLLowerESIMDKernelPropsPass::run(Module &M, ModuleAnalysisManager &MAM) {
Function *F = M.getFunction(SET_KERNEL_PROPS_FUNC_NAME);

if (!F) {
return PreservedAnalyses::all();
Expand Down
40 changes: 22 additions & 18 deletions llvm/tools/sycl-post-link/ModuleSplitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ groupEntryPointsByKernelType(const Module &M, bool EmitOnlyKernelsAsEntryPoints,
}

if (!EntryPointMap.empty()) {
for (auto& EPG : EntryPointMap) {
for (auto &EPG : EntryPointMap) {
EntryPointGroups.emplace_back(
EntryPointGroup{EPG.first, std::move(EPG.second), BlueprintProps});
EntryPointGroup& G = EntryPointGroups.back();
EntryPointGroup &G = EntryPointGroups.back();

if (G.GroupId == ESIMD_SCOPE_NAME) {
G.Props.HasESIMD = SyclEsimdSplitStatus::ESIMD_ONLY;
Expand All @@ -176,7 +176,7 @@ groupEntryPointsByKernelType(const Module &M, bool EmitOnlyKernelsAsEntryPoints,
} else {
// No entry points met, record this.
EntryPointGroups.emplace_back(EntryPointGroup{SYCL_SCOPE_NAME, {}});
EntryPointGroup& G = EntryPointGroups.back();
EntryPointGroup &G = EntryPointGroups.back();
G.Props.HasESIMD = SyclEsimdSplitStatus::SYCL_ONLY;
}

Expand Down Expand Up @@ -231,10 +231,10 @@ groupEntryPointsByScope(const Module &M, EntryPointsGroupScope EntryScope,

if (!EntryPointMap.empty()) {
EntryPointGroups.reserve(EntryPointMap.size());
for (auto& EPG : EntryPointMap) {
for (auto &EPG : EntryPointMap) {
EntryPointGroups.emplace_back(
EntryPointGroup{EPG.first, std::move(EPG.second), BlueprintProps});
EntryPointGroup& G = EntryPointGroups.back();
EntryPointGroup &G = EntryPointGroups.back();
G.Props.Scope = EntryScope;
}
} else {
Expand Down Expand Up @@ -264,7 +264,7 @@ EntryPointGroupVec groupEntryPointsByAttribute(
}
if (!EntryPointMap.empty()) {
EntryPointGroups.reserve(EntryPointMap.size());
for (auto& EPG : EntryPointMap) {
for (auto &EPG : EntryPointMap) {
EntryPointGroups.emplace_back(
EntryPointGroup{EPG.first, std::move(EPG.second), BlueprintProps});
F(EntryPointGroups.back());
Expand All @@ -281,29 +281,32 @@ EntryPointGroupVec groupEntryPointsByAttribute(
// edges are "calls" relation.
class CallGraph {
public:
using FunctionSet = SmallPtrSet<const Function*, 16>;
using FunctionSet = SmallPtrSet<const Function *, 16>;

private:
std::unordered_map<const Function*, FunctionSet> Graph;
SmallPtrSet<const Function*, 1> EmptySet;
std::unordered_map<const Function *, FunctionSet> Graph;
SmallPtrSet<const Function *, 1> EmptySet;

public:
CallGraph(const Module &M) {
for (const auto& F : M) {
for (const Value* U : F.users()) {
for (const auto &F : M) {
for (const Value *U : F.users()) {
if (const auto *I = dyn_cast<CallInst>(U)) {
if (I->getCalledFunction() == &F) {
const Function* F1 = I->getFunction();
const Function *F1 = I->getFunction();
Graph[F1].insert(&F);
}
}
}
}
}

iterator_range<FunctionSet::const_iterator> successors(const Function* F) const {
iterator_range<FunctionSet::const_iterator>
successors(const Function *F) const {
auto It = Graph.find(F);
return (It == Graph.end()) ? make_range(EmptySet.begin(), EmptySet.end()) : make_range(It->second.begin(), It->second.end());
return (It == Graph.end())
? make_range(EmptySet.begin(), EmptySet.end())
: make_range(It->second.begin(), It->second.end());
}
};

Expand All @@ -319,7 +322,7 @@ void collectFunctionsToExtract(SetVector<const GlobalValue *> &GVs,
while (Idx < GVs.size()) {
const auto *F = cast<Function>(GVs[Idx++]);

for (const Function* F1 : Deps.successors(F)) {
for (const Function *F1 : Deps.successors(F)) {
if (!F1->isDeclaration())
GVs.insert(F1);
}
Expand Down Expand Up @@ -550,7 +553,8 @@ void dumpEntryPoints(const Module &M, bool OnlyKernelsAreEntryPoints,
llvm::errs() << "}\n";
}

void ModuleDesc::assignMergedProperties(const ModuleDesc& MD1, const ModuleDesc& MD2) {
void ModuleDesc::assignMergedProperties(const ModuleDesc &MD1,
const ModuleDesc &MD2) {
EntryPoints.Props = MD1.EntryPoints.Props.merge(MD2.EntryPoints.Props);
Props.SpecConstsMet = MD1.Props.SpecConstsMet || MD2.Props.SpecConstsMet;
}
Expand Down Expand Up @@ -626,8 +630,8 @@ void ModuleDesc::dump() {
llvm::errs() << "split_module::ModuleDesc[" << Name << "] {\n";
llvm::errs() << " ESIMD:" << toString(EntryPoints.Props.HasESIMD)
<< ", SpecConstMet:" << (Props.SpecConstsMet ? "YES" : "NO")
<< ", DoubleGRF:" << (EntryPoints.Props.UsesDoubleGRF ? "YES" : "NO")
<< "\n";
<< ", DoubleGRF:"
<< (EntryPoints.Props.UsesDoubleGRF ? "YES" : "NO") << "\n";
dumpEntryPoints(entries(), EntryPoints.GroupId.str().c_str(), 1);
llvm::errs() << "}\n";
}
Expand Down
16 changes: 11 additions & 5 deletions llvm/tools/sycl-post-link/ModuleSplitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ struct EntryPointGroup {
// Scope represented by EPs in a group
EntryPointsGroupScope Scope = Scope_Global;

Properties merge(const Properties& Other) const {
Properties merge(const Properties &Other) const {
Properties Res;
Res.HasESIMD = HasESIMD == Other.HasESIMD ? HasESIMD : SyclEsimdSplitStatus::SYCL_AND_ESIMD;
Res.HasESIMD = HasESIMD == Other.HasESIMD
? HasESIMD
: SyclEsimdSplitStatus::SYCL_AND_ESIMD;
Res.UsesDoubleGRF = UsesDoubleGRF || Other.UsesDoubleGRF;
// Scope remains global
return Res;
Expand All @@ -80,9 +82,13 @@ struct EntryPointGroup {
: GroupId(GroupId), Functions(std::move(Functions)), Props(Props) {}

// Tells if this group has only ESIMD entry points (based on GroupId).
bool isEsimd() const { return Props.HasESIMD == SyclEsimdSplitStatus::ESIMD_ONLY; }
bool isEsimd() const {
return Props.HasESIMD == SyclEsimdSplitStatus::ESIMD_ONLY;
}
// Tells if this group has only SYCL entry points (based on GroupId).
bool isSycl() const { return Props.HasESIMD == SyclEsimdSplitStatus::SYCL_ONLY; }
bool isSycl() const {
return Props.HasESIMD == SyclEsimdSplitStatus::SYCL_ONLY;
}
// Tells if some entry points use double GRF mode.
bool isDoubleGRF() const { return Props.UsesDoubleGRF; }

Expand Down Expand Up @@ -121,7 +127,7 @@ class ModuleDesc {
rebuildEntryPoints(Names);
}

void assignMergedProperties(const ModuleDesc& MD1, const ModuleDesc& MD2);
void assignMergedProperties(const ModuleDesc &MD1, const ModuleDesc &MD2);

bool isESIMD() const { return EntryPoints.isEsimd(); }
bool isSYCL() const { return EntryPoints.isSycl(); }
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/sycl-post-link/Support.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ inline void error(const Twine &Msg) {
exit(1);
}

inline void warning(const Twine& Msg) {
inline void warning(const Twine &Msg) {
errs() << "sycl-post-link WARNING: " << Msg << '\n';
}

Expand Down
Loading

0 comments on commit c6710c5

Please sign in to comment.