LLVM  14.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 
18 #include "WebAssembly.h"
20 #include "WebAssemblySubtarget.h"
21 #include "llvm/ADT/SCCIterator.h"
28 #include "llvm/CodeGen/Passes.h"
29 #include "llvm/Support/Debug.h"
31 using namespace llvm;
32 
33 #define DEBUG_TYPE "wasm-mclower-prepass"
34 
35 namespace {
36 class WebAssemblyMCLowerPrePass final : public ModulePass {
37  StringRef getPassName() const override {
38  return "WebAssembly MC Lower Pre Pass";
39  }
40 
41  void getAnalysisUsage(AnalysisUsage &AU) const override {
42  AU.setPreservesCFG();
44  }
45 
46  bool runOnModule(Module &M) override;
47 
48 public:
49  static char ID; // Pass identification, replacement for typeid
50  WebAssemblyMCLowerPrePass() : ModulePass(ID) {}
51 };
52 } // end anonymous namespace
53 
56  WebAssemblyMCLowerPrePass, DEBUG_TYPE,
57  "Collects information ahead of time for MC lowering",
58  false, false)
59 
61  return new WebAssemblyMCLowerPrePass();
62 }
63 
64 // NOTE: this is a ModulePass since we need to enforce that this code has run
65 // for all functions before AsmPrinter. If this way of doing things is ever
66 // suboptimal, we could opt to make it a MachineFunctionPass and instead use
67 // something like createBarrierNoopPass() to enforce ordering.
68 bool WebAssemblyMCLowerPrePass::runOnModule(Module &M) {
69  auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
70  if (!MMIWP)
71  return true;
72 
73  MachineModuleInfo &MMI = MMIWP->getMMI();
75 
76  for (Function &F : M) {
78  if (!MF)
79  continue;
80 
81  LLVM_DEBUG(dbgs() << "********** MC Lower Pre Pass **********\n"
82  "********** Function: "
83  << MF->getName() << '\n');
84 
85  for (MachineBasicBlock &MBB : *MF) {
86  for (auto &MI : MBB) {
87  // FIXME: what should all be filtered out beyond these?
88  if (MI.isDebugInstr() || MI.isInlineAsm())
89  continue;
90  for (MachineOperand &MO : MI.uses()) {
91  if (MO.isSymbol()) {
92  MMIW.MachineSymbolsUsed.insert(MO.getSymbolName());
93  }
94  }
95  }
96  }
97  }
98  return true;
99 }
MachineModuleInfoImpls.h
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
WebAssembly.h
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:238
SCCIterator.h
llvm::MachineModuleInfoWasm::MachineSymbolsUsed
StringSet MachineSymbolsUsed
Definition: MachineModuleInfoImpls.h:113
llvm::Function
Definition: Function.h:62
llvm::StringSet::insert
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:33
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
F
#define F(x, y, z)
Definition: MD5.cpp:56
MachineRegisterInfo.h
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
MachineLoopInfo.h
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:78
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
WebAssemblyUtilities.h
WebAssemblyMCTargetDesc.h
INITIALIZE_PASS
INITIALIZE_PASS(WebAssemblyMCLowerPrePass, DEBUG_TYPE, "Collects information ahead of time for MC lowering", false, false) ModulePass *llvm
Definition: WebAssemblyMCLowerPrePass.cpp:55
Passes.h
llvm::createWebAssemblyMCLowerPrePass
ModulePass * createWebAssemblyMCLowerPrePass()
llvm::MachineFunction::getName
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Definition: MachineFunction.cpp:542
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
WebAssemblyMachineFunctionInfo.h
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:253
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MachineModuleInfoWasm
MachineModuleInfoWasm - This is a MachineModuleInfoImpl implementation for Wasm targets.
Definition: MachineModuleInfoImpls.h:107
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::MachineModuleInfo::getMachineFunction
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
Definition: MachineModuleInfo.cpp:286
MachineFrameInfo.h
WebAssemblySubtarget.h
MachineInstrBuilder.h
DEBUG_TYPE
#define DEBUG_TYPE
Definition: WebAssemblyMCLowerPrePass.cpp:33
llvm::Pass::getAnalysisUsage
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:93
raw_ostream.h
MachineFunction.h
Debug.h
llvm::MachineModuleInfo::getObjFileInfo
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
Definition: MachineModuleInfo.h:191
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37