@@ -174,6 +174,10 @@ namespace {
174
174
typedef std::map<const BasicBlock*, unsigned > BlockIndexMap;
175
175
typedef std::map<const Function*, BlockIndexMap> BlockAddressMap;
176
176
typedef std::map<const BasicBlock*, Block*> LLVMToRelooperMap;
177
+ struct AsmConstInfo {
178
+ int Id;
179
+ std::set<std::string> Sigs;
180
+ };
177
181
178
182
// / JSWriter - This class is the main chunk of code that converts an LLVM
179
183
// / module to JavaScript.
@@ -200,8 +204,7 @@ namespace {
200
204
std::vector<std::string> Exports; // additional exports
201
205
StringMap Aliases;
202
206
BlockAddressMap BlockAddresses;
203
- NameIntMap AsmConsts;
204
- IntIntSetMap AsmConstArities;
207
+ std::map<std::string, AsmConstInfo> AsmConsts; // code => { index, list of seen sigs }
205
208
NameSet FuncRelocatableExterns; // which externals are accessed in this function; we load them once at the beginning (avoids a potential call in a heap access, and might be faster)
206
209
207
210
std::string CantValidate;
@@ -330,7 +333,7 @@ namespace {
330
333
return ' i' ;
331
334
}
332
335
}
333
- std::string getFunctionSignature (const FunctionType *F, const std::string *Name= NULL ) {
336
+ std::string getFunctionSignature (const FunctionType *F) {
334
337
std::string Ret;
335
338
Ret += getFunctionSignatureLetter (F->getReturnType ());
336
339
for (FunctionType::param_iterator AI = F->param_begin (),
@@ -348,7 +351,7 @@ namespace {
348
351
unsigned getFunctionIndex (const Function *F) {
349
352
const std::string &Name = getJSName (F);
350
353
if (IndexedFunctions.find (Name) != IndexedFunctions.end ()) return IndexedFunctions[Name];
351
- std::string Sig = getFunctionSignature (F->getFunctionType (), &Name );
354
+ std::string Sig = getFunctionSignature (F->getFunctionType ());
352
355
FunctionTable& Table = ensureFunctionTable (F->getFunctionType ());
353
356
if (NoAliasingFunctionPointers) {
354
357
while (Table.size () < NextFunctionIndex) Table.push_back (" 0" );
@@ -455,7 +458,7 @@ namespace {
455
458
// Transform the string input into emscripten_asm_const_*(str, args1, arg2)
456
459
// into an id. We emit a map of id => string contents, and emscripten
457
460
// wraps it up so that calling that id calls that function.
458
- unsigned getAsmConstId (const Value *V, int Arity ) {
461
+ unsigned getAsmConstId (const Value *V, std::string Sig ) {
459
462
V = resolveFully (V);
460
463
const Constant *CI = cast<GlobalVariable>(V)->getInitializer ();
461
464
std::string code;
@@ -482,15 +485,18 @@ namespace {
482
485
}
483
486
}
484
487
}
485
- unsigned id ;
488
+ unsigned Id ;
486
489
if (AsmConsts.count (code) > 0 ) {
487
- id = AsmConsts[code];
490
+ auto & Info = AsmConsts[code];
491
+ Id = Info.Id ;
492
+ Info.Sigs .insert (Sig);
488
493
} else {
489
- id = AsmConsts.size ();
490
- AsmConsts[code] = id;
494
+ AsmConstInfo Info;
495
+ Info.Id = Id = AsmConsts.size ();
496
+ Info.Sigs .insert (Sig);
497
+ AsmConsts[code] = Info;
491
498
}
492
- AsmConstArities[id].insert (Arity);
493
- return id;
499
+ return Id;
494
500
}
495
501
496
502
// Test whether the given value is known to be an absolute value or one we turn into an absolute value
@@ -3301,44 +3307,24 @@ void JSWriter::printModuleBody() {
3301
3307
3302
3308
Out << " \" asmConsts\" : {" ;
3303
3309
first = true ;
3304
- for (NameIntMap::const_iterator I = AsmConsts. begin (), E = AsmConsts. end (); I != E; ++I ) {
3310
+ for (auto & I : AsmConsts) {
3305
3311
if (first) {
3306
3312
first = false ;
3307
3313
} else {
3308
3314
Out << " , " ;
3309
3315
}
3310
- Out << " \" " << utostr (I->second ) << " \" : \" " << I->first .c_str () << " \" " ;
3311
- }
3312
- Out << " }," ;
3313
-
3314
- // Output a structure like:
3315
- // "asmConstArities": {
3316
- // "<ASM_CONST_ID_1>": [<ARITY>, <ARITY>],
3317
- // "<ASM_CONST_ID_2>": [<ARITY>]
3318
- // }
3319
- // Each ASM_CONST_ID represents a single EM_ASM_* block in the code and each
3320
- // ARITY represents the number of arguments defined in the block in compiled
3321
- // output (which may vary, if the EM_ASM_* block is used inside a template).
3322
- Out << " \" asmConstArities\" : {" ;
3323
- first = true ;
3324
- for (IntIntSetMap::const_iterator I = AsmConstArities.begin (), E = AsmConstArities.end ();
3325
- I != E; ++I) {
3326
- if (!first) {
3327
- Out << " , " ;
3328
- }
3329
- Out << " \" " << utostr (I->first ) << " \" : [" ;
3330
- first = true ;
3331
- for (IntSet::const_iterator J = I->second .begin (), F = I->second .end ();
3332
- J != F; ++J) {
3333
- if (first) {
3334
- first = false ;
3316
+ Out << " \" " << utostr (I.second .Id ) << " \" : [\" " << I.first .c_str () << " \" , [" ;
3317
+ auto & Sigs = I.second .Sigs ;
3318
+ bool innerFirst = true ;
3319
+ for (auto & Sig : Sigs) {
3320
+ if (innerFirst) {
3321
+ innerFirst = false ;
3335
3322
} else {
3336
3323
Out << " , " ;
3337
3324
}
3338
- Out << utostr (*J) ;
3325
+ Out << " \" " << Sig << " \" " ;
3339
3326
}
3340
- first = false ;
3341
- Out << " ]" ;
3327
+ Out << " ]]" ;
3342
3328
}
3343
3329
Out << " }" ;
3344
3330
0 commit comments