aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target/R600/R600LowerConstCopy.cpp
blob: 70a2b138f94e4477df982025c1faa547b8bdd95a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//===-- R600LowerConstCopy.cpp - Propagate ConstCopy / lower them to MOV---===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
/// \file
/// This pass is intended to handle remaining ConstCopy pseudo MachineInstr.
/// ISel will fold each Const Buffer read inside scalar ALU. However it cannot
/// fold them inside vector instruction, like DOT4 or Cube ; ISel emits
/// ConstCopy instead. This pass (executed after ExpandingSpecialInstr) will try
/// to fold them if possible or replace them by MOV otherwise.
/// TODO : Implement the folding part, using Copy Propagation algorithm.
//
//===----------------------------------------------------------------------===//

#include "AMDGPU.h"
#include "R600InstrInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/IR/GlobalValue.h"

namespace llvm {

class R600LowerConstCopy : public MachineFunctionPass {
private:
  static char ID;
  const R600InstrInfo *TII;
public:
  R600LowerConstCopy(TargetMachine &tm);
  virtual bool runOnMachineFunction(MachineFunction &MF);

  const char *getPassName() const { return "R600 Eliminate Symbolic Operand"; }
};

char R600LowerConstCopy::ID = 0;


R600LowerConstCopy::R600LowerConstCopy(TargetMachine &tm) :
    MachineFunctionPass(ID),
    TII (static_cast<const R600InstrInfo *>(tm.getInstrInfo()))
{
}

bool R600LowerConstCopy::runOnMachineFunction(MachineFunction &MF) {
  for (MachineFunction::iterator BB = MF.begin(), BB_E = MF.end();
                                                  BB != BB_E; ++BB) {
    MachineBasicBlock &MBB = *BB;
    for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end();
                                                      I != E;) {
      MachineInstr &MI = *I;
      I = llvm::next(I);
      if (MI.getOpcode() != AMDGPU::CONST_COPY)
        continue;
      MachineInstr *NewMI = TII->buildDefaultInstruction(MBB, I, AMDGPU::MOV,
          MI.getOperand(0).getReg(), AMDGPU::ALU_CONST);
      NewMI->getOperand(9).setImm(MI.getOperand(1).getImm());
      MI.eraseFromParent();
    }
  }
  return false;
}

FunctionPass *createR600LowerConstCopy(TargetMachine &tm) {
  return new R600LowerConstCopy(tm);
}

}