34 #define DEBUG_TYPE "wasm" 38 "enable-emscripten-cxx-exceptions",
39 cl::desc(
"WebAssembly Emscripten-style exception handling"),
44 "enable-emscripten-sjlj",
45 cl::desc(
"WebAssembly Emscripten-style setjmp/longjmp handling"),
112 TT.isArch64Bit() ?
"e-m:e-p:64:64-i64:64-n32:64-S128" 113 :
"e-m:e-p:32:32-i64:64-n32:64-S128",
140 std::string FS)
const {
141 auto &
I = SubtargetMap[CPU + FS];
143 I = std::make_unique<WebAssemblySubtarget>(
TargetTriple, CPU, FS, *
this);
170 class CoalesceFeaturesAndStripAtomics final :
public ModulePass {
182 bool runOnModule(
Module &M)
override {
185 std::string FeatureStr = getFeatureString(Features);
187 replaceFeatures(
F, FeatureStr);
189 bool StrippedAtomics =
false;
190 bool StrippedTLS =
false;
192 if (!Features[WebAssembly::FeatureAtomics])
193 StrippedAtomics = stripAtomics(M);
195 if (!Features[WebAssembly::FeatureBulkMemory])
196 StrippedTLS = stripThreadLocals(M);
198 if (StrippedAtomics && !StrippedTLS)
199 stripThreadLocals(M);
200 else if (StrippedTLS && !StrippedAtomics)
203 recordFeatures(M, Features, StrippedAtomics || StrippedTLS);
221 std::string getFeatureString(
const FeatureBitset &Features) {
224 if (Features[KV.Value])
225 Ret += (
StringRef(
"+") + KV.Key +
",").str();
230 void replaceFeatures(
Function &
F,
const std::string &Features) {
233 F.
addFnAttr(
"target-features", Features);
236 bool stripAtomics(
Module &M) {
239 bool Stripped =
false;
263 bool stripThreadLocals(
Module &M) {
264 bool Stripped =
false;
266 if (GV.getThreadLocalMode() !=
267 GlobalValue::ThreadLocalMode::NotThreadLocal) {
269 GV.setThreadLocalMode(GlobalValue::ThreadLocalMode::NotThreadLocal);
277 std::string MDKey = (
StringRef(
"wasm-feature-") + KV.Key).str();
278 if (KV.Value == WebAssembly::FeatureAtomics && Stripped) {
282 assert(!Features[WebAssembly::FeatureAtomics] ||
283 !Features[WebAssembly::FeatureBulkMemory]);
286 }
else if (Features[KV.Value]) {
303 return getTM<WebAssemblyTargetMachine>();
306 FunctionPass *createTargetRegisterAllocator(
bool)
override;
308 void addIRPasses()
override;
309 bool addInstSelector()
override;
310 void addPostRegAlloc()
override;
311 bool addGCPasses()
override {
return false; }
312 void addPreEmitPass()
override;
315 bool addRegAssignmentFast()
override {
return false; }
318 bool addRegAssignmentOptimized()
override {
return false; }
329 return new WebAssemblyPassConfig(*
this, PM);
332 FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(
bool) {
341 void WebAssemblyPassConfig::addIRPasses() {
343 addPass(
new CoalesceFeaturesAndStripAtomics(&getWebAssemblyTargetMachine()));
386 bool WebAssemblyPassConfig::addInstSelector() {
401 void WebAssemblyPassConfig::addPostRegAlloc() {
423 void WebAssemblyPassConfig::addPreEmitPass() {
502 const auto &YamlMFI =
PreservedAnalyses run(Function &F, FunctionAnalysisManager &)
Represents a range in source code.
bool isOSEmscripten() const
Tests whether the OS is Emscripten.
StringRef getTargetFeatureString() const
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
FunctionPass * createWebAssemblyLowerBrUnless()
CodeModel::Model getEffectiveCodeModel(Optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value...
ModulePass * createWebAssemblyLowerEmscriptenEHSjLj(bool DoEH, bool DoSjLj)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
static cl::opt< bool > EnableEmSjLj("enable-emscripten-sjlj", cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"), cl::init(false))
This class represents lattice values for constants.
FunctionPass * createWebAssemblyCFGSort()
void initializeWebAssemblyOptimizeLiveIntervalsPass(PassRegistry &)
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
FunctionPass * createWebAssemblyArgumentMove()
A Module instance is used to store all the information related to an LLVM module. ...
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with...
unsigned DataSections
Emit data into separate sections.
void initializeWebAssemblyMemIntrinsicResultsPass(PassRegistry &)
char & FuncletLayoutID
This pass lays out funclets contiguously.
FunctionPass * createWebAssemblyPeephole()
void initializeWebAssemblyRegStackifyPass(PassRegistry &)
void initializeWebAssemblyArgumentMovePass(PassRegistry &)
yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const override
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
void initializeWebAssemblyFixIrreducibleControlFlowPass(PassRegistry &)
A pass that lowers atomic intrinsic into non-atomic intrinsics.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
virtual void addPreEmitPass()
This pass may be implemented by targets that want to run passes immediately before machine code is em...
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
FunctionPass * createWebAssemblyRegStackify()
FunctionPass * createWebAssemblyOptimizeReturned()
This file declares the WebAssembly-specific subclass of TargetLoweringObjectFile. ...
This file registers the WebAssembly target.
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
FunctionPass * createWebAssemblyRegNumbering()
FunctionPass * createLowerInvokePass()
void initializeWebAssemblyRegNumberingPass(PassRegistry &)
No attributes have been set.
void initializeWebAssemblyExceptionInfoPass(PassRegistry &)
void initializeOptimizeReturnedPass(PassRegistry &)
FunctionPass * createWebAssemblyRegColoring()
Target-Independent Code Generator Pass Configuration Options.
bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange) const override
Parse out the target's MachineFunctionInfo from the YAML reprsentation.
This file declares the WebAssembly-specific subclass of TargetMachine.
RegisterTargetMachine - Helper template for registering a target machine implementation, for use in the target machine initialization function.
const SubtargetFeatureKV WebAssemblyFeatureKV[WebAssembly::NumSubtargetFeatures]
unsigned FunctionSections
Emit functions into separate sections.
Used to provide key value pairs for feature and CPU bit flags.
FunctionPass * createUnreachableBlockEliminationPass()
createUnreachableBlockEliminationPass - The LLVM code generator does not work well with unreachable b...
StringRef getTargetCPU() const
unsigned UniqueSectionNames
ModulePass * createWebAssemblyAddMissingPrototypes()
void initializeWebAssemblyExplicitLocalsPass(PassRegistry &)
initializer< Ty > init(const Ty &Val)
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
void initializeWebAssemblyPeepholePass(PassRegistry &)
Container class for subtarget features.
FunctionPass * createWebAssemblyISelDag(WebAssemblyTargetMachine &TM, CodeGenOpt::Level OptLevel)
This pass converts a legalized DAG into a WebAssembly-specific DAG, ready for instruction scheduling...
static Reloc::Model getEffectiveRelocModel(Optional< Reloc::Model > RM)
FunctionPass * createWebAssemblyCallIndirectFixup()
ModulePass * createWebAssemblyLowerGlobalDtors()
char & PostRAMachineSinkingID
This pass perform post-ra machine sink for COPY instructions.
This file provides WebAssembly-specific target descriptions.
void initializeWebAssemblyCallIndirectFixupPass(PassRegistry &)
virtual bool addInstSelector()
addInstSelector - This method should install an instruction selector pass, which converts from LLVM c...
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
char & LiveDebugValuesID
LiveDebugValues pass.
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
void initializeWebAssemblyReplacePhysRegsPass(PassRegistry &)
FunctionPass class - This class is used to implement most global optimizations.
FunctionPass * createWebAssemblySetP2AlignOperands()
void initializeWebAssemblyLowerEmscriptenEHSjLjPass(PassRegistry &)
char & MachineCopyPropagationID
MachineCopyPropagation - This pass performs copy propagation on machine instructions.
static cl::opt< bool > EnableEmException("enable-emscripten-cxx-exceptions", cl::desc("WebAssembly Emscripten-style exception handling"), cl::init(false))
void initializeWebAssemblyLateEHPreparePass(PassRegistry &)
~WebAssemblyTargetMachine() override
Triple - Helper class for working with autoconf configuration names.
FunctionPass * createIndirectBrExpandPass()
char & PostRASchedulerID
createPostRAScheduler - This pass performs post register allocation scheduling.
ModulePass * createWebAssemblyFixFunctionBitcasts()
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
char & StackMapLivenessID
StackMapLiveness - This pass analyses the register live-out set of stackmap/patchpoint intrinsics and...
yaml::MachineFunctionInfo * convertFuncInfoToYAML(const MachineFunction &MF) const override
Allocate and initialize an instance of the YAML representation of the MachineFunctionInfo.
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
void initializeWebAssemblyLowerBrUnlessPass(PassRegistry &)
FunctionPass * createWebAssemblyMemIntrinsicResults()
FunctionPass * createWebAssemblyFixIrreducibleControlFlow()
Target - Wrapper for Target specific information.
virtual void addPostRegAlloc()
This method may be implemented by targets that want to run passes after register allocation pass pipe...
void initializeWebAssemblyCFGStackifyPass(PassRegistry &)
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
char & PatchableFunctionID
This pass implements the "patchable-function" attribute.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
const WebAssemblySubtarget * getSubtargetImpl(std::string CPU, std::string FS) const
StringRef getValueAsString() const
Return the attribute's value as a string.
FunctionPass * createWebAssemblyLateEHPrepare()
TargetTransformInfo getTargetTransformInfo(const Function &F) override
Get a TargetTransformInfo implementation for the target.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
This file declares WebAssembly-specific per-machine-function information.
char & MachineBlockPlacementID
MachineBlockPlacement - This pass places basic blocks based on branch probabilities.
WebAssemblyTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT)
Create an WebAssembly architecture model.
void LLVMInitializeWebAssemblyTarget()
void initializeWebAssemblyAddMissingPrototypesPass(PassRegistry &)
void initializeFixFunctionBitcastsPass(PassRegistry &)
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
FunctionPass * createWebAssemblyOptimizeLiveIntervals()
FunctionPass * createWebAssemblyCFGStackify()
void initializeWebAssemblyPrepareForLiveIntervalsPass(PassRegistry &)
void initializeWebAssemblySetP2AlignOperandsPass(PassRegistry &)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void initializeLowerGlobalDtorsPass(PassRegistry &)
Lightweight error class with error context and mandatory checking.
FunctionPass * createWebAssemblyPrepareForLiveIntervals()
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
iterator_range< global_iterator > globals()
char & ShrinkWrapID
ShrinkWrap pass. Look for the best place to insert save and restore.
StringRef - Represent a constant reference to a string, i.e.
A container for analyses that lazily runs them and caches their results.
unsigned TrapUnreachable
Emit target-specific trap instruction for 'unreachable' IR instructions.
Target & getTheWebAssemblyTarget32()
FunctionPass * createWebAssemblyReplacePhysRegs()
void initializeWebAssemblyCFGSortPass(PassRegistry &)
FunctionPass * createAtomicExpandPass()
Target & getTheWebAssemblyTarget64()
FunctionPass * createWebAssemblyExplicitLocals()
void initializeWebAssemblyRegColoringPass(PassRegistry &)
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...