[ORC] Rename MemLifetimePolicy to MemLifetime.

The *Policy suffix came from the earlier MemAllocPolicy type, where it was
included to distinguish the type from a memory-allocation operation.
MemLifetime is a noun already, so the *Policy suffix is just dead weight now.
This commit is contained in:
Lang Hames
2023-09-28 08:53:17 -07:00
parent e52899ea52
commit e994f84c8a
13 changed files with 42 additions and 47 deletions

View File

@@ -722,10 +722,10 @@ public:
void setMemProt(orc::MemProt Prot) { this->Prot = Prot; }
/// Get the memory lifetime policy for this section.
orc::MemLifetimePolicy getMemLifetimePolicy() const { return MLP; }
orc::MemLifetime getMemLifetime() const { return ML; }
/// Set the memory lifetime policy for this section.
void setMemLifetimePolicy(orc::MemLifetimePolicy MLP) { this->MLP = MLP; }
void setMemLifetime(orc::MemLifetime ML) { this->ML = ML; }
/// Returns the ordinal for this section.
SectionOrdinal getOrdinal() const { return SecOrdinal; }
@@ -793,7 +793,7 @@ private:
StringRef Name;
orc::MemProt Prot;
orc::MemLifetimePolicy MLP = orc::MemLifetimePolicy::Standard;
orc::MemLifetime ML = orc::MemLifetime::Standard;
SectionOrdinal SecOrdinal = 0;
BlockSet Blocks;
SymbolSet Symbols;

View File

