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"),
54 cl::desc(
"WebAssembly: output implicit locals in" 55 " instruction output for test purposes only."),
105 if (!TT.isOSEmscripten()) {
122 TT.isArch64Bit() ?
"e-m:e-p:64:64-i64:64-n32:64-S128" 123 :
"e-m:e-p:32:32-i64:64-n32:64-S128",
155 std::string
FS)
const {
156 auto &
I = SubtargetMap[CPU +
FS];
158 I = std::make_unique<WebAssemblySubtarget>(
TargetTriple, CPU,
FS, *
this);
165 Attribute CPUAttr =
F.getFnAttribute(
"target-cpu");
166 Attribute FSAttr =
F.getFnAttribute(
"target-features");
183 class CoalesceFeaturesAndStripAtomics final :
public ModulePass {
195 bool runOnModule(
Module &M)
override {
198 std::string FeatureStr = getFeatureString(Features);
201 replaceFeatures(
F, FeatureStr);
203 bool StrippedAtomics =
false;
204 bool StrippedTLS =
false;
206 if (!Features[WebAssembly::FeatureAtomics])
207 StrippedAtomics = stripAtomics(M);
209 if (!Features[WebAssembly::FeatureBulkMemory])
210 StrippedTLS = stripThreadLocals(M);
212 if (StrippedAtomics && !StrippedTLS)
213 stripThreadLocals(M);
214 else if (StrippedTLS && !StrippedAtomics)
217 recordFeatures(M, Features, StrippedAtomics || StrippedTLS);
235 std::string getFeatureString(
const FeatureBitset &Features) {
238 if (Features[KV.Value])
244 void replaceFeatures(
Function &
F,
const std::string &Features) {
245 F.removeFnAttr(
"target-features");
246 F.removeFnAttr(
"target-cpu");
247 F.addFnAttr(
"target-features", Features);
250 bool stripAtomics(
Module &M) {
253 bool Stripped =
false;
277 bool stripThreadLocals(
Module &M) {
278 bool Stripped =
false;
279 for (
auto &GV :
M.globals()) {
280 if (GV.isThreadLocal()) {
282 GV.setThreadLocal(
false);
290 if (Features[KV.Value]) {
292 std::string MDKey = (
StringRef(
"wasm-feature-") + KV.Key).str();
317 return getTM<WebAssemblyTargetMachine>();
320 FunctionPass *createTargetRegisterAllocator(
bool)
override;
322 void addIRPasses()
override;
323 bool addInstSelector()
override;
324 void addPostRegAlloc()
override;
325 bool addGCPasses()
override {
return false; }
326 void addPreEmitPass()
override;
329 bool addRegAssignAndRewriteFast()
override {
return false; }
332 bool addRegAssignAndRewriteOptimized()
override {
return false; }
343 return new WebAssemblyPassConfig(*
this, PM);
346 FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(
bool) {
355 void WebAssemblyPassConfig::addIRPasses() {
357 addPass(
new CoalesceFeaturesAndStripAtomics(&getWebAssemblyTargetMachine()));
400 bool WebAssemblyPassConfig::addInstSelector() {
419 void WebAssemblyPassConfig::addPostRegAlloc() {
441 void WebAssemblyPassConfig::addPreEmitPass() {
521 const auto &YamlMFI =
522 reinterpret_cast<const yaml::WebAssemblyFunctionInfo &>(MFI);
PreservedAnalyses run(Function &F, FunctionAnalysisManager &)
static cl::opt< bool > WasmDisableExplicitLocals("wasm-disable-explicit-locals", cl::Hidden, cl::desc("WebAssembly: output implicit locals in" " instruction output for test purposes only."), cl::init(false))
Represents a range in source code.
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.
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 &)
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,...
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()
WebAssembly Exception Handling.
bool isValid() const
Return true if the attribute is any kind of attribute.
void initializeWebAssemblyDebugFixupPass(PassRegistry &)
void initializeWebAssemblyExplicitLocalsPass(PassRegistry &)
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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)
ModulePass * createWebAssemblyLowerGlobalDtors()
char & PostRAMachineSinkingID
This pass perform post-ra machine sink for COPY instructions.
This file provides WebAssembly-specific target descriptions.
const WebAssemblySubtarget * getSubtargetImpl() const
virtual bool addInstSelector()
addInstSelector - This method should install an instruction selector pass, which converts from LLVM c...
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 setTargetFeatureString(StringRef FS)
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.
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
PostRAScheduler - This pass performs post register allocation scheduling.
ModulePass * createWebAssemblyFixFunctionBitcasts()
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyTarget()
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 ...
#define LLVM_EXTERNAL_VISIBILITY
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 &)
FunctionPass * createWebAssemblyFixBrTableDefaults()
FunctionPass * createWebAssemblyDebugFixup()
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 ...
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 initializeWebAssemblyAddMissingPrototypesPass(PassRegistry &)
void initializeFixFunctionBitcastsPass(PassRegistry &)
FunctionPass * createWebAssemblyOptimizeLiveIntervals()
FunctionPass * createWebAssemblyCFGStackify()
void initializeWebAssemblyPrepareForLiveIntervalsPass(PassRegistry &)
void initializeWebAssemblySetP2AlignOperandsPass(PassRegistry &)
void initializeLowerGlobalDtorsPass(PassRegistry &)
Lightweight error class with error context and mandatory checking.
FunctionPass * createWebAssemblyPrepareForLiveIntervals()
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...