Skip to content

Commit 98d893a

Browse files
Maqrkkyuri91
authored andcommitted
Remove special casing of global_ctors in GDA.
This is no longer necessary, as placing these in the start function during CallConstructors ensures they are reachable, and thus GDA will not remove them.
1 parent a78930b commit 98d893a

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

llvm/include/llvm/Cheerp/Utility.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ struct GlobalConstructor
308308
};
309309

310310
std::vector<llvm::Constant*> getGlobalConstructors(llvm::Module& M);
311+
void removeGlobalConstructorsGlobal(llvm::Module& M);
311312

312313
uint32_t getIntFromValue(const llvm::Value* v);
313314

llvm/lib/CheerpUtils/CallConstructors.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ PreservedAnalyses CallConstructorsPass::run(llvm::Module &M, llvm::ModuleAnalysi
6363
Builder.CreateCall(GetEnviron->getFunctionType(), GetEnviron);
6464

6565
for (Constant* C: cheerp::getGlobalConstructors(M))
66-
{
6766
Builder.CreateCall(Ty, cast<Function>(C->getAggregateElement(1)->stripPointerCastsSafe()));
68-
}
67+
removeGlobalConstructorsGlobal(M);
6968

7069
if (useUtilityThread)
7170
{

llvm/lib/CheerpUtils/GlobalDepsAnalyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ int GlobalDepsAnalyzer::filterModule( const DenseSet<const Function*>& droppedMa
15821582
bool isClient = TypeSupport::isClientGlobal(var);
15831583
if( var->hasInitializer() )
15841584
{
1585-
if( !WasmSharedModule && !isClient && var->getName()!="llvm.global_ctors" )
1585+
if( !WasmSharedModule && !isClient)
15861586
var->setLinkage(GlobalValue::InternalLinkage);
15871587
}
15881588
else if( !isClient && var->getName() != "__cxa_cheerp_clause_table")

llvm/lib/CheerpUtils/Utility.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,14 @@ std::vector<Constant*> getGlobalConstructors(Module& module)
10381038
return ret;
10391039
}
10401040

1041+
void removeGlobalConstructorsGlobal(Module& M)
1042+
{
1043+
GlobalVariable* var = M.getGlobalVariable("llvm.global_ctors");
1044+
if (!var)
1045+
return;
1046+
var->eraseFromParent();
1047+
}
1048+
10411049
const llvm::Loop* findCommonLoop(const llvm::LoopInfo* LI, const llvm::BasicBlock* first, const llvm::BasicBlock* second)
10421050
{
10431051
//Find the innermost common loop between two BB.

llvm/lib/CheerpWriter/CheerpWriter.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6719,9 +6719,6 @@ void CheerpWriter::compileGenericJS()
67196719
}
67206720
for ( const GlobalVariable & GV : module.getGlobalList() )
67216721
{
6722-
// Skip global ctors array
6723-
if (GV.getName() == "llvm.global_ctors")
6724-
continue;
67256722
if (GV.getSection() != StringRef("asmjs"))
67266723
compileGlobal(GV);
67276724
}

0 commit comments

Comments
 (0)