20#define DEBUG_TYPE "wasm-coalesce-features-and-strip-atomics"
23class WebAssemblyCoalesceFeaturesAndStripAtomicsLegacy final
34 WebAssemblyCoalesceFeaturesAndStripAtomicsLegacy(
38 bool runOnModule(
Module &M)
override;
42char WebAssemblyCoalesceFeaturesAndStripAtomicsLegacy::ID = 0;
44 "Coalesce features and strip atomics",
true,
false)
48 return new WebAssemblyCoalesceFeaturesAndStripAtomicsLegacy(&TM);
55 if (Features[KV.Value])
56 Ret += (
StringRef(
"+") + KV.key() +
",").str();
58 Ret += (
StringRef(
"-") + KV.key() +
",").str();
65static std::pair<FeatureBitset, std::string>
75 if (
F.isDeclaration())
79 Features |= AnyST->getFeatureBits();
88 Features = AnyST->getFeatureBits();
95 F.removeFnAttr(
"target-features");
96 F.removeFnAttr(
"target-cpu");
97 F.addFnAttr(
"target-features", Features);
103 bool Stripped =
false;
128 bool Stripped =
false;
129 for (
auto &GV : M.globals()) {
130 if (GV.isThreadLocal()) {
134 if (
II->getIntrinsicID() == Intrinsic::threadlocal_address &&
135 II->getArgOperand(0) == &GV) {
136 II->replaceAllUsesWith(&GV);
137 II->eraseFromParent();
143 GV.setThreadLocal(
false);
152 if (Features[KV.Value]) {
154 std::string MDKey = (
StringRef(
"wasm-feature-") + KV.key()).str();
178 bool StrippedAtomics =
false;
179 bool StrippedTLS =
false;
184 bool CooperativeThreading = ST->hasCooperativeMultithreading();
186 if (!Features[WebAssembly::FeatureAtomics]) {
188 if (!CooperativeThreading)
191 if (!Features[WebAssembly::FeatureBulkMemory] && !StrippedTLS) {
195 if (StrippedAtomics && !StrippedTLS && !CooperativeThreading)
197 else if (StrippedTLS && !StrippedAtomics)
206bool 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 std::string getFeatureString(const WebAssemblySubtarget *ST, const FeatureBitset &Features)
static bool coalesceFeaturesAndStripAtomics(Module &M, WebAssemblyTargetMachine *WasmTM)
static void recordFeatures(Module &M, const WebAssemblySubtarget *ST, const FeatureBitset &Features, bool Stripped)
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.
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.
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() const
Pass manager infrastructure for declaring and invalidating analyses.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ 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.