LLVM: lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

25using namespace llvm;

26

27#define DEBUG_TYPE "wasm-reg-numbering"

28

29namespace {

31 StringRef getPassName() const override {

32 return "WebAssembly Register Numbering";

33 }

34

35 void getAnalysisUsage(AnalysisUsage &AU) const override {

38 }

39

41

42public:

43 static char ID;

45};

46}

47

48char WebAssemblyRegNumbering::ID = 0;

50 "Assigns WebAssembly register numbers for virtual registers",

51 false, false)

52

54 return new WebAssemblyRegNumbering();

55}

56

57bool WebAssemblyRegNumbering::runOnMachineFunction(MachineFunction &MF) {

58 LLVM_DEBUG(dbgs() << "********** Register Numbering **********\n"

59 "********** Function: "

61

62 WebAssemblyFunctionInfo &MFI = *MF.getInfo();

64

66

67

68

69 MachineBasicBlock &EntryMBB = MF.front();

70 for (MachineInstr &MI : EntryMBB) {

72 break;

73

74 int64_t Imm = MI.getOperand(1).getImm();

76 << " -> WAReg " << Imm << "\n");

77 MFI.setWAReg(MI.getOperand(0).getReg(), Imm);

78 }

79

80

81

82

84 unsigned NumStackRegs = 0;

85

86 unsigned CurReg = MFI.getParams().size();

87 for (unsigned VRegIdx = 0; VRegIdx < NumVRegs; ++VRegIdx) {

88 Register VReg = Register::index2VirtReg(VRegIdx);

89

90 if (MRI.use_empty(VReg))

91 continue;

92

95 << (INT32_MIN | NumStackRegs) << "\n");

96 MFI.setWAReg(VReg, INT32_MIN | NumStackRegs++);

97 continue;

98 }

101 << "\n");

102 MFI.setWAReg(VReg, CurReg++);

103 }

104 }

105

106 return true;

107}

unsigned const MachineRegisterInfo * MRI

Promote Memory to Register

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

This file provides WebAssembly-specific target descriptions.

This file declares WebAssembly-specific per-machine-function information.

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:

FunctionPass class - This class is used to implement most global optimizations.

MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.

StringRef getName() const

getName - Return the name of the corresponding LLVM function.

MachineRegisterInfo & getRegInfo()

getRegInfo - Return information about the registers currently in use.

Ty * getInfo()

getInfo - Keep track of various per-function pieces of information for backends that would like to do...

const MachineBasicBlock & front() const

unsigned getNumVirtRegs() const

getNumVirtRegs - Return the number of virtual registers created.

StringRef - Represent a constant reference to a string, i.e.

void initWARegs(MachineRegisterInfo &MRI)

bool isVRegStackified(Register VReg) const

void setWAReg(Register VReg, unsigned WAReg)

unsigned getWAReg(Register VReg) const

const std::vector< MVT > & getParams() const

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

bool isArgument(unsigned Opc)

static const unsigned UnusedReg

This is an optimization pass for GlobalISel generic memory operations.

FunctionPass * createWebAssemblyRegNumbering()

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)

Prints virtual and physical registers with or without a TRI instance.