Skip to content

Commit d3f386d

Browse files
authored
Merge pull request #340 from maleadt/tb/irbuilder
Refactor in anticipation of breaking release
2 parents 53cf34b + 18ee381 commit d3f386d

29 files changed

+278
-211
lines changed

deps/LLVMExtra/include/LLVMExtra.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ LLVMValueRef LLVMBuildCallWithOpBundle(LLVMBuilderRef B, LLVMValueRef Fn,
158158
LLVMValueRef *Args, unsigned NumArgs,
159159
LLVMOperandBundleDefRef *Bundles, unsigned NumBundles,
160160
const char *Name);
161+
LLVMValueRef LLVMBuildCallWithOpBundle2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn,
162+
LLVMValueRef *Args, unsigned NumArgs,
163+
LLVMOperandBundleDefRef *Bundles, unsigned NumBundles,
164+
const char *Name);
161165
LLVMValueRef LLVMMetadataAsValue2(LLVMContextRef C, LLVMMetadataRef Metadata);
162166
void LLVMReplaceAllMetadataUsesWith(LLVMValueRef Old, LLVMValueRef New);
163167
void LLVMReplaceMDNodeOperandWith(LLVMMetadataRef MD, unsigned I, LLVMMetadataRef New);

deps/LLVMExtra/lib/llvm-api.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,28 @@ LLVMValueRef LLVMBuildCallWithOpBundle(LLVMBuilderRef B, LLVMValueRef Fn,
525525
llvm::IRBuilder<> *Builder = unwrap(B);
526526
llvm::ArrayRef<llvm::Value*> args = makeArrayRef(unwrap(Args), NumArgs);
527527

528-
FunctionType *FnT = unwrap<Function>(Fn)->getFunctionType();
528+
Value *V = unwrap(Fn);
529+
FunctionType *FnT = cast<FunctionType>(V->getType()->getPointerElementType());
529530
llvm::CallInst *CI = Builder->CreateCall(FnT, unwrap(Fn), args ,BundleArray, Name);
530531
return wrap(CI);
531532
}
532533

