[LLVMdev] AllocaInst for FunctionType?

Mehdi Amini mehdi.amini at apple.com
Thu Jan 15 03:20:28 PST 2015


> On Jan 15, 2015, at 3:05 AM, Alexander Poddey <alexander.poddey at gmx.net> wrote:
> 
> Hi,
> I'm trying to get my head around c++ - IR - c++ API and getting used 
> tramform manual information to code.
> 
> 
> The manual states alloca is defined for <type>. FunstionType is a type, so 
> alloca for functionType should be possible? Not?

I may not understand what you try to achieve because it does not make much sense to me :)

As far as I understand, an alloca instruction allocate space for a variable. It does not really make sense for it to be used with a function type (do you want to store a pointer to a function of this type?).

Maybe this would help: http://llvm.org/docs/tutorial/LangImpl7.html
(and in any case you can check how clang is using alloca to emit llvm IR)

OTH

Mehdi



> 
> 
> If we have a valid Module *m  
> 
> we can get an allocate instruction allocating space for a non-argumented 
> function as follows:
> 
> AllocaInst* pa2 = new AllocaInst( FunctionType::get( 
>            Type::getVoidTy(m->getContext()), false  )
>   , 1, "myName");
> 
> 
> but how about nonvar-argumented functions? E.g. I32,I16
> 
> std::vector<Type*>FuncTy_args;
> FuncTy_args.push_back(IntegerType::get(mod->getContext(), 32));
> FuncTy_args.push_back(IntegerType::get(mod->getContext(), 16));
> 
> 
> AllocaInst* pa3 = new AllocaInst( FunctionType::get( 
>    Type::getVoidTy(m->getContext()), FuncTy_args ,false  )
>    , 1, "MyName");
> 
> 
> does this make sense?
> I guess this might not be correct, because we explicitely introduce 
> FuncTy_args, where we only would like to know the 'necessary memory 
> footprint' of it, for alloca to be able to allocate it, not?
> 
> Alex
> 
> 
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev





More information about the llvm-dev mailing list