LLVM  6.0.0svn
Macros | Functions | Variables
AArch64ExpandPseudoInsts.cpp File Reference
#include "AArch64InstrInfo.h"
#include "AArch64Subtarget.h"
#include "MCTargetDesc/AArch64AddressingModes.h"
#include "Utils/AArch64BaseInfo.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Triple.h"
#include "llvm/CodeGen/LivePhysRegs.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/Pass.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cstdint>
#include <iterator>
#include <limits>
#include <utility>
Include dependency graph for AArch64ExpandPseudoInsts.cpp:

Go to the source code of this file.

Macros

#define AARCH64_EXPAND_PSEUDO_NAME   "AArch64 pseudo instruction expansion pass"
 

Functions

 INITIALIZE_PASS (AArch64ExpandPseudo, "aarch64-expand-pseudo", AARCH64_EXPAND_PSEUDO_NAME, false, false) static void transferImpOps(MachineInstr &OldMI
 Transfer implicit operands on the pseudo instruction to the instructions created from the expansion. More...
 
 for (unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
 
static uint64_t getChunk (uint64_t Imm, unsigned ChunkIdx)
 Helper function which extracts the specified 16-bit chunk from a 64-bit value. More...
 
static uint64_t replicateChunk (uint64_t Imm, unsigned FromIdx, unsigned ToIdx)
 Helper function which replicates a 16-bit chunk within a 64-bit value. More...
 
static bool tryOrrMovk (uint64_t UImm, uint64_t OrrImm, MachineInstr &MI, MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const AArch64InstrInfo *TII, unsigned ChunkIdx)
 Helper function which tries to materialize a 64-bit value with an ORR + MOVK instruction sequence. More...
 
static bool canUseOrr (uint64_t Chunk, uint64_t &Encoding)
 Check whether the given 16-bit chunk replicated to full 64-bit width can be materialized with an ORR instruction. More...
 
static bool tryToreplicateChunks (uint64_t UImm, MachineInstr &MI, MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const AArch64InstrInfo *TII)
 Check for identical 16-bit chunks within the constant and if so materialize them with a single ORR instruction. More...
 
static bool isStartChunk (uint64_t Chunk)
 Check whether this chunk matches the pattern '1...0...'. More...
 
static bool isEndChunk (uint64_t Chunk)
 Check whether this chunk matches the pattern '0...1...' This pattern ends a contiguous sequence of ones if we look at the bits from the LSB towards the MSB. More...
 
static uint64_t updateImm (uint64_t Imm, unsigned Idx, bool Clear)
 Clear or set all bits in the chunk at the given index. More...
 
static bool trySequenceOfOnes (uint64_t UImm, MachineInstr &MI, MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const AArch64InstrInfo *TII)
 Check whether the constant contains a sequence of contiguous ones, which might be interrupted by one or two chunks. More...
 

Variables

MachineInstrBuilderUseMI
 
MachineInstrBuilder MachineInstrBuilderDefMI
 

Macro Definition Documentation

◆ AARCH64_EXPAND_PSEUDO_NAME

#define AARCH64_EXPAND_PSEUDO_NAME   "AArch64 pseudo instruction expansion pass"

Definition at line 45 of file AArch64ExpandPseudoInsts.cpp.

Function Documentation

◆ canUseOrr()

static bool canUseOrr ( uint64_t  Chunk,
uint64_t &  Encoding 
)
static

Check whether the given 16-bit chunk replicated to full 64-bit width can be materialized with an ORR instruction.

Definition at line 163 of file AArch64ExpandPseudoInsts.cpp.

References llvm::AArch64_AM::processLogicalImmediate().

Referenced by tryToreplicateChunks().

◆ for()

for ( unsigned  i = Desc.getNumOperands(),
= OldMI.getNumOperands(); i != e; ++i 
)

◆ getChunk()

static uint64_t getChunk ( uint64_t  Imm,
unsigned  ChunkIdx 
)
static

Helper function which extracts the specified 16-bit chunk from a 64-bit value.

Definition at line 104 of file AArch64ExpandPseudoInsts.cpp.

References assert().

Referenced by replicateChunk(), tryOrrMovk(), trySequenceOfOnes(), and tryToreplicateChunks().

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( AArch64ExpandPseudo  ,
"aarch64-expand-pseudo"  ,
AARCH64_EXPAND_PSEUDO_NAME  ,
false  ,
false   
) &

Transfer implicit operands on the pseudo instruction to the instructions created from the expansion.

◆ isEndChunk()

static bool isEndChunk ( uint64_t  Chunk)
static

Check whether this chunk matches the pattern '0...1...' This pattern ends a contiguous sequence of ones if we look at the bits from the LSB towards the MSB.

Definition at line 276 of file AArch64ExpandPseudoInsts.cpp.

References llvm::isMask_64(), and llvm::max().

Referenced by trySequenceOfOnes().

◆ isStartChunk()

static bool isStartChunk ( uint64_t  Chunk)
static

Check whether this chunk matches the pattern '1...0...'.

This pattern starts a contiguous sequence of ones if we look at the bits from the LSB towards the MSB.

Definition at line 266 of file AArch64ExpandPseudoInsts.cpp.

References llvm::isMask_64(), and llvm::max().

Referenced by trySequenceOfOnes().

◆ replicateChunk()

static uint64_t replicateChunk ( uint64_t  Imm,
unsigned  FromIdx,
unsigned  ToIdx 
)
static

Helper function which replicates a 16-bit chunk within a 64-bit value.

Indices correspond to element numbers in a v4i16.

Definition at line 112 of file AArch64ExpandPseudoInsts.cpp.

References assert(), and getChunk().

Referenced by trySequenceOfOnes().

◆ tryOrrMovk()

static bool tryOrrMovk ( uint64_t  UImm,
uint64_t  OrrImm,
MachineInstr MI,
MachineBasicBlock MBB,
MachineBasicBlock::iterator MBBI,
const AArch64InstrInfo TII,
unsigned  ChunkIdx 
)
static

◆ trySequenceOfOnes()

static bool trySequenceOfOnes ( uint64_t  UImm,
MachineInstr MI,
MachineBasicBlock MBB,
MachineBasicBlock::iterator MBBI,
const AArch64InstrInfo TII 
)
static

Check whether the constant contains a sequence of contiguous ones, which might be interrupted by one or two chunks.

If so, materialize the sequence of contiguous ones with an ORR instruction. Materialize the chunks which are either interrupting the sequence or outside of the sequence with a MOVK instruction.

Assuming S is a chunk which starts the sequence (1...0...), E is a chunk which ends the sequence (0...1...). Then we are looking for constants which contain at least one S and E chunk. E.g. |E|A|B|S|, |A|E|B|S| or |A|B|E|S|.

We are also looking for constants like |S|A|B|E| where the contiguous sequence of ones wraps around the MSB into the LSB.

Definition at line 310 of file AArch64ExpandPseudoInsts.cpp.

References llvm::ARM_AM::add, llvm::MachineInstrBuilder::addConstantPoolIndex(), llvm::MachineInstrBuilder::addExternalSymbol(), llvm::MachineInstrBuilder::addGlobalAddress(), llvm::MachineInstrBuilder::addImm(), llvm::MachineInstrBuilder::addMBB(), llvm::MachineInstrBuilder::addReg(), llvm::MachineBasicBlock::addSuccessor(), llvm::MachineInstrBuilder::addUse(), llvm::AArch64ISD::ADRP, assert(), llvm::MachineBasicBlock::begin(), llvm::BuildMI(), llvm::computeAndAddLiveIns(), llvm::countLeadingZeros(), llvm::countTrailingZeros(), llvm::MachineFunction::CreateMachineBasicBlock(), llvm::RegState::Define, E, llvm::MachineBasicBlock::end(), llvm::AArch64CC::EQ, llvm::MachineInstr::eraseFromParent(), llvm::AArch64_AM::getArithExtendImm(), llvm::MachineBasicBlock::getBasicBlock(), getChunk(), llvm::TargetMachine::getCodeModel(), llvm::getDeadRegState(), llvm::MachineInstr::getDebugLoc(), llvm::MachineOperand::getGlobal(), llvm::MachineOperand::getImm(), llvm::MachineOperand::getIndex(), llvm::TargetSubtargetInfo::getInstrInfo(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::getKillRegState(), llvm::MachineOperand::getOffset(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineBasicBlock::getParent(), llvm::MachineOperand::getReg(), llvm::AArch64_AM::getShifterImm(), llvm::MachineFunction::getSubtarget(), llvm::MachineOperand::getSymbolName(), llvm::MachineFunction::getTarget(), llvm::MachineOperand::getTargetFlags(), llvm::TargetMachine::getTargetTriple(), llvm::X86II::Imm16, llvm::RegState::Implicit, llvm::MachineFunction::insert(), llvm::MachineOperand::isCPI(), llvm::MachineOperand::isDead(), isEndChunk(), llvm::MachineOperand::isGlobal(), llvm::Triple::isOSFuchsia(), isStartChunk(), llvm::MachineOperand::isSymbol(), llvm::MachineOperand::isUndef(), llvm::CodeModel::Kernel, llvm::RegState::Kill, llvm::AArch64ISD::LOADgot, llvm::AArch64_AM::LSL, llvm::BitmaskEnumDetail::Mask(), MI, llvm::AArch64II::MO_NC, llvm::AArch64II::MO_PAGE, llvm::AArch64II::MO_PAGEOFF, Modified, llvm::AArch64CC::NE, llvm::AArch64_AM::processLogicalImmediate(), replicateChunk(), llvm::ARCISD::RET, std::swap(), TII, tryOrrMovk(), tryToreplicateChunks(), llvm::RegState::Undef, updateImm(), llvm::AArch64_AM::UXTB, and llvm::AArch64_AM::UXTH.

◆ tryToreplicateChunks()

static bool tryToreplicateChunks ( uint64_t  UImm,
MachineInstr MI,
MachineBasicBlock MBB,
MachineBasicBlock::iterator MBBI,
const AArch64InstrInfo TII 
)
static

Check for identical 16-bit chunks within the constant and if so materialize them with a single ORR instruction.

The remaining one or two 16-bit chunks will be materialized with MOVK instructions.

This allows us to materialize constants like |A|B|A|A| or |A|B|C|A| (order of the chunks doesn't matter), assuming |A|A|A|A| can be materialized with an ORR instruction.

Definition at line 176 of file AArch64ExpandPseudoInsts.cpp.

References llvm::ARM_AM::add, llvm::MachineInstrBuilder::addImm(), llvm::BuildMI(), canUseOrr(), llvm::RegState::Define, llvm::WebAssembly::End, llvm::MachineInstr::eraseFromParent(), getChunk(), llvm::getDeadRegState(), llvm::MachineInstr::getDebugLoc(), llvm::MachineInstr::getOperand(), llvm::MachineOperand::getReg(), llvm::AArch64_AM::getShifterImm(), llvm::X86II::Imm16, llvm::MachineOperand::isDead(), and llvm::AArch64_AM::LSL.

Referenced by trySequenceOfOnes().

◆ updateImm()

static uint64_t updateImm ( uint64_t  Imm,
unsigned  Idx,
bool  Clear 
)
static

Clear or set all bits in the chunk at the given index.

Definition at line 284 of file AArch64ExpandPseudoInsts.cpp.

References llvm::BitmaskEnumDetail::Mask().

Referenced by trySequenceOfOnes().

Variable Documentation

◆ DefMI

Initial value:
{
const MCInstrDesc &Desc = OldMI.getDesc()
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:163

Definition at line 89 of file AArch64ExpandPseudoInsts.cpp.

Referenced by addSegmentsWithValNo(), canFoldIntoCSel(), llvm::LiveRangeEdit::checkRematerializable(), llvm::SIInstrInfo::commuteOpcode(), llvm::ScheduleDAGMILive::computeCyclicCriticalPath(), countOperands(), llvm::LiveRangeEdit::create(), llvm::createSIWholeQuadModePass(), llvm::createX86OptimizeLEAs(), CriticalPathStep(), definesFullReg(), llvm::SplitEditor::dump(), eraseGPOpnd(), llvm::LiveRangeEdit::eraseVirtReg(), getDepthOfOptCmov(), llvm::ARMHazardRecognizer::getHazardType(), llvm::MachineTraceMetrics::Trace::getInstrCycles(), llvm::AArch64RegisterBankInfo::getInstrMapping(), llvm::getOpcodeDef(), llvm::ARMBaseInstrInfo::getOperandLatency(), llvm::PPCInstrInfo::getRegisterInfo(), llvm::TargetSchedModel::getResourceBufferSize(), getSingleDef(), getUnderlyingObjects(), hoistAndMergeSGPRInits(), INITIALIZE_PASS(), isCrossCopy(), isFullCopyOf(), isKilled(), llvm::ARMBaseInstrInfo::isProfitableToDupForIfCvt(), isSourceDefinedByImplicitDef(), llvm::X86InstrInfo::isSubregFoldable(), isVirtualRegisterOperand(), llvm::TargetInstrInfo::isZeroCost(), llvm::AArch64InstrInfo::optimizeCondBranch(), llvm::LanaiInstrInfo::optimizeSelect(), llvm::ARMBaseInstrInfo::optimizeSelect(), pushDepHeight(), regIsPICBase(), regOverlapsSet(), removeCopies(), scavengeVReg(), llvm::TailDuplicator::tailDuplicateAndUpdate(), llvm::LegalizationArtifactCombiner::tryCombineAnyExt(), llvm::LegalizationArtifactCombiner::tryCombineInstruction(), llvm::LegalizationArtifactCombiner::tryCombineSExt(), llvm::LegalizationArtifactCombiner::tryCombineZExt(), llvm::LegalizationArtifactCombiner::tryFoldImplicitDef(), updatePhysDepsDownwards(), usedAsAddr(), llvm::MachineTraceMetrics::Ensemble::verify(), and llvm::LegalizerHelper::widenScalar().

◆ UseMI

Definition at line 88 of file AArch64ExpandPseudoInsts.cpp.

Referenced by addSegmentsWithValNo(), llvm::SIInstrInfo::commuteOpcode(), llvm::createHexagonHardwareLoops(), CriticalPathStep(), llvm::LiveRangeEdit::eraseVirtReg(), findOnlyInterestingUse(), llvm::ARMBaseInstrInfo::FoldImmediate(), for(), llvm::MachineTraceMetrics::Trace::getInstrCycles(), llvm::AArch64RegisterBankInfo::getInstrMapping(), llvm::ARMBaseInstrInfo::getOperandLatency(), llvm::PPCInstrInfo::getRegisterInfo(), llvm::RegScavenger::getRegsAvailable(), llvm::TargetSchedModel::getResourceBufferSize(), getUnderlyingObjects(), INITIALIZE_PASS(), isCrossCopy(), isDefLiveOut(), isFullCopyOf(), llvm::ARMBaseInstrInfo::isProfitableToDupForIfCvt(), llvm::X86InstrInfo::isSubregFoldable(), isUseSafeToFold(), isVirtualRegisterOperand(), llvm::TargetInstrInfo::isZeroCost(), llvm::MachineRegisterInfo::markUsesInDebugValueAsUndef(), mayLoadFromGOTOrConstantPool(), llvm::SIInstrInfo::moveToVALU(), multipleIterations(), llvm::PPCInstrInfo::optimizeCompareInstr(), llvm::SIInstrInfo::readlaneVGPRToSGPR(), regOverlapsSet(), removePhis(), llvm::MachineSSAUpdater::RewriteUse(), llvm::SelectionDAGISel::runOnMachineFunction(), llvm::ThumbRegisterInfo::saveScavengerRegister(), llvm::RegScavenger::scavengeRegister(), llvm::RegScavenger::scavengeRegisterBackwards(), llvm::LiveIntervals::shrinkToUses(), llvm::TailDuplicator::tailDuplicateAndUpdate(), tryChangeVGPRtoSGPRinCopy(), llvm::MachineTraceMetrics::Ensemble::updateDepth(), llvm::MachineTraceMetrics::Ensemble::updateDepths(), updatePhysDepsDownwards(), and usedAsAddr().