534+
LLVMValueRef LLVMBuildCallWithOpBundle2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn,
535+
LLVMValueRef *Args, unsigned NumArgs,
536+
LLVMOperandBundleDefRef *Bundles, unsigned NumBundles,
537+
const char *Name) {
538+
SmallVector<OperandBundleDef, 1> BundleArray;
539+
for (auto *Bundle : makeArrayRef(Bundles, NumBundles))
540+
BundleArray.push_back(*unwrap<OperandBundleDef>(Bundle));
541+
542+
llvm::IRBuilder<> *Builder = unwrap(B);
543+
llvm::ArrayRef<llvm::Value*> args = makeArrayRef(unwrap(Args), NumArgs);
544+
545+
FunctionType *FTy = unwrap<FunctionType>(Ty);
546+
llvm::CallInst *CI = Builder->CreateCall(FTy, unwrap(Fn), args ,BundleArray, Name);
547+
return wrap(CI);
548+
}
549+
533550
LLVMValueRef LLVMMetadataAsValue2(LLVMContextRef C, LLVMMetadataRef Metadata) {
534551
auto *MD = unwrap(Metadata);
535552
if (auto *VAM = dyn_cast<ValueAsMetadata>(MD))

examples/Kaleidoscope/codegen.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
mutable struct CodeGen
22
ctx::LLVM.Context
3-
builder::LLVM.Builder
3+
builder::LLVM.IRBuilder
44
current_scope::CurrentScope
55
mod::LLVM.Module
66

77
CodeGen(ctx::LLVM.Context) =
88
new(
99
ctx,
10-
LLVM.Builder(ctx),
10+
LLVM.IRBuilder(ctx),
1111
CurrentScope(),
1212
LLVM.Module("KaleidoscopeModule"; ctx),
1313
)
@@ -23,7 +23,7 @@ Base.show(io::IO, cg::CodeGen) = print(io, "CodeGen")
2323

2424
function create_entry_block_allocation(cg::CodeGen, fn::LLVM.Function, varname::String)
2525
local alloc
26-
LLVM.@dispose builder=LLVM.Builder(cg.ctx) begin
26+
LLVM.@dispose builder=LLVM.IRBuilder(cg.ctx) begin
2727
# Set the builder at the start of the function
2828
entry_block = LLVM.entry(fn)
2929
if isempty(LLVM.instructions(entry_block))

examples/constrained.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ meta(::Type{FPExceptStrict}) = "fpexcept.strict"
4545
intrinsic_fun = LLVM.Function(mod, intrinsic, [typ])
4646
ftype = LLVM.FunctionType(intrinsic,[typ])
4747
# generate IR
48-
@dispose builder=Builder(ctx) begin
48+
@dispose builder=IRBuilder(ctx) begin
4949
entry = BasicBlock(llvm_f, "entry"; ctx)
5050
position!(builder, entry)
5151
val = call!(builder, ftype, intrinsic_fun,

examples/generated.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121
llvmf, _ = create_function(eltyp, paramtyps)
2222

2323
# generate IR
24-
@dispose builder=Builder(ctx) begin
24+
@dispose builder=IRBuilder(ctx) begin
2525
entry = BasicBlock(llvmf, "entry"; ctx)
2626
position!(builder, entry)
2727

examples/sum.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121
sum = LLVM.Function(mod, "sum", fun_type)
2222

2323
# generate IR
24-
@dispose builder=Builder(ctx) begin
24+
@dispose builder=IRBuilder(ctx) begin
2525
entry = BasicBlock(sum, "entry"; ctx)
2626
position!(builder, entry)
2727

examples/sum_integrated.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ end
1818
sum, _ = create_function(ret_type, param_types)
1919

2020
# generate IR
21-
@dispose builder=Builder(ctx) begin
21+
@dispose builder=IRBuilder(ctx) begin
2222
entry = BasicBlock(sum, "entry"; ctx)
2323
position!(builder, entry)
2424

examples/sum_orc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function codegen!(mod::LLVM.Module, name, tm)
2222
sum = LLVM.Function(mod, name, ft)
2323

2424
# generate IR
25-
@dispose builder=Builder(ctx) begin
25+
@dispose builder=IRBuilder(ctx) begin
2626
entry = BasicBlock(sum, "entry"; ctx)
2727
position!(builder, entry)
2828

lib/libLLVM_extra.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ function LLVMBuildCallWithOpBundle(B, Fn, Args, NumArgs, Bundles, NumBundles, Na
399399
ccall((:LLVMBuildCallWithOpBundle, libLLVMExtra), LLVMValueRef, (LLVMBuilderRef, LLVMValueRef, Ptr{LLVMValueRef}, Cuint, Ptr{LLVMOperandBundleDefRef}, Cuint, Cstring), B, Fn, Args, NumArgs, Bundles, NumBundles, Name)
400400
end
401401

402+
function LLVMBuildCallWithOpBundle2(B, Ty, Fn, Args, NumArgs, Bundles, NumBundles, Name)
403+
ccall((:LLVMBuildCallWithOpBundle2, libLLVMExtra), LLVMValueRef, (LLVMBuilderRef, LLVMTypeRef, LLVMValueRef, Ptr{LLVMValueRef}, Cuint, Ptr{LLVMOperandBundleDefRef}, Cuint, Cstring), B, Ty, Fn, Args, NumArgs, Bundles, NumBundles, Name)
404+
end
405+
402406
function LLVMMetadataAsValue2(C, MD)
403407
ccall((:LLVMMetadataAsValue2, libLLVMExtra), LLVMValueRef, (LLVMContextRef, LLVMMetadataRef), C, MD)
404408
end

src/base.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ end
1515
# calling `refcheck` on the ref field argument
1616
macro checked(typedef)
1717
# decode structure definition
18-
if Meta.isexpr(typedef, :macrocall)
19-
# handle `@compat` prefixing 0.6-style type declarations
20-
typedef = macroexpand(typedef)
21-
end
2218
if Meta.isexpr(typedef, :struct)
2319
structure = typedef.args[2]
2420
body = typedef.args[3]

0 commit comments

Comments
 (0)