void
  ComponentInterface::call(FunctionHandle f, User::op_iterator args_begin,
      User::op_iterator args_end)
  {
    if (this->calls.find(f) == this->calls.end()) {
      std::vector<CallInfo*> calls;
      calls.push_back(CallInfo::Create(args_begin, args_end, 1));
      this->calls[f] = calls;
    } else {
      std::vector<CallInfo*>& calls = this->calls[f];
      for (std::vector<CallInfo*>::const_iterator begin = calls.begin(), end =
          calls.end(); begin != end; ++begin) {
        User::op_iterator cur = args_begin;
        for (std::vector<PrevirtType>::const_iterator i =
            (*begin)->args.begin(), e = (*begin)->args.end(); i != e; ++i) {
          if (i->refines(cur->get()) == NO_MATCH)
            goto no;
        }
        (*begin)->count++;
        return;
        no: continue;
      }

      this->calls[f].push_back(CallInfo::Create(args_begin, args_end, 1));
    }
  }
示例#2
0
void Preparer::replaceUndefsWithNull(User *I, ValueSet &Replaced) {
  if (Replaced.count(I))
    return;
  Replaced.insert(I);
  for (User::op_iterator OI = I->op_begin(); OI != I->op_end(); ++OI) {
    Value *V = OI->get();
    if (isa<UndefValue>(V) && V->getType()->isPointerTy()) {
      OI->set(ConstantPointerNull::get(cast<PointerType>(V->getType())));
    }
    if (User *I2 = dyn_cast<User>(V)) {
      replaceUndefsWithNull(I2, Replaced);
    }
  }
}
示例#3
0
// hunt back till you find the string..
std::string Aa::locate_portname_for_io_call(llvm::Value *strptr)
{
	std::string ret_string;
	ConstantArray* konst = NULL;
	ConstantExpr* konst_expr = NULL;
	GetElementPtrInst* gep_instr;

	std::deque<llvm::Value*> queue;
	queue.push_back(strptr);

	while (!queue.empty()) {
		llvm::Value *val = queue.front();
		queue.pop_front();
		konst = dyn_cast<ConstantArray>(val);
		if (konst != NULL)
			break;


		konst_expr = dyn_cast<ConstantExpr>(val);
		if (konst_expr != NULL)
		{
			ret_string = locate_portname_from_constant_expression(konst_expr);
			break;
		}

		gep_instr = dyn_cast<GetElementPtrInst>(val);
		if(gep_instr != NULL)
		{
			ret_string = locate_portname_from_gep_instruction(gep_instr);
			break;
		}

		if (!isa<User>(val))
			continue;

		User *u = dyn_cast<User>(val);
		for (User::op_iterator oi = u->op_begin(), oe = u->op_end(); oi != oe; ++oi) {
			llvm::Value *opnd = oi->get();
			queue.push_back(opnd);
		}
	}

	if(konst != NULL)
	{
		if(konst->isString())
			ret_string = konst->getAsString();
	}

	return(ret_string);
}
/*
getPipelineCopies finds all copies that should be made at each pipeline level.
A copy should be made if a value A is used by some instruction B, but the pipeline
level of B is more than 1 less than the pipeline level of the instruction that
acts as a definition of A. For every pipeline level between the two instructions,
a pipeline copy needs to be made at that pipeline level.
getPipelineCopies returns a map from pipeline level -> connection information, 
where the connection information is a map from (A, A->getName()) -> (BasicBlock
that defines A, list of Blocks that need a copy at that pipeline level).
*/
std::map< int, std::map<AnalyzeCopyPass::instructionPair, AnalyzeCopyPass::connectionList> > getPipelineCopies( std::map<DFBasicBlock*, bool> pipelineBlocks )
{
  std::map< int, std::map<AnalyzeCopyPass::instructionPair, AnalyzeCopyPass::connectionList> > ret;
  //go through each block in the pipeline, checking to see if any of the values
  //it uses need copies made
  for(std::map<DFBasicBlock*, bool>::iterator PBI = pipelineBlocks.begin(); PBI != pipelineBlocks.end(); ++PBI)
  {
    DFBasicBlock* currBlock = PBI->first;
    Instruction* currInst = currBlock->getFirstNonPHI();
    //the pipeline level of where the current block actually starts is
    //its base pipeline level + its delay
    int currBlock_top_level = currBlock->getPipelineLevel() + currBlock->getDelay();
    //go through the list of values this block uses; check each one to see if
    //copies need to be made
    for(User::op_iterator op = currInst->op_begin(); op != currInst->op_end(); ++op)
    {
      Instruction* inst = dynamic_cast<Instruction*>(&**op);
      if ( !inst )
        continue;
      Instruction* possibleDef = getDefinitionInstruction(inst, currBlock);
      DFBasicBlock* nextBlock = possibleDef->getParent()->getDFBasicBlock();
      //we need to create a copy for every level between our top and the 
      //pipeline level of the block that defines that value
      for( int level = currBlock_top_level; level < nextBlock->getPipelineLevel(); ++level )
      {
        Instruction* i = dynamic_cast<Instruction*>(op->get());
        ret[level][AnalyzeCopyPass::instructionPair(i,i->getName())].first = nextBlock;
        if( level == currBlock_top_level )
        {
          ret[level][AnalyzeCopyPass::instructionPair(i,i->getName())].second.push_back( currBlock );
        }
      }            
    }
  }
  return ret;
}