//===-- VectorElementize.cpp - Remove unreachable blocks for codegen --===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This pass converts operations on vector types to operations on their
// element types.
//
// For generic binary and unary vector instructions, the conversion is simple.
// Suppose we have
// av = bv Vop cv
// where av, bv, and cv are vector virtual registers, and Vop is a vector op.
// This gets converted to the following :
// a1 = b1 Sop c1
// a2 = b2 Sop c2
//
// VectorToScalarMap maintains the vector vreg to scalar vreg mapping.
// For the above example, the map will look as follows:
// av => [a1, a2]
// bv => [b1, b2]
//
// In addition, initVectorInfo creates the following opcode->opcode map.
// Vop => Sop
// OtherVop => OtherSop
// ...
//
// For vector specific instructions like vecbuild, vecshuffle etc, the
// conversion is different. Look at comments near the functions with
// prefix createVec<...>.
//
//===----------------------------------------------------------------------===//
#include "NVPTX.h"
#include "NVPTXTargetMachine.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/Constant.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/Pass.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Type.h"
using namespace llvm;
namespace {
class LLVM_LIBRARY_VISIBILITY VectorElementize : public MachineFunctionPass {
virtual bool runOnMachineFunction(MachineFunction &F);
NVPTXTargetMachine &TM;
MachineRegisterInfo *MRI;
const NVPTXRegisterInfo *RegInfo;
const NVPTXInstrInfo *InstrInfo;
llvm::DenseMap<const TargetRegisterClass *, const TargetRegisterClass *>
RegClassMap;
llvm::DenseMap<unsigned, bool> SimpleMoveMap;
llvm::DenseMap<unsigned, SmallVector<unsigned, 4> > VectorToScalarMap;
bool isVectorInstr(MachineInstr *);
SmallVector<unsigned, 4> getScalarRegisters(unsigned);
unsigned getScalarVersion(unsigned);
unsigned getScalarVersion(MachineInstr *);
bool isVectorRegister(unsigned);
const TargetRegisterClass *getScalarRegClass(const TargetRegisterClass *RC);
unsigned numCopiesNeeded(MachineInstr *);
void createLoadCopy(MachineFunction&, MachineInstr *,
std::vector<MachineInstr *>&);
void createStoreCopy(MachineFunction&, MachineInstr *,
std::vector<MachineInstr *>&);
void createVecDest(MachineFunction&, MachineInstr *,
std::vector<MachineInstr *>&);
void createCopies(MachineFunction&, MachineInstr *,
std::vector<MachineInstr *>&);
unsigned copyProp(MachineFunction&);
unsigned removeDeadMoves(MachineFunction&);
void e