LLVM的函数

参考文档

Module

LLVM 模块类是其他所有 LLVM IR 对象的顶级容器。LLVM 模块类能够包含全局变量、函数、该模块所依赖的其他模块和符号表等对象的列表。这里将提供了 LLVM 模块的构造函数:

1
2
3
4
5
explicit Module(StringRef ModuleID, LLVMContext& C);
// 创建Context
LLVMContext& context = getGlobalContext();
// 创建Module
Module* module = new Module("test", context);

Function

1
2
3
4
5
6
7
8
9
//构造一个函数的类型:
FunctionType * FunctionType::get(Type* Result, ArrayRef< Type* > Params, bool isVarArg) [static]

//声明一个函数(先判断是否存在,若不存在则create):
static Function* llvm::Function::Create(FunctionType* Ty, LinkageTypes Linkage, const Twine& N = "",
Module* M = nullptr) [inline, static]
void llvm::Function::setCallingConv(CallingConv::ID CC)
void setAttributes(const AttrListPtr &attrs) //与4.0的文档不一样
//4.0文档中是:Function::setAttributes(AttributeSet Attrs)

Instruction

1
2
//返回Instruction所在的BasicBlock*
BasicBlock* llvm::Instruction::getParent()

Loop

1
2
//Return true if the specified basic block is in this loop.
bool llvm::LoopBase< BlockT, LoopT >::contains ( const BlockT * BB ) const