diff options
author | Danila Malyutin <danilaml@users.noreply.github.com> | 2024-01-19 17:15:36 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-19 17:15:36 +0400 |
commit | 9ad7d8f0e4628f0f2d70a6c30299fe8be6bc18c4 (patch) | |
tree | b7685a8b3770dc72668bd9fd38d084269085fc9c /llvm/lib/CodeGen/StackMaps.cpp | |
parent | 1ab418beb3cc9c31ebb2d5779069426d761ceb8f (diff) | |
download | llvm-9ad7d8f0e4628f0f2d70a6c30299fe8be6bc18c4.zip llvm-9ad7d8f0e4628f0f2d70a6c30299fe8be6bc18c4.tar.gz llvm-9ad7d8f0e4628f0f2d70a6c30299fe8be6bc18c4.tar.bz2 |
[Statepoint] Optimize Location structure size (#78600)
Reduce its size from 24 to 12 bytes. Improves memory consumption when
dealing with statepoint-heavy code.
Diffstat (limited to 'llvm/lib/CodeGen/StackMaps.cpp')
-rw-r--r-- | llvm/lib/CodeGen/StackMaps.cpp | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/llvm/lib/CodeGen/StackMaps.cpp b/llvm/lib/CodeGen/StackMaps.cpp index f9115e4..f45bcaf 100644 --- a/llvm/lib/CodeGen/StackMaps.cpp +++ b/llvm/lib/CodeGen/StackMaps.cpp @@ -207,7 +207,7 @@ static unsigned getDwarfRegNum(unsigned Reg, const TargetRegisterInfo *TRI) { MachineInstr::const_mop_iterator StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI, MachineInstr::const_mop_iterator MOE, LocationVec &Locs, - LiveOutVec &LiveOuts) const { + LiveOutVec &LiveOuts) { const TargetRegisterInfo *TRI = AP.MF->getSubtarget().getRegisterInfo(); if (MOI->isImm()) { switch (MOI->getImm()) { @@ -238,7 +238,22 @@ StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI, ++MOI; assert(MOI->isImm() && "Expected constant operand."); int64_t Imm = MOI->getImm(); - Locs.emplace_back(Location::Constant, sizeof(int64_t), 0, Imm); + if (isInt<32>(Imm)) { + Locs.emplace_back(Location::Constant, sizeof(int64_t), 0, Imm); + } else { + // ConstPool is intentionally a MapVector of 'uint64_t's (as + // opposed to 'int64_t's). We should never be in a situation + // where we have to insert either the tombstone or the empty + // keys into a map, and for a DenseMap<uint64_t, T> these are + // (uint64_t)0 and (uint64_t)-1. They can be and are + // represented using 32 bit integers. + assert((uint64_t)Imm != DenseMapInfo<uint64_t>::getEmptyKey() && + (uint64_t)Imm != DenseMapInfo<uint64_t>::getTombstoneKey() && + "empty and tombstone keys should fit in 32 bits!"); + auto Result = ConstPool.insert(std::make_pair(Imm, Imm)); + Locs.emplace_back(Location::ConstantIndex, sizeof(int64_t), 0, + Result.first - ConstPool.begin()); + } break; } } @@ -497,27 +512,6 @@ void StackMaps::recordStackMapOpers(const MCSymbol &MILabel, while (MOI != MOE) MOI = parseOperand(MOI, MOE, Locations, LiveOuts); - // Move large constants into the constant pool. - for (auto &Loc : Locations) { - // Constants are encoded as sign-extended integers. - // -1 is directly encoded as .long 0xFFFFFFFF with no constant pool. - if (Loc.Type == Location::Constant && !isInt<32>(Loc.Offset)) { - Loc.Type = Location::ConstantIndex; - // ConstPool is intentionally a MapVector of 'uint64_t's (as - // opposed to 'int64_t's). We should never be in a situation - // where we have to insert either the tombstone or the empty - // keys into a map, and for a DenseMap<uint64_t, T> these are - // (uint64_t)0 and (uint64_t)-1. They can be and are - // represented using 32 bit integers. - assert((uint64_t)Loc.Offset != DenseMapInfo<uint64_t>::getEmptyKey() && - (uint64_t)Loc.Offset != - DenseMapInfo<uint64_t>::getTombstoneKey() && - "empty and tombstone keys should fit in 32 bits!"); - auto Result = ConstPool.insert(std::make_pair(Loc.Offset, Loc.Offset)); - Loc.Offset = Result.first - ConstPool.begin(); - } - } - // Create an expression to calculate the offset of the callsite from function // entry. const MCExpr *CSOffsetExpr = MCBinaryExpr::createSub( |