LLVM: lib/Target/LoongArch/LoongArchDeadRegisterDefinitions.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

20

21using namespace llvm;

22#define DEBUG_TYPE "loongarch-dead-defs"

23#define LoongArch_DEAD_REG_DEF_NAME "LoongArch Dead register definitions"

24

25STATISTIC(NumDeadDefsReplaced, "Number of dead definitions replaced");

26

27namespace {

29public:

30 static char ID;

31

33 bool runOnMachineFunction(MachineFunction &MF) override;

34 void getAnalysisUsage(AnalysisUsage &AU) const override {

36 AU.addRequired();

38 AU.addRequired();

40 AU.addPreserved();

43 }

44

46};

47}

48

49char LoongArchDeadRegisterDefinitions::ID = 0;

52

54 return new LoongArchDeadRegisterDefinitions();

55}

56

57bool LoongArchDeadRegisterDefinitions::runOnMachineFunction(

60 return false;

61

63 LiveIntervals &LIS = getAnalysis().getLIS();

64 LLVM_DEBUG(dbgs() << "***** LoongArchDeadRegisterDefinitions *****\n");

65

66 bool MadeChange = false;

67 for (MachineBasicBlock &MBB : MF) {

68 for (MachineInstr &MI : MBB) {

69

70 const MCInstrDesc &Desc = MI.getDesc();

71 if (Desc.mayLoad() && Desc.mayStore() &&

72 Desc.hasUnmodeledSideEffects())

73 continue;

74 for (int I = 0, E = Desc.getNumDefs(); I != E; ++I) {

75 MachineOperand &MO = MI.getOperand(I);

77 continue;

78

79 if (MI.isRegTiedToUseOperand(I)) {

80 LLVM_DEBUG(dbgs() << " Ignoring, def is tied operand.\n");

81 continue;

82 }

85 continue;

86 LLVM_DEBUG(dbgs() << " Dead def operand #" << I << " in:\n ";

88 const TargetRegisterClass *RC = TII->getRegClass(Desc, I);

89 if (!(RC && RC->contains(LoongArch::R0))) {

90 LLVM_DEBUG(dbgs() << " Ignoring, register is not a GPR.\n");

91 continue;

92 }

95 MO.setReg(LoongArch::R0);

96 LLVM_DEBUG(dbgs() << " Replacing with zero register. New:\n ";

98 ++NumDeadDefsReplaced;

99 MadeChange = true;

100 }

101 }

102 }

103

104 return MadeChange;

105}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

const HexagonInstrInfo * TII

#define LoongArch_DEAD_REG_DEF_NAME

Definition LoongArchDeadRegisterDefinitions.cpp:23

Promote Memory to Register

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

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

#define STATISTIC(VARNAME, DESC)

AnalysisUsage & addRequired()

AnalysisUsage & addPreserved()

Add the specified Pass class to the set of analyses preserved by this 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.

bool hasInterval(Register Reg) const

void removeInterval(Register Reg)

Interval removal.

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.

const TargetSubtargetInfo & getSubtarget() const

getSubtarget - Return the subtarget for which this machine code is being compiled.

Function & getFunction()

Return the LLVM function that this machine code represents.

bool isReg() const

isReg - Tests if this is a MO_Register operand.

LLVM_ABI void setReg(Register Reg)

Change the register this operand corresponds to.

bool isEarlyClobber() const

Register getReg() const

getReg - Returns the register number.

virtual void print(raw_ostream &OS, const Module *M) const

print - Print out the internal state of the pass.

constexpr bool isVirtual() const

Return true if the specified register number is in the virtual register namespace.

bool contains(Register Reg) const

Return true if the specified register is included in this register class.

virtual const TargetInstrInfo * getInstrInfo() const

unsigned ID

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

This is an optimization pass for GlobalISel generic memory operations.

FunctionPass * createLoongArchDeadRegisterDefinitionsPass()

LLVM_ABI raw_ostream & dbgs()

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