Restrict sin/cos optimization to 64-bit only for now. 32-bit is a bit messy and less...
[oota-llvm.git] / lib / Target / R600 / R600LowerConstCopy.cpp
1 //===-- R600LowerConstCopy.cpp - Propagate ConstCopy / lower them to MOV---===//
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 //
10 /// \file
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.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #include "AMDGPU.h"
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"
26
27 namespace llvm {
28
29 class R600LowerConstCopy : public MachineFunctionPass {
30 private:
31   static char ID;
32   const R600InstrInfo *TII;
33 public:
34   R600LowerConstCopy(TargetMachine &tm);
35   virtual bool runOnMachineFunction(MachineFunction &MF);
36
37   const char *getPassName() const { return "R600 Eliminate Symbolic Operand"; }
38 };
39
40 char R600LowerConstCopy::ID = 0;
41
42
43 R600LowerConstCopy::R600LowerConstCopy(TargetMachine &tm) :
44     MachineFunctionPass(ID),
45     TII (static_cast<const R600InstrInfo *>(tm.getInstrInfo()))
46 {
47 }
48
49 bool R600LowerConstCopy::runOnMachineFunction(MachineFunction &MF) {
50   for (MachineFunction::iterator BB = MF.begin(), BB_E = MF.end();
51                                                   BB != BB_E; ++BB) {
52     MachineBasicBlock &MBB = *BB;
53     for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end();
54                                                       I != E;) {
55       MachineInstr &MI = *I;
56       I = llvm::next(I);
57       if (MI.getOpcode() != AMDGPU::CONST_COPY)
58         continue;
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());
62       MI.eraseFromParent();
63     }
64   }
65   return false;
66 }
67
68 FunctionPass *createR600LowerConstCopy(TargetMachine &tm) {
69   return new R600LowerConstCopy(tm);
70 }
71
72 }
73
74