1 #include <magic/support/VariableRefs.h>
7 //===----------------------------------------------------------------------===//
8 // Constructors, destructor, and operators
9 //===----------------------------------------------------------------------===//
11 VariableRefs::VariableRefs() {
15 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
19 bool VariableRefs::isUnnecessaryInstruction(Instruction
* inst
) const {
20 //have already instruction in the entry block, skip
21 if(instructionInEntryBlock
) {
24 //have already instruction in the same block, skip
25 if(instruction
&& inst
->getParent() == instruction
->getParent()) {
32 Instruction
* VariableRefs::getInstruction() const {
36 bool VariableRefs::isInstructionInEntryBlock() const {
37 return instructionInEntryBlock
;
40 //===----------------------------------------------------------------------===//
41 // Other public methods
42 //===----------------------------------------------------------------------===//
44 void VariableRefs::addInstruction(Instruction
* inst
) {
45 //no instruction yet, update instruction
50 //have already instruction in another block, give up and resort to a single instruction in the entry block
51 setFunctionEntryInstruction(inst
->getParent()->getParent());
54 void VariableRefs::clear() {
56 instructionInEntryBlock
= false;
59 //===----------------------------------------------------------------------===//
61 //===----------------------------------------------------------------------===//
63 void VariableRefs::setFunctionEntryInstruction(Function
* function
) {
64 this->instruction
= function
->front().getFirstNonPHI();
65 this->instructionInEntryBlock
= true;