예제 #1
0
SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalVariable(GlobalVariable &GV){
  if (!GV.hasDefinitiveInitializer())
    return unknown();

  APInt Size(IntTyBits, TD->getTypeAllocSize(GV.getType()->getElementType()));
  return std::make_pair(align(Size, GV.getAlignment()), Zero);
}
예제 #2
0
Function* HeterotbbTransform::create_new_join(Module &M,Function *join) {

    //reduce->dump();
    if(!templat) {
        DEBUG(dbgs()<<"NO Template Found\n");
        return NULL;
    }
    //join_main->dump();
    DEBUG(dbgs()<<"Objext size array"<<object_size_hetero<<"\n");

    //create a global with 64*object/4 size
    GlobalVariable *gb = M.getGlobalVariable("opencl_kernel_join_name_local_arr",true);
    //gb->dump();
    Value *val=gb->getOperand(0);
    //if(isa<ArrayType>(val->getType()))DEBUG(dbgs()<<"YES\n");
    //since we are creating an integer array, the size gets divided by 4

    // Do not make it a global variable -- make it a local variable with annotation for local
    int local_size = 64*object_size_hetero;
    /*const*/ ArrayType *arr= ArrayType::get(Type::getInt32Ty(M.getContext()),(64*object_size_hetero)/4);

    /*vector<Constant *> Initializer;
    APInt zero(32,0);
    for(int i=0;i<(16*object_size_hetero);i++){
    Initializer.push_back(ConstantInt::get(M.getContext(),zero));
    }
    Constant *init = ConstantArray::get(arr, Initializer);
    GlobalVariable *new_gb = new GlobalVariable(M, arr, false, GlobalVariable::InternalLinkage,init, "__hetero_local_"+join->getName()+"__local__arr",gb,false,3);
    new_gb->setAlignment(gb->getAlignment());
    DEBUG(dbgs()<<"Global Created\n");
    new_gb->dump();
    */
    vector</*const*/ Type *> params;
    int temp_size=0;
    object_size_hetero=0;

    //	void join(class.name *,class.name *)
    //re-write join
    const FunctionType *FTy = join->getFunctionType();
    Function::arg_iterator ArgI = join->arg_begin();
    //	class.name *
    params.push_back(PointerType::get((dyn_cast<PointerType>(ArgI->getType())->getElementType()),3));
    params.push_back(PointerType::get((dyn_cast<PointerType>(ArgI->getType())->getElementType()),3));

    /*const*/ Type *RetTy = FTy->getReturnType();
    FunctionType *NFty = FunctionType::get(RetTy,params, false);
    Function *NF=Function::Create(NFty, join->getLinkage(), join->getName()+"_inline");
    NF->copyAttributesFrom(join);
#if EXPLICIT_REWRITE
    copy_function(NF,join);
#else
    ValueToValueMapTy VMap;
    for(Function::arg_iterator FI = join->arg_begin(), FE=join->arg_end(), DI=NF->arg_begin(); FE!=FI; ++FI,++DI) {
        DI->setName(FI->getName());
        VMap[FI]=DI;
    }
    CloneFunctionWithExistingBBInto(NF, NULL, join, VMap);
#endif
    //NF->removeFnAttr(Attributes::get(NF->getContext(), Attribute::NoInline));
    NF->addFnAttr(Attribute::AlwaysInline);
    join->getParent()->getFunctionList().insert(join, NF);

    params.clear();
    const FunctionType *FTemp = templat->getFunctionType();
    //create a new template
    for(Function::arg_iterator FI = templat->arg_begin(), FE=templat->arg_end(); FE!=FI; ++FI) {
        params.push_back(FI->getType());
    }
    //	templat->replaceUsesOfWith(reduce,NF);
    RetTy = FTy->getReturnType();
    NFty = FunctionType::get(RetTy,params, false);
    Function *templat_copy =Function::Create(NFty, join->getLinkage(), join->getName()+"_hetero");
    templat_copy->copyAttributesFrom(templat);
#if EXPLICIT_REWRITE
    copy_function(templat_copy,templat);
#else
    ValueToValueMapTy VMapp;
    for(Function::arg_iterator FI = templat->arg_begin(), FE=templat->arg_end(), DI=templat_copy->arg_begin(); FE!=FI; ++FI,++DI) {
        DI->setName(FI->getName());
        VMapp[FI]=DI;
    }
    CloneFunctionWithExistingBBInto(templat_copy, NULL, templat, VMapp);
#endif

    /* create a local variable with the following type */
    Function::iterator BI = templat_copy->begin();
    BasicBlock::iterator II = BI->begin();
    Instruction *insn = &(*II);
    Constant *l_size = ConstantInt::get(Type::getInt32Ty(M.getContext()), local_size);
    Instruction *new_gb_ = new AllocaInst(arr, l_size, gb->getAlignment(), "hetero_local", insn);
    //new_gb_->dump();
    Value *Elts[] = {MDString::get(M.getContext(), new_gb_->getName())};
    MDNode *Node = MDNode::get(M.getContext(), Elts);
    new_gb_->setMetadata("local",Node);

    Instruction *new_gb= CastInst::Create(Instruction::BitCast, new_gb_,
                                          PointerType::get(arr,3), "hetero_local_cast", insn);
    //new_gb->dump();
    Value *Elts1[] = {MDString::get(M.getContext(), new_gb->getName())};
    MDNode *Node1 = MDNode::get(M.getContext(), Elts1);
    new_gb->setMetadata("local_cast",Node1);

    edit_template_function(M,templat_copy,NF,gb,new_gb);
    templat->getParent()->getFunctionList().insert(templat, templat_copy);

    return templat_copy;
}