-
Notifications
You must be signed in to change notification settings - Fork 734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SYCL] Move SYCL Module Splitting to library. Part 2 #13282
Changes from all commits
7f07cb4
19fca2c
900e729
44851de
4ba59e6
53168e1
07ecdc5
d3892d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ add_llvm_component_library(LLVMSYCLLowerIR | |
LINK_COMPONENTS | ||
Analysis | ||
Core | ||
Passes | ||
Support | ||
ipo | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,16 +12,20 @@ | |
#include "llvm/ADT/SetVector.h" | ||
#include "llvm/ADT/SmallPtrSet.h" | ||
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/Bitcode/BitcodeWriterPass.h" | ||
#include "llvm/IR/Constants.h" | ||
#include "llvm/IR/Function.h" | ||
#include "llvm/IR/InstIterator.h" | ||
#include "llvm/IR/Instructions.h" | ||
#include "llvm/IR/LegacyPassManager.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/IRPrinter/IRPrintingPasses.h" | ||
#include "llvm/Passes/PassBuilder.h" | ||
#include "llvm/SYCLLowerIR/DeviceGlobals.h" | ||
#include "llvm/SYCLLowerIR/LowerInvokeSimd.h" | ||
#include "llvm/SYCLLowerIR/SYCLUtils.h" | ||
#include "llvm/Support/Error.h" | ||
#include "llvm/Support/FileSystem.h" | ||
#include "llvm/Transforms/IPO.h" | ||
#include "llvm/Transforms/IPO/GlobalDCE.h" | ||
#include "llvm/Transforms/IPO/StripDeadPrototypes.h" | ||
|
@@ -733,6 +737,14 @@ void EntryPointGroup::rebuild(const Module &M) { | |
Functions.insert(const_cast<Function *>(&F)); | ||
} | ||
|
||
std::string ModuleDesc::makeSymbolTable() const { | ||
std::string ST; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The total size of a string is rarely small to benefit from small string optimizations. C++ mangled names are very long. What size would you suggest for SmallString for this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not that it would fit into a pre-allocated area on the stack, it is that |
||
for (const Function *F : EntryPoints.Functions) | ||
ST += (Twine(F->getName()) + "\n").str(); | ||
|
||
return ST; | ||
} | ||
|
||
namespace { | ||
// This is a helper class, which allows to group/categorize function based on | ||
// provided rules. It is intended to be used in device code split | ||
|
@@ -1143,5 +1155,63 @@ SmallVector<ModuleDesc, 2> splitByESIMD(ModuleDesc &&MD, | |
return Result; | ||
} | ||
|
||
static Error saveModuleIRInFile(Module &M, StringRef FilePath, | ||
bool OutputAssembly) { | ||
int FD = -1; | ||
if (std::error_code EC = sys::fs::openFileForWrite(FilePath, FD)) | ||
return errorCodeToError(EC); | ||
|
||
raw_fd_ostream OS(FD, true); | ||
ModulePassManager MPM; | ||
ModuleAnalysisManager MAM; | ||
PassBuilder PB; | ||
PB.registerModuleAnalyses(MAM); | ||
if (OutputAssembly) | ||
MPM.addPass(PrintModulePass(OS)); | ||
else | ||
MPM.addPass(BitcodeWriterPass(OS)); | ||
|
||
MPM.run(M, MAM); | ||
return Error::success(); | ||
} | ||
|
||
static Expected<SplitModule> saveModuleDesc(ModuleDesc &MD, std::string Prefix, | ||
bool OutputAssembly) { | ||
SplitModule SM; | ||
Prefix += OutputAssembly ? ".ll" : ".bc"; | ||
Error E = saveModuleIRInFile(MD.getModule(), Prefix, OutputAssembly); | ||
if (E) | ||
return E; | ||
|
||
SM.ModuleFilePath = Prefix; | ||
SM.Symbols = MD.makeSymbolTable(); | ||
return SM; | ||
} | ||
|
||
Expected<std::vector<SplitModule>> | ||
splitSYCLModule(std::unique_ptr<Module> M, ModuleSplitterSettings Settings) { | ||
ModuleDesc MD = std::move(M); // makeModuleDesc() ? | ||
// FIXME: false arguments are temporary for now. | ||
auto Splitter = | ||
getDeviceCodeSplitter(std::move(MD), Settings.Mode, false, false); | ||
size_t ID = 0; | ||
std::vector<SplitModule> OutputImages; | ||
while (Splitter->hasMoreSplits()) { | ||
ModuleDesc MD2 = Splitter->nextSplit(); | ||
MD2.fixupLinkageOfDirectInvokeSimdTargets(); | ||
|
||
std::string OutIRFileName = (Settings.OutputPrefix + "_" + Twine(ID)).str(); | ||
auto SplittedImageOrErr = | ||
saveModuleDesc(MD2, OutIRFileName, Settings.OutputAssembly); | ||
if (!SplittedImageOrErr) | ||
return SplittedImageOrErr.takeError(); | ||
|
||
OutputImages.emplace_back(std::move(*SplittedImageOrErr)); | ||
++ID; | ||
} | ||
|
||
return OutputImages; | ||
} | ||
|
||
} // namespace module_split | ||
} // namespace llvm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this new data structure? Can we not continue to use IrPropSymFilenameTriple?
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is possible.