示例#1
0
 void MetaProcessor::setFileStream(llvm::StringRef file, bool append, int fd,
             llvm::SmallVector<llvm::SmallString<128>, 2>& prevFileStack) {
   // If we have a fileName to redirect to store it.
   if (!file.empty()) {
     prevFileStack.push_back(file);
     // pop and push a null terminating 0.
     // SmallVectorImpl<T> does not have a c_str(), thus instead of casting to
     // a SmallString<T> we null terminate the data that we have and pop the
     // 0 char back.
     prevFileStack.back().push_back(0);
     prevFileStack.back().pop_back();
     if (!append) {
       FILE * f;
       if (!(f = fopen(file.data(), "w"))) {
         llvm::errs() << "cling::MetaProcessor::setFileStream:"
                      " The file path " << file.data() << "is not valid.";
       } else {
         fclose(f);
       }
     }
   // Else unredirection, so switch to the previous file.
   } else {
     // If there is no previous file on the stack we pop the file
     if (!prevFileStack.empty()) {
       prevFileStack.pop_back();
     }
   }
 }
示例#2
0
void ldc::DIBuilder::AddFields(AggregateDeclaration *sd, ldc::DIFile file,
                               llvm::SmallVector<LLMetadata *, 16> &elems) {
  size_t narr = sd->fields.dim;
  elems.reserve(narr);
  for (auto vd : sd->fields) {
    elems.push_back(CreateMemberType(vd->loc.linnum, vd->type, file,
                                     vd->toChars(), vd->offset,
                                     vd->prot().kind));
  }
}
示例#3
0
文件: ics.cpp 项目: Daetalus/pyston
 void* alloc() {
     if (free_chunks.empty()) {
         int protection = PROT_READ | PROT_WRITE | PROT_EXEC;
         int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT;
         char* addr = (char*)mmap(NULL, region_size, protection, flags, -1, 0);
         for (int i = 0; i < region_size / chunk_size; ++i) {
             free_chunks.push_back(&addr[i * chunk_size]);
         }
     }
     return free_chunks.pop_back_val();
 }
示例#4
0
void
CodeGenFunction::ExpandTypeToArgs(QualType Ty, RValue RV,
                                  llvm::SmallVector<llvm::Value*, 16> &Args) {
  const RecordType *RT = Ty->getAsStructureType();
  assert(RT && "Can only expand structure types.");

  RecordDecl *RD = RT->getDecl();
  assert(RV.isAggregate() && "Unexpected rvalue during struct expansion");
  llvm::Value *Addr = RV.getAggregateAddr();
  for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
         i != e; ++i) {
    FieldDecl *FD = *i;
    QualType FT = FD->getType();

    // FIXME: What are the right qualifiers here?
    LValue LV = EmitLValueForField(Addr, FD, false, 0);
    if (CodeGenFunction::hasAggregateLLVMType(FT)) {
      ExpandTypeToArgs(FT, RValue::getAggregate(LV.getAddress()), Args);
    } else {
      RValue RV = EmitLoadOfLValue(LV, FT);
      assert(RV.isScalar() &&
             "Unexpected non-scalar rvalue during struct expansion.");
      Args.push_back(RV.getScalarVal());
    }
  }
}
示例#5
0
CGFunctionInfo::CGFunctionInfo(QualType ResTy,
                               const llvm::SmallVector<QualType, 16> &ArgTys) {
    NumArgs = ArgTys.size();
    Args = new ArgInfo[1 + NumArgs];
    Args[0].type = ResTy;
    for (unsigned i = 0; i < NumArgs; ++i)
        Args[1 + i].type = ArgTys[i];
}
示例#6
0
/**
 * Check if rank arguments of send, recv pair match.
 *
 * @return is matching
 */
