More to IRBuilder and Instruction
This commit is contained in:
parent
b9ac22d136
commit
fe383ca326
3 changed files with 90 additions and 19 deletions
|
|
@ -14,6 +14,7 @@
|
||||||
#include <llvm/Analysis/Verifier.h>
|
#include <llvm/Analysis/Verifier.h>
|
||||||
#include <llvm/Constants.h>
|
#include <llvm/Constants.h>
|
||||||
#include <llvm/Intrinsics.h>
|
#include <llvm/Intrinsics.h>
|
||||||
|
#include <llvm/IRBuilder.h>
|
||||||
|
|
||||||
#include "auto_pyobject.h"
|
#include "auto_pyobject.h"
|
||||||
|
|
||||||
|
|
@ -732,3 +733,17 @@ PyObject* BasicBlock_getInstList(llvm::BasicBlock* BB)
|
||||||
"llvm::Instruction");
|
"llvm::Instruction");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
PyObject* IRBuilder_CreateAggregateRet(llvm::IRBuilder<>* builder,
|
||||||
|
PyObject* Vals,
|
||||||
|
unsigned N)
|
||||||
|
{
|
||||||
|
using namespace llvm;
|
||||||
|
std::vector<Value*> vec_values;
|
||||||
|
bool ok = extract<Value>::from_py_sequence(vec_values, Vals, "llvm::Value");
|
||||||
|
if (not ok) return NULL;
|
||||||
|
Value** ptr_values = &vec_values[0];
|
||||||
|
ReturnInst* inst = builder->CreateAggregateRet(ptr_values, N);
|
||||||
|
return pycapsule_new(inst, "llvm::Value", "llvm:ReturnInst");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from binding import *
|
||||||
from namespace import llvm
|
from namespace import llvm
|
||||||
from LLVMContext import LLVMContext
|
from LLVMContext import LLVMContext
|
||||||
from BasicBlock import BasicBlock
|
from BasicBlock import BasicBlock
|
||||||
|
from Instruction import Instruction
|
||||||
from Instruction import ReturnInst, CallInst, BranchInst, SwitchInst
|
from Instruction import ReturnInst, CallInst, BranchInst, SwitchInst
|
||||||
from Instruction import IndirectBrInst, InvokeInst, ResumeInst, PHINode
|
from Instruction import IndirectBrInst, InvokeInst, ResumeInst, PHINode
|
||||||
from Instruction import UnreachableInst, AllocaInst, LoadInst, StoreInst
|
from Instruction import UnreachableInst, AllocaInst, LoadInst, StoreInst
|
||||||
|
|
@ -23,12 +24,30 @@ class IRBuilder:
|
||||||
new = Constructor(ref(LLVMContext))
|
new = Constructor(ref(LLVMContext))
|
||||||
delete = Destructor()
|
delete = Destructor()
|
||||||
|
|
||||||
SetInsertPoint = Method(Void, ptr(BasicBlock))
|
GetInsertBlock = Method(ptr(BasicBlock))
|
||||||
|
|
||||||
|
_SetInsertPoint_end_of_bb = Method(Void, ptr(BasicBlock))
|
||||||
|
_SetInsertPoint_end_of_bb.realname = 'SetInsertPoint'
|
||||||
|
_SetInsertPoint_before_instr = Method(Void, ptr(Instruction))
|
||||||
|
_SetInsertPoint_before_instr.realname = 'SetInsertPoint'
|
||||||
|
|
||||||
|
@CustomPythonMethod
|
||||||
|
def SetInsertPoint(self, pt):
|
||||||
|
if isinstance(pt, Instruction):
|
||||||
|
return self._SetInsertPoint_before_instr(pt)
|
||||||
|
elif isinstance(pt, BasicBlock):
|
||||||
|
return self._SetInsertPoint_end_of_bb(pt)
|
||||||
|
else:
|
||||||
|
raise ValueError("Expected either an Instruction or a BasicBlock")
|
||||||
|
|
||||||
isNamePreserving = Method(cast(Bool, bool))
|
isNamePreserving = Method(cast(Bool, bool))
|
||||||
|
|
||||||
CreateRetVoid = Method(ptr(ReturnInst))
|
CreateRetVoid = Method(ptr(ReturnInst))
|
||||||
CreateRet = Method(ptr(ReturnInst), ptr(Value))
|
CreateRet = Method(ptr(ReturnInst), ptr(Value))
|
||||||
|
CreateAggregateRet = CustomMethod('IRBuilder_CreateAggregateRet',
|
||||||
|
PyObjectPtr, # ptr(ReturnInst),
|
||||||
|
PyObjectPtr, # list of Value
|
||||||
|
cast(int, Unsigned))
|
||||||
|
|
||||||
CreateBr = Method(ptr(BranchInst), ptr(BasicBlock))
|
CreateBr = Method(ptr(BranchInst), ptr(BasicBlock))
|
||||||
|
|
||||||
|
|
@ -42,9 +61,18 @@ class IRBuilder:
|
||||||
CreateIndirectBr = Method(ptr(IndirectBrInst), ptr(Value),
|
CreateIndirectBr = Method(ptr(IndirectBrInst), ptr(Value),
|
||||||
cast(int, Unsigned)).require_only(1)
|
cast(int, Unsigned)).require_only(1)
|
||||||
|
|
||||||
CreateInvoke = Method(ptr(InvokeInst), ptr(Value), ptr(BasicBlock),
|
_CreateInvoke = Method(ptr(InvokeInst), ptr(Value), ptr(BasicBlock),
|
||||||
ptr(BasicBlock), ref(SmallVector_Value),
|
ptr(BasicBlock), ref(SmallVector_Value),
|
||||||
cast(str, StringRef)).require_only(4)
|
cast(str, StringRef)).require_only(4)
|
||||||
|
_CreateInvoke.realname = 'CreateInvoke'
|
||||||
|
|
||||||
|
@CustomPythonMethod
|
||||||
|
def CreateInvoke(self, *args):
|
||||||
|
import extra
|
||||||
|
args = list(args)
|
||||||
|
valuelist = args[3]
|
||||||
|
args[3] = extra.make_small_vector_from_values(*valuelist)
|
||||||
|
return self._CreateInvoke(*args)
|
||||||
|
|
||||||
CreateResume = Method(ptr(ResumeInst), ptr(Value))
|
CreateResume = Method(ptr(ResumeInst), ptr(Value))
|
||||||
|
|
||||||
|
|
@ -114,8 +142,11 @@ class IRBuilder:
|
||||||
ptr(Value), cast(str, StringRef)).require_only(1)
|
ptr(Value), cast(str, StringRef)).require_only(1)
|
||||||
|
|
||||||
|
|
||||||
CreateAlloca = Method(ptr(AllocaInst), ptr(Type), ptr(Value),
|
CreateAlloca = Method(ptr(AllocaInst),
|
||||||
cast(str, StringRef)).require_only(2)
|
ptr(Type), # ty
|
||||||
|
ptr(Value), # arysize = 0
|
||||||
|
cast(str, StringRef), # name = ''
|
||||||
|
).require_only(1)
|
||||||
|
|
||||||
CreateLoad = Method(ptr(LoadInst),
|
CreateLoad = Method(ptr(LoadInst),
|
||||||
ptr(Value), cast(str, StringRef)).require_only(1)
|
ptr(Value), cast(str, StringRef)).require_only(1)
|
||||||
|
|
@ -208,6 +239,14 @@ class IRBuilder:
|
||||||
cast(str, StringRef)).require_only(2)
|
cast(str, StringRef)).require_only(2)
|
||||||
_CreateCall.realname = 'CreateCall'
|
_CreateCall.realname = 'CreateCall'
|
||||||
|
|
||||||
|
@CustomPythonMethod
|
||||||
|
def CreateCall(self, *args):
|
||||||
|
import extra
|
||||||
|
args = list(args)
|
||||||
|
valuelist = args[1]
|
||||||
|
args[1] = extra.make_small_vector_from_values(*valuelist)
|
||||||
|
return self._CreateCall(*args)
|
||||||
|
|
||||||
# Skip specialized CreateICmp* and CreateFCmp*
|
# Skip specialized CreateICmp* and CreateFCmp*
|
||||||
|
|
||||||
CreateICmp = Method(ptr(Value), CmpInst.Predicate, ptr(Value), ptr(Value),
|
CreateICmp = Method(ptr(Value), CmpInst.Predicate, ptr(Value), ptr(Value),
|
||||||
|
|
@ -219,13 +258,6 @@ class IRBuilder:
|
||||||
CreatePHI = Method(ptr(PHINode), ptr(Type), cast(int, Unsigned),
|
CreatePHI = Method(ptr(PHINode), ptr(Type), cast(int, Unsigned),
|
||||||
cast(str, StringRef)).require_only(2)
|
cast(str, StringRef)).require_only(2)
|
||||||
|
|
||||||
@CustomPythonMethod
|
|
||||||
def CreateCall(self, *args):
|
|
||||||
import extra
|
|
||||||
args = list(args)
|
|
||||||
valuelist = args[1]
|
|
||||||
args[1] = extra.make_small_vector_from_values(*valuelist)
|
|
||||||
return self._CreateCall(*args)
|
|
||||||
|
|
||||||
CreateSelect = Method(ptr(Value), ptr(Value), ptr(Value), ptr(Value),
|
CreateSelect = Method(ptr(Value), ptr(Value), ptr(Value), ptr(Value),
|
||||||
cast(str, StringRef)).require_only(3)
|
cast(str, StringRef)).require_only(3)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ from ADT.StringRef import StringRef
|
||||||
from CallingConv import CallingConv
|
from CallingConv import CallingConv
|
||||||
from Attributes import Attributes
|
from Attributes import Attributes
|
||||||
from Constant import ConstantInt
|
from Constant import ConstantInt
|
||||||
|
from Type import Type
|
||||||
|
|
||||||
|
|
||||||
Instruction = llvm.Class(User)
|
Instruction = llvm.Class(User)
|
||||||
|
|
@ -57,6 +58,17 @@ FPToSIInst = llvm.Class(CastInst)
|
||||||
FPToUIInst = llvm.Class(CastInst)
|
FPToUIInst = llvm.Class(CastInst)
|
||||||
FPTruncInst = llvm.Class(CastInst)
|
FPTruncInst = llvm.Class(CastInst)
|
||||||
|
|
||||||
|
AtomicOrdering = llvm.Enum('AtomicOrdering',
|
||||||
|
'NotAtomic', 'Unordered', 'Monotonic', 'Acquire',
|
||||||
|
'Release', 'AcquireRelease',
|
||||||
|
'SequentiallyConsistent')
|
||||||
|
|
||||||
|
SynchronizationScope = llvm.Enum('SynchronizationScope',
|
||||||
|
'SingleThread', 'CrossThread')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Instruction
|
@Instruction
|
||||||
class Instruction:
|
class Instruction:
|
||||||
removeFromParent = Method()
|
removeFromParent = Method()
|
||||||
|
|
@ -129,6 +141,18 @@ class CallInst:
|
||||||
setCalledFunction = Method(Void, ptr(Function))
|
setCalledFunction = Method(Void, ptr(Function))
|
||||||
isInlineAsm = Method(cast(Bool, bool))
|
isInlineAsm = Method(cast(Bool, bool))
|
||||||
|
|
||||||
|
CreateMalloc = StaticMethod(ptr(Instruction),
|
||||||
|
ptr(BasicBlock), # insertAtEnd
|
||||||
|
ptr(Type), # intptrty
|
||||||
|
ptr(Type), # allocty
|
||||||
|
ptr(Value), # allocsz
|
||||||
|
ptr(Value), # array size = 0
|
||||||
|
ptr(Function), # malloc fn = 0
|
||||||
|
cast(str, StringRef), # name
|
||||||
|
).require_only(4)
|
||||||
|
|
||||||
|
CreateFree = StaticMethod(ptr(Instruction), ptr(Value), ptr(BasicBlock))
|
||||||
|
|
||||||
@CmpInst
|
@CmpInst
|
||||||
class CmpInst:
|
class CmpInst:
|
||||||
Predicate = Enum('FCMP_FALSE', 'FCMP_OEQ', 'FCMP_OGT', 'FCMP_OGE',
|
Predicate = Enum('FCMP_FALSE', 'FCMP_OEQ', 'FCMP_OGT', 'FCMP_OGE',
|
||||||
|
|
@ -201,6 +225,10 @@ class StoreInst:
|
||||||
getAlignment = Method(cast(Unsigned, int))
|
getAlignment = Method(cast(Unsigned, int))
|
||||||
setAlignment = Method(Void, cast(int, Unsigned))
|
setAlignment = Method(Void, cast(int, Unsigned))
|
||||||
|
|
||||||
|
setAtomic = Method(Void,
|
||||||
|
AtomicOrdering,
|
||||||
|
SynchronizationScope).require_only(1)
|
||||||
|
|
||||||
classof = StaticMethod(cast(Bool, bool), ptr(Value))
|
classof = StaticMethod(cast(Bool, bool), ptr(Value))
|
||||||
|
|
||||||
@TerminatorInst
|
@TerminatorInst
|
||||||
|
|
@ -298,6 +326,10 @@ class LoadInst:
|
||||||
getAlignment = Method(cast(Unsigned, int))
|
getAlignment = Method(cast(Unsigned, int))
|
||||||
setAlignment = Method(Void, cast(int, Unsigned))
|
setAlignment = Method(Void, cast(int, Unsigned))
|
||||||
|
|
||||||
|
setAtomic = Method(Void,
|
||||||
|
AtomicOrdering,
|
||||||
|
SynchronizationScope).require_only(1)
|
||||||
|
|
||||||
classof = StaticMethod(cast(Bool, bool), ptr(Value))
|
classof = StaticMethod(cast(Bool, bool), ptr(Value))
|
||||||
|
|
||||||
@VAArgInst
|
@VAArgInst
|
||||||
|
|
@ -345,11 +377,3 @@ class FPToUIInst:
|
||||||
class FPTruncInst:
|
class FPTruncInst:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
AtomicOrdering = llvm.Enum('AtomicOrdering',
|
|
||||||
'NotAtomic', 'Unordered', 'Monotonic', 'Acquire',
|
|
||||||
'Release', 'AcquireRelease',
|
|
||||||
'SequentiallyConsistent')
|
|
||||||
|
|
||||||
SynchronizationScope = llvm.Enum('SynchronizationScope',
|
|
||||||
'SingleThread', 'CrossThread')
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue