1 //===-- SIPropagateImmReads.cpp - Lower Immediate Reads Pass --------------===//
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 //===----------------------------------------------------------------------===//
10 // We can't do this in the ConvertToISA pass, because later passes might
11 // create LOADCONST_* instructions that we would miss. This is why we need
12 // a separate pass for this.
14 //===----------------------------------------------------------------------===//
17 #include "AMDGPUUtil.h"
18 #include "SIInstrInfo.h"
19 #include "llvm/CodeGen/MachineFunctionPass.h"
24 class SIPropagateImmReadsPass
: public MachineFunctionPass
{
31 SIPropagateImmReadsPass(TargetMachine
&tm
) :
32 MachineFunctionPass(ID
), TM(tm
) { }
34 virtual bool runOnMachineFunction(MachineFunction
&MF
);
36 } /* End anonymous namespace */
38 char SIPropagateImmReadsPass::ID
= 0;
40 FunctionPass
*llvm::createSIPropagateImmReadsPass(TargetMachine
&tm
) {
41 return new SIPropagateImmReadsPass(tm
);
44 bool SIPropagateImmReadsPass::runOnMachineFunction(MachineFunction
&MF
)
46 const SIInstrInfo
* TII
= static_cast<const SIInstrInfo
*>(TM
.getInstrInfo());
48 for (MachineFunction::iterator BB
= MF
.begin(), BB_E
= MF
.end();
50 MachineBasicBlock
&MBB
= *BB
;
51 for (MachineBasicBlock::iterator I
= MBB
.begin(), Next
= llvm::next(I
);
52 I
!= MBB
.end(); I
= Next
, Next
= llvm::next(I
)) {
53 MachineInstr
&MI
= *I
;
55 switch (MI
.getOpcode()) {
56 case AMDIL::LOADCONST_f32
:
57 case AMDIL::LOADCONST_i32
:
63 /* XXX: Create and use S_MOV_IMM for SREGs */
64 BuildMI(MBB
, I
, MBB
.findDebugLoc(I
), TII
->get(AMDIL::V_MOV_IMM
))
65 .addOperand(MI
.getOperand(0))
66 .addOperand(MI
.getOperand(1));