@@ -292,8 +292,8 @@ private:
/// address of that block using the Segment's AllocGroup. Once memory has been
/// populated, clients can call finalize to finalize the memory.
///
/// Note: Segments with MemLifetimePolicy::NoAlloc are not permitted, since
/// they would not be useful, and their presence is likely to indicate a bug.
/// Note: Segments with MemLifetime::NoAlloc are not permitted, since they would
/// not be useful, and their presence is likely to indicate a bug.
class SimpleSegmentAlloc {
public:
/// Describes a segment to be allocated.

View File

@@ -72,7 +72,7 @@ inline MemProt fromSysMemoryProtectionFlags(sys::Memory::ProtectionFlags PF) {
/// deallocated if a call is made to
/// JITLinkMemoryManager::InFlightAllocation::abandon. The policies below apply
/// to finalized allocations.
enum class MemLifetimePolicy {
enum class MemLifetime {
/// Standard memory should be allocated by the allocator and then deallocated
/// when the deallocate method is called for the finalized allocation.
Standard,
@@ -89,15 +89,15 @@ enum class MemLifetimePolicy {
};
/// Print a MemDeallocPolicy.
inline raw_ostream &operator<<(raw_ostream &OS, MemLifetimePolicy MLP) {
inline raw_ostream &operator<<(raw_ostream &OS, MemLifetime MLP) {
switch (MLP) {
case MemLifetimePolicy::Standard:
case MemLifetime::Standard:
OS << "standard";
break;
case MemLifetimePolicy::Finalize:
case MemLifetime::Finalize:
OS << "finalize";
break;
case MemLifetimePolicy::NoAlloc:
case MemLifetime::NoAlloc:
OS << "noalloc";
break;
}
@@ -124,11 +124,11 @@ public:
AllocGroup() = default;
/// Create an AllocGroup from a MemProt only -- uses
/// MemLifetimePolicy::Standard.
/// MemLifetime::Standard.
AllocGroup(MemProt MP) : Id(static_cast<underlying_type>(MP)) {}
/// Create an AllocGroup from a MemProt and a MemLifetimePolicy.
AllocGroup(MemProt MP, MemLifetimePolicy MLP)
/// Create an AllocGroup from a MemProt and a MemLifetime.
AllocGroup(MemProt MP, MemLifetime MLP)
: Id(static_cast<underlying_type>(MP) |
(static_cast<underlying_type>(MLP) << BitsForProt)) {}
@@ -137,9 +137,9 @@ public:
return static_cast<MemProt>(Id & ((1U << BitsForProt) - 1));
}
/// Returns the MemLifetimePolicy for this group.
MemLifetimePolicy getMemLifetimePolicy() const {
return static_cast<MemLifetimePolicy>(Id >> BitsForProt);
/// Returns the MemLifetime for this group.
MemLifetime getMemLifetime() const {
return static_cast<MemLifetime>(Id >> BitsForProt);
}
friend bool operator==(const AllocGroup &LHS, const AllocGroup &RHS) {
@@ -203,8 +203,7 @@ private:
/// Print an AllocGroup.
inline raw_ostream &operator<<(raw_ostream &OS, AllocGroup AG) {
return OS << '(' << AG.getMemProt() << ", " << AG.getMemLifetimePolicy()
<< ')';
return OS << '(' << AG.getMemProt() << ", " << AG.getMemLifetime() << ')';
}
} // end namespace orc

View File

@@ -36,10 +36,9 @@ struct RemoteAllocGroup {
RemoteAllocGroup(MemProt Prot, bool FinalizeLifetime)
: Prot(Prot), FinalizeLifetime(FinalizeLifetime) {}
RemoteAllocGroup(const AllocGroup &AG) : Prot(AG.getMemProt()) {
assert(AG.getMemLifetimePolicy() != orc::MemLifetimePolicy::NoAlloc &&
assert(AG.getMemLifetime() != orc::MemLifetime::NoAlloc &&
"Cannot use no-alloc memory in a remote alloc request");
FinalizeLifetime =
AG.getMemLifetimePolicy() == orc::MemLifetimePolicy::Finalize;
FinalizeLifetime = AG.getMemLifetime() == orc::MemLifetime::Finalize;
}
MemProt Prot;

View File

@@ -161,7 +161,7 @@ Error COFFLinkGraphBuilder::graphifySections() {
if (!GraphSec) {
GraphSec = &G->createSection(SectionName, Prot);
if ((*Sec)->Characteristics & COFF::IMAGE_SCN_LNK_REMOVE)
GraphSec->setMemLifetimePolicy(orc::MemLifetimePolicy::NoAlloc);
GraphSec->setMemLifetime(orc::MemLifetime::NoAlloc);
}
if (GraphSec->getMemProt() != Prot)
return make_error<JITLinkError>("MemProt should match");

View File

@@ -366,7 +366,7 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySections() {
GraphSec = &G->createSection(*Name, Prot);
// Non-SHF_ALLOC sections get NoAlloc memory lifetimes.
if (!(Sec.sh_flags & ELF::SHF_ALLOC)) {
GraphSec->setMemLifetimePolicy(orc::MemLifetimePolicy::NoAlloc);
GraphSec->setMemLifetime(orc::MemLifetime::NoAlloc);
LLVM_DEBUG({
dbgs() << " " << SecIndex << ": \"" << *Name
<< "\" is not a SHF_ALLOC section. Using NoAlloc lifetime.\n";

View File

@@ -134,8 +134,7 @@ private:
LLVM_DEBUG(dbgs() << "Fixing up blocks:\n");
for (auto &Sec : G.sections()) {
bool NoAllocSection =
Sec.getMemLifetimePolicy() == orc::MemLifetimePolicy::NoAlloc;
bool NoAllocSection = Sec.getMemLifetime() == orc::MemLifetime::NoAlloc;
for (auto *B : Sec.blocks()) {
LLVM_DEBUG(dbgs() << " " << *B << ":\n");
@@ -163,12 +162,11 @@ private:
// If B is a block in a Standard or Finalize section then make sure
// that no edges point to symbols in NoAlloc sections.
assert(
(NoAllocSection || !E.getTarget().isDefined() ||
E.getTarget().getBlock().getSection().getMemLifetimePolicy() !=
orc::MemLifetimePolicy::NoAlloc) &&
"Block in allocated section has edge pointing to no-alloc "
"section");
assert((NoAllocSection || !E.getTarget().isDefined() ||
E.getTarget().getBlock().getSection().getMemLifetime() !=
orc::MemLifetime::NoAlloc) &&
"Block in allocated section has edge pointing to no-alloc "
"section");
// Dispatch to LinkerImpl for fixup.
if (auto Err = impl().applyFixup(G, *B, E))

View File

@@ -26,10 +26,10 @@ BasicLayout::BasicLayout(LinkGraph &G) : G(G) {
for (auto &Sec : G.sections()) {
// Skip empty sections, and sections with NoAlloc lifetime policies.
if (Sec.blocks().empty() ||
Sec.getMemLifetimePolicy() == orc::MemLifetimePolicy::NoAlloc)
Sec.getMemLifetime() == orc::MemLifetime::NoAlloc)
continue;
auto &Seg = Segments[{Sec.getMemProt(), Sec.getMemLifetimePolicy()}];
auto &Seg = Segments[{Sec.getMemProt(), Sec.getMemLifetime()}];
for (auto *B : Sec.blocks())
if (LLVM_LIKELY(!B->isZeroFill()))
Seg.ContentBlocks.push_back(B);
@@ -90,7 +90,7 @@ BasicLayout::getContiguousPageBasedLayoutSizes(uint64_t PageSize) {
inconvertibleErrorCode());
uint64_t SegSize = alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize);
if (AG.getMemLifetimePolicy() == orc::MemLifetimePolicy::Standard)
if (AG.getMemLifetime() == orc::MemLifetime::Standard)
SegsSizes.StandardSegs += SegSize;
else
SegsSizes.FinalizeSegs += SegSize;
@@ -164,15 +164,15 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr,
auto &AG = KV.first;
auto &Seg = KV.second;
assert(AG.getMemLifetimePolicy() != orc::MemLifetimePolicy::NoAlloc &&
assert(AG.getMemLifetime() != orc::MemLifetime::NoAlloc &&
"NoAlloc segments are not supported by SimpleSegmentAlloc");
auto AGSectionName =
AGSectionNames[static_cast<unsigned>(AG.getMemProt()) |
static_cast<bool>(AG.getMemLifetimePolicy()) << 3];
static_cast<bool>(AG.getMemLifetime()) << 3];
auto &Sec = G->createSection(AGSectionName, AG.getMemProt());
Sec.setMemLifetimePolicy(AG.getMemLifetimePolicy());
Sec.setMemLifetime(AG.getMemLifetime());
if (Seg.ContentSize != 0) {
NextAddr =
@@ -419,10 +419,9 @@ void InProcessMemoryManager::allocate(const JITLinkDylib *JD, LinkGraph &G,
auto &AG = KV.first;
auto &Seg = KV.second;
auto &SegAddr =
(AG.getMemLifetimePolicy() == orc::MemLifetimePolicy::Standard)
? NextStandardSegAddr
: NextFinalizeSegAddr;
auto &SegAddr = (AG.getMemLifetime() == orc::MemLifetime::Standard)
? NextStandardSegAddr
: NextFinalizeSegAddr;
Seg.WorkingMem = SegAddr.toPtr<char *>();
Seg.Addr = SegAddr;

View File

@@ -192,7 +192,7 @@ Error MachOLinkGraphBuilder::createNormalizedSections() {
// TODO: Are there any other criteria for NoAlloc lifetime?
if (NSec.Flags & MachO::S_ATTR_DEBUG)
NSec.GraphSection->setMemLifetimePolicy(orc::MemLifetimePolicy::NoAlloc);
NSec.GraphSection->setMemLifetime(orc::MemLifetime::NoAlloc);
IndexToSection.insert(std::make_pair(SecIndex, std::move(NSec)));
}

View File

@@ -110,7 +110,7 @@ public:
if (isDebugSection(Sec))
DebugSections.push_back({&Sec, nullptr});
else if (Sec.getMemLifetimePolicy() != MemLifetimePolicy::NoAlloc)
else if (Sec.getMemLifetime() != MemLifetime::NoAlloc)
NonDebugSections.push_back({&Sec, nullptr});
}

View File

@@ -322,8 +322,8 @@ void SharedMemoryMapper::initialize(MemoryMapper::AllocInfo &AI,
std::memset(Base + Segment.ContentSize, 0, Segment.ZeroFillSize);
tpctypes::SharedMemorySegFinalizeRequest SegReq;
SegReq.RAG = {Segment.AG.getMemProt(), Segment.AG.getMemLifetimePolicy() ==
MemLifetimePolicy::Finalize};
SegReq.RAG = {Segment.AG.getMemProt(),
Segment.AG.getMemLifetime() == MemLifetime::Finalize};
SegReq.Addr = AI.MappingBase + Segment.Offset;
SegReq.Size = Segment.ContentSize + Segment.ZeroFillSize;

View File

@@ -512,7 +512,7 @@ public:
auto FixedAI = std::move(AI);
FixedAI.MappingBase -= DeltaAddr;
for (auto &Seg : FixedAI.Segments)
Seg.AG = {MemProt::Read | MemProt::Write, Seg.AG.getMemLifetimePolicy()};
Seg.AG = {MemProt::Read | MemProt::Write, Seg.AG.getMemLifetime()};
FixedAI.Actions.clear();
InProcessMemoryMapper::initialize(
FixedAI, [this, OnInitialized = std::move(OnInitialized)](

View File

@@ -798,7 +798,7 @@ TEST(LinkGraphTest, BasicLayoutHonorsNoAlloc) {
// Create a NoAlloc section and block.
auto &Sec2 =
G.createSection("__metadata", orc::MemProt::Read | orc::MemProt::Write);
Sec2.setMemLifetimePolicy(orc::MemLifetimePolicy::NoAlloc);
Sec2.setMemLifetime(orc::MemLifetime::NoAlloc);
G.createContentBlock(Sec2, BlockContent.slice(0, 8), orc::ExecutorAddr(), 8,
0);