bool MPICheckerAST::rankArgsMatch(const MPICall &sendCall,
                                  const MPICall &recvCall,
                                  const MPIRankCase &sendCase,
                                  const MPIRankCase &recvCase) const {
    // match special case
    if (isFirstLastPair(sendCall, recvCall, sendCase, recvCase)) return true;

    // compare ranks
    const auto &rankArgSend = sendCall.arg(MPIPointToPoint::kRank);
    const auto &rankArgRecv = recvCall.arg(MPIPointToPoint::kRank);

    if (rankArgSend.valueSequence().size() !=
            rankArgRecv.valueSequence().size())
        return false;

    // build sequences without last operator(skip first element)
    const llvm::SmallVector<std::string, 4> sendValSeq{
        rankArgSend.valueSequence().begin() + 1,
        rankArgSend.valueSequence().end()},
    recvValSeq{rankArgRecv.valueSequence().begin() + 1,
               rankArgRecv.valueSequence().end()};

    bool containsSubtraction{false};
    for (size_t i = 0; i < sendValSeq.size(); ++i) {
        if (sendValSeq[i] == "-" || recvValSeq[i] == "-") {
            containsSubtraction = true;
            break;
        }
    }

    // check ordered
    if (containsSubtraction && (sendValSeq != recvValSeq)) return false;
    // check permutation
    if (!containsSubtraction &&
            (!cont::isPermutation(sendValSeq, recvValSeq))) {
        return false;
    }
    // last (value|var|function) must be identical
    if (sendValSeq.back() != recvValSeq.back()) return false;
    // last operator must be inverse
    if (!rankArgSend.isLastOperatorInverse(rankArgRecv)) return false;

    return true;
}
  void IncrementalParser::Parse(llvm::StringRef input, 
                                llvm::SmallVector<DeclGroupRef, 4>& DGRs) {

    Parse(input);
    for (llvm::SmallVector<ChainedConsumer::DGRInfo, 64>::iterator 
           I = m_Consumer->DeclsQueue.begin(), E = m_Consumer->DeclsQueue.end();
         I != E; ++I) {
      DGRs.push_back((*I).D);
    }
  }
示例#8
0
static void
populateParentNamespaces(llvm::SmallVector<Reference, 4> &Namespaces,
                         const T *D) {
  const auto *DC = dyn_cast<DeclContext>(D);
  while ((DC = DC->getParent())) {
    if (const auto *N = dyn_cast<NamespaceDecl>(DC))
      Namespaces.emplace_back(getUSRForDecl(N), N->getNameAsString(),
                              InfoType::IT_namespace);
    else if (const auto *N = dyn_cast<RecordDecl>(DC))
      Namespaces.emplace_back(getUSRForDecl(N), N->getNameAsString(),
                              InfoType::IT_record);
    else if (const auto *N = dyn_cast<FunctionDecl>(DC))
      Namespaces.emplace_back(getUSRForDecl(N), N->getNameAsString(),
                              InfoType::IT_function);
    else if (const auto *N = dyn_cast<EnumDecl>(DC))
      Namespaces.emplace_back(getUSRForDecl(N), N->getNameAsString(),
                              InfoType::IT_enum);
  }
}
std::string clang_c_convertert::parse_float(
  llvm::SmallVector<char, 32> &src,
  mp_integer &significand,
  mp_integer &exponent)
{
  // {digit}{dot}{31 digits}[+-]{exponent}

  unsigned p = 0;

  // get whole number
  std::string str_whole_number = "";
  str_whole_number += src[p++];

  // skip dot
  assert(src[p] == '.');
  p++;

  // get fraction part
  std::string str_fraction_part = "";
  while (src[p] != 'E')
    str_fraction_part += src[p++];

  // skip E
  assert(src[p] == 'E');
  p++;

  // get exponent
  assert(src[p] == '+' || src[p] == '-');

  // skip +
  if(src[p] == '+')
    p++;

  std::string str_exponent = "";
  str_exponent += src[p++];

  while (p < src.size())
    str_exponent += src[p++];

  std::string str_number = str_whole_number + str_fraction_part;

  if (str_number.empty())
    significand = 0;
  else
    significand = string2integer(str_number);

  if (str_exponent.empty())
    exponent = 0;
  else
    exponent = string2integer(str_exponent);

  exponent -= str_fraction_part.size();

  return str_whole_number;
}
示例#10
0
void
SROAMemoryUseAnalyzer::
createAllocas(llvm::SmallVector<AllocStackInst *, 4> &NewAllocations) {
  SILBuilderWithScope B(AI);
  SILType Type = AI->getType().getObjectType();

  if (TT) {
    for (unsigned EltNo : indices(TT->getElementTypes())) {
      SILType EltTy = Type.getTupleElementType(EltNo);
      NewAllocations.push_back(B.createAllocStack(AI->getLoc(), EltTy));
    }
  } else {
    assert(SD && "SD should not be null since either it or TT must be set at "
           "this point.");
    SILModule &M = AI->getModule();
    for (auto *D : SD->getStoredProperties())
      NewAllocations.push_back(B.createAllocStack(AI->getLoc(),
                                                  Type.getFieldType(D, M)));
  }
}
示例#11
0
CGFunctionInfo::CGFunctionInfo(unsigned _CallingConvention,
                               QualType ResTy,
                               const llvm::SmallVector<QualType, 16> &ArgTys) 
  : CallingConvention(_CallingConvention),
    EffectiveCallingConvention(_CallingConvention)
{
  NumArgs = ArgTys.size();
  Args = new ArgInfo[1 + NumArgs];
  Args[0].type = ResTy;
  for (unsigned i = 0; i < NumArgs; ++i)
    Args[1 + i].type = ArgTys[i];
}
示例#12
0
void MPIChecker::allRegionsUsedByWait(
    llvm::SmallVector<const MemRegion *, 2> &ReqRegions,
    const MemRegion *const MR, const CallEvent &CE, CheckerContext &Ctx) const {

  MemRegionManager *const RegionManager = MR->getMemRegionManager();

  if (FuncClassifier->isMPI_Waitall(CE.getCalleeIdentifier())) {
    const MemRegion *SuperRegion{nullptr};
    if (const ElementRegion *const ER = MR->getAs<ElementRegion>()) {
      SuperRegion = ER->getSuperRegion();
    }

    // A single request is passed to MPI_Waitall.
    if (!SuperRegion) {
      ReqRegions.push_back(MR);
      return;
    }

    const auto &Size = Ctx.getStoreManager().getSizeInElements(
        Ctx.getState(), SuperRegion,
        CE.getArgExpr(1)->getType()->getPointeeType());
    const llvm::APSInt &ArrSize = Size.getAs<nonloc::ConcreteInt>()->getValue();

    for (size_t i = 0; i < ArrSize; ++i) {
      const NonLoc Idx = Ctx.getSValBuilder().makeArrayIndex(i);

      const ElementRegion *const ER = RegionManager->getElementRegion(
          CE.getArgExpr(1)->getType()->getPointeeType(), Idx, SuperRegion,
          Ctx.getASTContext());

      ReqRegions.push_back(ER->getAs<MemRegion>());
    }
  } else if (FuncClassifier->isMPI_Wait(CE.getCalleeIdentifier())) {
    ReqRegions.push_back(MR);
  }
}
示例#13
0
void SetCreator::FindConnections(const EquivalenceScope::InfluenceObject *Obj) {
  for(size_t I = 0; I < Connections.size(); ++I) {
    if(Visited[I]) continue;

    if(Connections[I].A.Obj == Obj ||
       Connections[I].B.Obj == Obj) {
      Visited[I] = true;
      Result.push_back(Connections[I].A);
      Result.push_back(Connections[I].B);

      if(Connections[I].A.Obj == Obj)
        FindConnections(Connections[I].B.Obj);
      else
        FindConnections(Connections[I].A.Obj);
    }
  }
}
示例#14
0
 /// Insert a block into the worklist and set its stack depth.
 void insert(SILBasicBlock *BB, int StackDepth) {
   auto Iter = Block2StackDepth.find(BB);
   if (Iter != Block2StackDepth.end()) {
     // We already handled the block.
     assert(StackDepth >= 0);
     if (Iter->second < 0) {
       // Update the stack depth if we didn't set it yet for the block.
       Iter->second = StackDepth;
     } else {
       assert(Iter->second == StackDepth &&
                "inconsistent stack depth at a CFG merge point");
     }
   } else {
     Block2StackDepth[BB] = StackDepth;
     ToHandle.push_back(BB);
   }
 }
