diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | 41 | ||||
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.h | 6 |
3 files changed, 34 insertions, 22 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index c50c6476ec5..436076f33b9 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1697,9 +1697,6 @@ MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal( getContext().getWasmSection(Name, Kind, Group, MCContext::GenericSectionID); - if (TM.Options.ThreadModel != ThreadModel::Single) - Section->setPassive(); - return Section; } @@ -1730,11 +1727,7 @@ static MCSectionWasm *selectWasmSectionForGlobal( (*NextUniqueID)++; } - MCSectionWasm* Section = Ctx.getWasmSection(Name, Kind, Group, UniqueID); - if (Section->isWasmData() && TM.Options.ThreadModel != ThreadModel::Single) - Section->setPassive(); - - return Section; + return Ctx.getWasmSection(Name, Kind, Group, UniqueID); } MCSection *TargetLoweringObjectFileWasm::SelectSectionForGlobal( diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 8e8b4878c52..768ab7a099c 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -115,6 +115,10 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine( initAsmInfo(); + // Create a subtarget using the unmodified target machine features to + // initialize the used feature set with explicitly enabled features. + getSubtargetImpl(getTargetCPU(), getTargetFeatureString()); + // Note that we don't use setRequiresStructuredCFG(true). It disables // optimizations than we're ok with, and want, such as critical edge // splitting and tail merging. @@ -123,6 +127,17 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine( WebAssemblyTargetMachine::~WebAssemblyTargetMachine() = default; // anchor. const WebAssemblySubtarget * +WebAssemblyTargetMachine::getSubtargetImpl(std::string CPU, + std::string FS) const { + auto &I = SubtargetMap[CPU + FS]; + if (!I) { + I = llvm::make_unique<WebAssemblySubtarget>(TargetTriple, CPU, FS, *this); + UsedFeatures |= I->getFeatureBits(); + } + return I.get(); +} + +const WebAssemblySubtarget * WebAssemblyTargetMachine::getSubtargetImpl(const Function &F) const { Attribute CPUAttr = F.getFnAttribute("target-cpu"); Attribute FSAttr = F.getFnAttribute("target-features"); @@ -134,15 +149,12 @@ WebAssemblyTargetMachine::getSubtargetImpl(const Function &F) const { ? FSAttr.getValueAsString().str() : TargetFS; - auto &I = SubtargetMap[CPU + FS]; - if (!I) { - // This needs to be done before we create a new subtarget since any - // creation will depend on the TM and the code generation flags on the - // function that reside in TargetOptions. - resetTargetOptions(F); - I = llvm::make_unique<WebAssemblySubtarget>(TargetTriple, CPU, FS, *this); - } - return I.get(); + // This needs to be done before we create a new subtarget since any + // creation will depend on the TM and the code generation flags on the + // function that reside in TargetOptions. + resetTargetOptions(F); + + return getSubtargetImpl(CPU, FS); } namespace { @@ -202,14 +214,15 @@ FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) { //===----------------------------------------------------------------------===// void WebAssemblyPassConfig::addIRPasses() { - if (TM->Options.ThreadModel == ThreadModel::Single) { - // In "single" mode, atomics get lowered to non-atomics. - addPass(createLowerAtomicPass()); - addPass(new StripThreadLocal()); - } else { + if (static_cast<WebAssemblyTargetMachine *>(TM) + ->getUsedFeatures()[WebAssembly::FeatureAtomics]) { // Expand some atomic operations. WebAssemblyTargetLowering has hooks which // control specifically what gets lowered. addPass(createAtomicExpandPass()); + } else { + // If atomics are not enabled, they get lowered to non-atomics. + addPass(createLowerAtomicPass()); + addPass(new StripThreadLocal()); } // Add signatures to prototype-less function declarations diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.h b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.h index e13ad7d4eac..0630797fe81 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.h +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.h @@ -23,6 +23,7 @@ namespace llvm { class WebAssemblyTargetMachine final : public LLVMTargetMachine { std::unique_ptr<TargetLoweringObjectFile> TLOF; mutable StringMap<std::unique_ptr<WebAssemblySubtarget>> SubtargetMap; + mutable FeatureBitset UsedFeatures; public: WebAssemblyTargetMachine(const Target &T, const Triple &TT, StringRef CPU, @@ -32,6 +33,9 @@ public: bool JIT); ~WebAssemblyTargetMachine() override; + + const WebAssemblySubtarget *getSubtargetImpl(std::string CPU, + std::string FS) const; const WebAssemblySubtarget * getSubtargetImpl(const Function &F) const override; @@ -42,6 +46,8 @@ public: return TLOF.get(); } + FeatureBitset getUsedFeatures() const { return UsedFeatures; } + TargetTransformInfo getTargetTransformInfo(const Function &F) override; bool usesPhysRegsForPEI() const override { return false; } |