当前位置: 首页>>代码示例>>C++>>正文


C++ IRBuilder类代码示例

本文整理汇总了C++中IRBuilder的典型用法代码示例。如果您正苦于以下问题:C++ IRBuilder类的具体用法?C++ IRBuilder怎么用?C++ IRBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IRBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: EmitFWrite

/// EmitFWrite - Emit a call to the fwrite function.  This assumes that Ptr is
/// a pointer, Size is an 'intptr_t', and File is a pointer to FILE.
void llvm::EmitFWrite(Value *Ptr, Value *Size, Value *File,
                      IRBuilder<> &B, const TargetData *TD) {
  Module *M = B.GetInsertBlock()->getParent()->getParent();
  AttributeWithIndex AWI[3];
  AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture);
  AWI[1] = AttributeWithIndex::get(4, Attribute::NoCapture);
  AWI[2] = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
  LLVMContext &Context = B.GetInsertBlock()->getContext();
  Constant *F;
  if (File->getType()->isPointerTy())
    F = M->getOrInsertFunction("fwrite", AttrListPtr::get(AWI, 3),
                               TD->getIntPtrType(Context),
                               B.getInt8PtrTy(),
                               TD->getIntPtrType(Context),
                               TD->getIntPtrType(Context),
                               File->getType(), NULL);
  else
    F = M->getOrInsertFunction("fwrite", TD->getIntPtrType(Context),
                               B.getInt8PtrTy(),
                               TD->getIntPtrType(Context),
                               TD->getIntPtrType(Context),
                               File->getType(), NULL);
  CallInst *CI = B.CreateCall4(F, CastToCStr(Ptr, B), Size,
                        ConstantInt::get(TD->getIntPtrType(Context), 1), File);

  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
    CI->setCallingConv(Fn->getCallingConv());
}
开发者ID:HenderOrlando,项目名称:clamav-bytecode-compiler,代码行数:30,代码来源:BuildLibCalls.cpp

示例2: Visit

void ASTCodeGenVisitor::Visit(DecrData* s) {
  IRBuilder<> builder = builders_.top();
  Value* ptr_val = builder.CreateLoad(ptr_);
  Value* result = builder.CreateAdd(ptr_val, neg_one);
  builder.CreateStore(result, ptr_);
  VisitNextASTNode(s);
}
开发者ID:dtwitty,项目名称:brainfuck-llvm,代码行数:7,代码来源:codegen_ast.cpp

示例3: assert

Value* MultiplicationExpression::getValue() {
    assert(leftExpression != NULL);
    assert(rightExpression != NULL);

    IRBuilder<>* builder = codegen::getBuilder();
    return builder->CreateMul(leftExpression->getValue(), rightExpression->getValue());
}
开发者ID:Legacy25,项目名称:ValkyrieDB,代码行数:7,代码来源:Expression.cpp

示例4: reorderSubVector

static void reorderSubVector(MVT VT, SmallVectorImpl<Value *> &TransposedMatrix,
  ArrayRef<Value *> Vec, ArrayRef<uint32_t> VPShuf,
  unsigned VecElems, unsigned Stride,
  IRBuilder<> Builder) {

  if (VecElems == 16) {
    for (unsigned i = 0; i < Stride; i++)
      TransposedMatrix[i] = Builder.CreateShuffleVector(
        Vec[i], UndefValue::get(Vec[i]->getType()), VPShuf);
    return;
  }

  SmallVector<uint32_t, 32> OptimizeShuf;
  Value *Temp[8];

  for (unsigned i = 0; i < (VecElems / 16) * Stride; i += 2) {
    genShuffleBland(VT, VPShuf, OptimizeShuf, (i / Stride) * 16,
      (i + 1) / Stride * 16);
    Temp[i / 2] = Builder.CreateShuffleVector(
      Vec[i % Stride], Vec[(i + 1) % Stride], OptimizeShuf);
    OptimizeShuf.clear();
  }

  if (VecElems == 32) {
    std::copy(Temp, Temp + Stride, TransposedMatrix.begin());
    return;
  }
  else
    for (unsigned i = 0; i < Stride; i++)
      TransposedMatrix[i] =
      Builder.CreateShuffleVector(Temp[2 * i], Temp[2 * i + 1], Concat);
}
开发者ID:BNieuwenhuizen,项目名称:llvm,代码行数:32,代码来源:X86InterleavedAccess.cpp

