1 //===-- R600LowerConstCopy.cpp - Propagate ConstCopy / lower them to MOV---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This pass is intended to handle remaining ConstCopy pseudo MachineInstr.
12 /// ISel will fold each Const Buffer read inside scalar ALU. However it cannot
13 /// fold them inside vector instruction, like DOT4 or Cube ; ISel emits
14 /// ConstCopy instead. This pass (executed after ExpandingSpecialInstr) will try
15 /// to fold them if possible or replace them by MOV otherwise.
16 /// TODO : Implement the folding part, using Copy Propagation algorithm.
18 //===----------------------------------------------------------------------===//
21 #include "R600InstrInfo.h"
22 #include "llvm/CodeGen/MachineFunction.h"
23 #include "llvm/CodeGen/MachineFunctionPass.h"
24 #include "llvm/CodeGen/MachineInstrBuilder.h"
25 #include "llvm/IR/GlobalValue.h"
29 class R600LowerConstCopy : public MachineFunctionPass {
32 const R600InstrInfo *TII;
34 R600LowerConstCopy(TargetMachine &tm);
35 virtual bool runOnMachineFunction(MachineFunction &MF);
37 const char *getPassName() const { return "R600 Eliminate Symbolic Operand"; }
40 char R600LowerConstCopy::ID = 0;
43 R600LowerConstCopy::R600LowerConstCopy(TargetMachine &tm) :
44 MachineFunctionPass(ID),
45 TII (static_cast<const R600InstrInfo *>(tm.getInstrInfo()))
49 bool R600LowerConstCopy::runOnMachineFunction(MachineFunction &MF) {
50 for (MachineFunction::iterator BB = MF.begin(), BB_E = MF.end();
52 MachineBasicBlock &MBB = *BB;
53 for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end();
55 MachineInstr &MI = *I;
57 if (MI.getOpcode() != AMDGPU::CONST_COPY)
59 MachineInstr *NewMI = TII->buildDefaultInstruction(MBB, I, AMDGPU::MOV,
60 MI.getOperand(0).getReg(), AMDGPU::ALU_CONST);
61 NewMI->getOperand(9).setImm(MI.getOperand(1).getImm());
68 FunctionPass *createR600LowerConstCopy(TargetMachine &tm) {
69 return new R600LowerConstCopy(tm);