13
13
#ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
14
14
#define LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
15
15
16
- #include " JITLinkMemoryManager.h"
17
16
#include " llvm/ADT/DenseMap.h"
18
17
#include " llvm/ADT/DenseSet.h"
19
18
#include " llvm/ADT/Optional.h"
20
19
#include " llvm/ADT/STLExtras.h"
21
20
#include " llvm/ADT/Triple.h"
21
+ #include " llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
22
+ #include " llvm/ExecutionEngine/JITLink/MemoryFlags.h"
22
23
#include " llvm/ExecutionEngine/JITSymbol.h"
23
24
#include " llvm/Support/Allocator.h"
24
25
#include " llvm/Support/Endian.h"
25
26
#include " llvm/Support/Error.h"
26
27
#include " llvm/Support/FormatVariadic.h"
27
28
#include " llvm/Support/MathExtras.h"
28
- #include " llvm/Support/Memory.h"
29
29
#include " llvm/Support/MemoryBuffer.h"
30
30
31
31
#include < map>
@@ -225,14 +225,15 @@ class Block : public Addressable {
225
225
226
226
// / Get the content for this block. Block must not be a zero-fill block.
227
227
ArrayRef<char > getContent () const {
228
- assert (Data && " Section does not contain content" );
228
+ assert (Data && " Block does not contain content" );
229
229
return ArrayRef<char >(Data, Size);
230
230
}
231
231
232
232
// / Set the content for this block.
233
233
// / Caller is responsible for ensuring the underlying bytes are not
234
234
// / deallocated while pointed to by this block.
235
235
void setContent (ArrayRef<char > Content) {
236
+ assert (Content.data () && " Setting null content" );
236
237
Data = Content.data ();
237
238
Size = Content.size ();
238
239
ContentMutable = false ;
@@ -251,6 +252,7 @@ class Block : public Addressable {
251
252
// / to call this on a block with immutable content -- consider using
252
253
// / getMutableContent instead.
253
254
MutableArrayRef<char > getAlreadyMutableContent () {
255
+ assert (Data && " Block does not contain content" );
254
256
assert (ContentMutable && " Content is not mutable" );
255
257
return MutableArrayRef<char >(const_cast <char *>(Data), Size);
256
258
}
@@ -260,6 +262,7 @@ class Block : public Addressable {
260
262
// / The caller is responsible for ensuring that the memory pointed to by
261
263
// / MutableContent is not deallocated while pointed to by this block.
262
264
void setMutableContent (MutableArrayRef<char > MutableContent) {
265
+ assert (MutableContent.data () && " Setting null content" );
263
266
Data = MutableContent.data ();
264
267
Size = MutableContent.size ();
265
268
ContentMutable = true ;
@@ -295,6 +298,7 @@ class Block : public Addressable {
295
298
// / Add an edge to this block.
296
299
void addEdge (Edge::Kind K, Edge::OffsetT Offset, Symbol &Target,
297
300
Edge::AddendT Addend) {
301
+ assert (!isZeroFill () && " Adding edge to zero-fill block?" );
298
302
Edges.push_back (Edge (K, Offset, Target, Addend));
299
303
}
300
304
@@ -640,8 +644,7 @@ class Section {
640
644
friend class LinkGraph ;
641
645
642
646
private:
643
- Section (StringRef Name, sys::Memory::ProtectionFlags Prot,
644
- SectionOrdinal SecOrdinal)
647
+ Section (StringRef Name, MemProt Prot, SectionOrdinal SecOrdinal)
645
648
: Name(Name), Prot(Prot), SecOrdinal(SecOrdinal) {}
646
649
647
650
using SymbolSet = DenseSet<Symbol *>;
@@ -666,12 +669,16 @@ class Section {
666
669
StringRef getName () const { return Name; }
667
670
668
671
// / Returns the protection flags for this section.
669
- sys::Memory::ProtectionFlags getProtectionFlags () const { return Prot; }
672
+ MemProt getMemProt () const { return Prot; }
670
673
671
674
// / Set the protection flags for this section.
672
- void setProtectionFlags (sys::Memory::ProtectionFlags Prot) {
673
- this ->Prot = Prot;
674
- }
675
+ void setMemProt (MemProt Prot) { this ->Prot = Prot; }
676
+
677
+ // / Get the deallocation policy for this section.
678
+ MemDeallocPolicy getMemDeallocPolicy () const { return MDP; }
679
+
680
+ // / Set the deallocation policy for this section.
681
+ void setMemDeallocPolicy (MemDeallocPolicy MDP) { this ->MDP = MDP; }
675
682
676
683
// / Returns the ordinal for this section.
677
684
SectionOrdinal getOrdinal () const { return SecOrdinal; }
@@ -686,6 +693,7 @@ class Section {
686
693
return make_range (Blocks.begin (), Blocks.end ());
687
694
}
688
695
696
+ // / Returns the number of blocks in this section.
689
697
BlockSet::size_type blocks_size () const { return Blocks.size (); }
690
698
691
699
// / Returns an iterator over the symbols defined in this section.
@@ -734,7 +742,8 @@ class Section {
734
742
}
735
743
736
744
StringRef Name;
737
- sys::Memory::ProtectionFlags Prot;
745
+ MemProt Prot;
746
+ MemDeallocPolicy MDP = MemDeallocPolicy::Standard;
738
747
SectionOrdinal SecOrdinal = 0 ;
739
748
BlockSet Blocks;
740
749
SymbolSet Symbols;
@@ -916,6 +925,11 @@ class LinkGraph {
916
925
: Name(std::move(Name)), TT(TT), PointerSize(PointerSize),
917
926
Endianness (Endianness), GetEdgeKindName(std::move(GetEdgeKindName)) {}
918
927
928
+ LinkGraph (const LinkGraph &) = delete;
929
+ LinkGraph &operator =(const LinkGraph &) = delete ;
930
+ LinkGraph (LinkGraph &&) = delete;
931
+ LinkGraph &operator =(LinkGraph &&) = delete ;
932
+
919
933
// / Returns the name of this graph (usually the name of the original
920
934
// / underlying MemoryBuffer).
921
935
const std::string &getName () const { return Name; }
@@ -962,7 +976,7 @@ class LinkGraph {
962
976
}
963
977
964
978
// / Create a section with the given name, protection flags, and alignment.
965
- Section &createSection (StringRef Name, sys::Memory::ProtectionFlags Prot) {
979
+ Section &createSection (StringRef Name, MemProt Prot) {
966
980
assert (llvm::find_if (Sections,
967
981
[&](std::unique_ptr<Section> &Sec) {
968
982
return Sec->getName () == Name;
@@ -1350,6 +1364,13 @@ class LinkGraph {
1350
1364
Sections.erase (I);
1351
1365
}
1352
1366
1367
+ // / Accessor for the AllocActions object for this graph. This can be used to
1368
+ // / register allocation action calls prior to finalization.
1369
+ // /
1370
+ // / Accessing this object after finalization will result in undefined
1371
+ // / behavior.
1372
+ JITLinkMemoryManager::AllocActions &allocActions () { return AAs; }
1373
+
1353
1374
// / Dump the graph.
1354
1375
void dump (raw_ostream &OS);
1355
1376
@@ -1366,6 +1387,7 @@ class LinkGraph {
1366
1387
SectionList Sections;
1367
1388
ExternalSymbolSet ExternalSymbols;
1368
1389
ExternalSymbolSet AbsoluteSymbols;
1390
+ JITLinkMemoryManager::AllocActions AAs;
1369
1391
};
1370
1392
1371
1393
inline MutableArrayRef<char > Block::getMutableContent (LinkGraph &G) {
@@ -1655,8 +1677,7 @@ class JITLinkContext {
1655
1677
// / finalized (i.e. emitted to memory and memory permissions set). If all of
1656
1678
// / this objects dependencies have also been finalized then the code is ready
1657
1679
// / to run.
1658
- virtual void
1659
- notifyFinalized (std::unique_ptr<JITLinkMemoryManager::Allocation> A) = 0 ;
1680
+ virtual void notifyFinalized (JITLinkMemoryManager::FinalizedAlloc Alloc) = 0;
1660
1681
1661
1682
// / Called by JITLink prior to linking to determine whether default passes for
1662
1683
// / the target should be added. The default implementation returns true.
0 commit comments