示例5: insertStores

void InstructionReplace::insertStores(llvm::Module& M)
{
	for(llvm::Module::iterator F = M.begin(), ME = M.end(); F != ME; ++F) {
		//if(!F->getFnAttributes().hasAttribute(Attributes::AttrVal::MaskedCopy)) { continue; }
		llvm::Function* Fun = maskedfn[F];
		vector<Value*> outputshares;
		ReturnInst* tbd = NULL;
		auto arg = Fun->arg_begin();
		for(unsigned int i = 0; i <= MaskingOrder; i++) { ++arg; }
		for(unsigned int i = 0; i <= MaskingOrder; i++) { outputshares.push_back(arg++); }
		for(llvm::Function::iterator BB = Fun->begin(),
		    FE = Fun->end();
		    BB != FE;
		    ++BB) {
			for( llvm::BasicBlock::iterator i = BB->begin(); i != BB->end(); i++) {
				if(tbd != NULL) {tbd->eraseFromParent(); tbd = NULL;}
				if(!isa<ReturnInst>(i)) {continue;}
				ReturnInst* ri = cast<ReturnInst>(i);
				IRBuilder<> ib = llvm::IRBuilder<>(BB->getContext());
				ib.SetInsertPoint(i);
				vector<Value*> shares = MaskValue(ri->getReturnValue(), ri);
				for(unsigned int i = 0; i <= MaskingOrder; i++) { ib.CreateStore(shares[i], outputshares[i]); }
				ib.CreateRetVoid();
				tbd = ri;
			}
		}
		if(tbd != NULL) {tbd->eraseFromParent(); tbd = NULL;}
	}
}
开发者ID:giovannizingaro,项目名称:llvm,代码行数:29,代码来源:InstructionReplace.cpp

示例6:

void MmixLlvm::Private::emitIncl(VerticeContext& vctx, IRBuilder<>& builder,  MXByte xarg, MXWyde yzarg)
{
	Value *xval0 = vctx.getRegister(xarg);
	Value* result = builder.CreateAdd(xval0, builder.getInt64((MXOcta) yzarg));
	assignRegister(vctx, builder, xarg, result);
	builder.CreateBr(vctx.getOCExit());
}
开发者ID:xuhd,项目名称:llvmmmix,代码行数:7,代码来源:ImmYZImpl.cpp

示例7: codeGen

Value* While::codeGen(CodeGenContext &context) {

  //Value* conditionValue = condition.codeGen(context);

  IRBuilder<> *builder = context.currentBuilder();
  Function *mainFunction = builder->GetInsertBlock()->getParent();

  BasicBlock *condBb = BasicBlock::Create(getGlobalContext(), "whilecond",
      mainFunction);
  BasicBlock *doBb = BasicBlock::Create(getGlobalContext(), "whiledo");
  BasicBlock *afterWhileBb = BasicBlock::Create(getGlobalContext(), "afterWhile");


  builder->CreateBr(condBb);
  builder->SetInsertPoint(condBb);
  Value* conditionValue = condition.codeGen(context);
  builder->CreateCondBr(conditionValue, doBb, afterWhileBb);
  condBb = builder->GetInsertBlock();

  mainFunction->getBasicBlockList().push_back(doBb);
  builder->SetInsertPoint(doBb);
  Value *doValue = (*doStmt).codeGen(context);
  builder->CreateBr(condBb);
  doBb = builder->GetInsertBlock();

  mainFunction->getBasicBlockList().push_back(afterWhileBb);
  builder->SetInsertPoint(afterWhileBb);
  return NULL;

}
开发者ID:raincoat,项目名称:toy-llvm-frondend,代码行数:30,代码来源:codegen.cpp

