2009-08-08 03:21:23 +00:00
|
|
|
//===-- Thumb2SizeReduction.cpp - Thumb2 code size reduction pass -*- C++ -*-=//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "t2-reduce-size"
|
|
|
|
#include "ARM.h"
|
|
|
|
#include "ARMBaseInstrInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "ARMBaseRegisterInfo.h"
|
2011-04-19 18:11:49 +00:00
|
|
|
#include "ARMSubtarget.h"
|
2011-07-20 23:34:39 +00:00
|
|
|
#include "MCTargetDesc/ARMAddressingModes.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "Thumb2InstrInfo.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2009-08-08 03:21:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Function.h" // To access Function attributes
|
2009-08-10 07:20:37 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-08-08 03:21:23 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-08-23 03:41:05 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-08-08 03:21:23 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-08-10 06:57:42 +00:00
|
|
|
STATISTIC(NumNarrows, "Number of 32-bit instrs reduced to 16-bit ones");
|
|
|
|
STATISTIC(Num2Addrs, "Number of 32-bit instrs reduced to 2addr 16-bit ones");
|
2009-08-11 08:52:18 +00:00
|
|
|
STATISTIC(NumLdSts, "Number of 32-bit load / store reduced to 16-bit ones");
|
2009-08-08 03:21:23 +00:00
|
|
|
|
2009-08-11 21:11:32 +00:00
|
|
|
static cl::opt<int> ReduceLimit("t2-reduce-limit",
|
|
|
|
cl::init(-1), cl::Hidden);
|
|
|
|
static cl::opt<int> ReduceLimit2Addr("t2-reduce-limit2",
|
|
|
|
cl::init(-1), cl::Hidden);
|
|
|
|
static cl::opt<int> ReduceLimitLdSt("t2-reduce-limit3",
|
|
|
|
cl::init(-1), cl::Hidden);
|
2009-08-10 07:20:37 +00:00
|
|
|
|
2009-08-08 03:21:23 +00:00
|
|
|
namespace {
|
|
|
|
/// ReduceTable - A static table with information on mapping from wide
|
|
|
|
/// opcodes to narrow
|
|
|
|
struct ReduceEntry {
|
2012-03-11 07:16:55 +00:00
|
|
|
uint16_t WideOpc; // Wide opcode
|
|
|
|
uint16_t NarrowOpc1; // Narrow opcode to transform to
|
|
|
|
uint16_t NarrowOpc2; // Narrow opcode when it's two-address
|
2009-08-08 03:21:23 +00:00
|
|
|
uint8_t Imm1Limit; // Limit of immediate field (bits)
|
|
|
|
uint8_t Imm2Limit; // Limit of immediate field when it's two-address
|
|
|
|
unsigned LowRegs1 : 1; // Only possible if low-registers are used
|
|
|
|
unsigned LowRegs2 : 1; // Only possible if low-registers are used (2addr)
|
2009-08-12 01:49:45 +00:00
|
|
|
unsigned PredCC1 : 2; // 0 - If predicated, cc is on and vice versa.
|
2009-08-08 03:21:23 +00:00
|
|
|
// 1 - No cc field.
|
2009-08-12 01:49:45 +00:00
|
|
|
// 2 - Always set CPSR.
|
2009-08-12 18:35:50 +00:00
|
|
|
unsigned PredCC2 : 2;
|
2011-04-19 18:11:49 +00:00
|
|
|
unsigned PartFlag : 1; // 16-bit instruction does partial flag update
|
2009-08-08 03:21:23 +00:00
|
|
|
unsigned Special : 1; // Needs to be dealt with specially
|
2012-12-20 19:59:30 +00:00
|
|
|
unsigned AvoidMovs: 1; // Avoid movs with shifter operand (for Swift)
|
2009-08-08 03:21:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const ReduceEntry ReduceTable[] = {
|
2012-12-20 19:59:30 +00:00
|
|
|
// Wide, Narrow1, Narrow2, imm1,imm2, lo1, lo2, P/C,PF,S,AM
|
|
|
|
{ ARM::t2ADCrr, 0, ARM::tADC, 0, 0, 0, 1, 0,0, 0,0,0 },
|
|
|
|
{ ARM::t2ADDri, ARM::tADDi3, ARM::tADDi8, 3, 8, 1, 1, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2ADDrr, ARM::tADDrr, ARM::tADDhirr, 0, 0, 1, 0, 0,1, 0,0,0 },
|
|
|
|
{ ARM::t2ADDSri,ARM::tADDi3, ARM::tADDi8, 3, 8, 1, 1, 2,2, 0,1,0 },
|
|
|
|
{ ARM::t2ADDSrr,ARM::tADDrr, 0, 0, 0, 1, 0, 2,0, 0,1,0 },
|
|
|
|
{ ARM::t2ANDrr, 0, ARM::tAND, 0, 0, 0, 1, 0,0, 1,0,0 },
|
|
|
|
{ ARM::t2ASRri, ARM::tASRri, 0, 5, 0, 1, 0, 0,0, 1,0,1 },
|
|
|
|
{ ARM::t2ASRrr, 0, ARM::tASRrr, 0, 0, 0, 1, 0,0, 1,0,1 },
|
|
|
|
{ ARM::t2BICrr, 0, ARM::tBIC, 0, 0, 0, 1, 0,0, 1,0,0 },
|
|
|
|
//FIXME: Disable CMN, as CCodes are backwards from compare expectations
|
|
|
|
//{ ARM::t2CMNrr, ARM::tCMN, 0, 0, 0, 1, 0, 2,0, 0,0,0 },
|
|
|
|
{ ARM::t2CMNzrr, ARM::tCMNz, 0, 0, 0, 1, 0, 2,0, 0,0,0 },
|
|
|
|
{ ARM::t2CMPri, ARM::tCMPi8, 0, 8, 0, 1, 0, 2,0, 0,0,0 },
|
|
|
|
{ ARM::t2CMPrr, ARM::tCMPhir, 0, 0, 0, 0, 0, 2,0, 0,1,0 },
|
|
|
|
{ ARM::t2EORrr, 0, ARM::tEOR, 0, 0, 0, 1, 0,0, 1,0,0 },
|
|
|
|
// FIXME: adr.n immediate offset must be multiple of 4.
|
|
|
|
//{ ARM::t2LEApcrelJT,ARM::tLEApcrelJT, 0, 0, 0, 1, 0, 1,0, 0,0,0 },
|
|
|
|
{ ARM::t2LSLri, ARM::tLSLri, 0, 5, 0, 1, 0, 0,0, 1,0,1 },
|
|
|
|
{ ARM::t2LSLrr, 0, ARM::tLSLrr, 0, 0, 0, 1, 0,0, 1,0,1 },
|
|
|
|
{ ARM::t2LSRri, ARM::tLSRri, 0, 5, 0, 1, 0, 0,0, 1,0,1 },
|
|
|
|
{ ARM::t2LSRrr, 0, ARM::tLSRrr, 0, 0, 0, 1, 0,0, 1,0,1 },
|
|
|
|
// FIXME: tMOVi8 and tMVN also partially update CPSR but they are less
|
|
|
|
// likely to cause issue in the loop. As a size / performance workaround,
|
|
|
|
// they are not marked as such.
|
|
|
|
{ ARM::t2MOVi, ARM::tMOVi8, 0, 8, 0, 1, 0, 0,0, 0,0,0 },
|
|
|
|
{ ARM::t2MOVi16,ARM::tMOVi8, 0, 8, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
// FIXME: Do we need the 16-bit 'S' variant?
|
|
|
|
{ ARM::t2MOVr,ARM::tMOVr, 0, 0, 0, 0, 0, 1,0, 0,0,0 },
|
|
|
|
{ ARM::t2MUL, 0, ARM::tMUL, 0, 0, 0, 1, 0,0, 1,0,0 },
|
|
|
|
{ ARM::t2MVNr, ARM::tMVN, 0, 0, 0, 1, 0, 0,0, 0,0,0 },
|
|
|
|
{ ARM::t2ORRrr, 0, ARM::tORR, 0, 0, 0, 1, 0,0, 1,0,0 },
|
|
|
|
{ ARM::t2REV, ARM::tREV, 0, 0, 0, 1, 0, 1,0, 0,0,0 },
|
|
|
|
{ ARM::t2REV16, ARM::tREV16, 0, 0, 0, 1, 0, 1,0, 0,0,0 },
|
|
|
|
{ ARM::t2REVSH, ARM::tREVSH, 0, 0, 0, 1, 0, 1,0, 0,0,0 },
|
|
|
|
{ ARM::t2RORrr, 0, ARM::tROR, 0, 0, 0, 1, 0,0, 1,0,0 },
|
|
|
|
{ ARM::t2RSBri, ARM::tRSB, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2RSBSri,ARM::tRSB, 0, 0, 0, 1, 0, 2,0, 0,1,0 },
|
|
|
|
{ ARM::t2SBCrr, 0, ARM::tSBC, 0, 0, 0, 1, 0,0, 0,0,0 },
|
|
|
|
{ ARM::t2SUBri, ARM::tSUBi3, ARM::tSUBi8, 3, 8, 1, 1, 0,0, 0,0,0 },
|
|
|
|
{ ARM::t2SUBrr, ARM::tSUBrr, 0, 0, 0, 1, 0, 0,0, 0,0,0 },
|
|
|
|
{ ARM::t2SUBSri,ARM::tSUBi3, ARM::tSUBi8, 3, 8, 1, 1, 2,2, 0,0,0 },
|
|
|
|
{ ARM::t2SUBSrr,ARM::tSUBrr, 0, 0, 0, 1, 0, 2,0, 0,0,0 },
|
|
|
|
{ ARM::t2SXTB, ARM::tSXTB, 0, 0, 0, 1, 0, 1,0, 0,1,0 },
|
|
|
|
{ ARM::t2SXTH, ARM::tSXTH, 0, 0, 0, 1, 0, 1,0, 0,1,0 },
|
|
|
|
{ ARM::t2TSTrr, ARM::tTST, 0, 0, 0, 1, 0, 2,0, 0,0,0 },
|
|
|
|
{ ARM::t2UXTB, ARM::tUXTB, 0, 0, 0, 1, 0, 1,0, 0,1,0 },
|
|
|
|
{ ARM::t2UXTH, ARM::tUXTH, 0, 0, 0, 1, 0, 1,0, 0,1,0 },
|
|
|
|
|
|
|
|
// FIXME: Clean this up after splitting each Thumb load / store opcode
|
|
|
|
// into multiple ones.
|
|
|
|
{ ARM::t2LDRi12,ARM::tLDRi, ARM::tLDRspi, 5, 8, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2LDRs, ARM::tLDRr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2LDRBi12,ARM::tLDRBi, 0, 5, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2LDRBs, ARM::tLDRBr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2LDRHi12,ARM::tLDRHi, 0, 5, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2LDRHs, ARM::tLDRHr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2LDRSBs,ARM::tLDRSB, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2LDRSHs,ARM::tLDRSH, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2STRi12,ARM::tSTRi, ARM::tSTRspi, 5, 8, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2STRs, ARM::tSTRr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2STRBi12,ARM::tSTRBi, 0, 5, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2STRBs, ARM::tSTRBr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2STRHi12,ARM::tSTRHi, 0, 5, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
{ ARM::t2STRHs, ARM::tSTRHr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
|
|
|
|
|
|
|
|
{ ARM::t2LDMIA, ARM::tLDMIA, 0, 0, 0, 1, 1, 1,1, 0,1,0 },
|
|
|
|
{ ARM::t2LDMIA_RET,0, ARM::tPOP_RET, 0, 0, 1, 1, 1,1, 0,1,0 },
|
|
|
|
{ ARM::t2LDMIA_UPD,ARM::tLDMIA_UPD,ARM::tPOP,0, 0, 1, 1, 1,1, 0,1,0 },
|
|
|
|
// ARM::t2STM (with no basereg writeback) has no Thumb1 equivalent
|
|
|
|
{ ARM::t2STMIA_UPD,ARM::tSTMIA_UPD, 0, 0, 0, 1, 1, 1,1, 0,1,0 },
|
|
|
|
{ ARM::t2STMDB_UPD, 0, ARM::tPUSH, 0, 0, 1, 1, 1,1, 0,1,0 }
|
2009-08-08 03:21:23 +00:00
|
|
|
};
|
|
|
|
|
2009-10-25 06:33:48 +00:00
|
|
|
class Thumb2SizeReduce : public MachineFunctionPass {
|
2009-08-08 03:21:23 +00:00
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
Thumb2SizeReduce();
|
|
|
|
|
2009-08-15 07:59:10 +00:00
|
|
|
const Thumb2InstrInfo *TII;
|
2011-04-19 18:11:49 +00:00
|
|
|
const ARMSubtarget *STI;
|
2009-08-08 03:21:23 +00:00
|
|
|
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF);
|
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "Thumb2 instruction size reduction pass";
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// ReduceOpcodeMap - Maps wide opcode to index of entry in ReduceTable.
|
|
|
|
DenseMap<unsigned, unsigned> ReduceOpcodeMap;
|
|
|
|
|
2011-10-27 21:21:05 +00:00
|
|
|
bool canAddPseudoFlagDep(MachineInstr *Def, MachineInstr *Use,
|
|
|
|
bool IsSelfLoop);
|
2011-04-19 18:11:49 +00:00
|
|
|
|
2009-08-12 01:49:45 +00:00
|
|
|
bool VerifyPredAndCC(MachineInstr *MI, const ReduceEntry &Entry,
|
|
|
|
bool is2Addr, ARMCC::CondCodes Pred,
|
|
|
|
bool LiveCPSR, bool &HasCC, bool &CCDead);
|
|
|
|
|
2009-08-11 08:52:18 +00:00
|
|
|
bool ReduceLoadStore(MachineBasicBlock &MBB, MachineInstr *MI,
|
|
|
|
const ReduceEntry &Entry);
|
|
|
|
|
|
|
|
bool ReduceSpecial(MachineBasicBlock &MBB, MachineInstr *MI,
|
2011-04-19 18:11:49 +00:00
|
|
|
const ReduceEntry &Entry, bool LiveCPSR,
|
2011-10-27 21:21:05 +00:00
|
|
|
MachineInstr *CPSRDef, bool IsSelfLoop);
|
2009-08-11 08:52:18 +00:00
|
|
|
|
2009-08-08 03:21:23 +00:00
|
|
|
/// ReduceTo2Addr - Reduce a 32-bit instruction to a 16-bit two-address
|
|
|
|
/// instruction.
|
2009-08-10 02:37:24 +00:00
|
|
|
bool ReduceTo2Addr(MachineBasicBlock &MBB, MachineInstr *MI,
|
|
|
|
const ReduceEntry &Entry,
|
2011-10-27 21:21:05 +00:00
|
|
|
bool LiveCPSR, MachineInstr *CPSRDef,
|
|
|
|
bool IsSelfLoop);
|
2009-08-08 03:21:23 +00:00
|
|
|
|
|
|
|
/// ReduceToNarrow - Reduce a 32-bit instruction to a 16-bit
|
|
|
|
/// non-two-address instruction.
|
2009-08-10 02:37:24 +00:00
|
|
|
bool ReduceToNarrow(MachineBasicBlock &MBB, MachineInstr *MI,
|
|
|
|
const ReduceEntry &Entry,
|
2011-10-27 21:21:05 +00:00
|
|
|
bool LiveCPSR, MachineInstr *CPSRDef,
|
|
|
|
bool IsSelfLoop);
|
2009-08-08 03:21:23 +00:00
|
|
|
|
2012-12-18 00:13:11 +00:00
|
|
|
/// ReduceMI - Attempt to reduce MI, return true on success.
|
|
|
|
bool ReduceMI(MachineBasicBlock &MBB, MachineInstr *MI,
|
|
|
|
bool LiveCPSR, MachineInstr *CPSRDef,
|
|
|
|
bool IsSelfLoop);
|
|
|
|
|
2009-08-08 03:21:23 +00:00
|
|
|
/// ReduceMBB - Reduce width of instructions in the specified basic block.
|
|
|
|
bool ReduceMBB(MachineBasicBlock &MBB);
|
2012-12-18 22:47:16 +00:00
|
|
|
|
2012-12-20 19:59:30 +00:00
|
|
|
bool OptimizeSize;
|
2012-12-18 22:47:16 +00:00
|
|
|
bool MinimizeSize;
|
2009-08-08 03:21:23 +00:00
|
|
|
};
|
|
|
|
char Thumb2SizeReduce::ID = 0;
|
|
|
|
}
|
|
|
|
|
2010-08-06 18:33:48 +00:00
|
|
|
Thumb2SizeReduce::Thumb2SizeReduce() : MachineFunctionPass(ID) {
|
2012-12-20 19:59:30 +00:00
|
|
|
OptimizeSize = MinimizeSize = false;
|
2009-08-08 03:21:23 +00:00
|
|
|
for (unsigned i = 0, e = array_lengthof(ReduceTable); i != e; ++i) {
|
|
|
|
unsigned FromOpc = ReduceTable[i].WideOpc;
|
|
|
|
if (!ReduceOpcodeMap.insert(std::make_pair(FromOpc, i)).second)
|
|
|
|
assert(false && "Duplicated entries?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-28 19:10:37 +00:00
|
|
|
static bool HasImplicitCPSRDef(const MCInstrDesc &MCID) {
|
2012-03-08 08:22:45 +00:00
|
|
|
for (const uint16_t *Regs = MCID.getImplicitDefs(); *Regs; ++Regs)
|
2009-08-12 01:49:45 +00:00
|
|
|
if (*Regs == ARM::CPSR)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-19 18:11:49 +00:00
|
|
|
/// canAddPseudoFlagDep - For A9 (and other out-of-order) implementations,
|
|
|
|
/// the 's' 16-bit instruction partially update CPSR. Abort the
|
|
|
|
/// transformation to avoid adding false dependency on last CPSR setting
|
|
|
|
/// instruction which hurts the ability for out-of-order execution engine
|
|
|
|
/// to do register renaming magic.
|
|
|
|
/// This function checks if there is a read-of-write dependency between the
|
|
|
|
/// last instruction that defines the CPSR and the current instruction. If there
|
|
|
|
/// is, then there is no harm done since the instruction cannot be retired
|
|
|
|
/// before the CPSR setting instruction anyway.
|
|
|
|
/// Note, we are not doing full dependency analysis here for the sake of compile
|
|
|
|
/// time. We're not looking for cases like:
|
|
|
|
/// r0 = muls ...
|
|
|
|
/// r1 = add.w r0, ...
|
|
|
|
/// ...
|
|
|
|
/// = mul.w r1
|
|
|
|
/// In this case it would have been ok to narrow the mul.w to muls since there
|
|
|
|
/// are indirect RAW dependency between the muls and the mul.w
|
|
|
|
bool
|
2011-10-27 21:21:05 +00:00
|
|
|
Thumb2SizeReduce::canAddPseudoFlagDep(MachineInstr *Def, MachineInstr *Use,
|
|
|
|
bool FirstInSelfLoop) {
|
2012-12-18 22:47:16 +00:00
|
|
|
// Disable the check for -Oz (aka OptimizeForSizeHarder).
|
|
|
|
if (MinimizeSize || !STI->avoidCPSRPartialUpdate())
|
2011-04-19 18:11:49 +00:00
|
|
|
return false;
|
|
|
|
|
2011-10-27 21:21:05 +00:00
|
|
|
if (!Def)
|
|
|
|
// If this BB loops back to itself, conservatively avoid narrowing the
|
|
|
|
// first instruction that does partial flag update.
|
|
|
|
return FirstInSelfLoop;
|
|
|
|
|
2011-04-19 18:11:49 +00:00
|
|
|
SmallSet<unsigned, 2> Defs;
|
|
|
|
for (unsigned i = 0, e = Def->getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = Def->getOperand(i);
|
|
|
|
if (!MO.isReg() || MO.isUndef() || MO.isUse())
|
|
|
|
continue;
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (Reg == 0 || Reg == ARM::CPSR)
|
|
|
|
continue;
|
|
|
|
Defs.insert(Reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Use->getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = Use->getOperand(i);
|
|
|
|
if (!MO.isReg() || MO.isUndef() || MO.isDef())
|
|
|
|
continue;
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (Defs.count(Reg))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No read-after-write dependency. The narrowing will add false dependency.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-12 01:49:45 +00:00
|
|
|
bool
|
|
|
|
Thumb2SizeReduce::VerifyPredAndCC(MachineInstr *MI, const ReduceEntry &Entry,
|
|
|
|
bool is2Addr, ARMCC::CondCodes Pred,
|
|
|
|
bool LiveCPSR, bool &HasCC, bool &CCDead) {
|
2009-08-09 19:17:19 +00:00
|
|
|
if ((is2Addr && Entry.PredCC2 == 0) ||
|
|
|
|
(!is2Addr && Entry.PredCC1 == 0)) {
|
|
|
|
if (Pred == ARMCC::AL) {
|
|
|
|
// Not predicated, must set CPSR.
|
2009-08-10 02:37:24 +00:00
|
|
|
if (!HasCC) {
|
|
|
|
// Original instruction was not setting CPSR, but CPSR is not
|
|
|
|
// currently live anyway. It's ok to set it. The CPSR def is
|
|
|
|
// dead though.
|
|
|
|
if (!LiveCPSR) {
|
|
|
|
HasCC = true;
|
|
|
|
CCDead = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-08-09 19:17:19 +00:00
|
|
|
} else {
|
|
|
|
// Predicated, must not set CPSR.
|
2009-08-10 02:37:24 +00:00
|
|
|
if (HasCC)
|
|
|
|
return false;
|
2009-08-09 19:17:19 +00:00
|
|
|
}
|
2009-08-12 01:49:45 +00:00
|
|
|
} else if ((is2Addr && Entry.PredCC2 == 2) ||
|
|
|
|
(!is2Addr && Entry.PredCC1 == 2)) {
|
|
|
|
/// Old opcode has an optional def of CPSR.
|
|
|
|
if (HasCC)
|
|
|
|
return true;
|
2010-09-14 20:35:46 +00:00
|
|
|
// If old opcode does not implicitly define CPSR, then it's not ok since
|
|
|
|
// these new opcodes' CPSR def is not meant to be thrown away. e.g. CMP.
|
2009-08-12 01:49:45 +00:00
|
|
|
if (!HasImplicitCPSRDef(MI->getDesc()))
|
|
|
|
return false;
|
|
|
|
HasCC = true;
|
2009-08-09 19:17:19 +00:00
|
|
|
} else {
|
2009-08-10 02:37:24 +00:00
|
|
|
// 16-bit instruction does not set CPSR.
|
|
|
|
if (HasCC)
|
|
|
|
return false;
|
2009-08-09 19:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-11 21:11:32 +00:00
|
|
|
static bool VerifyLowRegs(MachineInstr *MI) {
|
|
|
|
unsigned Opc = MI->getOpcode();
|
2010-11-16 01:16:36 +00:00
|
|
|
bool isPCOk = (Opc == ARM::t2LDMIA_RET || Opc == ARM::t2LDMIA ||
|
|
|
|
Opc == ARM::t2LDMDB || Opc == ARM::t2LDMIA_UPD ||
|
2011-02-08 22:39:40 +00:00
|
|
|
Opc == ARM::t2LDMDB_UPD);
|
2010-11-16 01:16:36 +00:00
|
|
|
bool isLROk = (Opc == ARM::t2STMIA_UPD || Opc == ARM::t2STMDB_UPD);
|
2011-06-29 23:25:04 +00:00
|
|
|
bool isSPOk = isPCOk || isLROk;
|
2009-08-11 21:11:32 +00:00
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(i);
|
|
|
|
if (!MO.isReg() || MO.isImplicit())
|
|
|
|
continue;
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (Reg == 0 || Reg == ARM::CPSR)
|
|
|
|
continue;
|
|
|
|
if (isPCOk && Reg == ARM::PC)
|
|
|
|
continue;
|
|
|
|
if (isLROk && Reg == ARM::LR)
|
|
|
|
continue;
|
2009-11-19 06:32:27 +00:00
|
|
|
if (Reg == ARM::SP) {
|
|
|
|
if (isSPOk)
|
|
|
|
continue;
|
|
|
|
if (i == 1 && (Opc == ARM::t2LDRi12 || Opc == ARM::t2STRi12))
|
|
|
|
// Special case for these ldr / str with sp as base register.
|
|
|
|
continue;
|
|
|
|
}
|
2009-08-11 21:11:32 +00:00
|
|
|
if (!isARMLowRegister(Reg))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-11 08:52:18 +00:00
|
|
|
bool
|
|
|
|
Thumb2SizeReduce::ReduceLoadStore(MachineBasicBlock &MBB, MachineInstr *MI,
|
|
|
|
const ReduceEntry &Entry) {
|
2009-08-11 21:11:32 +00:00
|
|
|
if (ReduceLimitLdSt != -1 && ((int)NumLdSts >= ReduceLimitLdSt))
|
|
|
|
return false;
|
|
|
|
|
2009-08-11 08:52:18 +00:00
|
|
|
unsigned Scale = 1;
|
|
|
|
bool HasImmOffset = false;
|
|
|
|
bool HasShift = false;
|
2009-11-19 06:32:27 +00:00
|
|
|
bool HasOffReg = true;
|
2009-08-11 21:11:32 +00:00
|
|
|
bool isLdStMul = false;
|
|
|
|
unsigned Opc = Entry.NarrowOpc1;
|
|
|
|
unsigned OpNum = 3; // First 'rest' of operands.
|
2009-11-19 06:32:27 +00:00
|
|
|
uint8_t ImmLimit = Entry.Imm1Limit;
|
2010-11-16 01:16:36 +00:00
|
|
|
|
2009-08-11 08:52:18 +00:00
|
|
|
switch (Entry.WideOpc) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected Thumb2 load / store opcode!");
|
2012-08-28 03:11:27 +00:00
|
|
|
case ARM::t2LDRi12:
|
2010-12-14 03:36:38 +00:00
|
|
|
case ARM::t2STRi12:
|
|
|
|
if (MI->getOperand(1).getReg() == ARM::SP) {
|
2009-11-19 06:32:27 +00:00
|
|
|
Opc = Entry.NarrowOpc2;
|
|
|
|
ImmLimit = Entry.Imm2Limit;
|
|
|
|
HasOffReg = false;
|
|
|
|
}
|
2010-12-14 03:36:38 +00:00
|
|
|
|
2009-08-11 08:52:18 +00:00
|
|
|
Scale = 4;
|
2011-02-08 22:39:40 +00:00
|
|
|
HasImmOffset = true;
|
|
|
|
HasOffReg = false;
|
2009-08-11 08:52:18 +00:00
|
|
|
break;
|
2012-08-28 03:11:27 +00:00
|
|
|
case ARM::t2LDRBi12:
|
2009-08-11 08:52:18 +00:00
|
|
|
case ARM::t2STRBi12:
|
2011-02-08 22:39:40 +00:00
|
|
|
HasImmOffset = true;
|
|
|
|
HasOffReg = false;
|
2009-08-11 08:52:18 +00:00
|
|
|
break;
|
|
|
|
case ARM::t2LDRHi12:
|
|
|
|
case ARM::t2STRHi12:
|
|
|
|
Scale = 2;
|
2011-02-08 22:39:40 +00:00
|
|
|
HasImmOffset = true;
|
|
|
|
HasOffReg = false;
|
2009-08-11 08:52:18 +00:00
|
|
|
break;
|
2012-08-28 03:11:27 +00:00
|
|
|
case ARM::t2LDRs:
|
|
|
|
case ARM::t2LDRBs:
|
|
|
|
case ARM::t2LDRHs:
|
2009-08-11 08:52:18 +00:00
|
|
|
case ARM::t2LDRSBs:
|
|
|
|
case ARM::t2LDRSHs:
|
|
|
|
case ARM::t2STRs:
|
|
|
|
case ARM::t2STRBs:
|
|
|
|
case ARM::t2STRHs:
|
|
|
|
HasShift = true;
|
2009-08-11 21:11:32 +00:00
|
|
|
OpNum = 4;
|
2009-08-11 08:52:18 +00:00
|
|
|
break;
|
2010-11-16 01:16:36 +00:00
|
|
|
case ARM::t2LDMIA:
|
|
|
|
case ARM::t2LDMDB: {
|
2009-08-11 21:11:32 +00:00
|
|
|
unsigned BaseReg = MI->getOperand(0).getReg();
|
2010-11-16 01:16:36 +00:00
|
|
|
if (!isARMLowRegister(BaseReg) || Entry.WideOpc != ARM::t2LDMIA)
|
2010-03-13 01:08:20 +00:00
|
|
|
return false;
|
2010-12-14 03:36:38 +00:00
|
|
|
|
2010-09-07 22:30:53 +00:00
|
|
|
// For the non-writeback version (this one), the base register must be
|
|
|
|
// one of the registers being loaded.
|
|
|
|
bool isOK = false;
|
|
|
|
for (unsigned i = 4; i < MI->getNumOperands(); ++i) {
|
|
|
|
if (MI->getOperand(i).getReg() == BaseReg) {
|
|
|
|
isOK = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-14 03:36:38 +00:00
|
|
|
|
2010-09-07 22:30:53 +00:00
|
|
|
if (!isOK)
|
|
|
|
return false;
|
|
|
|
|
2010-03-13 01:08:20 +00:00
|
|
|
OpNum = 0;
|
|
|
|
isLdStMul = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-16 01:16:36 +00:00
|
|
|
case ARM::t2LDMIA_RET: {
|
2010-03-13 01:08:20 +00:00
|
|
|
unsigned BaseReg = MI->getOperand(1).getReg();
|
|
|
|
if (BaseReg != ARM::SP)
|
|
|
|
return false;
|
|
|
|
Opc = Entry.NarrowOpc2; // tPOP_RET
|
2010-11-16 01:16:36 +00:00
|
|
|
OpNum = 2;
|
2010-03-13 01:08:20 +00:00
|
|
|
isLdStMul = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-16 01:16:36 +00:00
|
|
|
case ARM::t2LDMIA_UPD:
|
|
|
|
case ARM::t2LDMDB_UPD:
|
|
|
|
case ARM::t2STMIA_UPD:
|
|
|
|
case ARM::t2STMDB_UPD: {
|
2010-03-13 01:08:20 +00:00
|
|
|
OpNum = 0;
|
2010-12-14 03:36:38 +00:00
|
|
|
|
2010-03-13 01:08:20 +00:00
|
|
|
unsigned BaseReg = MI->getOperand(1).getReg();
|
|
|
|
if (BaseReg == ARM::SP &&
|
2010-11-16 01:16:36 +00:00
|
|
|
(Entry.WideOpc == ARM::t2LDMIA_UPD ||
|
|
|
|
Entry.WideOpc == ARM::t2STMDB_UPD)) {
|
2010-03-13 01:08:20 +00:00
|
|
|
Opc = Entry.NarrowOpc2; // tPOP or tPUSH
|
2010-11-16 01:16:36 +00:00
|
|
|
OpNum = 2;
|
|
|
|
} else if (!isARMLowRegister(BaseReg) ||
|
|
|
|
(Entry.WideOpc != ARM::t2LDMIA_UPD &&
|
|
|
|
Entry.WideOpc != ARM::t2STMIA_UPD)) {
|
2009-08-11 21:11:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-12-14 03:36:38 +00:00
|
|
|
|
2009-08-11 21:11:32 +00:00
|
|
|
isLdStMul = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-11 08:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned OffsetReg = 0;
|
|
|
|
bool OffsetKill = false;
|
|
|
|
if (HasShift) {
|
|
|
|
OffsetReg = MI->getOperand(2).getReg();
|
|
|
|
OffsetKill = MI->getOperand(2).isKill();
|
2010-12-14 03:36:38 +00:00
|
|
|
|
2009-08-11 08:52:18 +00:00
|
|
|
if (MI->getOperand(3).getImm())
|
|
|
|
// Thumb1 addressing mode doesn't support shift.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned OffsetImm = 0;
|
|
|
|
if (HasImmOffset) {
|
|
|
|
OffsetImm = MI->getOperand(2).getImm();
|
2009-11-19 06:32:27 +00:00
|
|
|
unsigned MaxOffset = ((1 << ImmLimit) - 1) * Scale;
|
2010-12-14 03:36:38 +00:00
|
|
|
|
|
|
|
if ((OffsetImm & (Scale - 1)) || OffsetImm > MaxOffset)
|
2009-08-11 08:52:18 +00:00
|
|
|
// Make sure the immediate field fits.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the 16-bit load / store instruction.
|
|
|
|
DebugLoc dl = MI->getDebugLoc();
|
2011-12-14 02:11:42 +00:00
|
|
|
MachineInstrBuilder MIB = BuildMI(MBB, MI, dl, TII->get(Opc));
|
2009-08-11 21:11:32 +00:00
|
|
|
if (!isLdStMul) {
|
2010-12-07 00:45:21 +00:00
|
|
|
MIB.addOperand(MI->getOperand(0));
|
2011-02-08 22:39:40 +00:00
|
|
|
MIB.addOperand(MI->getOperand(1));
|
2010-12-14 03:36:38 +00:00
|
|
|
|
|
|
|
if (HasImmOffset)
|
|
|
|
MIB.addImm(OffsetImm / Scale);
|
|
|
|
|
2009-08-11 21:11:32 +00:00
|
|
|
assert((!HasShift || OffsetReg) && "Invalid so_reg load / store address!");
|
2009-08-11 09:37:40 +00:00
|
|
|
|
2009-11-19 06:32:27 +00:00
|
|
|
if (HasOffReg)
|
|
|
|
MIB.addReg(OffsetReg, getKillRegState(OffsetKill));
|
2009-08-11 21:11:32 +00:00
|
|
|
}
|
2009-08-11 08:52:18 +00:00
|
|
|
|
|
|
|
// Transfer the rest of operands.
|
|
|
|
for (unsigned e = MI->getNumOperands(); OpNum != e; ++OpNum)
|
|
|
|
MIB.addOperand(MI->getOperand(OpNum));
|
|
|
|
|
2009-11-19 06:32:27 +00:00
|
|
|
// Transfer memoperands.
|
2011-04-29 05:24:29 +00:00
|
|
|
MIB->setMemRefs(MI->memoperands_begin(), MI->memoperands_end());
|
2009-11-19 06:32:27 +00:00
|
|
|
|
2011-03-05 18:43:38 +00:00
|
|
|
// Transfer MI flags.
|
|
|
|
MIB.setMIFlags(MI->getFlags());
|
|
|
|
|
2009-08-23 03:41:05 +00:00
|
|
|
DEBUG(errs() << "Converted 32-bit: " << *MI << " to 16-bit: " << *MIB);
|
2009-08-11 08:52:18 +00:00
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
MBB.erase_instr(MI);
|
2009-08-11 08:52:18 +00:00
|
|
|
++NumLdSts;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Thumb2SizeReduce::ReduceSpecial(MachineBasicBlock &MBB, MachineInstr *MI,
|
|
|
|
const ReduceEntry &Entry,
|
2011-10-27 21:21:05 +00:00
|
|
|
bool LiveCPSR, MachineInstr *CPSRDef,
|
|
|
|
bool IsSelfLoop) {
|
2011-06-29 23:25:04 +00:00
|
|
|
unsigned Opc = MI->getOpcode();
|
|
|
|
if (Opc == ARM::t2ADDri) {
|
|
|
|
// If the source register is SP, try to reduce to tADDrSPi, otherwise
|
|
|
|
// it's a normal reduce.
|
|
|
|
if (MI->getOperand(1).getReg() != ARM::SP) {
|
2011-10-27 21:21:05 +00:00
|
|
|
if (ReduceTo2Addr(MBB, MI, Entry, LiveCPSR, CPSRDef, IsSelfLoop))
|
2011-06-29 23:25:04 +00:00
|
|
|
return true;
|
2011-10-27 21:21:05 +00:00
|
|
|
return ReduceToNarrow(MBB, MI, Entry, LiveCPSR, CPSRDef, IsSelfLoop);
|
2011-06-29 23:25:04 +00:00
|
|
|
}
|
|
|
|
// Try to reduce to tADDrSPi.
|
|
|
|
unsigned Imm = MI->getOperand(2).getImm();
|
|
|
|
// The immediate must be in range, the destination register must be a low
|
2011-06-30 02:22:49 +00:00
|
|
|
// reg, the predicate must be "always" and the condition flags must not
|
|
|
|
// be being set.
|
2011-07-01 19:07:09 +00:00
|
|
|
if (Imm & 3 || Imm > 1020)
|
2011-06-29 23:25:04 +00:00
|
|
|
return false;
|
|
|
|
if (!isARMLowRegister(MI->getOperand(0).getReg()))
|
|
|
|
return false;
|
2011-06-30 02:22:49 +00:00
|
|
|
if (MI->getOperand(3).getImm() != ARMCC::AL)
|
|
|
|
return false;
|
2011-06-29 23:25:04 +00:00
|
|
|
const MCInstrDesc &MCID = MI->getDesc();
|
|
|
|
if (MCID.hasOptionalDef() &&
|
|
|
|
MI->getOperand(MCID.getNumOperands()-1).getReg() == ARM::CPSR)
|
|
|
|
return false;
|
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
MachineInstrBuilder MIB = BuildMI(MBB, MI, MI->getDebugLoc(),
|
2011-06-29 23:25:04 +00:00
|
|
|
TII->get(ARM::tADDrSPi))
|
|
|
|
.addOperand(MI->getOperand(0))
|
|
|
|
.addOperand(MI->getOperand(1))
|
|
|
|
.addImm(Imm / 4); // The tADDrSPi has an implied scale by four.
|
2011-08-24 17:46:13 +00:00
|
|
|
AddDefaultPred(MIB);
|
2011-06-29 23:25:04 +00:00
|
|
|
|
|
|
|
// Transfer MI flags.
|
|
|
|
MIB.setMIFlags(MI->getFlags());
|
|
|
|
|
|
|
|
DEBUG(errs() << "Converted 32-bit: " << *MI << " to 16-bit: " <<*MIB);
|
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
MBB.erase_instr(MI);
|
2011-06-29 23:25:04 +00:00
|
|
|
++NumNarrows;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-11 21:11:32 +00:00
|
|
|
if (Entry.LowRegs1 && !VerifyLowRegs(MI))
|
2009-08-11 08:52:18 +00:00
|
|
|
return false;
|
|
|
|
|
2011-12-07 07:15:52 +00:00
|
|
|
if (MI->mayLoad() || MI->mayStore())
|
2009-08-11 08:52:18 +00:00
|
|
|
return ReduceLoadStore(MBB, MI, Entry);
|
2009-08-12 01:49:45 +00:00
|
|
|
|
|
|
|
switch (Opc) {
|
|
|
|
default: break;
|
2011-02-08 22:39:40 +00:00
|
|
|
case ARM::t2ADDSri:
|
2009-08-12 01:49:45 +00:00
|
|
|
case ARM::t2ADDSrr: {
|
|
|
|
unsigned PredReg = 0;
|
|
|
|
if (getInstrPredicate(MI, PredReg) == ARMCC::AL) {
|
|
|
|
switch (Opc) {
|
|
|
|
default: break;
|
|
|
|
case ARM::t2ADDSri: {
|
2011-10-27 21:21:05 +00:00
|
|
|
if (ReduceTo2Addr(MBB, MI, Entry, LiveCPSR, CPSRDef, IsSelfLoop))
|
2009-08-12 01:49:45 +00:00
|
|
|
return true;
|
|
|
|
// fallthrough
|
|
|
|
}
|
|
|
|
case ARM::t2ADDSrr:
|
2011-10-27 21:21:05 +00:00
|
|
|
return ReduceToNarrow(MBB, MI, Entry, LiveCPSR, CPSRDef, IsSelfLoop);
|
2009-08-12 01:49:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ARM::t2RSBri:
|
|
|
|
case ARM::t2RSBSri:
|
2011-07-27 16:47:19 +00:00
|
|
|
case ARM::t2SXTB:
|
|
|
|
case ARM::t2SXTH:
|
|
|
|
case ARM::t2UXTB:
|
|
|
|
case ARM::t2UXTH:
|
2009-08-12 01:49:45 +00:00
|
|
|
if (MI->getOperand(2).getImm() == 0)
|
2011-10-27 21:21:05 +00:00
|
|
|
return ReduceToNarrow(MBB, MI, Entry, LiveCPSR, CPSRDef, IsSelfLoop);
|
2009-08-12 01:49:45 +00:00
|
|
|
break;
|
2009-11-24 00:44:37 +00:00
|
|
|
case ARM::t2MOVi16:
|
|
|
|
// Can convert only 'pure' immediate operands, not immediates obtained as
|
|
|
|
// globals' addresses.
|
|
|
|
if (MI->getOperand(1).isImm())
|
2011-10-27 21:21:05 +00:00
|
|
|
return ReduceToNarrow(MBB, MI, Entry, LiveCPSR, CPSRDef, IsSelfLoop);
|
2009-11-24 00:44:37 +00:00
|
|
|
break;
|
2010-12-07 20:41:06 +00:00
|
|
|
case ARM::t2CMPrr: {
|
2010-12-03 23:54:18 +00:00
|
|
|
// Try to reduce to the lo-reg only version first. Why there are two
|
|
|
|
// versions of the instruction is a mystery.
|
|
|
|
// It would be nice to just have two entries in the master table that
|
|
|
|
// are prioritized, but the table assumes a unique entry for each
|
|
|
|
// source insn opcode. So for now, we hack a local entry record to use.
|
|
|
|
static const ReduceEntry NarrowEntry =
|
2012-12-20 19:59:30 +00:00
|
|
|
{ ARM::t2CMPrr,ARM::tCMPr, 0, 0, 0, 1, 1,2, 0, 0,1,0 };
|
2011-10-27 21:21:05 +00:00
|
|
|
if (ReduceToNarrow(MBB, MI, NarrowEntry, LiveCPSR, CPSRDef, IsSelfLoop))
|
2010-12-03 23:54:18 +00:00
|
|
|
return true;
|
2011-10-27 21:21:05 +00:00
|
|
|
return ReduceToNarrow(MBB, MI, Entry, LiveCPSR, CPSRDef, IsSelfLoop);
|
2010-12-03 23:54:18 +00:00
|
|
|
}
|
2009-08-12 01:49:45 +00:00
|
|
|
}
|
2009-08-11 08:52:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-08 03:21:23 +00:00
|
|
|
bool
|
2009-08-10 02:37:24 +00:00
|
|
|
Thumb2SizeReduce::ReduceTo2Addr(MachineBasicBlock &MBB, MachineInstr *MI,
|
|
|
|
const ReduceEntry &Entry,
|
2011-10-27 21:21:05 +00:00
|
|
|
bool LiveCPSR, MachineInstr *CPSRDef,
|
|
|
|
bool IsSelfLoop) {
|
2009-08-11 21:11:32 +00:00
|
|
|
|
|
|
|
if (ReduceLimit2Addr != -1 && ((int)Num2Addrs >= ReduceLimit2Addr))
|
|
|
|
return false;
|
|
|
|
|
2012-12-20 19:59:30 +00:00
|
|
|
if (!MinimizeSize && !OptimizeSize && Entry.AvoidMovs &&
|
|
|
|
STI->avoidMOVsShifterOperand())
|
|
|
|
// Don't issue movs with shifter operand for some CPUs unless we
|
|
|
|
// are optimizing / minimizing for size.
|
|
|
|
return false;
|
|
|
|
|
2009-08-10 02:37:24 +00:00
|
|
|
unsigned Reg0 = MI->getOperand(0).getReg();
|
|
|
|
unsigned Reg1 = MI->getOperand(1).getReg();
|
2012-02-24 00:33:36 +00:00
|
|
|
// t2MUL is "special". The tied source operand is second, not first.
|
|
|
|
if (MI->getOpcode() == ARM::t2MUL) {
|
2012-02-24 00:53:11 +00:00
|
|
|
unsigned Reg2 = MI->getOperand(2).getReg();
|
|
|
|
// Early exit if the regs aren't all low regs.
|
|
|
|
if (!isARMLowRegister(Reg0) || !isARMLowRegister(Reg1)
|
|
|
|
|| !isARMLowRegister(Reg2))
|
|
|
|
return false;
|
|
|
|
if (Reg0 != Reg2) {
|
2012-02-24 00:33:36 +00:00
|
|
|
// If the other operand also isn't the same as the destination, we
|
|
|
|
// can't reduce.
|
|
|
|
if (Reg1 != Reg0)
|
|
|
|
return false;
|
|
|
|
// Try to commute the operands to make it a 2-address instruction.
|
|
|
|
MachineInstr *CommutedMI = TII->commuteInstruction(MI);
|
|
|
|
if (!CommutedMI)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (Reg0 != Reg1) {
|
2010-06-24 16:50:20 +00:00
|
|
|
// Try to commute the operands to make it a 2-address instruction.
|
|
|
|
unsigned CommOpIdx1, CommOpIdx2;
|
|
|
|
if (!TII->findCommutedOpIndices(MI, CommOpIdx1, CommOpIdx2) ||
|
|
|
|
CommOpIdx1 != 1 || MI->getOperand(CommOpIdx2).getReg() != Reg0)
|
|
|
|
return false;
|
|
|
|
MachineInstr *CommutedMI = TII->commuteInstruction(MI);
|
|
|
|
if (!CommutedMI)
|
|
|
|
return false;
|
|
|
|
}
|
2009-08-08 03:21:23 +00:00
|
|
|
if (Entry.LowRegs2 && !isARMLowRegister(Reg0))
|
|
|
|
return false;
|
|
|
|
if (Entry.Imm2Limit) {
|
2009-08-10 02:37:24 +00:00
|
|
|
unsigned Imm = MI->getOperand(2).getImm();
|
2009-08-08 03:21:23 +00:00
|
|
|
unsigned Limit = (1 << Entry.Imm2Limit) - 1;
|
|
|
|
if (Imm > Limit)
|
|
|
|
return false;
|
|
|
|
} else {
|
2009-08-10 02:37:24 +00:00
|
|
|
unsigned Reg2 = MI->getOperand(2).getReg();
|
2009-08-08 03:21:23 +00:00
|
|
|
if (Entry.LowRegs2 && !isARMLowRegister(Reg2))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-10 06:57:42 +00:00
|
|
|
// Check if it's possible / necessary to transfer the predicate.
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &NewMCID = TII->get(Entry.NarrowOpc2);
|
2009-08-10 06:57:42 +00:00
|
|
|
unsigned PredReg = 0;
|
|
|
|
ARMCC::CondCodes Pred = getInstrPredicate(MI, PredReg);
|
|
|
|
bool SkipPred = false;
|
|
|
|
if (Pred != ARMCC::AL) {
|
2011-06-28 19:10:37 +00:00
|
|
|
if (!NewMCID.isPredicable())
|
2009-08-10 06:57:42 +00:00
|
|
|
// Can't transfer predicate, fail.
|
|
|
|
return false;
|
|
|
|
} else {
|
2011-06-28 19:10:37 +00:00
|
|
|
SkipPred = !NewMCID.isPredicable();
|
2009-08-10 06:57:42 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 03:21:23 +00:00
|
|
|
bool HasCC = false;
|
2009-08-10 02:37:24 +00:00
|
|
|
bool CCDead = false;
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &MCID = MI->getDesc();
|
|
|
|
if (MCID.hasOptionalDef()) {
|
|
|
|
unsigned NumOps = MCID.getNumOperands();
|
2009-08-10 02:37:24 +00:00
|
|
|
HasCC = (MI->getOperand(NumOps-1).getReg() == ARM::CPSR);
|
|
|
|
if (HasCC && MI->getOperand(NumOps-1).isDead())
|
|
|
|
CCDead = true;
|
|
|
|
}
|
2009-08-10 06:57:42 +00:00
|
|
|
if (!VerifyPredAndCC(MI, Entry, true, Pred, LiveCPSR, HasCC, CCDead))
|
2009-08-09 19:17:19 +00:00
|
|
|
return false;
|
2009-08-08 03:21:23 +00:00
|
|
|
|
2011-04-19 18:11:49 +00:00
|
|
|
// Avoid adding a false dependency on partial flag update by some 16-bit
|
|
|
|
// instructions which has the 's' bit set.
|
2011-06-28 19:10:37 +00:00
|
|
|
if (Entry.PartFlag && NewMCID.hasOptionalDef() && HasCC &&
|
2011-10-27 21:21:05 +00:00
|
|
|
canAddPseudoFlagDep(CPSRDef, MI, IsSelfLoop))
|
2011-04-19 18:11:49 +00:00
|
|
|
return false;
|
|
|
|
|
2009-08-08 03:21:23 +00:00
|
|
|
// Add the 16-bit instruction.
|
2009-08-10 02:37:24 +00:00
|
|
|
DebugLoc dl = MI->getDebugLoc();
|
2011-12-14 02:11:42 +00:00
|
|
|
MachineInstrBuilder MIB = BuildMI(MBB, MI, dl, NewMCID);
|
2009-08-10 02:37:24 +00:00
|
|
|
MIB.addOperand(MI->getOperand(0));
|
2011-06-28 19:10:37 +00:00
|
|
|
if (NewMCID.hasOptionalDef()) {
|
2009-08-15 07:59:10 +00:00
|
|
|
if (HasCC)
|
|
|
|
AddDefaultT1CC(MIB, CCDead);
|
|
|
|
else
|
|
|
|
AddNoT1CC(MIB);
|
|
|
|
}
|
2009-08-09 19:17:19 +00:00
|
|
|
|
|
|
|
// Transfer the rest of operands.
|
2011-06-28 19:10:37 +00:00
|
|
|
unsigned NumOps = MCID.getNumOperands();
|
2009-08-10 06:57:42 +00:00
|
|
|
for (unsigned i = 1, e = MI->getNumOperands(); i != e; ++i) {
|
2011-06-28 19:10:37 +00:00
|
|
|
if (i < NumOps && MCID.OpInfo[i].isOptionalDef())
|
2009-08-10 06:57:42 +00:00
|
|
|
continue;
|
2011-06-28 19:10:37 +00:00
|
|
|
if (SkipPred && MCID.OpInfo[i].isPredicate())
|
2009-08-10 06:57:42 +00:00
|
|
|
continue;
|
|
|
|
MIB.addOperand(MI->getOperand(i));
|
|
|
|
}
|
2009-08-08 03:21:23 +00:00
|
|
|
|
2011-03-05 18:43:38 +00:00
|
|
|
// Transfer MI flags.
|
|
|
|
MIB.setMIFlags(MI->getFlags());
|
|
|
|
|
2009-08-23 03:41:05 +00:00
|
|
|
DEBUG(errs() << "Converted 32-bit: " << *MI << " to 16-bit: " << *MIB);
|
2009-08-08 03:21:23 +00:00
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
MBB.erase_instr(MI);
|
2009-08-08 03:21:23 +00:00
|
|
|
++Num2Addrs;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-08-10 02:37:24 +00:00
|
|
|
Thumb2SizeReduce::ReduceToNarrow(MachineBasicBlock &MBB, MachineInstr *MI,
|
|
|
|
const ReduceEntry &Entry,
|
2011-10-27 21:21:05 +00:00
|
|
|
bool LiveCPSR, MachineInstr *CPSRDef,
|
|
|
|
bool IsSelfLoop) {
|
2009-08-11 21:11:32 +00:00
|
|
|
if (ReduceLimit != -1 && ((int)NumNarrows >= ReduceLimit))
|
|
|
|
return false;
|
|
|
|
|
2012-12-20 19:59:30 +00:00
|
|
|
if (!MinimizeSize && !OptimizeSize && Entry.AvoidMovs &&
|
|
|
|
STI->avoidMOVsShifterOperand())
|
|
|
|
// Don't issue movs with shifter operand for some CPUs unless we
|
|
|
|
// are optimizing / minimizing for size.
|
|
|
|
return false;
|
|
|
|
|
2009-08-09 19:17:19 +00:00
|
|
|
unsigned Limit = ~0U;
|
|
|
|
if (Entry.Imm1Limit)
|
2011-06-29 23:25:04 +00:00
|
|
|
Limit = (1 << Entry.Imm1Limit) - 1;
|
2009-08-09 19:17:19 +00:00
|
|
|
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &MCID = MI->getDesc();
|
|
|
|
for (unsigned i = 0, e = MCID.getNumOperands(); i != e; ++i) {
|
|
|
|
if (MCID.OpInfo[i].isPredicate())
|
2009-08-09 19:17:19 +00:00
|
|
|
continue;
|
2009-08-10 02:37:24 +00:00
|
|
|
const MachineOperand &MO = MI->getOperand(i);
|
2009-08-09 19:17:19 +00:00
|
|
|
if (MO.isReg()) {
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (!Reg || Reg == ARM::CPSR)
|
|
|
|
continue;
|
|
|
|
if (Entry.LowRegs1 && !isARMLowRegister(Reg))
|
|
|
|
return false;
|
2009-08-11 23:00:31 +00:00
|
|
|
} else if (MO.isImm() &&
|
2011-06-28 19:10:37 +00:00
|
|
|
!MCID.OpInfo[i].isPredicate()) {
|
2011-06-29 23:25:04 +00:00
|
|
|
if (((unsigned)MO.getImm()) > Limit)
|
2009-08-09 19:17:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-10 06:57:42 +00:00
|
|
|
// Check if it's possible / necessary to transfer the predicate.
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &NewMCID = TII->get(Entry.NarrowOpc1);
|
2009-08-10 06:57:42 +00:00
|
|
|
unsigned PredReg = 0;
|
|
|
|
ARMCC::CondCodes Pred = getInstrPredicate(MI, PredReg);
|
|
|
|
bool SkipPred = false;
|
|
|
|
if (Pred != ARMCC::AL) {
|
2011-06-28 19:10:37 +00:00
|
|
|
if (!NewMCID.isPredicable())
|
2009-08-10 06:57:42 +00:00
|
|
|
// Can't transfer predicate, fail.
|
|
|
|
return false;
|
|
|
|
} else {
|
2011-06-28 19:10:37 +00:00
|
|
|
SkipPred = !NewMCID.isPredicable();
|
2009-08-10 06:57:42 +00:00
|
|
|
}
|
|
|
|
|
2009-08-09 19:17:19 +00:00
|
|
|
bool HasCC = false;
|
2009-08-10 02:37:24 +00:00
|
|
|
bool CCDead = false;
|
2011-06-28 19:10:37 +00:00
|
|
|
if (MCID.hasOptionalDef()) {
|
|
|
|
unsigned NumOps = MCID.getNumOperands();
|
2009-08-10 02:37:24 +00:00
|
|
|
HasCC = (MI->getOperand(NumOps-1).getReg() == ARM::CPSR);
|
|
|
|
if (HasCC && MI->getOperand(NumOps-1).isDead())
|
|
|
|
CCDead = true;
|
|
|
|
}
|
2009-08-10 06:57:42 +00:00
|
|
|
if (!VerifyPredAndCC(MI, Entry, false, Pred, LiveCPSR, HasCC, CCDead))
|
2009-08-09 19:17:19 +00:00
|
|
|
return false;
|
|
|
|
|
2011-04-19 18:11:49 +00:00
|
|
|
// Avoid adding a false dependency on partial flag update by some 16-bit
|
|
|
|
// instructions which has the 's' bit set.
|
2011-06-28 19:10:37 +00:00
|
|
|
if (Entry.PartFlag && NewMCID.hasOptionalDef() && HasCC &&
|
2011-10-27 21:21:05 +00:00
|
|
|
canAddPseudoFlagDep(CPSRDef, MI, IsSelfLoop))
|
2011-04-19 18:11:49 +00:00
|
|
|
return false;
|
|
|
|
|
2009-08-09 19:17:19 +00:00
|
|
|
// Add the 16-bit instruction.
|
2009-08-10 02:37:24 +00:00
|
|
|
DebugLoc dl = MI->getDebugLoc();
|
2011-12-14 02:11:42 +00:00
|
|
|
MachineInstrBuilder MIB = BuildMI(MBB, MI, dl, NewMCID);
|
2009-08-10 02:37:24 +00:00
|
|
|
MIB.addOperand(MI->getOperand(0));
|
2011-06-28 19:10:37 +00:00
|
|
|
if (NewMCID.hasOptionalDef()) {
|
2009-08-15 07:59:10 +00:00
|
|
|
if (HasCC)
|
|
|
|
AddDefaultT1CC(MIB, CCDead);
|
|
|
|
else
|
|
|
|
AddNoT1CC(MIB);
|
|
|
|
}
|
2009-08-09 19:17:19 +00:00
|
|
|
|
|
|
|
// Transfer the rest of operands.
|
2011-06-28 19:10:37 +00:00
|
|
|
unsigned NumOps = MCID.getNumOperands();
|
2009-08-10 06:57:42 +00:00
|
|
|
for (unsigned i = 1, e = MI->getNumOperands(); i != e; ++i) {
|
2011-06-28 19:10:37 +00:00
|
|
|
if (i < NumOps && MCID.OpInfo[i].isOptionalDef())
|
2009-08-10 06:57:42 +00:00
|
|
|
continue;
|
2011-06-28 19:10:37 +00:00
|
|
|
if ((MCID.getOpcode() == ARM::t2RSBSri ||
|
2011-07-27 16:47:19 +00:00
|
|
|
MCID.getOpcode() == ARM::t2RSBri ||
|
|
|
|
MCID.getOpcode() == ARM::t2SXTB ||
|
|
|
|
MCID.getOpcode() == ARM::t2SXTH ||
|
|
|
|
MCID.getOpcode() == ARM::t2UXTB ||
|
|
|
|
MCID.getOpcode() == ARM::t2UXTH) && i == 2)
|
2009-08-12 01:49:45 +00:00
|
|
|
// Skip the zero immediate operand, it's now implicit.
|
|
|
|
continue;
|
2011-06-28 19:10:37 +00:00
|
|
|
bool isPred = (i < NumOps && MCID.OpInfo[i].isPredicate());
|
2009-08-11 23:00:31 +00:00
|
|
|
if (SkipPred && isPred)
|
|
|
|
continue;
|
|
|
|
const MachineOperand &MO = MI->getOperand(i);
|
2011-06-29 23:25:04 +00:00
|
|
|
if (MO.isReg() && MO.isImplicit() && MO.getReg() == ARM::CPSR)
|
|
|
|
// Skip implicit def of CPSR. Either it's modeled as an optional
|
|
|
|
// def now or it's already an implicit def on the new instruction.
|
|
|
|
continue;
|
|
|
|
MIB.addOperand(MO);
|
2009-08-10 06:57:42 +00:00
|
|
|
}
|
2011-06-28 19:10:37 +00:00
|
|
|
if (!MCID.isPredicable() && NewMCID.isPredicable())
|
2009-08-12 01:49:45 +00:00
|
|
|
AddDefaultPred(MIB);
|
2009-08-09 19:17:19 +00:00
|
|
|
|
2011-03-05 18:43:38 +00:00
|
|
|
// Transfer MI flags.
|
|
|
|
MIB.setMIFlags(MI->getFlags());
|
|
|
|
|
2009-08-23 03:41:05 +00:00
|
|
|
DEBUG(errs() << "Converted 32-bit: " << *MI << " to 16-bit: " << *MIB);
|
2009-08-09 19:17:19 +00:00
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
MBB.erase_instr(MI);
|
2009-08-09 19:17:19 +00:00
|
|
|
++NumNarrows;
|
|
|
|
return true;
|
2009-08-08 03:21:23 +00:00
|
|
|
}
|
|
|
|
|
2011-04-19 18:11:49 +00:00
|
|
|
static bool UpdateCPSRDef(MachineInstr &MI, bool LiveCPSR, bool &DefCPSR) {
|
2009-08-10 02:37:24 +00:00
|
|
|
bool HasDef = false;
|
|
|
|
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = MI.getOperand(i);
|
2009-08-12 01:49:45 +00:00
|
|
|
if (!MO.isReg() || MO.isUndef() || MO.isUse())
|
2009-08-10 02:37:24 +00:00
|
|
|
continue;
|
|
|
|
if (MO.getReg() != ARM::CPSR)
|
|
|
|
continue;
|
2011-04-19 18:11:49 +00:00
|
|
|
|
|
|
|
DefCPSR = true;
|
2009-08-12 01:49:45 +00:00
|
|
|
if (!MO.isDead())
|
|
|
|
HasDef = true;
|
|
|
|
}
|
2009-08-10 02:37:24 +00:00
|
|
|
|
2009-08-12 01:49:45 +00:00
|
|
|
return HasDef || LiveCPSR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool UpdateCPSRUse(MachineInstr &MI, bool LiveCPSR) {
|
|
|
|
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = MI.getOperand(i);
|
|
|
|
if (!MO.isReg() || MO.isUndef() || MO.isDef())
|
|
|
|
continue;
|
|
|
|
if (MO.getReg() != ARM::CPSR)
|
|
|
|
continue;
|
2009-08-10 02:37:24 +00:00
|
|
|
assert(LiveCPSR && "CPSR liveness tracking is wrong!");
|
|
|
|
if (MO.isKill()) {
|
|
|
|
LiveCPSR = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-12 01:49:45 +00:00
|
|
|
return LiveCPSR;
|
2009-08-10 02:37:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-18 00:13:11 +00:00
|
|
|
bool Thumb2SizeReduce::ReduceMI(MachineBasicBlock &MBB, MachineInstr *MI,
|
|
|
|
bool LiveCPSR, MachineInstr *CPSRDef,
|
|
|
|
bool IsSelfLoop) {
|
|
|
|
unsigned Opcode = MI->getOpcode();
|
|
|
|
DenseMap<unsigned, unsigned>::iterator OPI = ReduceOpcodeMap.find(Opcode);
|
|
|
|
if (OPI == ReduceOpcodeMap.end())
|
|
|
|
return false;
|
|
|
|
const ReduceEntry &Entry = ReduceTable[OPI->second];
|
|
|
|
|
|
|
|
// Don't attempt normal reductions on "special" cases for now.
|
|
|
|
if (Entry.Special)
|
|
|
|
return ReduceSpecial(MBB, MI, Entry, LiveCPSR, CPSRDef, IsSelfLoop);
|
|
|
|
|
|
|
|
// Try to transform to a 16-bit two-address instruction.
|
|
|
|
if (Entry.NarrowOpc2 &&
|
|
|
|
ReduceTo2Addr(MBB, MI, Entry, LiveCPSR, CPSRDef, IsSelfLoop))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Try to transform to a 16-bit non-two-address instruction.
|
|
|
|
if (Entry.NarrowOpc1 &&
|
|
|
|
ReduceToNarrow(MBB, MI, Entry, LiveCPSR, CPSRDef, IsSelfLoop))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-08 03:21:23 +00:00
|
|
|
bool Thumb2SizeReduce::ReduceMBB(MachineBasicBlock &MBB) {
|
|
|
|
bool Modified = false;
|
|
|
|
|
2009-08-10 06:57:42 +00:00
|
|
|
// Yes, CPSR could be livein.
|
2010-04-13 16:53:51 +00:00
|
|
|
bool LiveCPSR = MBB.isLiveIn(ARM::CPSR);
|
2011-04-19 18:11:49 +00:00
|
|
|
MachineInstr *CPSRDef = 0;
|
2011-12-14 02:11:42 +00:00
|
|
|
MachineInstr *BundleMI = 0;
|
2009-08-10 06:57:42 +00:00
|
|
|
|
2011-10-27 21:21:05 +00:00
|
|
|
// If this BB loops back to itself, conservatively avoid narrowing the
|
|
|
|
// first instruction that does partial flag update.
|
|
|
|
bool IsSelfLoop = MBB.isSuccessor(&MBB);
|
2012-04-06 23:43:50 +00:00
|
|
|
MachineBasicBlock::instr_iterator MII = MBB.instr_begin(),E = MBB.instr_end();
|
2011-12-14 02:11:42 +00:00
|
|
|
MachineBasicBlock::instr_iterator NextMII;
|
2009-08-08 03:21:23 +00:00
|
|
|
for (; MII != E; MII = NextMII) {
|
2009-12-03 00:50:42 +00:00
|
|
|
NextMII = llvm::next(MII);
|
2009-08-08 03:21:23 +00:00
|
|
|
|
2009-08-10 02:37:24 +00:00
|
|
|
MachineInstr *MI = &*MII;
|
2011-12-14 02:11:42 +00:00
|
|
|
if (MI->isBundle()) {
|
|
|
|
BundleMI = MI;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-12 01:49:45 +00:00
|
|
|
LiveCPSR = UpdateCPSRUse(*MI, LiveCPSR);
|
|
|
|
|
2012-12-18 00:46:39 +00:00
|
|
|
// Does NextMII belong to the same bundle as MI?
|
|
|
|
bool NextInSameBundle = NextMII != E && NextMII->isBundledWithPred();
|
|
|
|
|
2012-12-18 00:13:11 +00:00
|
|
|
if (ReduceMI(MBB, MI, LiveCPSR, CPSRDef, IsSelfLoop)) {
|
|
|
|
Modified = true;
|
|
|
|
MachineBasicBlock::instr_iterator I = prior(NextMII);
|
|
|
|
MI = &*I;
|
2012-12-18 00:46:39 +00:00
|
|
|
// Removing and reinserting the first instruction in a bundle will break
|
|
|
|
// up the bundle. Fix the bundling if it was broken.
|
|
|
|
if (NextInSameBundle && !NextMII->isBundledWithPred())
|
|
|
|
NextMII->bundleWithPred();
|
2009-08-08 03:21:23 +00:00
|
|
|
}
|
|
|
|
|
2012-12-18 00:46:39 +00:00
|
|
|
if (!NextInSameBundle && MI->isInsideBundle()) {
|
2011-12-14 02:11:42 +00:00
|
|
|
// FIXME: Since post-ra scheduler operates on bundles, the CPSR kill
|
|
|
|
// marker is only on the BUNDLE instruction. Process the BUNDLE
|
|
|
|
// instruction as we finish with the bundled instruction to work around
|
|
|
|
// the inconsistency.
|
2011-12-17 01:25:34 +00:00
|
|
|
if (BundleMI->killsRegister(ARM::CPSR))
|
|
|
|
LiveCPSR = false;
|
|
|
|
MachineOperand *MO = BundleMI->findRegisterDefOperand(ARM::CPSR);
|
|
|
|
if (MO && !MO->isDead())
|
|
|
|
LiveCPSR = true;
|
|
|
|
}
|
2011-12-14 02:11:42 +00:00
|
|
|
|
2011-04-19 18:11:49 +00:00
|
|
|
bool DefCPSR = false;
|
|
|
|
LiveCPSR = UpdateCPSRDef(*MI, LiveCPSR, DefCPSR);
|
2011-12-07 07:15:52 +00:00
|
|
|
if (MI->isCall()) {
|
2011-04-19 18:11:49 +00:00
|
|
|
// Calls don't really set CPSR.
|
|
|
|
CPSRDef = 0;
|
2011-10-27 21:21:05 +00:00
|
|
|
IsSelfLoop = false;
|
|
|
|
} else if (DefCPSR) {
|
2011-04-19 18:11:49 +00:00
|
|
|
// This is the last CPSR defining instruction.
|
|
|
|
CPSRDef = MI;
|
2011-10-27 21:21:05 +00:00
|
|
|
IsSelfLoop = false;
|
|
|
|
}
|
2009-08-08 03:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Thumb2SizeReduce::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
const TargetMachine &TM = MF.getTarget();
|
2009-08-15 07:59:10 +00:00
|
|
|
TII = static_cast<const Thumb2InstrInfo*>(TM.getInstrInfo());
|
2011-04-19 18:11:49 +00:00
|
|
|
STI = &TM.getSubtarget<ARMSubtarget>();
|
2009-08-08 03:21:23 +00:00
|
|
|
|
2012-12-20 19:59:30 +00:00
|
|
|
// Optimizing / minimizing size?
|
2012-12-30 10:32:01 +00:00
|
|
|
AttributeSet FnAttrs = MF.getFunction()->getAttributes();
|
|
|
|
OptimizeSize = FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
|
|
|
|
Attribute::OptimizeForSize);
|
|
|
|
MinimizeSize = FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
|
|
|
|
Attribute::MinSize);
|
2012-12-18 22:47:16 +00:00
|
|
|
|
2009-08-08 03:21:23 +00:00
|
|
|
bool Modified = false;
|
|
|
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
|
|
|
|
Modified |= ReduceMBB(*I);
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// createThumb2SizeReductionPass - Returns an instance of the Thumb2 size
|
|
|
|
/// reduction pass.
|
|
|
|
FunctionPass *llvm::createThumb2SizeReductionPass() {
|
|
|
|
return new Thumb2SizeReduce();
|
|
|
|
}
|