Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Llvm14 dev #4

Closed
wants to merge 14 commits into from
45 changes: 45 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
ZIGDIR=$HOME/github/zig
LLVMDIR=$HOME/github/llvm-project-14.0.5.src
OUTDIR=$HOME/local/llvm
export CXX=g++

set -ex

# cd $LLVMDIR/llvm
# mkdir -p build-release
# cd build-release
# cmake .. -DCMAKE_INSTALL_PREFIX=$OUTDIR \
# -DCMAKE_PREFIX_PATH=$OUTDIR \
# -DCMAKE_BUILD_TYPE=Release \
# -DLLVM_ENABLE_LIBXML2=OFF \
# -DLLVM_ENABLE_ASSERTIONS=ON \
# -DCMAKE_CXX_FLAGS="-g2" \
# -G Ninja \
# -DLLVM_PARALLEL_LINK_JOBS=1
# ninja install

# Lld
# cd $LLVMDIR/lld
# mkdir -p build-release
# cd build-release
# cmake .. -DCMAKE_INSTALL_PREFIX=$OUTDIR -DCMAKE_PREFIX_PATH=$OUTDIR -DCMAKE_BUILD_TYPE=Release -G Ninja -DLLVM_PARALLEL_LINK_JOBS=1 -DCMAKE_CXX_STANDARD=17
# ninja install


# Clang
# cd $LLVMDIR/clang
# mkdir -p build-release
# cd build-release
# cmake .. -DCMAKE_INSTALL_PREFIX=$OUTDIR -DCMAKE_PREFIX_PATH=$OUTDIR -DCMAKE_BUILD_TYPE=Release -G Ninja -DLLVM_PARALLEL_LINK_JOBS=1
# ninja install

mkdir -p $ZIGDIR/build; cd $ZIGDIR/build
# TODO: remove all deprecated calls
cmake .. \
-DCMAKE_PREFIX_PATH=$OUTDIR \
-DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations -g2" \

make VERBOSE=1 install

cd $ZIGDIR
./build/zig test -I test test/behavior.zig
84 changes: 9 additions & 75 deletions lib/std/atomic/Atomic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -231,83 +231,17 @@ pub fn Atomic(comptime T: type) type {
}

