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
20 changes: 10 additions & 10 deletions llvm/include/llvm/Cheerp/GlobalDepsAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ class GlobalDepsAnalyzer
/**
* Get a list of the classes which require bases info
*/
const std::unordered_set<llvm::StructType*> & classesWithBaseInfo() const { return classesWithBaseInfoNeeded; }
const llvm::DenseSet<llvm::StructType*> & classesWithBaseInfo() const { return classesWithBaseInfoNeeded; }

/**
* Get a list of the classes which are allocated in the code
*/
const std::unordered_set<llvm::StructType*> & classesUsed() const { return classesNeeded; }
const llvm::DenseSet<llvm::StructType*> & classesUsed() const { return classesNeeded; }

/**
* Get a list of the arrays which are dynamically allocated with unknown size
*/
const std::unordered_set<llvm::Type*> & dynAllocArrays() const { return arraysNeeded; }
const llvm::DenseSet<llvm::Type*> & dynAllocArrays() const { return arraysNeeded; }

/**
* Get a list of the arrays which are dynamically resized
*/
const std::unordered_set<llvm::Type*> & dynResizeArrays() const { return arrayResizesNeeded; }
const llvm::DenseSet<llvm::Type*> & dynResizeArrays() const { return arrayResizesNeeded; }

/**
* Get a list of the asm.js functions called from genericjs
Expand Down Expand Up @@ -244,13 +244,13 @@ class GlobalDepsAnalyzer
//Determine whether an instruction is atomic.
bool isAtomicInstruction(const llvm::Instruction& I);

std::unordered_set< const llvm::GlobalValue * > reachableGlobals; // Set of all the reachable globals
llvm::DenseSet< const llvm::GlobalValue * > reachableGlobals; // Set of all the reachable globals

FixupMap varsFixups;
std::unordered_set<llvm::StructType* > classesWithBaseInfoNeeded;
std::unordered_set<llvm::StructType* > classesNeeded;
std::unordered_set<llvm::Type* > arraysNeeded;
std::unordered_set<llvm::Type* > arrayResizesNeeded;
llvm::DenseSet<llvm::StructType* > classesWithBaseInfoNeeded;
llvm::DenseSet<llvm::StructType* > classesNeeded;
llvm::DenseSet<llvm::Type* > arraysNeeded;
llvm::DenseSet<llvm::Type* > arrayResizesNeeded;
DeterministicFunctionSet asmJSExportedFunctions;
DeterministicAliasSet asmJSExportedAliases;
DeterministicFunctionSet asmJSImportedFunctions;
Expand All @@ -259,7 +259,7 @@ class GlobalDepsAnalyzer
std::vector< llvm::GlobalValue * > externals;
std::vector< const llvm::Function* > functionsQueue;

std::unordered_map<llvm::StructType*, uint32_t> basesInfo;
llvm::DenseMap<llvm::StructType*, uint32_t> basesInfo;

std::array<bool, BuiltinInstr::numGenericBuiltins()> hasBuiltin;

Expand Down
35 changes: 12 additions & 23 deletions llvm/lib/CheerpUtils/GlobalDepsAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,15 @@ bool GlobalDepsAnalyzer::runOnModule( llvm::Module & module )

simplifyCalls(module);

if (!llcPass)
{
for (Function& F : module.getFunctionList())
bool anyWasmFuncAddrTaken = false;
// Replace calls like 'printf("Hello!")' with 'puts("Hello!")'.
for (Function& F : module.getFunctionList()) {
bool asmjs = F.getSection() == StringRef("asmjs");
if (asmjs) {
anyWasmFuncAddrTaken |= F.hasAddressTaken();
}
if (!llcPass)
{
//Those intrinsics may come back as result of other optimizations
//And we may need the actual functions to lower the intrinsics
const auto builtinID = BuiltinInstr::getMathBuiltin(F);
const auto typedBuiltinID = TypedBuiltinInstr::getMathTypedBuiltin(F);

Expand All @@ -204,20 +207,10 @@ bool GlobalDepsAnalyzer::runOnModule( llvm::Module & module )
|| F.getName() == "memset"
|| F.getName() == "memmove")
{
if (TypedBuiltinInstr::isAlwaysExactNatively(typedBuiltinID))
continue;
extendLifetime(&F);
if (!TypedBuiltinInstr::isAlwaysExactNatively(typedBuiltinID))
extendLifetime(&F);
}
}
}

bool anyWasmFuncAddrTaken = false;
// Replace calls like 'printf("Hello!")' with 'puts("Hello!")'.
for (Function& F : module.getFunctionList()) {
bool asmjs = F.getSection() == StringRef("asmjs");
if (asmjs) {
anyWasmFuncAddrTaken |= F.hasAddressTaken();
}
for (BasicBlock& bb : F)
{
bool advance = false; //Do not advance at the start
Expand Down Expand Up @@ -835,7 +828,7 @@ bool GlobalDepsAnalyzer::runOnModule( llvm::Module & module )
uint32_t firstBase = cast<ConstantInt>(cast<ConstantAsMetadata>(basesMeta->getOperand(0))->getValue())->getZExtValue();
StructType * t = StructType::getTypeByName(module.getContext(), name.drop_back(6));
if (t)
basesInfo.emplace(t, firstBase);
basesInfo.try_emplace(t, firstBase);
}
}

Expand Down Expand Up @@ -886,8 +879,6 @@ bool GlobalDepsAnalyzer::runOnModule( llvm::Module & module )
llvm::errs() << "warning: _startPreThread function point not found, and -pthread is linked\n";
}

processEnqueuedFunctions();

// Flush out all functions
processEnqueuedFunctions();

Expand Down Expand Up @@ -1064,7 +1055,6 @@ bool GlobalDepsAnalyzer::runOnModule( llvm::Module & module )

//Check agains the previous set what CallInstruction are actually impossible (and remove them)
std::vector<llvm::CallBase*> unreachList;
std::vector<std::pair<llvm::CallBase*, llvm::Function*> > devirtualizedCalls;

//Fixing function casts implies that new functions types will be created
//Exporting the table implies that functions can be added outside of our control
Expand Down Expand Up @@ -1106,7 +1096,6 @@ bool GlobalDepsAnalyzer::runOnModule( llvm::Module & module )
// Always an asmjs functions, thus it is ok to perform ptr to int conversions
replaceCallOfBitCastWithBitCastOfCall(*ci, false, true);

devirtualizedCalls.push_back({ci, toBeCalledFunc});
}
else
{
Expand Down Expand Up @@ -1235,7 +1224,7 @@ bool GlobalDepsAnalyzer::runOnModule( llvm::Module & module )
}
}

std::unordered_set<llvm::Function*> modifiedFunctions;
llvm::DenseSet<llvm::Function*> modifiedFunctions;

//Processing has to be done in reverse, so that multiple unreachable callInst in the same BasicBlock are processed from the last to the first
//This avoid erasing the latter ones while processing the first
Expand Down
Loading