-
Notifications
You must be signed in to change notification settings - Fork 8
/
CondMovPass.cpp
81 lines (65 loc) · 2.66 KB
/
CondMovPass.cpp
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
75
76
77
78
79
80
81
//===-- EpiphanyCondMovPass.cpp -----------------------===//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "epiphany_condmovpass"
#include "Epiphany.h"
#include "EpiphanyMachineFunctionInfo.h"
#include "EpiphanySubtarget.h"
#include "EpiphanyTargetMachine.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetRegisterInfo.h"
using namespace llvm;
namespace {
class EpiphanyCondMovPass : public MachineFunctionPass {
private:
EpiphanyTargetMachine& QTM;
public:
static char ID;
EpiphanyCondMovPass(EpiphanyTargetMachine& TM) : MachineFunctionPass(ID), QTM(TM) {}
const char *getPassName() const {
return "Epiphany movCC cleanup";
}
bool runOnMachineFunction(MachineFunction &Fn);
};
char EpiphanyCondMovPass::ID = 0;
bool EpiphanyCondMovPass::runOnMachineFunction(MachineFunction &Fn) {
bool modified = false;
// Loop over all of the basic blocks.
for(MachineFunction::iterator MBBb = Fn.begin(), MBBe = Fn.end(); MBBb != MBBe; ++MBBb) {
MachineBasicBlock* MBB = MBBb;
std::vector<MachineInstr*> killmeplease;
// Loop over all instructions.
for(MachineBasicBlock::iterator MII = MBB->begin(), E = MBB->end(); MII != E; ++MII){
MachineInstr *MI = &*MII;
if((MI->getOpcode() == Epiphany::MOVww || MI->getOpcode() == Epiphany::MOVss) && MI->getOperand(0).isReg() && MI->getOperand(1).isReg() && MI->getOperand(0).getReg() == MI->getOperand(1).getReg())
killmeplease.push_back(MI);
}
if(!killmeplease.empty()){
modified = true;
for (std::vector<MachineInstr*>::iterator kb = killmeplease.begin(), ke = killmeplease.end(); kb != ke ; kb++)
(*kb)->eraseFromParent(); // we can safely do this because mov Rd, Rd is a nop with no side effects.
}
}
return modified;
}
}// namespace
//===----------------------------------------------------------------------===//
// Public Constructor Functions
//===----------------------------------------------------------------------===//
FunctionPass *llvm::createEpiphanyCondMovPass(EpiphanyTargetMachine &TM) {
return new EpiphanyCondMovPass(TM);
}