Esempio n. 1
0
 void fillParamsToArgs(llvm::CallInst const* const C,
                       llvm::Function const* const F,
                       ParamsToArgs& toArgs)
 {
     llvm::Function::const_arg_iterator p = F->arg_begin();
     std::size_t a = 0;
     for ( ; a < C->getNumArgOperands(); ++a, ++p)
     {
         llvm::Value const* const P = &*p;
         llvm::Value const* const A = C->getArgOperand(a);
         if (!isConstantValue(A))
             toArgs[P] = A;
     }
 }
/// Returns true if a given value is constant.
/// The value is considered to be constant if it is:
/// - a literal
/// - a tuple or a struct whose fields are all constants
static bool isConstantValue(SILValue V) {
  if (isa<LiteralInst>(V))
    return true;
  if (auto *TI = dyn_cast<TupleInst>(V)) {
    for (auto E : TI->getElements()) {
      if (!isConstantValue(E))
        return false;
    }
    return true;
  }
  if (auto *SI = dyn_cast<StructInst>(V)) {
    for (auto E : SI->getElements()) {
      if (!isConstantValue(E))
        return false;
    }
    return true;
  }
  if (auto *MT = dyn_cast<MetatypeInst>(V)) {
    if (!MT->getType().hasArchetype())
      return true;
  }
  return false;
}
bool swift::isPureCall(FullApplySite AI, SideEffectAnalysis *SEA) {
  // If a call has only constant arguments and the call is pure, i.e. has
  // no side effects, then we should always inline it.
  SideEffectAnalysis::FunctionEffects ApplyEffects;
  SEA->getEffects(ApplyEffects, AI);
  auto GE = ApplyEffects.getGlobalEffects();
  if (GE.mayRead() || GE.mayWrite() || GE.mayRetain() || GE.mayRelease())
    return false;
  // Check if all parameters are constant.
  auto Args = AI.getArgumentsWithoutIndirectResults();
  for (auto Arg : Args) {
    if (!isConstantValue(Arg)) {
      return false;
    }
  }
  return true;
}
Esempio n. 4
0
bool CAstWrapper::isConstantOfType(jobject castNode, jclass type) {
  //
  // one might think this test against null is not needed, since
  // IsInstanceoOf ought to return false given null and any type at
  // all, which is what happens with the `instanceof'operator in Java.
  // This does not seem to be the case however.
  //
  if (isConstantValue(castNode)) {
    jobject jval = env->CallObjectMethod(castNode, getValue);
    THROW_ANY_EXCEPTION(java_ex);
    jboolean result = env->IsInstanceOf(jval, type);
    THROW_ANY_EXCEPTION(java_ex);
    
    return (bool) result;
  } else {
    return false;
  }
}