blob: 92bec82da2beef1fc1a475bf2154459bff9c287f (
plain)
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
|
#include <magic/support/VariableRefs.h>
using namespace llvm;
namespace llvm {
//===----------------------------------------------------------------------===//
// Constructors, destructor, and operators
//===----------------------------------------------------------------------===//
VariableRefs::VariableRefs() {
clear();
}
//===----------------------------------------------------------------------===//
// Getters
//===----------------------------------------------------------------------===//
bool VariableRefs::isUnnecessaryInstruction(Instruction* inst) const {
//have already instruction in the entry block, skip
if(instructionInEntryBlock) {
return true;
}
//have already instruction in the same block, skip
if(instruction && inst->getParent() == instruction->getParent()) {
return true;
}
return false;
}
Instruction* VariableRefs::getInstruction() const {
return instruction;
}
bool VariableRefs::isInstructionInEntryBlock() const {
return instructionInEntryBlock;
}
//===----------------------------------------------------------------------===//
// Other public methods
//===----------------------------------------------------------------------===//
void VariableRefs::addInstruction(Instruction* inst) {
//no instruction yet, update instruction
if(!instruction) {
instruction = inst;
return;
}
//have already instruction in another block, give up and resort to a single instruction in the entry block
setFunctionEntryInstruction(inst->getParent()->getParent());
}
void VariableRefs::clear() {
instruction = NULL;
instructionInEntryBlock = false;
}
//===----------------------------------------------------------------------===//
// Private methods
//===----------------------------------------------------------------------===//
void VariableRefs::setFunctionEntryInstruction(Function* function) {
this->instruction = function->front().getFirstNonPHI();
this->instructionInEntryBlock = true;
}
}
|