-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathDataPathPromotion.cpp
More file actions
executable file
·96 lines (88 loc) · 3.4 KB
/
DataPathPromotion.cpp
File metadata and controls
executable file
·96 lines (88 loc) · 3.4 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//====- DataPathPromotion.cpp - Perpare for RTL code generation -*- C++ -*-===//
//
// The Shang HLS frameowrk //
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implement the DataPathPromotion pass, promote the operation in
// DataPath from ChainedOpc to ControlOpc according to the restraint.
//
//===----------------------------------------------------------------------===//
#include "vtm/VerilogBackendMCTargetDesc.h"
#include "vtm/Passes.h"
#include "vtm/VFInfo.h"
#include "vtm/VRegisterInfo.h"
#include "vtm/VInstrInfo.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
using namespace llvm;
namespace {
struct DataPathPromotion : public MachineFunctionPass {
// Mapping the PHI number to accutally register.
std::map<unsigned, unsigned> PHIsMap;
static char ID;
DataPathPromotion() : MachineFunctionPass(ID) {}
bool runOnMachineFunction(MachineFunction &MF) {
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
for (MachineBasicBlock::instr_iterator II = I->instr_begin(),
IE = I->instr_end(); II != IE; ++II) {
MachineInstr *MI = II;
switch(MI->getOpcode()) {
default:
break;
case VTM::VOpAdd_c: {
unsigned Size = VInstrInfo::getBitWidth(MI->getOperand(0));
if (!getFUDesc(VFUs::AddSub)->shouldBeChained(Size-1))
MI->setDesc(VInstrInfo::getDesc(VTM::VOpAdd));
break;
}
case VTM::VOpICmp_c: {
unsigned Size = VInstrInfo::getBitWidth(MI->getOperand(3));
if (!getFUDesc(VFUs::ICmp)->shouldBeChained(Size))
MI->setDesc(VInstrInfo::getDesc(VTM::VOpICmp));
break;
}
case VTM::VOpSHL_c: {
unsigned Size = VInstrInfo::getBitWidth(MI->getOperand(0));
if (!getFUDesc(VFUs::Shift)->shouldBeChained(Size))
MI->setDesc(VInstrInfo::getDesc(VTM::VOpSHL));
break;
}
case VTM::VOpSRA_c: {
unsigned Size = VInstrInfo::getBitWidth(MI->getOperand(0));
if (!getFUDesc(VFUs::Shift)->shouldBeChained(Size))
MI->setDesc(VInstrInfo::getDesc(VTM::VOpSRA));
break;
}
case VTM::VOpSRL_c: {
unsigned Size = VInstrInfo::getBitWidth(MI->getOperand(0));
if (!getFUDesc(VFUs::Shift)->shouldBeChained(Size))
MI->setDesc(VInstrInfo::getDesc(VTM::VOpSRL));
break;
}
case VTM::VOpMultLoHi_c:
case VTM::VOpMult_c: {
unsigned Size = VInstrInfo::getBitWidth(MI->getOperand(0));
if (!getFUDesc(VFUs::Mult)->shouldBeChained(Size))
MI->setDesc(VInstrInfo::getDesc(VTM::VOpMult));
break;
}
}
}
return true;
}
const char *getPassName() const {
return "Data Path Promotion Pass";
}
};
}
char DataPathPromotion::ID = 0;
Pass *llvm::createDataPathPromotionPass() {
return new DataPathPromotion();
}