Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
ThreadSafeModule.cpp
Go to the documentation of this file.
1//===-- ThreadSafeModule.cpp - Thread safe Module, Context, and Utilities
2//h-===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
11#include "llvm/Bitcode/BitcodeReader.h"
12#include "llvm/Bitcode/BitcodeWriter.h"
13#include "llvm/Transforms/Utils/Cloning.h"
14
15namespacellvm {
16namespaceorc {
17
18ThreadSafeModulecloneToNewContext(constThreadSafeModule &TSM,
19GVPredicate ShouldCloneDef,
20GVModifier UpdateClonedDefSource) {
21assert(TSM &&"Can not clone null module");
22
23if (!ShouldCloneDef)
24 ShouldCloneDef = [](constGlobalValue &) {returntrue; };
25
26return TSM.withModuleDo([&](Module &M) {
27SmallVector<char, 1> ClonedModuleBuffer;
28
29 {
30 std::set<GlobalValue *> ClonedDefsInSrc;
31ValueToValueMapTy VMap;
32auto Tmp =CloneModule(M, VMap, [&](constGlobalValue *GV) {
33if (ShouldCloneDef(*GV)) {
34 ClonedDefsInSrc.insert(const_cast<GlobalValue *>(GV));
35returntrue;
36 }
37returnfalse;
38 });
39
40if (UpdateClonedDefSource)
41for (auto *GV : ClonedDefsInSrc)
42 UpdateClonedDefSource(*GV);
43
44BitcodeWriter BCWriter(ClonedModuleBuffer);
45
46 BCWriter.writeModule(*Tmp);
47 BCWriter.writeSymtab();
48 BCWriter.writeStrtab();
49 }
50
51MemoryBufferRef ClonedModuleBufferRef(
52StringRef(ClonedModuleBuffer.data(), ClonedModuleBuffer.size()),
53"cloned module buffer");
54ThreadSafeContext NewTSCtx(std::make_unique<LLVMContext>());
55
56autoClonedModule =cantFail(
57parseBitcodeFile(ClonedModuleBufferRef, *NewTSCtx.getContext()));
58ClonedModule->setModuleIdentifier(M.getName());
59returnThreadSafeModule(std::move(ClonedModule), std::move(NewTSCtx));
60 });
61}
62
63}// end namespace orc
64}// end namespace llvm
BitcodeReader.h
BitcodeWriter.h
Cloning.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ThreadSafeModule.h
llvm::BitcodeWriter
Definition:BitcodeWriter.h:32
llvm::BitcodeWriter::writeStrtab
void writeStrtab()
Write the bitcode file's string table.
Definition:BitcodeWriter.cpp:5323
llvm::BitcodeWriter::writeSymtab
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
Definition:BitcodeWriter.cpp:5291
llvm::BitcodeWriter::writeModule
void writeModule(const Module &M, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the buffer specified at construction time.
Definition:BitcodeWriter.cpp:5342
llvm::GlobalValue
Definition:GlobalValue.h:48
llvm::MemoryBufferRef
Definition:MemoryBufferRef.h:22
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition:Module.h:65
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVectorTemplateCommon::data
pointer data()
Return a pointer to the vector's buffer, even if empty().
Definition:SmallVector.h:286
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::ValueMap< const Value *, WeakTrackingVH >
llvm::ValueMap::insert
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition:ValueMap.h:172
llvm::orc::ThreadSafeContext
An LLVMContext together with an associated mutex that can be used to lock the context to prevent conc...
Definition:ThreadSafeModule.h:29
llvm::orc::ThreadSafeContext::getContext
LLVMContext * getContext()
Returns a pointer to the LLVMContext that was used to construct this instance, or null if the instanc...
Definition:ThreadSafeModule.h:61
llvm::orc::ThreadSafeModule
An LLVM Module together with a shared ThreadSafeContext.
Definition:ThreadSafeModule.h:77
llvm::orc::ThreadSafeModule::withModuleDo
decltype(auto) withModuleDo(Func &&F)
Locks the associated ThreadSafeContext and calls the given function on the contained Module.
Definition:ThreadSafeModule.h:133
llvm::orc::GVPredicate
std::function< bool(const GlobalValue &)> GVPredicate
Definition:ThreadSafeModule.h:169
llvm::orc::GVModifier
std::function< void(GlobalValue &)> GVModifier
Definition:ThreadSafeModule.h:170
llvm::orc::cloneToNewContext
ThreadSafeModule cloneToNewContext(const ThreadSafeModule &TSMW, GVPredicate ShouldCloneDef=GVPredicate(), GVModifier UpdateClonedDefSource=GVModifier())
Clones the given module on to a new context.
Definition:ThreadSafeModule.cpp:18
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::parseBitcodeFile
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, ParserCallbacks Callbacks={})
Read the specified bitcode file, returning the module.
Definition:BitcodeReader.cpp:8721
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition:Error.h:756
llvm::CloneFunctionChangeType::ClonedModule
@ ClonedModule
llvm::CloneModule
std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
Definition:CloneModule.cpp:39

Generated on Fri Jul 18 2025 11:28:08 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp