Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion llvm/include/llvm/Cheerp/TypeOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class TypeOptimizer

llvm::Module* module;
const llvm::DataLayout* DL;
std::unordered_set<const llvm::Type*> uncollapsibleSecondaryBases;
std::unordered_map<const llvm::StructType*,std::set<llvm::StructType*>> downcastSourceToDestinationsMapping;
std::unordered_map<const llvm::StructType*, std::vector<std::pair<uint32_t, uint32_t>>> membersMappingData;
std::unordered_map<llvm::GlobalValue*, llvm::Constant*> globalsMapping;
Expand Down
19 changes: 0 additions & 19 deletions llvm/lib/CheerpUtils/TypeOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,6 @@ void TypeOptimizer::gatherAllTypesInfo(const Module& M)
uint32_t fieldIndex = cast<ConstantInt>(*std::prev(GEP->op_end()))->getZExtValue();
escapingFields.emplace(containerStructType, fieldIndex, TypeAndIndex::STRUCT_MEMBER);
}

// Mark classes that cannot be collapsed because they are used as a secondary base
for (const auto sTy : M.getIdentifiedStructTypes())
{
uint32_t firstBase;
uint32_t baseCount;
if (TypeSupport::getBasesInfo(M, sTy, firstBase, baseCount))
{
for (uint32_t i = firstBase; i< (firstBase + baseCount); i++)
{
if (!sTy->getElementType(i)->isStructTy())
continue;
uncollapsibleSecondaryBases.insert(sTy->getElementType(i));
}
}
}
}

/**
Expand Down Expand Up @@ -310,9 +294,6 @@ bool TypeOptimizer::canCollapseStruct(llvm::StructType* st, llvm::StructType* ne
assert(st->isLiteral());
return true;
}
// Secondary bases used inside a hierarchy where a downcast is performed on cannot safely be collapsed
if (uncollapsibleSecondaryBases.count(st))
return false;
// Stop if the element is just a int8, we may be dealing with an empty struct
// Empty structs are unsafe as the int8 inside is just a placeholder and will be replaced
// by a different type in a derived class
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/CheerpWriter/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,14 @@ uint32_t CheerpWriter::compileClassTypeRecursive(const std::string& baseName, St

for(uint32_t i=firstBase;i<(firstBase+localBaseCount);i++)
{
// If a base was collapsed, fill its index in the array with null.
// It won't be accessed but we need to keep the indexing consistent.
if(!currentType->getElementType(i)->isStructTy())
{
stream << "a[" << baseCount << "]=null;" << NewLine;
baseCount++;
continue;
}
SmallString<16> buf;
llvm::raw_svector_ostream bufStream(buf);
bufStream << ".a" << i;
Expand Down
Loading