diff options
author | Ayke van Laethem <[email protected]> | 2019-11-23 00:27:18 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2020-03-25 20:17:46 +0100 |
commit | 6dafb6c65e90daac5113c7638e6d0b16ed599a52 (patch) | |
tree | 6fd9c92711dae1207106999c8bc4cfd7cbbbc0ed /compiler/llvm.go | |
parent | b8d20535ba198331beba8b415e98d435902b851f (diff) | |
download | tinygo-6dafb6c65e90daac5113c7638e6d0b16ed599a52.tar.gz tinygo-6dafb6c65e90daac5113c7638e6d0b16ed599a52.zip |
compiler: refactor creating of channel operations
Diffstat (limited to 'compiler/llvm.go')
-rw-r--r-- | compiler/llvm.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/compiler/llvm.go b/compiler/llvm.go index 30a96f427..2a9f6c9d9 100644 --- a/compiler/llvm.go +++ b/compiler/llvm.go @@ -33,6 +33,16 @@ func (c *Compiler) createTemporaryAlloca(t llvm.Type, name string) (alloca, bitc return llvmutil.CreateTemporaryAlloca(c.builder, c.mod, t, name) } +// createTemporaryAlloca creates a new alloca in the entry block and adds +// lifetime start infromation in the IR signalling that the alloca won't be used +// before this point. +// +// This is useful for creating temporary allocas for intrinsics. Don't forget to +// end the lifetime using emitLifetimeEnd after you're done with it. +func (b *builder) createTemporaryAlloca(t llvm.Type, name string) (alloca, bitcast, size llvm.Value) { + return llvmutil.CreateTemporaryAlloca(b.Builder, b.mod, t, name) +} + // emitLifetimeEnd signals the end of an (alloca) lifetime by calling the // llvm.lifetime.end intrinsic. It is commonly used together with // createTemporaryAlloca. @@ -40,6 +50,13 @@ func (c *Compiler) emitLifetimeEnd(ptr, size llvm.Value) { llvmutil.EmitLifetimeEnd(c.builder, c.mod, ptr, size) } +// emitLifetimeEnd signals the end of an (alloca) lifetime by calling the +// llvm.lifetime.end intrinsic. It is commonly used together with +// createTemporaryAlloca. +func (b *builder) emitLifetimeEnd(ptr, size llvm.Value) { + llvmutil.EmitLifetimeEnd(b.Builder, b.mod, ptr, size) +} + // emitPointerPack packs the list of values into a single pointer value using // bitcasts, or else allocates a value on the heap if it cannot be packed in the // pointer value directly. It returns the pointer with the packed data. |