blob: 07a4b3d717002f3bf315b24874918261e7f382e4 [file] [log] [blame]
Ahmed Bougacha6756a2c2016-07-27 14:31:55 +00001//===- llvm/CodeGen/GlobalISel/InstructionSelector.cpp -----------*- C++ -*-==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10/// This file implements the InstructionSelector class.
11//===----------------------------------------------------------------------===//
12
13#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
14#include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
15#include "llvm/CodeGen/MachineInstr.h"
16#include "llvm/Target/TargetInstrInfo.h"
17#include "llvm/Target/TargetRegisterInfo.h"
18
19#define DEBUG_TYPE "instructionselector"
20
21using namespace llvm;
22
23InstructionSelector::InstructionSelector() {}
24
25bool InstructionSelector::constrainSelectedInstRegOperands(
26 MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI,
27 const RegisterBankInfo &RBI) const {
28 MachineBasicBlock &MBB = *I.getParent();
29 MachineFunction &MF = *MBB.getParent();
30 MachineRegisterInfo &MRI = MF.getRegInfo();
31
32 for (unsigned OpI = 0, OpE = I.getNumExplicitOperands(); OpI != OpE; ++OpI) {
33 MachineOperand &MO = I.getOperand(OpI);
34 DEBUG(dbgs() << "Converting operand: " << MO << '\n');
35
36 assert(MO.isReg() && "Unsupported binop non-reg operand");
37
38 const TargetRegisterClass *RC = TII.getRegClass(I.getDesc(), OpI, &TRI, MF);
39 assert(RC && "Selected inst should have regclass operand");
40
41 // If the operand is a vreg, we should constrain its regclass, and only
42 // insert COPYs if that's impossible.
43 // If the operand is a physreg, we only insert COPYs if the register class
44 // doesn't contain the register.
45 if (RBI.constrainGenericRegister(MO.getReg(), *RC, MRI))
46 continue;
47
48 DEBUG(dbgs() << "Constraining with COPYs isn't implemented yet");
49 return false;
50 }
51 return true;
52}