LLVM: lib/Target/Hexagon/HexagonFixupHwLoops.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

24

25using namespace llvm;

26

29 cl::desc("Restrict range of loopN instructions (testing only)"));

30

31namespace {

33 public:

34 static char ID;

35

37

38 bool runOnMachineFunction(MachineFunction &MF) override;

39

40 MachineFunctionProperties getRequiredProperties() const override {

41 return MachineFunctionProperties().setNoVRegs();

42 }

43

44 StringRef getPassName() const override {

45 return "Hexagon Hardware Loop Fixup";

46 }

47

48 void getAnalysisUsage(AnalysisUsage &AU) const override {

51 }

52

53 private:

54

55

56

57 bool fixupLoopInstrs(MachineFunction &MF);

58

59

60

61 void useExtLoopInstr(MachineFunction &MF,

63 };

64

65 char HexagonFixupHwLoops::ID = 0;

66}

67

69 "Hexagon Hardware Loops Fixup", false, false)

70

72 return new HexagonFixupHwLoops();

73}

74

75

77 return MI.getOpcode() == Hexagon::J2_loop0r ||

78 MI.getOpcode() == Hexagon::J2_loop0i ||

79 MI.getOpcode() == Hexagon::J2_loop1r ||

80 MI.getOpcode() == Hexagon::J2_loop1i;

81}

82

83bool HexagonFixupHwLoops::runOnMachineFunction(MachineFunction &MF) {

85 return false;

86 return fixupLoopInstrs(MF);

87}

88

89

90

91

92

93

94

95

96

97bool HexagonFixupHwLoops::fixupLoopInstrs(MachineFunction &MF) {

98

99

100 unsigned InstOffset = 0;

101

102 DenseMap<const MachineBasicBlock *, unsigned> BlockToInstOffset;

103

104 const HexagonInstrInfo *HII =

105 static_cast<const HexagonInstrInfo *>(MF.getSubtarget().getInstrInfo());

106

107

108 for (const MachineBasicBlock &MBB : MF) {

110

111

112

114 }

115

116 BlockToInstOffset[&MBB] = InstOffset;

117 for (const MachineInstr &MI : MBB)

119 }

120

121

122

124 for (MachineBasicBlock &MBB : MF) {

125 InstOffset = BlockToInstOffset[&MBB];

126

127

130 while (MII != MIE) {

131 unsigned InstSize = HII->getSize(*MII);

132 if (MII->isMetaInstruction()) {

133 ++MII;

134 continue;

135 }

137 assert(MII->getOperand(0).isMBB() &&

138 "Expect a basic block as loop operand");

139 MachineBasicBlock *TargetBB = MII->getOperand(0).getMBB();

141 BlockToInstOffset[TargetBB]);

143 useExtLoopInstr(MF, MII);

146 } else {

147 ++MII;

148 }

149 } else {

150 ++MII;

151 }

152 InstOffset += InstSize;

153 }

154 }

155

157}

158

159

160void HexagonFixupHwLoops::useExtLoopInstr(MachineFunction &MF,

163 MachineBasicBlock *MBB = MII->getParent();

165 MachineInstrBuilder MIB;

166 unsigned newOp;

167 switch (MII->getOpcode()) {

168 case Hexagon::J2_loop0r:

169 newOp = Hexagon::J2_loop0rext;

170 break;

171 case Hexagon::J2_loop0i:

172 newOp = Hexagon::J2_loop0iext;

173 break;

174 case Hexagon::J2_loop1r:

175 newOp = Hexagon::J2_loop1rext;

176 break;

177 case Hexagon::J2_loop1i:

178 newOp = Hexagon::J2_loop1iext;

179 break;

180 default:

182 }

184

185 for (unsigned i = 0; i < MII->getNumOperands(); ++i)

186 MIB.add(MII->getOperand(i));

187}

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

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

This file defines the DenseMap class.

const HexagonInstrInfo * TII

static cl::opt< unsigned > MaxLoopRange("hexagon-loop-range", cl::Hidden, cl::init(200), cl::desc("Restrict range of loopN instructions (testing only)"))

static bool isHardwareLoop(const MachineInstr &MI)

Returns true if the instruction is a hardware loop instruction.

Definition HexagonFixupHwLoops.cpp:76

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

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.

unsigned getSize(const MachineInstr &MI) const

LLVM_ABI instr_iterator erase(instr_iterator I)

Remove an instruction from the instruction list and delete it.

Align getAlignment() const

Return alignment of the basic block.

MachineInstrBundleIterator< MachineInstr > iterator

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.

const MachineInstrBuilder & add(const MachineOperand &MO) const

Representation of each machine instruction.

virtual const TargetInstrInfo * getInstrInfo() const

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

constexpr char Align[]

Key for Kernel::Arg::Metadata::mAlign.

unsigned ID

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

initializer< Ty > init(const Ty &Val)

This is an optimization pass for GlobalISel generic memory operations.

MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)

Builder interface. Specify how to create the initial instruction itself.

FunctionPass * createHexagonFixupHwLoops()

uint64_t alignTo(uint64_t Size, Align A)

Returns a multiple of A needed to store Size bytes.

constexpr T AbsoluteDifference(U X, V Y)

Subtract two unsigned integers, X and Y, of type T and return the absolute value of the result.