示例8: EmitMemSet

void EmitMemSet(IRBuilder<>& B, Value* Dst, Value* Val, Value* Len,
                const Analysis& A) {
    Dst = B.CreateBitCast(Dst, PointerType::getUnqual(B.getInt8Ty()));

    CallSite CS = B.CreateMemSet(Dst, Val, Len, 1 /*Align*/, false /*isVolatile*/);
    if (A.CGNode)
        A.CGNode->addCalledFunction(CS, A.CG->getOrInsertFunction(CS.getCalledFunction()));
}
开发者ID:Axure,项目名称:ldc,代码行数:8,代码来源:GarbageCollect2Stack.cpp

示例9: Visit

void CNodeCodeGenVisitor::Visit(CSet* s) {
  IRBuilder<> builder = builders_.top();

  Value* offset_ptr = builder.CreateGEP(ptr_, GetPtrOffset(s->GetOffset()));
  Value* set_val = GetDataOffset(s->GetAmt());
  builder.CreateStore(set_val, offset_ptr);
  VisitNextCNode(s);
}
开发者ID:dtwitty,项目名称:brainfuck-llvm,代码行数:8,代码来源:codegen_canon.cpp

示例10: optimize

void optimize(IRUnit& unit, IRBuilder& irBuilder, TransKind kind) {
  auto finishPass = [&](const char* msg) {
    dumpTrace(6, unit, folly::format("after {}", msg).str().c_str());
    assert(checkCfg(unit));
    assert(checkTmpsSpanningCalls(unit));
    if (debug) {
      forEachInst(rpoSortCfg(unit), assertOperandTypes);
    }
  };

  auto doPass = [&](void (*fn)(IRUnit&), const char* msg) {
    fn(unit);
    finishPass(msg);
  };

  auto dce = [&](const char* which) {
    if (!RuntimeOption::EvalHHIRDeadCodeElim) return;
    eliminateDeadCode(unit);
    finishPass(folly::format("{} DCE", which).str().c_str());
  };

  if (RuntimeOption::EvalHHIRRelaxGuards) {
    auto const simpleRelax = kind == TransProfile;
    auto changed = relaxGuards(unit, *irBuilder.guards(), simpleRelax);
    if (changed) finishPass("guard relaxation");
  }

  if (RuntimeOption::EvalHHIRRefcountOpts) {
    optimizeRefcounts(unit);
    finishPass("refcount opts");
  }

  dce("initial");

  if (RuntimeOption::EvalHHIRPredictionOpts) {
    doPass(optimizePredictions, "prediction opts");
  }

  if (RuntimeOption::EvalHHIRExtraOptPass
      && (RuntimeOption::EvalHHIRCse
          || RuntimeOption::EvalHHIRSimplification)) {
    irBuilder.reoptimize();
    finishPass("reoptimize");
    // Cleanup any dead code left around by CSE/Simplification
    // Ideally, this would be controlled by a flag returned
    // by optimzeTrace indicating whether DCE is necessary
    dce("reoptimize");
  }

  if (RuntimeOption::EvalHHIRJumpOpts) {
    doPass(optimizeJumps, "jumpopts");
    dce("jump opts");
  }

  if (RuntimeOption::EvalHHIRGenerateAsserts) {
    doPass(insertAsserts, "RefCnt asserts");
  }
}
开发者ID:Kofel,项目名称:hhvm,代码行数:58,代码来源:opt.cpp

示例11: lookup_main_filter_function