示例#15
0
// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
// information in the program executable. The argument information stored
// includes the argument name, its type, the address and access qualifiers used.
// FIXME: Add type, address, and access qualifiers.
static void GenOpenCLArgMetadata(const FunctionDecl *FD, llvm::Function *Fn,
                                 CodeGenModule &CGM,llvm::LLVMContext &Context,
                                 llvm::SmallVector <llvm::Value*, 5> &kernelMDArgs) {
  
  // Create MDNodes that represents the kernel arg metadata.
  // Each MDNode is a list in the form of "key", N number of values which is
  // the same number of values as their are kernel arguments.
  
  // MDNode for the kernel argument names.
  SmallVector<llvm::Value*, 8> argNames;
  argNames.push_back(llvm::MDString::get(Context, "kernel_arg_name"));
  
  for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) {
    const ParmVarDecl *parm = FD->getParamDecl(i);
    
    // Get argument name.
    argNames.push_back(llvm::MDString::get(Context, parm->getName()));
    
  }
  // Add MDNode to the list of all metadata.
  kernelMDArgs.push_back(llvm::MDNode::get(Context, argNames));
}
示例#16
0
bool SetCreator::CreateSet(ASTContext &C) {
  SmallVector<EquivalenceSet::Object, 16> Objects;
  const EquivalenceScope::InfluenceObject *Obj = nullptr;
  for(size_t I = 0; I < Connections.size(); ++I) {
    if(Visited[I]) continue;
    Obj = Connections[I].A.Obj;
  }
  if(!Obj) return false;

  Result.clear();
  FindConnections(Obj);
  llvm::SmallPtrSet<VarDecl*, 16> ProcessedObjects;
  for(auto I : Result) {
    if(ProcessedObjects.insert(I.Obj->Var).second)
      Objects.push_back(EquivalenceSet::Object(I.Obj->Var, I.E));
  }

  auto Set = EquivalenceSet::Create(C, Objects);
  for(auto I : Objects)
    I.Var->setStorageSet(Set);
  return true;
}
示例#17
0
  ///\brief Checks for clashing names when trying to extract a declaration.
  ///
  ///\returns true if there is another declaration with the same name
  bool DeclExtractor::CheckForClashingNames(
                                  const llvm::SmallVector<NamedDecl*, 4>& Decls,
                                            DeclContext* DC, Scope* S) {
    for (size_t i = 0; i < Decls.size(); ++i) {
      NamedDecl* ND = Decls[i];

      if (TagDecl* TD = dyn_cast<TagDecl>(ND)) {
        LookupResult Previous(*m_Sema, ND->getDeclName(), ND->getLocation(),
                              Sema::LookupTagName, Sema::ForRedeclaration
                              );

        m_Sema->LookupName(Previous, S);

        // There is no function diagnosing the redeclaration of tags (eg. enums).
        // So either we have to do it by hand or we can call the top-most
        // function that does the check. Currently the top-most clang function
        // doing the checks creates an AST node, which we don't want.
        if (!CheckTagDeclaration(TD, Previous))
          return true;
      }
      else if (VarDecl* VD = dyn_cast<VarDecl>(ND)) {
        LookupResult Previous(*m_Sema, ND->getDeclName(), ND->getLocation(),
                              Sema::LookupOrdinaryName, Sema::ForRedeclaration
                              );

        m_Sema->LookupName(Previous, S);
        m_Sema->CheckVariableDeclaration(VD, Previous);
        if (VD->isInvalidDecl())
          return true;
        // This var decl will likely get referenced later; claim that it's used.
        VD->setIsUsed();
      }
    }

    return false;
  }
