diff options
Diffstat (limited to 'source/slang/slang-ir-link.cpp')
| -rw-r--r-- | source/slang/slang-ir-link.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index 4e6ad74a4..e556fd738 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -89,6 +89,25 @@ struct IRSpecContextBase } }; +enum class GlobalValueClass +{ + StructKey, + Other +}; + +// Get the "class" of a global value. If there are more than one value of the same class, +// only one value in each class will be selected during linking. +GlobalValueClass getGlobalValueClass(IRInst* value) +{ + switch (value->op) + { + case kIROp_StructKey: + return GlobalValueClass::StructKey; + default: + return GlobalValueClass::Other; + } +} + void registerClonedValue( IRSpecContextBase* context, IRInst* clonedValue, @@ -128,9 +147,11 @@ void registerClonedValue( IROriginalValuesForClone const& originalValues) { registerClonedValue(context, clonedValue, originalValues.originalVal); + auto valueClass = getGlobalValueClass(clonedValue); for( auto s = originalValues.sym; s; s = s->nextWithSameName ) { - registerClonedValue(context, clonedValue, s->irGlobalValue); + if (getGlobalValueClass(s->irGlobalValue) == valueClass) + registerClonedValue(context, clonedValue, s->irGlobalValue); } } @@ -1153,7 +1174,6 @@ IRInst* cloneGlobalValueImpl( return clonedValue; } - /// Clone a global value, which has the given `originalLinkage`. /// /// The `originalVal` is a known global IR value with that linkage, if one is available. @@ -1214,10 +1234,12 @@ IRInst* cloneGlobalValueWithLinkage( // definitions over declarations. // IRInst* bestVal = nullptr; + auto valueClass = getGlobalValueClass(originalVal); for(IRSpecSymbol* ss = sym; ss; ss = ss->nextWithSameName ) { IRInst* newVal = ss->irGlobalValue; - if(isBetterForTarget(context, newVal, bestVal)) + if (getGlobalValueClass(newVal) == valueClass && + isBetterForTarget(context, newVal, bestVal)) bestVal = newVal; } |