inline fn x86BitRmw(self: *Self, comptime op: BitRmwOp, bit: Bit, comptime ordering: Ordering) u1 {
const old_bit: u8 = switch (@sizeOf(T)) {
2 => switch (op) {
.Set => asm volatile ("lock btsw %[bit], %[ptr]"
// LLVM doesn't support u1 flag register return values
: [result] "={@ccc}" (-> u8),
: [ptr] "*m" (&self.value),
[bit] "X" (@as(T, bit)),
: "cc", "memory"
),
.Reset => asm volatile ("lock btrw %[bit], %[ptr]"
// LLVM doesn't support u1 flag register return values
: [result] "={@ccc}" (-> u8),
: [ptr] "*m" (&self.value),
[bit] "X" (@as(T, bit)),
: "cc", "memory"
),
.Toggle => asm volatile ("lock btcw %[bit], %[ptr]"
// LLVM doesn't support u1 flag register return values
: [result] "={@ccc}" (-> u8),
: [ptr] "*m" (&self.value),
[bit] "X" (@as(T, bit)),
: "cc", "memory"
),
},
4 => switch (op) {
.Set => asm volatile ("lock btsl %[bit], %[ptr]"
// LLVM doesn't support u1 flag register return values
: [result] "={@ccc}" (-> u8),
: [ptr] "*m" (&self.value),
[bit] "X" (@as(T, bit)),
: "cc", "memory"
),
.Reset => asm volatile ("lock btrl %[bit], %[ptr]"
// LLVM doesn't support u1 flag register return values
: [result] "={@ccc}" (-> u8),
: [ptr] "*m" (&self.value),
[bit] "X" (@as(T, bit)),
: "cc", "memory"
),
.Toggle => asm volatile ("lock btcl %[bit], %[ptr]"
// LLVM doesn't support u1 flag register return values
: [result] "={@ccc}" (-> u8),
: [ptr] "*m" (&self.value),
[bit] "X" (@as(T, bit)),
: "cc", "memory"
),
},
8 => switch (op) {
.Set => asm volatile ("lock btsq %[bit], %[ptr]"
// LLVM doesn't support u1 flag register return values
: [result] "={@ccc}" (-> u8),
: [ptr] "*m" (&self.value),
[bit] "X" (@as(T, bit)),
: "cc", "memory"
),
.Reset => asm volatile ("lock btrq %[bit], %[ptr]"
// LLVM doesn't support u1 flag register return values
: [result] "={@ccc}" (-> u8),
: [ptr] "*m" (&self.value),
[bit] "X" (@as(T, bit)),
: "cc", "memory"
),
.Toggle => asm volatile ("lock btcq %[bit], %[ptr]"
// LLVM doesn't support u1 flag register return values
: [result] "={@ccc}" (-> u8),
: [ptr] "*m" (&self.value),
[bit] "X" (@as(T, bit)),
: "cc", "memory"
),
},
else => @compileError("Invalid atomic type " ++ @typeName(T)),
};
// LLVM14: broken LLVM module found: Operand for indirect constraint must have elementtype attribute
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline asm changes in LLVM14. Rolledback to an holder version of this code which uses less inline asm

// %6 = call i8 asm sideeffect "lock btsl $2, $1", "={@ccc},*m,X,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %3, i32 %5), !dbg !644076

// TODO: emit appropriate tsan fence if compiling with tsan
_ = ordering;
const mask = @as(T, 1) << bit;
const value = switch (op) {
.Set => self.fetchOr(mask, ordering),
.Reset => self.fetchAnd(~mask, ordering),
.Toggle => self.fetchXor(mask, ordering),
};

return @intCast(u1, old_bit);
return @boolToInt(value & mask != 0);
}
});
};
Expand Down
1 change: 1 addition & 0 deletions src/codegen/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ pub const Object = struct {
} else {
_ = self.llvm_module.addAlias(
llvm_global.typeOf(),
0, // TODO(gwenzek) addrSpace
llvm_global,
exp_name_z,
);
Expand Down
5 changes: 4 additions & 1 deletion src/codegen/llvm/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,10 @@ pub const Builder = opaque {
pub const buildStore = LLVMBuildStore;
extern fn LLVMBuildStore(*const Builder, Val: *const Value, Ptr: *const Value) *const Value;

pub const buildLoad = LLVMBuildLoad2;
pub const buildLoad = LLVMBuildLoad;
extern fn LLVMBuildLoad(*const Builder, PointerVal: *const Value, Name: [*:0]const u8) *const Value;
// TODO(gwenzek): replace buildLoad with buildLoad2
pub const buildLoad2 = LLVMBuildLoad2;
extern fn LLVMBuildLoad2(*const Builder, Ty: *const Type, PointerVal: *const Value, Name: [*:0]const u8) *const Value;

pub const buildNeg = LLVMBuildNeg;
Expand Down
2 changes: 1 addition & 1 deletion src/link/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
// We will invoke ourselves as a child process to gain access to LLD.
// This is necessary because LLD does not behave properly as a library -
// it calls exit() and does not reset all global data between invocations.
try argv.appendSlice(&[_][]const u8{ comp.self_exe_path.?, "ld.lld" });
try argv.appendSlice(&[_][]const u8{"/home/guw/local/llvm/bin/ld.lld"});
if (is_obj) {
try argv.append("-r");
}
Expand Down
6 changes: 3 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4353,11 +4353,11 @@ pub fn lldMain(
const llvm = @import("codegen/llvm/bindings.zig");
const argc = @intCast(c_int, argv.len);
if (mem.eql(u8, args[1], "ld.lld")) {
break :rc llvm.LinkELF(argc, argv.ptr, can_exit_early);
break :rc llvm.LinkELF(argc, argv.ptr, true, false);
} else if (mem.eql(u8, args[1], "lld-link")) {
break :rc llvm.LinkCOFF(argc, argv.ptr, can_exit_early);
break :rc llvm.LinkCOFF(argc, argv.ptr, true, false);
} else if (mem.eql(u8, args[1], "wasm-ld")) {
break :rc llvm.LinkWasm(argc, argv.ptr, can_exit_early);
break :rc llvm.LinkWasm(argc, argv.ptr, true, false);
} else {
unreachable;
}
Expand Down
1 change: 1 addition & 0 deletions src/stage1/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9321,6 +9321,7 @@ static void resolve_llvm_types_pointer(CodeGen *g, ZigType *type, ResolveStatus

if (type->data.pointer.host_int_bytes == 0) {
assertNoError(type_resolve(g, elem_type, ResolveStatusLLVMFwdDecl));
// TODO: use opaque pointers everywhere
type->llvm_type = LLVMPointerType(elem_type->llvm_type, 0);
uint64_t debug_size_in_bits = 8*get_store_size_bytes(type->size_in_bits);
uint64_t debug_align_in_bits = 8*type->abi_align;
Expand Down
Loading