LLVM 20.0.0git
WebAssemblyMCLowerPrePass.cpp
Go to the documentation of this file.
1//===-- WebAssemblyMCLowerPrePass.cpp - Prepare for MC lower --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Some information in MC lowering / asm printing gets generated as
11/// instructions get emitted, but may be necessary at the start, such as for
12/// .globaltype declarations. This pass collects this information.
13///
14//===----------------------------------------------------------------------===//
15
17#include "WebAssembly.h"
28#include "llvm/CodeGen/Passes.h"
29#include "llvm/IR/Module.h"
30#include "llvm/Support/Debug.h"
32using namespace llvm;
33
34#define DEBUG_TYPE "wasm-mclower-prepass"
35
36namespace {
37class WebAssemblyMCLowerPrePass final : public ModulePass {
38 StringRef getPassName() const override {
39 return "WebAssembly MC Lower Pre Pass";
40 }
41
42 void getAnalysisUsage(AnalysisUsage &AU) const override {
43 AU.setPreservesCFG();
45 }
46
47 bool runOnModule(Module &M) override;
48
49public:
50 static char ID; // Pass identification, replacement for typeid
51 WebAssemblyMCLowerPrePass() : ModulePass(ID) {}
52};
53} // end anonymous namespace
54
55char WebAssemblyMCLowerPrePass::ID = 0;
57 WebAssemblyMCLowerPrePass, DEBUG_TYPE,
58 "Collects information ahead of time for MC lowering",
59 false, false)
60
62 return new WebAssemblyMCLowerPrePass();
63}
64
65// NOTE: this is a ModulePass since we need to enforce that this code has run
66// for all functions before AsmPrinter. If this way of doing things is ever
67// suboptimal, we could opt to make it a MachineFunctionPass and instead use
68// something like createBarrierNoopPass() to enforce ordering.
69//
70// The information stored here is essential for emitExternalDecls in the Wasm
71// AsmPrinter
72bool WebAssemblyMCLowerPrePass::runOnModule(Module &M) {
73 auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
74 if (!MMIWP)
75 return true;
76
77 MachineModuleInfo &MMI = MMIWP->getMMI();
79
80 for (Function &F : M) {
82 if (!MF)
83 continue;
84
85 LLVM_DEBUG(dbgs() << "********** MC Lower Pre Pass **********\n"
86 "********** Function: "
87 << MF->getName() << '\n');
88
89 for (MachineBasicBlock &MBB : *MF) {
90 for (auto &MI : MBB) {
91 // FIXME: what should all be filtered out beyond these?
92 if (MI.isDebugInstr() || MI.isInlineAsm())
93 continue;
94 for (MachineOperand &MO : MI.uses()) {
95 if (MO.isSymbol()) {
96 MMIW.MachineSymbolsUsed.insert(MO.getSymbolName());
97 }
98 }
99 }
100 }
101 }
102 return true;
103}
MachineBasicBlock & MBB
#define LLVM_DEBUG(X)
Definition: Debug.h:101
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
#define DEBUG_TYPE
This file provides WebAssembly-specific target descriptions.
This file declares WebAssembly-specific per-machine-function information.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This file contains the declaration of the WebAssembly-specific utility functions.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
Represent the analysis usage information of a pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:256
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineModuleInfoWasm - This is a MachineModuleInfoImpl implementation for Wasm targets.
SetVector< StringRef > MachineSymbolsUsed
This class contains meta information specific to a module.
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
MachineOperand class - Representation of each machine instruction operand.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:251
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:98
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
ModulePass * createWebAssemblyMCLowerPrePass()