diff options
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 3fe6ccf..83cd57d 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -233,13 +233,30 @@ public: private: FeatureBitset coalesceFeatures(const Module &M) { - FeatureBitset Features = - WasmTM - ->getSubtargetImpl(std::string(WasmTM->getTargetCPU()), - std::string(WasmTM->getTargetFeatureString())) - ->getFeatureBits(); - for (auto &F : M) + // Union the features of all defined functions. Start with an empty set, so + // that if a feature is disabled in every function, we'll compute it as + // disabled. If any function lacks a target-features attribute, it'll + // default to the target CPU from the `TargetMachine`. + FeatureBitset Features; + bool AnyDefinedFuncs = false; + for (auto &F : M) { + if (F.isDeclaration()) + continue; + Features |= WasmTM->getSubtargetImpl(F)->getFeatureBits(); + AnyDefinedFuncs = true; + } + + // If we have no defined functions, use the target CPU from the + // `TargetMachine`. + if (!AnyDefinedFuncs) { + Features = + WasmTM + ->getSubtargetImpl(std::string(WasmTM->getTargetCPU()), + std::string(WasmTM->getTargetFeatureString())) + ->getFeatureBits(); + } + return Features; } |