Skip to content

Commit

Permalink
Fix gccbuiltins_*.di generation for LLVM >= 15. (#4350)
Browse files Browse the repository at this point in the history
Fix gccbuiltins_*.di generation for LLVM >= 15.
Adds simple testcase to test that generation of intrinsics import files is indeed happening. This uncovered missing vector type aliases for MIPS, fixed that too.
Resolves issue #4347
  • Loading branch information
JohanEngelen authored Mar 15, 2023
1 parent c5cf086 commit 2153c76
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
8 changes: 8 additions & 0 deletions runtime/druntime/src/core/simd.d
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ template Vector(T)

/* Handy aliases
*/
version (LDC)
{
static if (is(Vector!(void[4]))) alias Vector!(void[4]) void4; ///
static if (is(Vector!(byte[4]))) alias Vector!(byte[4]) byte4; ///
static if (is(Vector!(ubyte[4]))) alias Vector!(ubyte[4]) ubyte4; ///
static if (is(Vector!(short[2]))) alias Vector!(short[2]) short2; ///
static if (is(Vector!(ushort[2]))) alias Vector!(ushort[2]) ushort2; ///
}
static if (is(Vector!(void[8]))) alias Vector!(void[8]) void8; ///
static if (is(Vector!(double[1]))) alias Vector!(double[1]) double1; ///
static if (is(Vector!(float[2]))) alias Vector!(float[2]) float2; ///
Expand Down
35 changes: 35 additions & 0 deletions tests/compilable/intrinsics_imports.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Very basic test to check that instrinsics include file is made correctly.
// Related to https://github.com/ldc-developers/ldc/issues/4347

// Just do SemA, no codegen, such that it works on all CI systems.
// RUN: %ldc -o- %s

import core.simd;
static import ldc.gccbuiltins_aarch64;
static import ldc.gccbuiltins_arm;
static import ldc.gccbuiltins_mips;
static import ldc.gccbuiltins_nvvm;
static import ldc.gccbuiltins_ppc;
static import ldc.gccbuiltins_x86;

short2 s2;
short8 s8;
double2 d2;
void* ptr;

void main()
{
ldc.gccbuiltins_aarch64.__builtin_arm_isb(1);

ldc.gccbuiltins_arm.__builtin_arm_dmb(2);

short2 mips = ldc.gccbuiltins_mips.__builtin_mips_addq_s_ph(s2, s2);

double nvvm = ldc.gccbuiltins_nvvm.__nvvm_fma_rz_d(1.0, 2.0, 3.0);

short8 ppc8 = ldc.gccbuiltins_ppc.__builtin_altivec_crypto_vpmsumh(s8, s8);

ldc.gccbuiltins_x86.__builtin_ia32_lfence();
ldc.gccbuiltins_x86.__builtin_ia32_umonitor(ptr);
double2 x86 = ldc.gccbuiltins_x86.__builtin_ia32_maxpd(d2, d2);
}
10 changes: 8 additions & 2 deletions utils/gen_gccbuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
using namespace std;
using namespace llvm;

#if LDC_LLVM_VER >= 1500
#define BUILTIN_NAME_STRING "ClangBuiltinName"
#else
#define BUILTIN_NAME_STRING "GCCBuiltinName"
#endif

string dtype(Record* rec, bool readOnlyMem)
{
Init* typeInit = rec->getValueInit("VT");
Expand Down Expand Up @@ -85,10 +91,10 @@ StringRef attributes(ListInit* propertyList)

void processRecord(raw_ostream& os, Record& rec, string arch)
{
if(!rec.getValue("GCCBuiltinName"))
if(!rec.getValue(BUILTIN_NAME_STRING))
return;

const StringRef builtinName = rec.getValueAsString("GCCBuiltinName");
const StringRef builtinName = rec.getValueAsString(BUILTIN_NAME_STRING);
string name = rec.getName().str();

if(name.substr(0, 4) != "int_" || name.find(arch) == string::npos)
Expand Down

0 comments on commit 2153c76

Please sign in to comment.