diff options
author | Ahmed Bougacha <ahmed.bougacha@gmail.com> | 2016-07-27 14:31:55 +0000 |
---|---|---|
committer | Ahmed Bougacha <ahmed.bougacha@gmail.com> | 2016-07-27 14:31:55 +0000 |
commit | 6756a2c95335fba8bece4402e62f5057a20f3b4c (patch) | |
tree | 709ff96a5dff1a43cd8648f7001709782eb47020 /llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp | |
parent | 5e402eec7bc306343cfba703fd4d4acc981b4ead (diff) | |
download | bcm5719-llvm-6756a2c95335fba8bece4402e62f5057a20f3b4c.tar.gz bcm5719-llvm-6756a2c95335fba8bece4402e62f5057a20f3b4c.zip |
[GlobalISel] Introduce an instruction selector.
And implement it for AArch64, supporting x/w ADD/OR.
Differential Revision: https://reviews.llvm.org/D22373
llvm-svn: 276875
Diffstat (limited to 'llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp')
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp b/llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp new file mode 100644 index 00000000000..07a4b3d7170 --- /dev/null +++ b/llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp @@ -0,0 +1,52 @@ +//===- llvm/CodeGen/GlobalISel/InstructionSelector.cpp -----------*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// \file +/// This file implements the InstructionSelector class. +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/GlobalISel/InstructionSelector.h" +#include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h" +#include "llvm/CodeGen/MachineInstr.h" +#include "llvm/Target/TargetInstrInfo.h" +#include "llvm/Target/TargetRegisterInfo.h" + +#define DEBUG_TYPE "instructionselector" + +using namespace llvm; + +InstructionSelector::InstructionSelector() {} + +bool InstructionSelector::constrainSelectedInstRegOperands( + MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, + const RegisterBankInfo &RBI) const { + MachineBasicBlock &MBB = *I.getParent(); + MachineFunction &MF = *MBB.getParent(); + MachineRegisterInfo &MRI = MF.getRegInfo(); + + for (unsigned OpI = 0, OpE = I.getNumExplicitOperands(); OpI != OpE; ++OpI) { + MachineOperand &MO = I.getOperand(OpI); + DEBUG(dbgs() << "Converting operand: " << MO << '\n'); + + assert(MO.isReg() && "Unsupported binop non-reg operand"); + + const TargetRegisterClass *RC = TII.getRegClass(I.getDesc(), OpI, &TRI, MF); + assert(RC && "Selected inst should have regclass operand"); + + // If the operand is a vreg, we should constrain its regclass, and only + // insert COPYs if that's impossible. + // If the operand is a physreg, we only insert COPYs if the register class + // doesn't contain the register. + if (RBI.constrainGenericRegister(MO.getReg(), *RC, MRI)) + continue; + + DEBUG(dbgs() << "Constraining with COPYs isn't implemented yet"); + return false; + } + return true; +} |