forked from microsoft/llvm-mctoll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MachineInstructionRaiser.h
83 lines (71 loc) · 3.14 KB
/
MachineInstructionRaiser.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
//===-- MachineInstructionRaiser.h ------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains the declaration of MachineInstructionRaiser class used
// by llvm-mctoll. This class encapsulates the raising of MachineInstruction
// to LLVM Instruction
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_MCTOLL_MACHINEINSTRUCTIONRAISER_H
#define LLVM_TOOLS_LLVM_MCTOLL_MACHINEINSTRUCTIONRAISER_H
#include "MCInstRaiser.h"
#include "ModuleRaiser.h"
#include "llvm/CodeGen/MachineFunction.h"
using namespace llvm;
// Structure holding all necessary information to raise control
// transfer (i.e., branch) instructions during a post-processing
// phase.
typedef struct {
BasicBlock *CandidateBlock;
// This is the MachineInstr that needs to be raised
const MachineInstr *CandidateMachineInstr;
// A vector of values that could be of use while raising
// CandidateMachineInstr. If it is a call instruction,
// this vector has the Values corresponding to argument
// registers (TODO : need to handles arguments passed on stack)
// If this is a conditional branch instruction, it contains the
// EFLAG bit values.
std::vector<Value *> RegValues;
// Flag to indicate that CandidateMachineInstr has been raised
bool Raised;
} ControlTransferInfo;
class MachineInstructionRaiser {
public:
MachineInstructionRaiser() = delete;
MachineInstructionRaiser(MachineFunction &machFunc, const ModuleRaiser *mr,
MCInstRaiser *mcir = nullptr)
: MF(machFunc), raisedFunction(nullptr), mcInstRaiser(mcir), MR(mr),
PrintPass(false) {}
virtual ~MachineInstructionRaiser(){};
virtual bool raise() { return true; };
virtual FunctionType *getRaisedFunctionPrototype() = 0;
virtual int getArgumentNumber(unsigned PReg) = 0;
virtual Value *getRegOrArgValue(unsigned PReg, int MBBNo) = 0;
virtual bool buildFuncArgTypeVector(const std::set<MCPhysReg> &,
std::vector<Type *> &) = 0;
Function *getRaisedFunction() { return raisedFunction; }
MCInstRaiser *getMCInstRaiser() { return mcInstRaiser; }
MachineFunction &getMF() { return MF; };
const ModuleRaiser *getModuleRaiser() { return MR; }
std::vector<ControlTransferInfo *> getControlTransferInfo() {
return CTInfo;
};
protected:
MachineFunction &MF;
// This is the Function object that holds the raised abstraction of MF.
// Not the the function associated with MF should not be referenced or
// updated. It was created just to enable the creation of MF.
Function *raisedFunction;
MCInstRaiser *mcInstRaiser;
const ModuleRaiser *MR;
// A vector of information to be used for raising of control transfer
// (i.e., Call and Terminator) instructions.
std::vector<ControlTransferInfo *> CTInfo;
bool PrintPass;
};
#endif // LLVM_TOOLS_LLVM_MCTOLL_MACHINEINSTRUCTIONRAISER_H