Exemplo n.º 1
0
    const FunctionType *getCalleePrototype(const CallInst *C) {
	assert(!isInlineAssembly(C) && "Inline assembly is not supported!");

	const Value *callie = C->getCalledValue();

        if (const Function *fn = dyn_cast<Function>(callie))
            return fn->getFunctionType();
        else if (const PointerType *ptrType =
		dyn_cast<PointerType>(callie->getType()))
            return dyn_cast<FunctionType>(ptrType->getElementType());

	assert(0 && "Invalid callie type");
    }
Exemplo n.º 2
0
    bool isPointerManipulation(llvm::Instruction const* const I) {
        if (isa<AllocaInst>(I)) {
          return false;
        } else if (I->getOpcode() == llvm::Instruction::Load)
        {
            if (llvm::dyn_cast<llvm::PointerType const>(
                        I->getOperand(0)->getType())->
                    getElementType()->isPointerTy())
                return true;
        }
        else if (I->getOpcode() == llvm::Instruction::Store)
        {
            if (I->getOperand(0)->getType()->isPointerTy())
                return true;
        }
        else if (I->getOpcode() == llvm::Instruction::BitCast)
        {
            if (I->getType()->isPointerTy() &&
                    I->getOperand(0)->getType()->isPointerTy())
                return true;
        }
        else if (I->getOpcode() == llvm::Instruction::GetElementPtr)
        //else if (llvm::GetElementPtrInst const* const gep =
        //            llvm::dyn_cast<llvm::GetElementPtrInst>(I))
        {
            return true;
        } else if (const llvm::CallInst *C =
                        llvm::dyn_cast<llvm::CallInst>(I)) {
          if (isInlineAssembly(C))
            return false;
          return memoryManStuff(C->getCalledValue());
        } else if (const PHINode *PHI = dyn_cast<PHINode>(I)) {
          return isPointerValue(PHI);
        } else if (const ExtractValueInst *EV =
                   dyn_cast<const ExtractValueInst>(I)) {
          return isPointerValue(EV);
        } else if (const InsertValueInst *IV =
                   dyn_cast<const InsertValueInst>(I)) {
          return isPointerValue(IV->getInsertedValueOperand());
        } else if (isa<IntToPtrInst>(I)) {
          return true;
        } else if (const SelectInst *SEL = dyn_cast<SelectInst>(I)) {
          if (isPointerValue(SEL))
            return true;
        }

        assert(!isPointerValue(I) &&
               "Instruction cannot be a of pointer type here!");

        return false;
    }
Exemplo n.º 3
0
void buildCallMaps(Module const& M, FunctionsMap& F,
		CallsMap& C) {
    for (Module::const_iterator f = M.begin(); f != M.end(); ++f) {
	if (!f->isDeclaration())
	    F.insert(std::make_pair(f->getFunctionType(), &*f));
	for (Function::const_iterator b = f->begin(); b != f->end(); ++b) {
	    for (BasicBlock::const_iterator i = b->begin(); i != b->end(); ++i)
		if (const CallInst *CI = dyn_cast<CallInst>(&*i)) {
		    if (!isInlineAssembly(CI) && !callToMemoryManStuff(CI))
			C.insert(std::make_pair(getCalleePrototype(CI), CI));
		} else if (const StoreInst *SI = dyn_cast<StoreInst>(&*i)) {
		    const Value *r = SI->getValueOperand();
		    if (hasExtraReference(r) && memoryManStuff(r)) {
			const Function *fn = dyn_cast<Function>(r);
			F.insert(std::make_pair(fn->getFunctionType(), fn));
		    }
		}
	}
    }
}
Exemplo n.º 4
0
    // C is the call instruction. F is the function being called.
    void FwdStaticSlicerHelper::getRelevantVarsAtCall(llvm::CallInst const* const C,
			       llvm::Function const* const F,
			       const ValSet::const_iterator &_b, // Relevant vars begin
			       const ValSet::const_iterator &e,  // Relevant vars end
             RelevantSet &out) {

      DEBUG( errs()  << "getRelevantVarsAtCall " );
      DEBUG( C->print(errs()) );
      DEBUG( errs() << F->getName() << "\n" );

      assert(!isInlineAssembly(C) && "Inline assembly is not supported!");
      const Function *caller = C->getParent()->getParent();

      ArgsToParams toParams;
      fillArgsToParams(C, F, toParams);

      // Iterate on all relevant vars
      for (ValSet::const_iterator b(_b); b != e; ++b) {
        DEBUG( errs() << "Check: " << b->first->getName() << "\n" );
        ArgsToParams::const_iterator it = toParams.find(*b);
        if (it != toParams.end()){
          // Insert all the relevant arguments
          out.insert(it->second);
          DEBUG( "Insert argument " );
          DEBUG( errs() << it->second.first->getName() );
          DEBUG( "\n" );
        //} else if (!isLocalToFunction(b->first, F)) {
        } else if (!isLocalToFunction(b->first, caller)) {
          // Insert global relevant variables
          out.insert(*b);
          DEBUG( "Insert global " );
          DEBUG( errs() << b->first->getName() );
          DEBUG( "\n" );
        }
      }
    }
Exemplo n.º 5
0
 bool callToVoidFunction(llvm::CallInst const* const C)
 {
   if (isInlineAssembly(C))
     return false;
   return C->getType()->getTypeID() == llvm::Type::VoidTyID;
 }