forked from Hoernchen/Epiphany
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEpiphanyVregLoadStoreOptimizer.h
103 lines (85 loc) · 4.06 KB
/
EpiphanyVregLoadStoreOptimizer.h
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
97
98
99
100
101
102
103
//===---------------------EpiphanyFpuConfigPass.h--------------------------===//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef _LLVM_LIB_TARGET_EPIPHANY_EPIPHANYVREGLSOPASS_H
#define _LLVM_LIB_TARGET_EPIPHANY_EPIPHANYVREGLSOPASS_H
#include "Epiphany.h"
#include "EpiphanyConfig.h"
#include "EpiphanyMachineFunction.h"
#include "EpiphanySubtarget.h"
#include "EpiphanyTargetMachine.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.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"
namespace llvm {
void initializeEpiphanyVregLoadStoreOptimizerPass(PassRegistry&);
typedef struct LoadStoreFlags {
// If a matching instruction is found, MergeForward is set to true if the
// merge is to remove the first instruction and replace the second with
// a pair-wise insn, and false if the reverse is true.
bool MergeForward;
bool BasedOnVirtualFI;
LoadStoreFlags() : MergeForward(false), BasedOnVirtualFI(true) {}
void setMergeForward(bool V = true) { MergeForward = V; }
bool getMergeForward() const { return MergeForward; }
void setBasedOnVirtualFI(bool V = true) { BasedOnVirtualFI = V; }
bool isBasedOnVirtualFI() const { return BasedOnVirtualFI; }
} LoadStoreFlags;
class EpiphanyVregLoadStoreOptimizer : public MachineFunctionPass {
private:
const EpiphanyInstrInfo *TII;
const TargetRegisterInfo *TRI;
const EpiphanySubtarget *Subtarget;
const EpiphanyFrameLowering *TFI;
MachineFunction *MF;
MachineRegisterInfo *MRI;
MachineFrameInfo *MFI;
// Track which registers have been modified and used.
BitVector ModifiedRegs, UsedRegs, ModifiedFrameIdxs, UsedFrameIdxs, ObjectMapped;
SmallVector<std::pair<int, int>, 128> PairedIdxs;
bool StackGrowsDown;
int64_t LastLocalBlockOffset = -4;
bool optimizeBlock(MachineBasicBlock &MBB);
bool tryToPairLoadStoreInst(MachineBasicBlock::iterator &MBBI);
bool isAlignmentCorrect(MachineInstr &FirstMI, MachineInstr &SecondMI, bool UsingVirtualFI);
MachineBasicBlock::iterator findMatchingInst(MachineBasicBlock::iterator I,
LoadStoreFlags &Flags, unsigned Limit);
MachineBasicBlock::iterator mergePairedInsns(MachineBasicBlock::iterator I,
MachineBasicBlock::iterator Paired, const LoadStoreFlags &Flags);
MachineInstrBuilder mergeFrameBasedInsns(unsigned PairedOp,
MachineBasicBlock::iterator I, MachineBasicBlock::iterator Paired,
const LoadStoreFlags &Flags);
void cleanKillFlags(MachineOperand RegOp0, MachineOperand RegOp1,
MachineBasicBlock::iterator I, MachineBasicBlock::iterator Paired,
bool MergeForward);
public:
static char ID;
EpiphanyVregLoadStoreOptimizer() : MachineFunctionPass(ID) {
initializeEpiphanyVregLoadStoreOptimizerPass(*PassRegistry::getPassRegistry());
}
StringRef getPassName() const {
return "Epiphany Vreg Load/Store Optimization Pass";
}
bool runOnMachineFunction(MachineFunction &MF);
void mergeRegBasedInsns(unsigned int PairedOp, MachineBasicBlock::iterator iterator,
MachineBasicBlock::iterator bundleIterator, const LoadStoreFlags &Flags, int64_t i,
MachineOperand operand, MachineOperand machineOperand);
};
} // namespace llvm
#endif