1 #include <magic/support/VariableRefs.h> 2 3 using namespace llvm; 4 5 namespace llvm { 6 7 //===----------------------------------------------------------------------===// 8 // Constructors, destructor, and operators 9 //===----------------------------------------------------------------------===// 10 VariableRefs()11VariableRefs::VariableRefs() { 12 clear(); 13 } 14 15 //===----------------------------------------------------------------------===// 16 // Getters 17 //===----------------------------------------------------------------------===// 18 isUnnecessaryInstruction(Instruction * inst) const19bool VariableRefs::isUnnecessaryInstruction(Instruction* inst) const { 20 //have already instruction in the entry block, skip 21 if(instructionInEntryBlock) { 22 return true; 23 } 24 //have already instruction in the same block, skip 25 if(instruction && inst->getParent() == instruction->getParent()) { 26 return true; 27 } 28 29 return false; 30 } 31 getInstruction() const32Instruction* VariableRefs::getInstruction() const { 33 return instruction; 34 } 35 isInstructionInEntryBlock() const36bool VariableRefs::isInstructionInEntryBlock() const { 37 return instructionInEntryBlock; 38 } 39 40 //===----------------------------------------------------------------------===// 41 // Other public methods 42 //===----------------------------------------------------------------------===// 43 addInstruction(Instruction * inst)44void VariableRefs::addInstruction(Instruction* inst) { 45 //no instruction yet, update instruction 46 if(!instruction) { 47 instruction = inst; 48 return; 49 } 50 //have already instruction in another block, give up and resort to a single instruction in the entry block 51 setFunctionEntryInstruction(inst->getParent()->getParent()); 52 } 53 clear()54void VariableRefs::clear() { 55 instruction = NULL; 56 instructionInEntryBlock = false; 57 } 58 59 //===----------------------------------------------------------------------===// 60 // Private methods 61 //===----------------------------------------------------------------------===// 62 setFunctionEntryInstruction(Function * function)63void VariableRefs::setFunctionEntryInstruction(Function* function) { 64 this->instruction = function->front().getFirstNonPHI(); 65 this->instructionInEntryBlock = true; 66 } 67 68 } 69