LLVM 22.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
16#include "WebAssembly.h"
21#include "llvm/CodeGen/Passes.h"
22#include "llvm/IR/Module.h"
23#include "llvm/Support/Debug.h"
25using namespace llvm;
26
27#define DEBUG_TYPE "wasm-mclower-prepass"
28
29namespace {
30class WebAssemblyMCLowerPrePass final : public ModulePass {
31 StringRef getPassName() const override {
32 return "WebAssembly MC Lower Pre Pass";
33 }
34
35 void getAnalysisUsage(AnalysisUsage &AU) const override {
36 AU.setPreservesCFG();
38 }
39
40 bool runOnModule(Module &M) override;
41
42public:
43 static char ID; // Pass identification, replacement for typeid
44 WebAssemblyMCLowerPrePass() : ModulePass(ID) {}
45};
46} // end anonymous namespace
47
48char WebAssemblyMCLowerPrePass::ID = 0;
50 WebAssemblyMCLowerPrePass, DEBUG_TYPE,
51 "Collects information ahead of time for MC lowering",
52 false, false)
53
55 return new WebAssemblyMCLowerPrePass();
56}
57
58// NOTE: this is a ModulePass since we need to enforce that this code has run
59// for all functions before AsmPrinter. If this way of doing things is ever
60// suboptimal, we could opt to make it a MachineFunctionPass and instead use
61// something like createBarrierNoopPass() to enforce ordering.
62//
63// The information stored here is essential for emitExternalDecls in the Wasm
64// AsmPrinter
65bool WebAssemblyMCLowerPrePass::runOnModule(Module &M) {
66 auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
67 if (!MMIWP)
68 return true;
69
70 MachineModuleInfo &MMI = MMIWP->getMMI();
71 MachineModuleInfoWasm &MMIW = MMI.getObjFileInfo<MachineModuleInfoWasm>();
72
73 for (Function &F : M) {
74 MachineFunction *MF = MMI.getMachineFunction(F);
75 if (!MF)
76 continue;
77
78 LLVM_DEBUG(dbgs() << "********** MC Lower Pre Pass **********\n"
79 "********** Function: "
80 << MF->getName() << '\n');
81
82 for (MachineBasicBlock &MBB : *MF) {
83 for (auto &MI : MBB) {
84 // FIXME: what should all be filtered out beyond these?
85 if (MI.isDebugInstr() || MI.isInlineAsm())
86 continue;
87 for (MachineOperand &MO : MI.uses()) {
88 if (MO.isSymbol()) {
89 MMIW.MachineSymbolsUsed.insert(MO.getSymbolName());
90 }
91 }
92 }
93 }
94 }
95 return true;
96}
MachineBasicBlock & MBB
#define DEBUG_TYPE
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:55
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
#define LLVM_DEBUG(...)
Definition Debug.h:119
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.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:270
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
SetVector< StringRef > MachineSymbolsUsed
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
LLVM_ABI MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:255
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition Pass.cpp:112
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
ModulePass * createWebAssemblyMCLowerPrePass()