2018-09-19 12:54:22 +02:00
|
|
|
//===-- RISCVExpandPseudoInsts.cpp - Expand pseudo instructions -----------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-09-19 12:54:22 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a pass that expands pseudo instructions into target
|
|
|
|
// instructions. This pass should be run after register allocation but before
|
|
|
|
// the post-regalloc scheduling pass.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "RISCV.h"
|
|
|
|
#include "RISCVInstrInfo.h"
|
|
|
|
#include "RISCVTargetMachine.h"
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/LivePhysRegs.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define RISCV_EXPAND_PSEUDO_NAME "RISCV pseudo instruction expansion pass"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class RISCVExpandPseudo : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
const RISCVInstrInfo *TII;
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
RISCVExpandPseudo() : MachineFunctionPass(ID) {
|
|
|
|
initializeRISCVExpandPseudoPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
|
|
|
|
StringRef getPassName() const override { return RISCV_EXPAND_PSEUDO_NAME; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool expandMBB(MachineBasicBlock &MBB);
|
2020-07-14 12:15:01 +02:00
|
|
|
bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI);
|
2019-06-11 14:57:47 +02:00
|
|
|
bool expandAuipcInstPair(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI,
|
2020-07-14 12:15:01 +02:00
|
|
|
MachineBasicBlock::iterator &NextMBBI,
|
2019-06-11 14:57:47 +02:00
|
|
|
unsigned FlagsHi, unsigned SecondOpcode);
|
2019-04-01 16:42:56 +02:00
|
|
|
bool expandLoadLocalAddress(MachineBasicBlock &MBB,
|
2020-07-14 12:15:01 +02:00
|
|
|
MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI);
|
2019-06-11 14:57:47 +02:00
|
|
|
bool expandLoadAddress(MachineBasicBlock &MBB,
|
2020-07-14 12:15:01 +02:00
|
|
|
MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI);
|
2019-06-19 10:40:59 +02:00
|
|
|
bool expandLoadTLSIEAddress(MachineBasicBlock &MBB,
|
2020-07-14 12:15:01 +02:00
|
|
|
MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI);
|
2019-06-19 10:40:59 +02:00
|
|
|
bool expandLoadTLSGDAddress(MachineBasicBlock &MBB,
|
2020-07-14 12:15:01 +02:00
|
|
|
MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI);
|
2020-12-01 04:48:24 +01:00
|
|
|
bool expandVSetVL(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI);
|
2020-12-28 05:00:33 +01:00
|
|
|
bool expandVMSET_VMCLR(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI, unsigned Opcode);
|
2021-03-15 06:58:11 +01:00
|
|
|
bool expandVSPILL(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI);
|
|
|
|
bool expandVRELOAD(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI);
|
2018-09-19 12:54:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
char RISCVExpandPseudo::ID = 0;
|
|
|
|
|
|
|
|
bool RISCVExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
TII = static_cast<const RISCVInstrInfo *>(MF.getSubtarget().getInstrInfo());
|
|
|
|
bool Modified = false;
|
|
|
|
for (auto &MBB : MF)
|
|
|
|
Modified |= expandMBB(MBB);
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RISCVExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
|
|
|
|
bool Modified = false;
|
|
|
|
|
|
|
|
MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
|
|
|
|
while (MBBI != E) {
|
|
|
|
MachineBasicBlock::iterator NMBBI = std::next(MBBI);
|
2020-07-14 12:15:01 +02:00
|
|
|
Modified |= expandMI(MBB, MBBI, NMBBI);
|
2018-09-19 12:54:22 +02:00
|
|
|
MBBI = NMBBI;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RISCVExpandPseudo::expandMI(MachineBasicBlock &MBB,
|
2020-07-14 12:15:01 +02:00
|
|
|
MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI) {
|
[RISCV] Fix RISCVInstrInfo::getInstSizeInBytes for atomics pseudos
Summary:
Without these, the generic branch relaxation pass will underestimate the
range required for branches spanning these and we can end up with
"fixup value out of range" errors rather than relaxing the branches.
Some of the instructions in the expansion may end up being compressed
but exactly determining that is awkward, and these conservative values
should be safe, if slightly suboptimal in rare cases.
Reviewers: asb, lenary, luismarques, lewis-revill
Reviewed By: asb, luismarques
Subscribers: hiraditya, rbar, johnrusso, simoncook, sabuasal, niosHD, kito-cheng, shiva0217, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, jfb, PkmX, jocewei, psnobl, benna, Jim, s.egerton, pzheng, sameer.abuasal, apazos, evandro, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77443
2020-07-15 11:48:41 +02:00
|
|
|
// RISCVInstrInfo::getInstSizeInBytes hard-codes the number of expanded
|
|
|
|
// instructions for each pseudo, and must be updated when adding new pseudos
|
|
|
|
// or changing existing ones.
|
2018-09-19 12:54:22 +02:00
|
|
|
switch (MBBI->getOpcode()) {
|
2019-04-01 16:42:56 +02:00
|
|
|
case RISCV::PseudoLLA:
|
2020-07-14 12:15:01 +02:00
|
|
|
return expandLoadLocalAddress(MBB, MBBI, NextMBBI);
|
2019-06-11 14:57:47 +02:00
|
|
|
case RISCV::PseudoLA:
|
2020-07-14 12:15:01 +02:00
|
|
|
return expandLoadAddress(MBB, MBBI, NextMBBI);
|
2019-06-19 10:40:59 +02:00
|
|
|
case RISCV::PseudoLA_TLS_IE:
|
2020-07-14 12:15:01 +02:00
|
|
|
return expandLoadTLSIEAddress(MBB, MBBI, NextMBBI);
|
2019-06-19 10:40:59 +02:00
|
|
|
case RISCV::PseudoLA_TLS_GD:
|
2020-07-14 12:15:01 +02:00
|
|
|
return expandLoadTLSGDAddress(MBB, MBBI, NextMBBI);
|
2020-12-01 04:48:24 +01:00
|
|
|
case RISCV::PseudoVSETVLI:
|
2021-02-01 09:08:46 +01:00
|
|
|
case RISCV::PseudoVSETIVLI:
|
2020-12-01 04:48:24 +01:00
|
|
|
return expandVSetVL(MBB, MBBI);
|
2020-12-28 05:00:33 +01:00
|
|
|
case RISCV::PseudoVMCLR_M_B1:
|
|
|
|
case RISCV::PseudoVMCLR_M_B2:
|
|
|
|
case RISCV::PseudoVMCLR_M_B4:
|
|
|
|
case RISCV::PseudoVMCLR_M_B8:
|
|
|
|
case RISCV::PseudoVMCLR_M_B16:
|
|
|
|
case RISCV::PseudoVMCLR_M_B32:
|
|
|
|
case RISCV::PseudoVMCLR_M_B64:
|
|
|
|
// vmclr.m vd => vmxor.mm vd, vd, vd
|
|
|
|
return expandVMSET_VMCLR(MBB, MBBI, RISCV::VMXOR_MM);
|
|
|
|
case RISCV::PseudoVMSET_M_B1:
|
|
|
|
case RISCV::PseudoVMSET_M_B2:
|
|
|
|
case RISCV::PseudoVMSET_M_B4:
|
|
|
|
case RISCV::PseudoVMSET_M_B8:
|
|
|
|
case RISCV::PseudoVMSET_M_B16:
|
|
|
|
case RISCV::PseudoVMSET_M_B32:
|
|
|
|
case RISCV::PseudoVMSET_M_B64:
|
|
|
|
// vmset.m vd => vmxnor.mm vd, vd, vd
|
|
|
|
return expandVMSET_VMCLR(MBB, MBBI, RISCV::VMXNOR_MM);
|
2021-03-15 06:58:11 +01:00
|
|
|
case RISCV::PseudoVSPILL2_M1:
|
|
|
|
case RISCV::PseudoVSPILL2_M2:
|
|
|
|
case RISCV::PseudoVSPILL2_M4:
|
|
|
|
case RISCV::PseudoVSPILL3_M1:
|
|
|
|
case RISCV::PseudoVSPILL3_M2:
|
|
|
|
case RISCV::PseudoVSPILL4_M1:
|
|
|
|
case RISCV::PseudoVSPILL4_M2:
|
|
|
|
case RISCV::PseudoVSPILL5_M1:
|
|
|
|
case RISCV::PseudoVSPILL6_M1:
|
|
|
|
case RISCV::PseudoVSPILL7_M1:
|
|
|
|
case RISCV::PseudoVSPILL8_M1:
|
|
|
|
return expandVSPILL(MBB, MBBI);
|
|
|
|
case RISCV::PseudoVRELOAD2_M1:
|
|
|
|
case RISCV::PseudoVRELOAD2_M2:
|
|
|
|
case RISCV::PseudoVRELOAD2_M4:
|
|
|
|
case RISCV::PseudoVRELOAD3_M1:
|
|
|
|
case RISCV::PseudoVRELOAD3_M2:
|
|
|
|
case RISCV::PseudoVRELOAD4_M1:
|
|
|
|
case RISCV::PseudoVRELOAD4_M2:
|
|
|
|
case RISCV::PseudoVRELOAD5_M1:
|
|
|
|
case RISCV::PseudoVRELOAD6_M1:
|
|
|
|
case RISCV::PseudoVRELOAD7_M1:
|
|
|
|
case RISCV::PseudoVRELOAD8_M1:
|
|
|
|
return expandVRELOAD(MBB, MBBI);
|
2018-09-19 12:54:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-14 12:15:01 +02:00
|
|
|
bool RISCVExpandPseudo::expandAuipcInstPair(
|
|
|
|
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI, unsigned FlagsHi,
|
|
|
|
unsigned SecondOpcode) {
|
2019-04-01 16:42:56 +02:00
|
|
|
MachineFunction *MF = MBB.getParent();
|
|
|
|
MachineInstr &MI = *MBBI;
|
|
|
|
DebugLoc DL = MI.getDebugLoc();
|
|
|
|
|
[risc-v] Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Depends on D65919
Reviewers: lenary
Subscribers: jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision for full review was: https://reviews.llvm.org/D65962
llvm-svn: 368629
2019-08-13 00:41:02 +02:00
|
|
|
Register DestReg = MI.getOperand(0).getReg();
|
2020-07-14 12:15:01 +02:00
|
|
|
const MachineOperand &Symbol = MI.getOperand(1);
|
2019-04-01 16:42:56 +02:00
|
|
|
|
2020-07-14 12:15:01 +02:00
|
|
|
MachineBasicBlock *NewMBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
|
2019-04-01 16:42:56 +02:00
|
|
|
|
2020-07-14 12:15:01 +02:00
|
|
|
// Tell AsmPrinter that we unconditionally want the symbol of this label to be
|
|
|
|
// emitted.
|
|
|
|
NewMBB->setLabelMustBeEmitted();
|
2019-04-01 16:42:56 +02:00
|
|
|
|
2020-07-14 12:15:01 +02:00
|
|
|
MF->insert(++MBB.getIterator(), NewMBB);
|
2019-04-01 16:42:56 +02:00
|
|
|
|
2020-07-14 12:15:01 +02:00
|
|
|
BuildMI(NewMBB, DL, TII->get(RISCV::AUIPC), DestReg)
|
|
|
|
.addDisp(Symbol, 0, FlagsHi);
|
|
|
|
BuildMI(NewMBB, DL, TII->get(SecondOpcode), DestReg)
|
|
|
|
.addReg(DestReg)
|
|
|
|
.addMBB(NewMBB, RISCVII::MO_PCREL_LO);
|
|
|
|
|
|
|
|
// Move all the rest of the instructions to NewMBB.
|
|
|
|
NewMBB->splice(NewMBB->end(), &MBB, std::next(MBBI), MBB.end());
|
|
|
|
// Update machine-CFG edges.
|
|
|
|
NewMBB->transferSuccessorsAndUpdatePHIs(&MBB);
|
|
|
|
// Make the original basic block fall-through to the new.
|
|
|
|
MBB.addSuccessor(NewMBB);
|
|
|
|
|
|
|
|
// Make sure live-ins are correctly attached to this new basic block.
|
|
|
|
LivePhysRegs LiveRegs;
|
|
|
|
computeAndAddLiveIns(LiveRegs, *NewMBB);
|
|
|
|
|
|
|
|
NextMBBI = MBB.end();
|
2019-04-01 16:42:56 +02:00
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:57:47 +02:00
|
|
|
bool RISCVExpandPseudo::expandLoadLocalAddress(
|
2020-07-14 12:15:01 +02:00
|
|
|
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI) {
|
|
|
|
return expandAuipcInstPair(MBB, MBBI, NextMBBI, RISCVII::MO_PCREL_HI,
|
|
|
|
RISCV::ADDI);
|
2019-06-11 14:57:47 +02:00
|
|
|
}
|
|
|
|
|
2020-07-14 12:15:01 +02:00
|
|
|
bool RISCVExpandPseudo::expandLoadAddress(
|
|
|
|
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI) {
|
2019-06-11 14:57:47 +02:00
|
|
|
MachineFunction *MF = MBB.getParent();
|
|
|
|
|
|
|
|
unsigned SecondOpcode;
|
|
|
|
unsigned FlagsHi;
|
|
|
|
if (MF->getTarget().isPositionIndependent()) {
|
|
|
|
const auto &STI = MF->getSubtarget<RISCVSubtarget>();
|
|
|
|
SecondOpcode = STI.is64Bit() ? RISCV::LD : RISCV::LW;
|
|
|
|
FlagsHi = RISCVII::MO_GOT_HI;
|
|
|
|
} else {
|
|
|
|
SecondOpcode = RISCV::ADDI;
|
|
|
|
FlagsHi = RISCVII::MO_PCREL_HI;
|
|
|
|
}
|
2020-07-14 12:15:01 +02:00
|
|
|
return expandAuipcInstPair(MBB, MBBI, NextMBBI, FlagsHi, SecondOpcode);
|
2019-06-11 14:57:47 +02:00
|
|
|
}
|
|
|
|
|
2019-06-19 10:40:59 +02:00
|
|
|
bool RISCVExpandPseudo::expandLoadTLSIEAddress(
|
2020-07-14 12:15:01 +02:00
|
|
|
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI) {
|
2019-06-19 10:40:59 +02:00
|
|
|
MachineFunction *MF = MBB.getParent();
|
|
|
|
|
|
|
|
const auto &STI = MF->getSubtarget<RISCVSubtarget>();
|
|
|
|
unsigned SecondOpcode = STI.is64Bit() ? RISCV::LD : RISCV::LW;
|
2020-07-14 12:15:01 +02:00
|
|
|
return expandAuipcInstPair(MBB, MBBI, NextMBBI, RISCVII::MO_TLS_GOT_HI,
|
|
|
|
SecondOpcode);
|
2019-06-19 10:40:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RISCVExpandPseudo::expandLoadTLSGDAddress(
|
2020-07-14 12:15:01 +02:00
|
|
|
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
|
|
|
|
MachineBasicBlock::iterator &NextMBBI) {
|
|
|
|
return expandAuipcInstPair(MBB, MBBI, NextMBBI, RISCVII::MO_TLS_GD_HI,
|
|
|
|
RISCV::ADDI);
|
2019-06-19 10:40:59 +02:00
|
|
|
}
|
|
|
|
|
2020-12-01 04:48:24 +01:00
|
|
|
bool RISCVExpandPseudo::expandVSetVL(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI) {
|
2021-05-24 19:25:27 +02:00
|
|
|
assert(MBBI->getNumExplicitOperands() == 3 && MBBI->getNumOperands() >= 5 &&
|
|
|
|
"Unexpected instruction format");
|
2020-12-01 04:48:24 +01:00
|
|
|
|
|
|
|
DebugLoc DL = MBBI->getDebugLoc();
|
|
|
|
|
2021-02-01 09:08:46 +01:00
|
|
|
assert((MBBI->getOpcode() == RISCV::PseudoVSETVLI ||
|
|
|
|
MBBI->getOpcode() == RISCV::PseudoVSETIVLI) &&
|
2020-12-01 04:48:24 +01:00
|
|
|
"Unexpected pseudo instruction");
|
2021-02-01 09:08:46 +01:00
|
|
|
unsigned Opcode;
|
|
|
|
if (MBBI->getOpcode() == RISCV::PseudoVSETVLI)
|
|
|
|
Opcode = RISCV::VSETVLI;
|
|
|
|
else
|
|
|
|
Opcode = RISCV::VSETIVLI;
|
|
|
|
const MCInstrDesc &Desc = TII->get(Opcode);
|
2020-12-01 04:48:24 +01:00
|
|
|
assert(Desc.getNumOperands() == 3 && "Unexpected instruction format");
|
|
|
|
|
|
|
|
Register DstReg = MBBI->getOperand(0).getReg();
|
|
|
|
bool DstIsDead = MBBI->getOperand(0).isDead();
|
|
|
|
BuildMI(MBB, MBBI, DL, Desc)
|
|
|
|
.addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
|
|
|
|
.add(MBBI->getOperand(1)) // VL
|
|
|
|
.add(MBBI->getOperand(2)); // VType
|
|
|
|
|
|
|
|
MBBI->eraseFromParent(); // The pseudo instruction is gone now.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-28 05:00:33 +01:00
|
|
|
bool RISCVExpandPseudo::expandVMSET_VMCLR(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI,
|
|
|
|
unsigned Opcode) {
|
|
|
|
DebugLoc DL = MBBI->getDebugLoc();
|
|
|
|
Register DstReg = MBBI->getOperand(0).getReg();
|
|
|
|
const MCInstrDesc &Desc = TII->get(Opcode);
|
|
|
|
BuildMI(MBB, MBBI, DL, Desc, DstReg)
|
|
|
|
.addReg(DstReg, RegState::Undef)
|
|
|
|
.addReg(DstReg, RegState::Undef);
|
|
|
|
MBBI->eraseFromParent(); // The pseudo instruction is gone now.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-15 06:58:11 +01:00
|
|
|
bool RISCVExpandPseudo::expandVSPILL(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI) {
|
|
|
|
const TargetRegisterInfo *TRI =
|
|
|
|
MBB.getParent()->getSubtarget().getRegisterInfo();
|
|
|
|
DebugLoc DL = MBBI->getDebugLoc();
|
|
|
|
Register SrcReg = MBBI->getOperand(0).getReg();
|
|
|
|
Register Base = MBBI->getOperand(1).getReg();
|
|
|
|
Register VL = MBBI->getOperand(2).getReg();
|
|
|
|
auto ZvlssegInfo = TII->isRVVSpillForZvlsseg(MBBI->getOpcode());
|
|
|
|
if (!ZvlssegInfo)
|
|
|
|
return false;
|
|
|
|
unsigned NF = ZvlssegInfo->first;
|
|
|
|
unsigned LMUL = ZvlssegInfo->second;
|
|
|
|
assert(NF * LMUL <= 8 && "Invalid NF/LMUL combinations.");
|
|
|
|
unsigned Opcode = RISCV::VS1R_V;
|
|
|
|
unsigned SubRegIdx = RISCV::sub_vrm1_0;
|
|
|
|
static_assert(RISCV::sub_vrm1_7 == RISCV::sub_vrm1_0 + 7,
|
|
|
|
"Unexpected subreg numbering");
|
|
|
|
if (LMUL == 2) {
|
|
|
|
Opcode = RISCV::VS2R_V;
|
|
|
|
SubRegIdx = RISCV::sub_vrm2_0;
|
|
|
|
static_assert(RISCV::sub_vrm2_3 == RISCV::sub_vrm2_0 + 3,
|
|
|
|
"Unexpected subreg numbering");
|
|
|
|
} else if (LMUL == 4) {
|
|
|
|
Opcode = RISCV::VS4R_V;
|
|
|
|
SubRegIdx = RISCV::sub_vrm4_0;
|
|
|
|
static_assert(RISCV::sub_vrm4_1 == RISCV::sub_vrm4_0 + 1,
|
|
|
|
"Unexpected subreg numbering");
|
|
|
|
} else
|
|
|
|
assert(LMUL == 1 && "LMUL must be 1, 2, or 4.");
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < NF; ++I) {
|
|
|
|
BuildMI(MBB, MBBI, DL, TII->get(Opcode))
|
|
|
|
.addReg(TRI->getSubReg(SrcReg, SubRegIdx + I))
|
|
|
|
.addReg(Base)
|
|
|
|
.addMemOperand(*(MBBI->memoperands_begin()));
|
|
|
|
if (I != NF - 1)
|
|
|
|
BuildMI(MBB, MBBI, DL, TII->get(RISCV::ADD), Base)
|
|
|
|
.addReg(Base)
|
|
|
|
.addReg(VL);
|
|
|
|
}
|
|
|
|
MBBI->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RISCVExpandPseudo::expandVRELOAD(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI) {
|
|
|
|
const TargetRegisterInfo *TRI =
|
|
|
|
MBB.getParent()->getSubtarget().getRegisterInfo();
|
|
|
|
DebugLoc DL = MBBI->getDebugLoc();
|
|
|
|
Register DestReg = MBBI->getOperand(0).getReg();
|
|
|
|
Register Base = MBBI->getOperand(1).getReg();
|
|
|
|
Register VL = MBBI->getOperand(2).getReg();
|
|
|
|
auto ZvlssegInfo = TII->isRVVSpillForZvlsseg(MBBI->getOpcode());
|
|
|
|
if (!ZvlssegInfo)
|
|
|
|
return false;
|
|
|
|
unsigned NF = ZvlssegInfo->first;
|
|
|
|
unsigned LMUL = ZvlssegInfo->second;
|
|
|
|
assert(NF * LMUL <= 8 && "Invalid NF/LMUL combinations.");
|
|
|
|
unsigned Opcode = RISCV::VL1RE8_V;
|
|
|
|
unsigned SubRegIdx = RISCV::sub_vrm1_0;
|
|
|
|
static_assert(RISCV::sub_vrm1_7 == RISCV::sub_vrm1_0 + 7,
|
|
|
|
"Unexpected subreg numbering");
|
|
|
|
if (LMUL == 2) {
|
|
|
|
Opcode = RISCV::VL2RE8_V;
|
|
|
|
SubRegIdx = RISCV::sub_vrm2_0;
|
|
|
|
static_assert(RISCV::sub_vrm2_3 == RISCV::sub_vrm2_0 + 3,
|
|
|
|
"Unexpected subreg numbering");
|
|
|
|
} else if (LMUL == 4) {
|
|
|
|
Opcode = RISCV::VL4RE8_V;
|
|
|
|
SubRegIdx = RISCV::sub_vrm4_0;
|
|
|
|
static_assert(RISCV::sub_vrm4_1 == RISCV::sub_vrm4_0 + 1,
|
|
|
|
"Unexpected subreg numbering");
|
|
|
|
} else
|
|
|
|
assert(LMUL == 1 && "LMUL must be 1, 2, or 4.");
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < NF; ++I) {
|
|
|
|
BuildMI(MBB, MBBI, DL, TII->get(Opcode),
|
|
|
|
TRI->getSubReg(DestReg, SubRegIdx + I))
|
|
|
|
.addReg(Base)
|
|
|
|
.addMemOperand(*(MBBI->memoperands_begin()));
|
|
|
|
if (I != NF - 1)
|
|
|
|
BuildMI(MBB, MBBI, DL, TII->get(RISCV::ADD), Base)
|
|
|
|
.addReg(Base)
|
|
|
|
.addReg(VL);
|
|
|
|
}
|
|
|
|
MBBI->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-19 12:54:22 +02:00
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
INITIALIZE_PASS(RISCVExpandPseudo, "riscv-expand-pseudo",
|
|
|
|
RISCV_EXPAND_PSEUDO_NAME, false, false)
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
FunctionPass *createRISCVExpandPseudoPass() { return new RISCVExpandPseudo(); }
|
|
|
|
|
|
|
|
} // end of namespace llvm
|