diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/compiler.h | 2 | ||||
| -rw-r--r-- | source/slang/emit.cpp | 8 | ||||
| -rw-r--r-- | source/slang/ir-insts.h | 4 | ||||
| -rw-r--r-- | source/slang/ir-legalize-types.cpp | 16 | ||||
| -rw-r--r-- | source/slang/ir.cpp | 63 | ||||
| -rw-r--r-- | source/slang/ir.h | 9 | ||||
| -rw-r--r-- | source/slang/legalize-types.h | 3 | ||||
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 12 |
8 files changed, 57 insertions, 60 deletions
diff --git a/source/slang/compiler.h b/source/slang/compiler.h index fe3ee9533..a91e03c55 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -429,7 +429,7 @@ namespace Slang RootNamePool* getRootNamePool() { return &rootNamePool; } NamePool* getNamePool() { return &namePool; } - + Name* getNameObj(String name) { return namePool.getName(name); } // // Generated code for stdlib, etc. diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 3fa50b928..79fd2b444 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -4584,8 +4584,8 @@ emitDeclImpl(decl, nullptr); case kIROp_Func: { auto& mangledName = ((IRGlobalValue*)inst)->mangledName; - if(mangledName.Length() != 0) - return mangledName; + if(getText(mangledName).Length() != 0) + return getText(mangledName); } break; @@ -5582,7 +5582,7 @@ emitDeclImpl(decl, nullptr); // be better strategies (including just stuffing // a pointer to the original decl onto the callee). - UnmangleContext um(func->mangledName); + UnmangleContext um(getText(func->mangledName)); um.startUnmangling(); // We'll read through the qualified name of the @@ -7679,7 +7679,7 @@ emitDeclImpl(decl, nullptr); // actually *require* redeclaration...). // // TODO: can we detect this more robustly? - if(varDecl->mangledName.StartsWith("gl_")) + if(getText(varDecl->mangledName).StartsWith("gl_")) { // The variable represents an OpenGL system value, // so we will assume that it doesn't need to be declared. diff --git a/source/slang/ir-insts.h b/source/slang/ir-insts.h index 26cce054e..f41e8a506 100644 --- a/source/slang/ir-insts.h +++ b/source/slang/ir-insts.h @@ -406,7 +406,7 @@ struct SharedIRBuilder Dictionary<IRInstKey, IRInst*> globalValueNumberingMap; Dictionary<IRConstantKey, IRConstant*> constantMap; - Dictionary<String, IRWitnessTable*> witnessTableMap; + Dictionary<Name*, IRWitnessTable*> witnessTableMap; }; struct IRBuilderSourceLocRAII; @@ -523,7 +523,7 @@ struct IRBuilder IRWitnessTable* witnessTable, IRValue* requirementKey, IRValue* satisfyingVal); - IRWitnessTable* lookupWitnessTable(String mangledName); + IRWitnessTable* lookupWitnessTable(Name* mangledName); void registerWitnessTable(IRWitnessTable* table); IRBlock* createBlock(); IRBlock* emitBlock(); diff --git a/source/slang/ir-legalize-types.cpp b/source/slang/ir-legalize-types.cpp index 9cb32de8f..3a0edbb60 100644 --- a/source/slang/ir-legalize-types.cpp +++ b/source/slang/ir-legalize-types.cpp @@ -14,6 +14,7 @@ #include "ir-insts.h" #include "legalize-types.h" #include "mangle.h" +#include "name.h" namespace Slang { @@ -111,14 +112,13 @@ static void maybeRegisterLegalizedGlobal( // Check the mangled name of the symbol and don't register // symbols that don't have an external name (currently // indicated by them having an empty name string). - String mangledName = irGlobalVar->mangledName; - if (mangledName.Length() == 0) + if (getText(irGlobalVar->mangledName).Length() == 0) return; // Otherwise, register the legalized value for this symbol // under its mangled name, so that other code can still // find the right value(s) to use after legalization. - context->typeLegalizationContext->mapMangledNameToLegalIRValue.AddIfNotExists(mangledName, legalVal); + context->typeLegalizationContext->mapMangledNameToLegalIRValue.AddIfNotExists(irGlobalVar->mangledName, legalVal); } struct IRGlobalNameInfo @@ -893,12 +893,12 @@ static LegalVal declareSimpleVar( // a counter to each leaf variable generated from the original if (globalNameInfo) { - String mangledName = globalNameInfo->globalVar->mangledName; - if (mangledName.Length() != 0) + String mangledNameStr = getText(globalNameInfo->globalVar->mangledName); + if (mangledNameStr.Length() != 0) { - mangledName.append("L"); - mangledName.append(globalNameInfo->counter++); - globalVar->mangledName = mangledName; + mangledNameStr.append("L"); + mangledNameStr.append(globalNameInfo->counter++); + globalVar->mangledName = context->session->getNameObj(mangledNameStr); } } diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 090d0452b..8d3661452 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -11,7 +11,7 @@ namespace Slang IRGlobalValue* cloneGlobalValueWithMangledName( IRSpecContext* context, - String const& mangledName, + Name* mangledName, IRGlobalValue* originalVal); @@ -1277,7 +1277,7 @@ namespace Slang return entry; } - IRWitnessTable * IRBuilder::lookupWitnessTable(String mangledName) + IRWitnessTable * IRBuilder::lookupWitnessTable(Name* mangledName) { IRWitnessTable * result; if (sharedBuilder->witnessTableMap.TryGetValue(mangledName, result)) @@ -1816,7 +1816,7 @@ namespace Slang { auto irFunc = (IRFunc*) inst; dump(context, "@"); - dump(context, irFunc->mangledName.Buffer()); + dump(context, getText(irFunc->mangledName).Buffer()); } break; @@ -3202,7 +3202,7 @@ namespace Slang if( systemValueInfo ) { - globalVariable->mangledName = systemValueInfo->name; + globalVariable->mangledName = builder->getSession()->getNameObj(systemValueInfo->name); } builder->addLayoutDecoration(globalVariable, varLayout); @@ -3756,7 +3756,7 @@ namespace Slang // A map from mangled symbol names to zero or // more global IR values that have that name, // in the *original* module. - typedef Dictionary<String, RefPtr<IRSpecSymbol>> SymbolDictionary; + typedef Dictionary<Name*, RefPtr<IRSpecSymbol>> SymbolDictionary; SymbolDictionary symbols; // A map from values in the original IR module @@ -3775,7 +3775,7 @@ namespace Slang { // A map from the mangled name of a global variable // to the layout to use for it. - Dictionary<String, VarLayout*> globalVarLayouts; + Dictionary<Name*, VarLayout*> globalVarLayouts; IRSharedSpecContext* shared; @@ -4395,7 +4395,7 @@ namespace Slang EntryPointLayout* entryPointLayout) { // Look up the IR symbol by name - String mangledName = getMangledName(entryPointRequest->decl); + auto mangledName = context->getModule()->session->getNameObj(getMangledName(entryPointRequest->decl)); RefPtr<IRSpecSymbol> sym; if (!context->getSymbols().TryGetValue(mangledName, sym)) { @@ -4651,7 +4651,7 @@ namespace Slang // (It is okay for this parameter to be null). IRGlobalValue* cloneGlobalValueWithMangledName( IRSpecContext* context, - String const& mangledName, + Name* mangledName, IRGlobalValue* originalVal) { // Check if we've already cloned this value, for the case where @@ -4662,7 +4662,7 @@ namespace Slang return (IRGlobalValue*) clonedVal; } - if(mangledName.Length() == 0) + if(getText(mangledName).Length() == 0) { // If there is no mangled name, then we assume this is a local symbol, // and it can't possibly have multiple declarations. @@ -4710,7 +4710,7 @@ namespace Slang return cloneGlobalValueImpl(context, bestVal, sym); } - IRGlobalValue* cloneGlobalValueWithMangledName(IRSpecContext* context, String const& mangledName) + IRGlobalValue* cloneGlobalValueWithMangledName(IRSpecContext* context, Name* mangledName) { return cloneGlobalValueWithMangledName(context, mangledName, nullptr); } @@ -4736,12 +4736,12 @@ namespace Slang IRSharedSpecContext* sharedContext, IRGlobalValue* gv) { - String mangledName = gv->mangledName; + auto mangledName = gv->mangledName; // Don't try to register a symbol for global values // with no mangled name, since these represent symbols // that shouldn't get "linkage" - if (mangledName == "") + if (!getText(mangledName).Length()) return; RefPtr<IRSpecSymbol> sym = new IRSpecSymbol(); @@ -4890,7 +4890,7 @@ namespace Slang auto globalStructLayout = getGlobalStructLayout(newProgramLayout); for (auto globalVarLayout : globalStructLayout->fields) { - String mangledName = getMangledName(globalVarLayout->varDecl); + auto mangledName = compileRequest->mSession->getNameObj(getMangledName(globalVarLayout->varDecl)); context->globalVarLayouts.AddIfNotExists(mangledName, globalVarLayout); } @@ -4924,7 +4924,7 @@ namespace Slang IRGlobalValue* irDeclVal = cloneGlobalValueWithMangledName( state->getContext(), - mangledDeclName); + state->getContext()->getModule()->session->getNameObj(mangledDeclName)); if(!irDeclVal) return nullptr; @@ -5013,9 +5013,9 @@ namespace Slang { if( auto subtypeWitness = dynamic_cast<SubtypeWitness*>(val) ) { - String mangledName = getMangledNameForConformanceWitness( + auto mangledName = context->getModule()->session->getNameObj(getMangledNameForConformanceWitness( subtypeWitness->sub, - subtypeWitness->sup); + subtypeWitness->sup)); RefPtr<IRSpecSymbol> symbol; if (context->getSymbols().TryGetValue(mangledName, symbol)) @@ -5030,9 +5030,9 @@ namespace Slang auto subDeclRefGen = DeclRef<Decl>(subDeclRef->declRef.decl, createDefaultSubstitutions(context->builder->getSession(), subDeclRef->declRef.decl)); - String genericName = getMangledNameForConformanceWitness( + auto genericName = context->getModule()->session->getNameObj(getMangledNameForConformanceWitness( subDeclRefGen, - subtypeWitness->sup); + subtypeWitness->sup)); if (context->getSymbols().TryGetValue(genericName, symbol)) { auto specInst = context->builder->emitSpecializeInst(subtypeWitness->sup, symbol->irGlobalValue, subDeclRef->declRef); @@ -5280,8 +5280,8 @@ namespace Slang String specializedMangledName = getMangledNameForConformanceWitness(specDeclRef.Substitute(originalTable->subTypeDeclRef), specDeclRef.Substitute(originalTable->supTypeDeclRef)); - if (dstTable && dstTable->mangledName.Length()) - specializedMangledName = dstTable->mangledName; + if (dstTable && getText(dstTable->mangledName).Length()) + specializedMangledName = getText(dstTable->mangledName); // TODO: This is a terrible linear search, and we should // avoid it by building a dictionary ahead of time, @@ -5292,7 +5292,7 @@ namespace Slang auto module = sharedContext->module; for (auto gv = module->getFirstGlobalValue(); gv; gv = gv->getNextValue()) { - if (gv->mangledName == specializedMangledName) + if (getText(gv->mangledName) == specializedMangledName) return (IRWitnessTable*)gv; } } @@ -5311,7 +5311,7 @@ namespace Slang auto specTable = cloneWitnessTableWithoutRegistering(&context, originalTable, dstTable); // Set up the clone to recognize that it is no longer generic - specTable->mangledName = specializedMangledName; + specTable->mangledName = context.getModule()->session->getNameObj(specializedMangledName); specTable->genericDecl = nullptr; // Specialization of witness tables should trigger cascading specializations @@ -5348,9 +5348,10 @@ namespace Slang if (genericFunc->getGenericDecl() == specDeclRef.decl) specMangledName = getMangledName(specDeclRef); else - specMangledName = mangleSpecializedFuncName(genericFunc->mangledName, specDeclRef.substitutions); + specMangledName = mangleSpecializedFuncName(getText(genericFunc->mangledName), specDeclRef.substitutions); + auto specMangledNameObj = sharedContext->module->session->getNameObj(specMangledName); RefPtr<IRSpecSymbol> symb; - if (sharedContext->symbols.TryGetValue(specMangledName, symb)) + if (sharedContext->symbols.TryGetValue(specMangledNameObj, symb)) { return (IRFunc*)(symb->irGlobalValue); } @@ -5360,7 +5361,7 @@ namespace Slang // We can probalby use the same basic context, actually. for (auto gv = sharedContext->module->getFirstGlobalValue(); gv; gv = gv->getNextValue()) { - if (gv->mangledName == specMangledName) + if (gv->mangledName == specMangledNameObj) return (IRFunc*) gv; } @@ -5389,7 +5390,7 @@ namespace Slang auto specFunc = cloneSimpleFuncWithoutRegistering(&context, genericFunc); - specFunc->mangledName = specMangledName; + specFunc->mangledName = context.getModule()->session->getNameObj(specMangledName); // reduce specialized generic level by 1 if (specFunc->specializedGenericLevel >= 0) @@ -5503,7 +5504,7 @@ namespace Slang } // Build dictionary for witness tables - Dictionary<String, IRWitnessTable*> witnessTables; + Dictionary<Name*, IRWitnessTable*> witnessTables; for (auto gv = module->getFirstGlobalValue(); gv; gv = gv->getNextValue()) @@ -5602,7 +5603,7 @@ namespace Slang IRWitnessTable* witnessTable = nullptr; auto srcDeclRef = ((IRDeclRef*)lookupInst->sourceType.get())->declRef; auto interfaceDeclRef = ((IRDeclRef*)lookupInst->interfaceType.get())->declRef; - auto mangledName = getMangledNameForConformanceWitness(srcDeclRef, interfaceDeclRef); + auto mangledName = module->session->getNameObj(getMangledNameForConformanceWitness(srcDeclRef, interfaceDeclRef)); witnessTables.TryGetValue(mangledName, witnessTable); if (!witnessTable) @@ -5610,7 +5611,7 @@ namespace Slang // try specialize the witness table auto genDeclRef = srcDeclRef; genDeclRef.substitutions = createDefaultSubstitutions(module->session, genDeclRef.decl); - auto genName = getMangledNameForConformanceWitness(genDeclRef, interfaceDeclRef); + auto genName = module->session->getNameObj(getMangledNameForConformanceWitness(genDeclRef, interfaceDeclRef)); IRWitnessTable* genTable = nullptr; if (witnessTables.TryGetValue(genName, genTable)) { @@ -5718,7 +5719,7 @@ namespace Slang IRGlobalValue * rs = nullptr; while (globalVar) { - if (globalVar->mangledName == name) + if (getText(globalVar->mangledName) == name) { rs = globalVar; break; @@ -5739,7 +5740,7 @@ namespace Slang WitnessTableSpecializationWorkItem workItem; workItem.srcTable = (IRWitnessTable*)cloneGlobalValue(context, (IRWitnessTable*)(table)); workItem.dstTable = context->builder->createWitnessTable(); - workItem.dstTable->mangledName = getMangledNameForConformanceWitness(subDeclRefType->declRef, subtypeWitness->sup); + workItem.dstTable->mangledName = context->getModule()->session->getNameObj(getMangledNameForConformanceWitness(subDeclRefType->declRef, subtypeWitness->sup)); workItem.specDeclRef = subDeclRefType->declRef; witnessTablesToSpecailize.Add(workItem); table = workItem.dstTable; diff --git a/source/slang/ir.h b/source/slang/ir.h index 3d4899824..8f350827a 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -20,7 +20,7 @@ class FuncType; class Layout; class Type; class Session; - +class Name; struct IRFunc; struct IRGlobalValueWithCode; struct IRInst; @@ -480,7 +480,7 @@ struct IRGlobalValue : IRValue // The mangled name, for a symbol that should have linkage, // or which might have multiple declarations. - String mangledName; + Name* mangledName = nullptr; IRGlobalValue* nextGlobalValue; @@ -500,11 +500,6 @@ struct IRGlobalValue : IRValue void removeFromParent(); void moveToEnd(); - virtual void dispose() override - { - IRValue::dispose(); - mangledName = String(); - } }; /// @brief A global value that potentially holds executable code. diff --git a/source/slang/legalize-types.h b/source/slang/legalize-types.h index 2dffe1db9..0799e804d 100644 --- a/source/slang/legalize-types.h +++ b/source/slang/legalize-types.h @@ -26,6 +26,7 @@ #include "../core/basic.h" #include "syntax.h" #include "type-layout.h" +#include "name.h" namespace Slang { @@ -382,7 +383,7 @@ struct TypeLegalizationContext Dictionary<DeclRef<Decl>, LegalType> mapDeclRefToLegalType; // - Dictionary<String, LegalVal> mapMangledNameToLegalIRValue; + Dictionary<Name*, LegalVal> mapMangledNameToLegalIRValue; }; diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 8c858f4f3..fde52d2e3 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -2812,7 +2812,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> { for (auto subInheritanceDeclRef : getMembersOfType<InheritanceDecl>(baseInterfaceDeclRef)) { - auto cpyMangledName = getMangledNameForConformanceWitness(subType, subInheritanceDeclRef.getDecl()->getSup().type); + auto cpyMangledName = context->getSession()->getNameObj(getMangledNameForConformanceWitness(subType, subInheritanceDeclRef.getDecl()->getSup().type)); if (!witnessTablesDictionary.ContainsKey(cpyMangledName)) { auto cpyTable = context->irBuilder->createWitnessTable(); @@ -2820,14 +2820,14 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> context->irBuilder->createWitnessTableEntry(witnessTable, context->irBuilder->getDeclRefVal(subInheritanceDeclRef), cpyTable); cpyTable->entries = witnessTable->entries; - witnessTablesDictionary.Add(cpyMangledName, cpyTable); + witnessTablesDictionary.Add(cpyTable->mangledName, cpyTable); walkInheritanceHierarchyAndCreateWitnessTableCopies(witnessTable, subType, subInheritanceDeclRef.getDecl()); } } } } - Dictionary<String, IRWitnessTable*> witnessTablesDictionary; + Dictionary<Name*, IRWitnessTable*> witnessTablesDictionary; LoweredValInfo visitInheritanceDecl(InheritanceDecl* inheritanceDecl) { @@ -2859,7 +2859,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> // Construct the mangled name for the witness table, which depends // on the type that is conforming, and the type that it conforms to. - String mangledName = getMangledNameForConformanceWitness(type, superType); + auto mangledName = context->getSession()->getNameObj(getMangledNameForConformanceWitness(type, superType)); // Build an IR level witness table, which will represent the // conformance of the type to its super-type. @@ -2999,7 +2999,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> irGlobal = builder->createGlobalVar(varType); globalVal = LoweredValInfo::ptr(irGlobal); } - irGlobal->mangledName = getMangledName(decl); + irGlobal->mangledName = context->getSession()->getNameObj(getMangledName(decl)); if (decl) { @@ -3458,7 +3458,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> String mangledName = getMangledName(decl); - irFunc->mangledName = mangledName; + irFunc->mangledName = context->getSession()->getNameObj(mangledName); } ModuleDecl* findModuleDecl(Decl* decl) |
