2012-08-01 01:41:32 +02:00
|
|
|
//===-- MipsSERegisterInfo.cpp - MIPS32/64 Register Information -== -------===//
|
|
|
|
//
|
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
|
2012-08-01 01:41:32 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the MIPS32/64 implementation of the TargetRegisterInfo
|
|
|
|
// class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MipsSERegisterInfo.h"
|
|
|
|
#include "Mips.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "MipsMachineFunction.h"
|
2012-08-01 01:52:55 +02:00
|
|
|
#include "MipsSEInstrInfo.h"
|
2012-08-01 01:41:32 +02:00
|
|
|
#include "MipsSubtarget.h"
|
2015-03-12 06:43:57 +01:00
|
|
|
#include "MipsTargetMachine.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-11-08 02:01:31 +01:00
|
|
|
#include "llvm/CodeGen/TargetFrameLowering.h"
|
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Constants.h"
|
2014-03-06 01:46:21 +01:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2012-08-01 01:41:32 +02:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2012-08-01 01:41:32 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 00:55:11 +02:00
|
|
|
#define DEBUG_TYPE "mips-reg-info"
|
|
|
|
|
2015-03-12 06:43:57 +01:00
|
|
|
MipsSERegisterInfo::MipsSERegisterInfo() : MipsRegisterInfo() {}
|
2012-08-01 01:41:32 +02:00
|
|
|
|
2012-11-03 01:05:43 +01:00
|
|
|
bool MipsSERegisterInfo::
|
|
|
|
requiresRegisterScavenging(const MachineFunction &MF) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsSERegisterInfo::
|
|
|
|
requiresFrameIndexScavenging(const MachineFunction &MF) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-29 20:17:42 +01:00
|
|
|
const TargetRegisterClass *
|
|
|
|
MipsSERegisterInfo::intRegClass(unsigned Size) const {
|
|
|
|
if (Size == 4)
|
2013-08-07 01:08:38 +02:00
|
|
|
return &Mips::GPR32RegClass;
|
2013-03-29 20:17:42 +01:00
|
|
|
|
|
|
|
assert(Size == 8);
|
2013-08-07 01:08:38 +02:00
|
|
|
return &Mips::GPR64RegClass;
|
2013-03-29 20:17:42 +01:00
|
|
|
}
|
|
|
|
|
2016-07-18 15:17:31 +02:00
|
|
|
/// Get the size of the offset supported by the given load/store/inline asm.
|
2013-12-09 12:50:16 +01:00
|
|
|
/// The result includes the effects of any scale factors applied to the
|
|
|
|
/// instruction immediate.
|
2016-07-18 15:17:31 +02:00
|
|
|
static inline unsigned getLoadStoreOffsetSizeInBits(const unsigned Opcode,
|
|
|
|
MachineOperand MO) {
|
2013-11-30 14:47:57 +01:00
|
|
|
switch (Opcode) {
|
|
|
|
case Mips::LD_B:
|
|
|
|
case Mips::ST_B:
|
2013-12-09 12:50:16 +01:00
|
|
|
return 10;
|
|
|
|
case Mips::LD_H:
|
2013-11-30 14:47:57 +01:00
|
|
|
case Mips::ST_H:
|
2013-12-09 12:50:16 +01:00
|
|
|
return 10 + 1 /* scale factor */;
|
|
|
|
case Mips::LD_W:
|
2013-11-30 14:47:57 +01:00
|
|
|
case Mips::ST_W:
|
2013-12-09 12:50:16 +01:00
|
|
|
return 10 + 2 /* scale factor */;
|
|
|
|
case Mips::LD_D:
|
2013-11-30 14:47:57 +01:00
|
|
|
case Mips::ST_D:
|
2013-12-09 12:50:16 +01:00
|
|
|
return 10 + 3 /* scale factor */;
|
2016-07-18 15:17:31 +02:00
|
|
|
case Mips::LL:
|
|
|
|
case Mips::LL64:
|
|
|
|
case Mips::LLD:
|
|
|
|
case Mips::LLE:
|
|
|
|
case Mips::SC:
|
|
|
|
case Mips::SC64:
|
|
|
|
case Mips::SCD:
|
|
|
|
case Mips::SCE:
|
|
|
|
return 16;
|
|
|
|
case Mips::LLE_MM:
|
|
|
|
case Mips::LL_MM:
|
|
|
|
case Mips::SCE_MM:
|
|
|
|
case Mips::SC_MM:
|
|
|
|
return 12;
|
|
|
|
case Mips::LL64_R6:
|
|
|
|
case Mips::LL_R6:
|
|
|
|
case Mips::LLD_R6:
|
|
|
|
case Mips::SC64_R6:
|
|
|
|
case Mips::SCD_R6:
|
|
|
|
case Mips::SC_R6:
|
2018-05-20 19:21:00 +02:00
|
|
|
case Mips::LL_MMR6:
|
|
|
|
case Mips::SC_MMR6:
|
2016-07-18 15:17:31 +02:00
|
|
|
return 9;
|
|
|
|
case Mips::INLINEASM: {
|
|
|
|
unsigned ConstraintID = InlineAsm::getMemoryConstraintID(MO.getImm());
|
|
|
|
switch (ConstraintID) {
|
|
|
|
case InlineAsm::Constraint_ZC: {
|
|
|
|
const MipsSubtarget &Subtarget = MO.getParent()
|
|
|
|
->getParent()
|
|
|
|
->getParent()
|
|
|
|
->getSubtarget<MipsSubtarget>();
|
|
|
|
if (Subtarget.inMicroMipsMode())
|
|
|
|
return 12;
|
|
|
|
|
|
|
|
if (Subtarget.hasMips32r6())
|
|
|
|
return 9;
|
|
|
|
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
}
|
2013-11-30 14:47:57 +01:00
|
|
|
default:
|
2013-12-09 12:50:16 +01:00
|
|
|
return 16;
|
2013-11-30 14:47:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-09 13:47:12 +01:00
|
|
|
/// Get the scale factor applied to the immediate in the given load/store.
|
|
|
|
static inline unsigned getLoadStoreOffsetAlign(const unsigned Opcode) {
|
|
|
|
switch (Opcode) {
|
|
|
|
case Mips::LD_H:
|
|
|
|
case Mips::ST_H:
|
|
|
|
return 2;
|
|
|
|
case Mips::LD_W:
|
|
|
|
case Mips::ST_W:
|
|
|
|
return 4;
|
|
|
|
case Mips::LD_D:
|
|
|
|
case Mips::ST_D:
|
|
|
|
return 8;
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 01:41:32 +02:00
|
|
|
void MipsSERegisterInfo::eliminateFI(MachineBasicBlock::iterator II,
|
|
|
|
unsigned OpNo, int FrameIndex,
|
|
|
|
uint64_t StackSize,
|
|
|
|
int64_t SPOffset) const {
|
|
|
|
MachineInstr &MI = *II;
|
|
|
|
MachineFunction &MF = *MI.getParent()->getParent();
|
2016-07-28 20:40:00 +02:00
|
|
|
MachineFrameInfo &MFI = MF.getFrameInfo();
|
2013-01-30 01:26:49 +01:00
|
|
|
MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
|
2015-06-02 15:14:46 +02:00
|
|
|
|
2015-04-17 11:50:21 +02:00
|
|
|
MipsABIInfo ABI =
|
|
|
|
static_cast<const MipsTargetMachine &>(MF.getTarget()).getABI();
|
2015-06-02 15:14:46 +02:00
|
|
|
const MipsRegisterInfo *RegInfo =
|
|
|
|
static_cast<const MipsRegisterInfo *>(MF.getSubtarget().getRegisterInfo());
|
2012-08-01 01:41:32 +02:00
|
|
|
|
2016-07-28 20:40:00 +02:00
|
|
|
const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
|
2012-08-01 01:41:32 +02:00
|
|
|
int MinCSFI = 0;
|
|
|
|
int MaxCSFI = -1;
|
|
|
|
|
|
|
|
if (CSI.size()) {
|
|
|
|
MinCSFI = CSI[0].getFrameIdx();
|
|
|
|
MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();
|
|
|
|
}
|
|
|
|
|
2013-01-30 01:26:49 +01:00
|
|
|
bool EhDataRegFI = MipsFI->isEhDataRegFI(FrameIndex);
|
2015-10-26 13:38:43 +01:00
|
|
|
bool IsISRRegFI = MipsFI->isISRRegFI(FrameIndex);
|
2012-08-01 01:41:32 +02:00
|
|
|
// The following stack frame objects are always referenced relative to $sp:
|
|
|
|
// 1. Outgoing arguments.
|
|
|
|
// 2. Pointer to dynamically allocated stack space.
|
|
|
|
// 3. Locations for callee-saved registers.
|
2013-01-30 01:26:49 +01:00
|
|
|
// 4. Locations for eh data registers.
|
2015-10-26 13:38:43 +01:00
|
|
|
// 5. Locations for ISR saved Coprocessor 0 registers 12 & 14.
|
2012-08-01 01:41:32 +02:00
|
|
|
// Everything else is referenced relative to whatever register
|
|
|
|
// getFrameRegister() returns.
|
|
|
|
unsigned FrameReg;
|
|
|
|
|
2015-10-26 13:38:43 +01:00
|
|
|
if ((FrameIndex >= MinCSFI && FrameIndex <= MaxCSFI) || EhDataRegFI ||
|
|
|
|
IsISRRegFI)
|
2015-04-17 11:50:21 +02:00
|
|
|
FrameReg = ABI.GetStackPtr();
|
2015-06-02 15:14:46 +02:00
|
|
|
else if (RegInfo->needsStackRealignment(MF)) {
|
2016-07-28 20:40:00 +02:00
|
|
|
if (MFI.hasVarSizedObjects() && !MFI.isFixedObjectIndex(FrameIndex))
|
2015-06-02 15:14:46 +02:00
|
|
|
FrameReg = ABI.GetBasePtr();
|
2016-07-28 20:40:00 +02:00
|
|
|
else if (MFI.isFixedObjectIndex(FrameIndex))
|
2015-06-02 15:14:46 +02:00
|
|
|
FrameReg = getFrameRegister(MF);
|
|
|
|
else
|
|
|
|
FrameReg = ABI.GetStackPtr();
|
|
|
|
} else
|
2012-08-01 01:41:32 +02:00
|
|
|
FrameReg = getFrameRegister(MF);
|
|
|
|
|
|
|
|
// Calculate final offset.
|
|
|
|
// - There is no need to change the offset if the frame object is one of the
|
|
|
|
// following: an outgoing argument, pointer to a dynamically allocated
|
|
|
|
// stack space or a $gp restore location,
|
|
|
|
// - If the frame object is any of the following, its offset must be adjusted
|
|
|
|
// by adding the size of the stack:
|
|
|
|
// incoming argument, callee-saved register location or local variable.
|
2012-11-03 01:05:43 +01:00
|
|
|
bool IsKill = false;
|
2012-08-01 01:41:32 +02:00
|
|
|
int64_t Offset;
|
|
|
|
|
2012-09-26 21:18:19 +02:00
|
|
|
Offset = SPOffset + (int64_t)StackSize;
|
|
|
|
Offset += MI.getOperand(OpNo + 1).getImm();
|
2012-08-01 01:41:32 +02:00
|
|
|
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(errs() << "Offset : " << Offset << "\n"
|
|
|
|
<< "<--------->\n");
|
2012-08-01 01:41:32 +02:00
|
|
|
|
2013-11-30 14:15:21 +01:00
|
|
|
if (!MI.isDebugValue()) {
|
2013-11-30 14:47:57 +01:00
|
|
|
// Make sure Offset fits within the field available.
|
2013-12-09 12:50:16 +01:00
|
|
|
// For MSA instructions, this is a 10-bit signed immediate (scaled by
|
|
|
|
// element size), otherwise it is a 16-bit signed immediate.
|
2016-07-18 15:17:31 +02:00
|
|
|
unsigned OffsetBitSize =
|
|
|
|
getLoadStoreOffsetSizeInBits(MI.getOpcode(), MI.getOperand(OpNo - 1));
|
2019-09-27 14:54:21 +02:00
|
|
|
const Align OffsetAlign(getLoadStoreOffsetAlign(MI.getOpcode()));
|
2013-12-09 13:47:12 +01:00
|
|
|
if (OffsetBitSize < 16 && isInt<16>(Offset) &&
|
[Alignment] Move OffsetToAlignment to Alignment.h
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet, JDevlieghere, alexshap, rupprecht, jhenderson
Subscribers: sdardis, nemanjai, hiraditya, kbarton, jakehehrlich, jrtc27, MaskRay, atanasyan, jsji, seiya, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D67499
llvm-svn: 371742
2019-09-12 17:20:36 +02:00
|
|
|
(!isIntN(OffsetBitSize, Offset) || !isAligned(OffsetAlign, Offset))) {
|
2013-12-09 12:50:16 +01:00
|
|
|
// If we have an offset that needs to fit into a signed n-bit immediate
|
|
|
|
// (where n < 16) and doesn't, but does fit into 16-bits then use an ADDiu
|
2013-11-30 14:47:57 +01:00
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
|
|
|
DebugLoc DL = II->getDebugLoc();
|
2015-04-17 11:50:21 +02:00
|
|
|
const TargetRegisterClass *PtrRC =
|
|
|
|
ABI.ArePtrs64bit() ? &Mips::GPR64RegClass : &Mips::GPR32RegClass;
|
2013-11-30 14:47:57 +01:00
|
|
|
MachineRegisterInfo &RegInfo = MBB.getParent()->getRegInfo();
|
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).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, 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: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-15 21:22:08 +02:00
|
|
|
Register Reg = RegInfo.createVirtualRegister(PtrRC);
|
2013-11-30 14:47:57 +01:00
|
|
|
const MipsSEInstrInfo &TII =
|
|
|
|
*static_cast<const MipsSEInstrInfo *>(
|
2014-08-05 04:39:49 +02:00
|
|
|
MBB.getParent()->getSubtarget().getInstrInfo());
|
2015-04-17 11:50:21 +02:00
|
|
|
BuildMI(MBB, II, DL, TII.get(ABI.GetPtrAddiuOp()), Reg)
|
|
|
|
.addReg(FrameReg)
|
|
|
|
.addImm(Offset);
|
2013-11-30 14:47:57 +01:00
|
|
|
|
|
|
|
FrameReg = Reg;
|
|
|
|
Offset = 0;
|
|
|
|
IsKill = true;
|
|
|
|
} else if (!isInt<16>(Offset)) {
|
|
|
|
// Otherwise split the offset into 16-bit pieces and add it in multiple
|
|
|
|
// instructions.
|
2013-11-30 14:15:21 +01:00
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
|
|
|
DebugLoc DL = II->getDebugLoc();
|
2013-11-30 14:47:57 +01:00
|
|
|
unsigned NewImm = 0;
|
2013-11-30 14:15:21 +01:00
|
|
|
const MipsSEInstrInfo &TII =
|
|
|
|
*static_cast<const MipsSEInstrInfo *>(
|
2014-08-05 04:39:49 +02:00
|
|
|
MBB.getParent()->getSubtarget().getInstrInfo());
|
2013-11-30 14:47:57 +01:00
|
|
|
unsigned Reg = TII.loadImmediate(Offset, MBB, II, DL,
|
2014-04-25 07:30:21 +02:00
|
|
|
OffsetBitSize == 16 ? &NewImm : nullptr);
|
2015-04-17 11:50:21 +02:00
|
|
|
BuildMI(MBB, II, DL, TII.get(ABI.GetPtrAdduOp()), Reg).addReg(FrameReg)
|
2013-11-30 14:15:21 +01:00
|
|
|
.addReg(Reg, RegState::Kill);
|
|
|
|
|
|
|
|
FrameReg = Reg;
|
|
|
|
Offset = SignExtend64<16>(NewImm);
|
|
|
|
IsKill = true;
|
|
|
|
}
|
2012-08-01 01:41:32 +02:00
|
|
|
}
|
|
|
|
|
2012-11-03 01:05:43 +01:00
|
|
|
MI.getOperand(OpNo).ChangeToRegister(FrameReg, false, false, IsKill);
|
2012-08-01 01:41:32 +02:00
|
|
|
MI.getOperand(OpNo + 1).ChangeToImmediate(Offset);
|
|
|
|
}
|