示例#18
0
 SILBasicBlock *pop_back_val() { return ToHandle.pop_back_val(); }
示例#19
0
 bool empty() const { return ToHandle.empty(); }
    // Deal with all the call expr in the transaction.
    bool VisitCallExpr(CallExpr* TheCall) {
      if (FunctionDecl* FDecl = TheCall->getDirectCallee()) {
        std::bitset<32> ArgIndexs;
        for (FunctionDecl::redecl_iterator RI = FDecl->redecls_begin(),
             RE = FDecl->redecls_end(); RI != RE; ++RI) {
          for (specific_attr_iterator<NonNullAttr>
               I = RI->specific_attr_begin<NonNullAttr>(),
               E = RI->specific_attr_end<NonNullAttr>(); I != E; ++I) {
            NonNullAttr *NonNull = *I;

            // Store all the null attr argument's index into "ArgIndexs".
            for (NonNullAttr::args_iterator i = NonNull->args_begin(),
                 e = NonNull->args_end(); i != e; ++i) {

              // Get the argument with the nonnull attribute.
              const Expr* Arg = TheCall->getArg(*i);

              // Check whether we can get the argument'value. If the argument is
              // not null, then ignore this argument and continue to deal with the
              // next argument with the nonnull attribute.ArgIndexs.set(*i);
              bool Result;
              ASTContext& Context = m_Sema->getASTContext();
              if (Arg->EvaluateAsBooleanCondition(Result, Context) && Result) {
                continue;
              }
              ArgIndexs.set(*i);
            }
            break;
          }
        }

        if (ArgIndexs.any()) {

          // Get the function decl's name.
          std::string FName = getMangledName(FDecl);

          // Store the function decl's name into the vector.
          m_NonNullDeclNames.push_back(FName);

          // Store the function decl's name with its null attr args' indexes
          // into the map.
          m_NonNullArgIndexs.insert(std::make_pair(FName, ArgIndexs));
        }

        // FIXME: For now we will only work/check on declarations that are not
        // deserialized. We want to avoid our null deref transaformer to 
        // deserialize all the contents of a PCH/PCM.
        // We have to think of a better way to find the annotated 
        // declarations, without that to cause too much deserialization.
        Stmt* S = (FDecl->isFromASTFile()) ? 0 : FDecl->getBody();
        if (S) {
          for (Stmt::child_iterator II = S->child_begin(), EE = S->child_end();
               II != EE; ++II) {
            CallExpr* child = dyn_cast<CallExpr>(*II);
            if (child && child->getDirectCallee() != FDecl)
              VisitCallExpr(child);
          }
        }
      }
      return true; // returning false will abort the in-depth traversal.
    }
示例#21
0
void NativeRawSymbol::getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const {
  bytes.clear();
}
示例#22
0
文件: ics.cpp 项目: Daetalus/pyston
 void dealloc(void* ptr) {
     free_chunks.push_back(ptr); // TODO: we should probably delete some regions if this list gets to large
 }
示例#23
0
 bool VisitNamedDecl(const NamedDecl *ND) {
   if (F(*ND))
     Decls.push_back(ND);
   return true;
 }