Example #1
0
void vSSA::createSigmasIfNeeded(BasicBlock *BB)
{
	TerminatorInst *ti = BB->getTerminator();
	// If the condition used in the terminator instruction is a Comparison instruction:
	//for each operand of the CmpInst, create sigmas, depending on some conditions
	/*
	if(isa<BranchInst>(ti)){
		BranchInst * bc = cast<BranchInst>(ti);
		if(bc->isConditional()){
			Value * cond = bc->getCondition();
			CmpInst *comparison = dyn_cast<CmpInst>(cond);
			for (User::const_op_iterator it = comparison->op_begin(), e = comparison->op_end(); it != e; ++it) {
				Value *operand = *it;
				if (isa<Instruction>(operand) || isa<Argument>(operand)) {
					insertSigmas(ti, operand);
				}
			}
		}
	}
	*/
	
	// CASE 1: Branch Instruction
	BranchInst *bi = NULL;
	SwitchInst *si = NULL;
	if ((bi = dyn_cast<BranchInst>(ti))) {
		if (bi->isConditional()) {
			Value *condition = bi->getCondition();
			
			ICmpInst *comparison = dyn_cast<ICmpInst>(condition);
			
			if (comparison) {
				// Create sigmas for ICmp operands
				for (User::const_op_iterator opit = comparison->op_begin(), opend = comparison->op_end(); opit != opend; ++opit) {
					Value *operand = *opit;
					
					if (isa<Instruction>(operand) || isa<Argument>(operand)) {
						insertSigmas(ti, operand);
						
						// If the operand is a result of a indirect instruction (e.g. ZExt, SExt, Trunc),
						// Create sigmas for the operands of the operands too
						CastInst *cinst = NULL;
						if ((cinst = dyn_cast<CastInst>(operand))) {
							insertSigmas(ti, cinst->getOperand(0));
						}
					}
				}
			}
		}
	}
	// CASE 2: Switch Instruction
	
	else if ((si = dyn_cast<SwitchInst>(ti))) {
		Value *condition = si->getCondition();
		
		if (isa<Instruction>(condition) || isa<Argument>(condition)) {
			insertSigmas(ti, condition);
			
			// If the operand is a result of a indirect instruction (e.g. ZExt, SExt, Trunc),
			// Create sigmas for the operands of the operands too
			CastInst *cinst = NULL;
			if ((cinst = dyn_cast<CastInst>(condition))) {
				insertSigmas(ti, cinst->getOperand(0));
			}
		}
	}
	
}