void
code_emitter::setup_filter_function (bool is_main_filter_function)
{
    Function *filter_function = is_main_filter_function
	? lookup_main_filter_function(module, filter)
	: lookup_filter_function(module, filter);
    Function::arg_iterator args = filter_function->arg_begin();
    Value *slice_arg = NULL;

    if (is_main_filter_function)
    {
	slice_arg = args++;
	slice_arg->setName("slice");
    }
    else
    {
	invocation_arg = args++;
	invocation_arg->setName("invocation");
    }
    closure_arg = args++;
    closure_arg->setName("closure");
    if (is_main_filter_function)
    {
	x_vars_var = args++;
	x_vars_var->setName("x_vars");
	y_vars_var = args++;
	y_vars_var->setName("y_vars");
    }
    set_internal(::lookup_internal(filter->v.mathmap.internals, "x", true), args++);
    set_internal(::lookup_internal(filter->v.mathmap.internals, "y", true), args++);
    set_internal(::lookup_internal(filter->v.mathmap.internals, "t", true), args++);
    pools_arg = args++;
    pools_arg->setName("pools");

    BasicBlock *block = BasicBlock::Create("entry", filter_function);

    builder = new IRBuilder<> (block);

    if (is_main_filter_function)
    {
	x_vars_var = builder->CreateBitCast(x_vars_var, PointerType::getUnqual(x_vars_type));
	y_vars_var = builder->CreateBitCast(y_vars_var, PointerType::getUnqual(y_vars_type));
	frame_arg = builder->CreateCall(module->getFunction(string("get_slice_frame")), slice_arg);
	invocation_arg = builder->CreateCall(module->getFunction(string("get_frame_invocation")), frame_arg);
    }

    set_internals_from_invocation(invocation_arg);

    if (is_main_filter_function)
	set_xy_vars_from_frame ();
    else
	setup_xy_vars_from_closure ();

    alloc_complex_copy_var();

    current_function = filter_function;
}
开发者ID:WoodMath,项目名称:mathmap,代码行数:57,代码来源:llvm.cpp

示例12: BuildProgramFromCanon

Function* BuildProgramFromCanon(CNode* s, llvm::Module* module,
                                int store_size) {
  CNodeCodeGenVisitor visitor(module, store_size);
  s->Accept(visitor);
  IRBuilder<> builder = visitor.GetLastBuilder();
  builder.CreateRetVoid();
  Function* func = visitor.GetMain();
  return func;
}
开发者ID:dtwitty,项目名称:brainfuck-llvm,代码行数:9,代码来源:codegen_canon.cpp

示例13: compile_back

/// compile_back - Emit code for ']'
void BrainFTraceRecorder::compile_back(BrainFTraceNode *node,
                                       IRBuilder<>& builder) {
  if (node->right != (BrainFTraceNode*)~0ULL)
    compile_opcode(node->right, builder);
  else {
    HeaderPHI->addIncoming(DataPtr, builder.GetInsertBlock());
    builder.CreateBr(Header);
  }
}
开发者ID:resistor,项目名称:BrainFTracing,代码行数:10,代码来源:BrainFCodeGen.cpp

示例14: createCmpXchgInstFun

static void createCmpXchgInstFun(IRBuilder<> &Builder, Value *Addr,
                                 Value *Loaded, Value *NewVal,
                                 AtomicOrdering MemOpOrder,
                                 Value *&Success, Value *&NewLoaded) {
  Value* Pair = Builder.CreateAtomicCmpXchg(
      Addr, Loaded, NewVal, MemOpOrder,
      AtomicCmpXchgInst::getStrongestFailureOrdering(MemOpOrder));
  Success = Builder.CreateExtractValue(Pair, 1, "success");
  NewLoaded = Builder.CreateExtractValue(Pair, 0, "newloaded");
}
开发者ID:mirams,项目名称:opencor,代码行数:10,代码来源:AtomicExpandPass.cpp

示例15: insertTrailingFence

void AtomicExpandLoadLinked::insertTrailingFence(IRBuilder<> &Builder,
                                              AtomicOrdering Ord) {
  if (!TLI->getInsertFencesForAtomic())
    return;

  if (Ord == Acquire || Ord == AcquireRelease)
    Builder.CreateFence(Acquire);
  else if (Ord == SequentiallyConsistent)
    Builder.CreateFence(SequentiallyConsistent);
}
开发者ID:ADonut,项目名称:LLVM-GPGPU,代码行数:10,代码来源:AtomicExpandLoadLinkedPass.cpp


注:本文中的IRBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。