1 //===- ARCExpandPseudosPass - ARC expand pseudo loads -----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This pass expands stores with large offsets into an appropriate sequence.
10 //===----------------------------------------------------------------------===//
13 #include "ARCInstrInfo.h"
14 #include "ARCRegisterInfo.h"
15 #include "ARCSubtarget.h"
16 #include "llvm/ADT/Statistic.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/CodeGen/MachineInstrBuilder.h"
19 #include "llvm/CodeGen/MachineRegisterInfo.h"
23 #define DEBUG_TYPE "arc-expand-pseudos"
27 class ARCExpandPseudos
: public MachineFunctionPass
{
30 ARCExpandPseudos() : MachineFunctionPass(ID
) {}
32 bool runOnMachineFunction(MachineFunction
&Fn
) override
;
34 StringRef
getPassName() const override
{ return "ARC Expand Pseudos"; }
37 void ExpandStore(MachineFunction
&, MachineBasicBlock::iterator
);
39 const ARCInstrInfo
*TII
;
42 char ARCExpandPseudos::ID
= 0;
44 } // end anonymous namespace
46 static unsigned getMappedOp(unsigned PseudoOp
) {
55 llvm_unreachable("Unhandled pseudo op.");
59 void ARCExpandPseudos::ExpandStore(MachineFunction
&MF
,
60 MachineBasicBlock::iterator SII
) {
61 MachineInstr
&SI
= *SII
;
62 unsigned AddrReg
= MF
.getRegInfo().createVirtualRegister(&ARC::GPR32RegClass
);
64 isUInt
<6>(SI
.getOperand(2).getImm()) ? ARC::ADD_rru6
: ARC::ADD_rrlimm
;
65 BuildMI(*SI
.getParent(), SI
, SI
.getDebugLoc(), TII
->get(AddOpc
), AddrReg
)
66 .addReg(SI
.getOperand(1).getReg())
67 .addImm(SI
.getOperand(2).getImm());
68 BuildMI(*SI
.getParent(), SI
, SI
.getDebugLoc(),
69 TII
->get(getMappedOp(SI
.getOpcode())))
70 .addReg(SI
.getOperand(0).getReg())
76 bool ARCExpandPseudos::runOnMachineFunction(MachineFunction
&MF
) {
77 const ARCSubtarget
*STI
= &MF
.getSubtarget
<ARCSubtarget
>();
78 TII
= STI
->getInstrInfo();
79 bool ExpandedStore
= false;
80 for (auto &MBB
: MF
) {
81 MachineBasicBlock::iterator MBBI
= MBB
.begin(), E
= MBB
.end();
83 MachineBasicBlock::iterator NMBBI
= std::next(MBBI
);
84 switch (MBBI
->getOpcode()) {
88 ExpandStore(MF
, MBBI
);
100 FunctionPass
*llvm::createARCExpandPseudosPass() {
101 return new ARCExpandPseudos();