21#define DEBUG_TYPE "wasm-coalesce-features-and-strip-atomics"
24class WebAssemblyCoalesceFeaturesAndStripAtomicsLegacy final
35 WebAssemblyCoalesceFeaturesAndStripAtomicsLegacy(
39 bool runOnModule(
Module &M)
override;
43char WebAssemblyCoalesceFeaturesAndStripAtomicsLegacy::ID = 0;
45 "Coalesce features and strip atomics",
true,
false)
49 return new WebAssemblyCoalesceFeaturesAndStripAtomicsLegacy(&TM);
56 if (Features[KV.Value])
57 Ret += (
StringRef(
"+") + KV.key() +
",").str();
59 Ret += (
StringRef(
"-") + KV.key() +
",").str();
66static std::pair<FeatureBitset, std::string>
73 bool AnyDefined =
false;
75 if (
F.isDeclaration())
91 F.removeFnAttr(
"target-features");
92 F.removeFnAttr(
"target-cpu");
93 F.addFnAttr(
"target-features", Features);
99 bool Stripped =
false;
124 bool Stripped =
false;
125 for (
auto &GV : M.globals()) {
126 if (GV.isThreadLocal()) {
130 if (
II->getIntrinsicID() == Intrinsic::threadlocal_address &&
131 II->getArgOperand(0) == &GV) {
132 II->replaceAllUsesWith(&GV);
133 II->eraseFromParent();
139 GV.setThreadLocal(
false);
148 if (Features[KV.Value]) {
150 std::string MDKey = (
StringRef(
"wasm-feature-") + KV.key()).str();
174 bool StrippedAtomics =
false;
175 bool StrippedTLS =
false;
181 bool CooperativeThreading = ST->hasCooperativeMultithreading();
183 if (!Features[WebAssembly::FeatureAtomics]) {
185 if (!CooperativeThreading)
188 if (!Features[WebAssembly::FeatureBulkMemory] && !StrippedTLS) {
192 if (StrippedAtomics && !StrippedTLS && !CooperativeThreading)
194 else if (StrippedTLS && !StrippedAtomics)
197 bool Stripped = StrippedAtomics || StrippedTLS;
199 (Features[WebAssembly::FeatureAtomics] ||
200 (CooperativeThreading && Features[WebAssembly::FeatureBulkMemory])) &&
201 !M.getModuleFlag(
"thread-model")) {
211bool WebAssemblyCoalesceFeaturesAndStripAtomicsLegacy::runOnModule(
Module &M) {
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool coalesceFeaturesAndStripAtomics(Module &M, WebAssemblyTargetMachine *WasmTM)
static void recordFeatures(Module &M, const WebAssemblySubtarget *ST, const FeatureBitset &Features, bool Stripped)
static std::string getFeatureString(const MCSubtargetInfo &STI, const FeatureBitset &Features)
static bool stripAtomics(Module &M)
static void replaceFeatures(Function &F, const std::string &Features)
static bool stripThreadLocals(Module &M)
static std::pair< FeatureBitset, std::string > coalesceFeatures(const Module &M, WebAssemblyTargetMachine *WasmTM)
This file declares the WebAssembly-specific subclass of TargetMachine.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
Container class for subtarget features.
A wrapper class for inspecting calls to intrinsic functions.
A pass that lowers atomic intrinsic into non-atomic intrinsics.
Generic base class for all target subtargets.
const FeatureBitset & getFeatureBits() const
ArrayRef< SubtargetFeatureKV > getAllProcessorFeatures() const
Return processor features.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Represent a constant reference to a string, i.e.
const MCSubtargetInfo & getMCSubtargetInfo() const
StringRef getTargetFeatureString() const
StringRef getTargetCPU() const
void setTargetFeatureString(StringRef FS)
A Use represents the edge between a Value definition and its users.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
const WebAssemblySubtarget * getSubtargetImpl(StringRef CPU, StringRef FS) const
Pass manager infrastructure for declaring and invalidating analyses.
@ WASM_FEATURE_PREFIX_USED
@ WASM_FEATURE_PREFIX_DISALLOWED
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
ModulePass * createWebAssemblyCoalesceFeaturesAndStripAtomicsLegacyPass(WebAssemblyTargetMachine &TM)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Used to provide key value pairs for feature and CPU bit flags.