LLVM  8.0.1
WebAssemblyArgumentMove.cpp
Go to the documentation of this file.
1 //===-- WebAssemblyArgumentMove.cpp - Argument instruction moving ---------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file moves ARGUMENT instructions after ScheduleDAG scheduling.
12 ///
13 /// Arguments are really live-in registers, however, since we use virtual
14 /// registers and LLVM doesn't support live-in virtual registers, we're
15 /// currently making do with ARGUMENT instructions which are placed at the top
16 /// of the entry block. The trick is to get them to *stay* at the top of the
17 /// entry block.
18 ///
19 /// The ARGUMENTS physical register keeps these instructions pinned in place
20 /// during liveness-aware CodeGen passes, however one thing which does not
21 /// respect this is the ScheduleDAG scheduler. This pass is therefore run
22 /// immediately after that.
23 ///
24 /// This is all hopefully a temporary solution until we find a better solution
25 /// for describing the live-in nature of arguments.
26 ///
27 //===----------------------------------------------------------------------===//
28 
30 #include "WebAssembly.h"
32 #include "WebAssemblySubtarget.h"
33 #include "WebAssemblyUtilities.h"
36 #include "llvm/CodeGen/Passes.h"
37 #include "llvm/Support/Debug.h"
39 using namespace llvm;
40 
41 #define DEBUG_TYPE "wasm-argument-move"
42 
43 namespace {
44 class WebAssemblyArgumentMove final : public MachineFunctionPass {
45 public:
46  static char ID; // Pass identification, replacement for typeid
47  WebAssemblyArgumentMove() : MachineFunctionPass(ID) {}
48 
49  StringRef getPassName() const override { return "WebAssembly Argument Move"; }
50 
51  void getAnalysisUsage(AnalysisUsage &AU) const override {
52  AU.setPreservesCFG();
56  }
57 
58  bool runOnMachineFunction(MachineFunction &MF) override;
59 };
60 } // end anonymous namespace
61 
63 INITIALIZE_PASS(WebAssemblyArgumentMove, DEBUG_TYPE,
64  "Move ARGUMENT instructions for WebAssembly", false, false)
65 
67  return new WebAssemblyArgumentMove();
68 }
69 
70 bool WebAssemblyArgumentMove::runOnMachineFunction(MachineFunction &MF) {
71  LLVM_DEBUG({
72  dbgs() << "********** Argument Move **********\n"
73  << "********** Function: " << MF.getName() << '\n';
74  });
75 
76  bool Changed = false;
77  MachineBasicBlock &EntryMBB = MF.front();
78  MachineBasicBlock::iterator InsertPt = EntryMBB.end();
79 
80  // Look for the first NonArg instruction.
81  for (MachineInstr &MI : EntryMBB) {
83  InsertPt = MI;
84  break;
85  }
86  }
87 
88  // Now move any argument instructions later in the block
89  // to before our first NonArg instruction.
90  for (MachineInstr &MI : llvm::make_range(InsertPt, EntryMBB.end())) {
92  EntryMBB.insert(InsertPt, MI.removeFromParent());
93  Changed = true;
94  }
95  }
96 
97  return Changed;
98 }
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
FunctionPass * createWebAssemblyArgumentMove()
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
#define DEBUG_TYPE
AnalysisUsage & addPreservedID(const void *ID)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
This file contains the declaration of the WebAssembly-specific utility functions. ...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
This file provides WebAssembly-specific target descriptions.
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
const MachineBasicBlock & front() const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
bool isArgument(const MachineInstr &MI)
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:286
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
Representation of each machine instruction.
Definition: MachineInstr.h:64
This file declares WebAssembly-specific per-machine-function information.
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
#define LLVM_DEBUG(X)
Definition: Debug.h:123
INITIALIZE_PASS(WebAssemblyArgumentMove, DEBUG_TYPE, "Move ARGUMENT instructions for WebAssembly", false, false) FunctionPass *llvm