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));
    }
  }
static void removeLifetimeIntrinsicUsers(AllocaInst *AI) {
  // Knowing that this alloca is promotable, we know that it's safe to kill all
  // instructions except for load and store.
  // FIXME: This function isn't actually specific to lifetime instrinsics. It
  // also is redundant with the actual analysis of the loads and stores and
  // should be folded into that.

  SmallVector<Instruction *, 8> Worklist;
  SmallPtrSet<Instruction *, 8> Visited;
  SmallVector<Instruction *, 8> Dead;
  Worklist.push_back(AI);

  do {
    Instruction *I = Worklist.pop_back_val();

    if (I->use_empty()) {
      Dead.push_back(I);
      continue;
    }

    for (Value::use_iterator UI = I->use_begin(), UE = I->use_end();
         UI != UE; ++UI)
      if (!isa<LoadInst>(*UI) && !isa<StoreInst>(*UI) &&
          Visited.insert(cast<Instruction>(*UI)))
        Worklist.push_back(cast<Instruction>(*UI));
  } while (!Worklist.empty());

  while (!Dead.empty()) {
    Instruction *I = Dead.pop_back_val();

    // Don't delete the alloca itself.
    if (I == AI)
      continue;

    // Note that we open code the deletion algorithm here because we know
    // apriori that all of the instructions using an alloca that reaches here
    // are trivially dead when their use list becomes empty (The only risk are
    // lifetime markers which we specifically want to nuke). By coding it here
    // we can skip the triviality test and be more efficient.
    //
    // Null out all of the instruction's operands to see if any operand becomes
    // dead as we go.
    for (User::op_iterator OI = I->op_begin(), OE = I->op_end(); OI != OE;
         ++OI) {
      Instruction *Op = dyn_cast<Instruction>(*OI);
      if (!Op)
        continue;

      OI->set(0);
      if (!Op->use_empty())
        continue;

      Dead.push_back(Op);
    }
    I->eraseFromParent();
  }
}
Exemple #3
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);
    }
  }
}
Exemple #4
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;
}