Skip to content

Commit

Permalink
Merged master:ed398c3ca404 into amd-gfx:6f1c05b7154e
Browse files Browse the repository at this point in the history
Local branch amd-gfx 6f1c05b Merged master:161ae1f39816 into amd-gfx:da5e1e7f68df
Remote branch master ed398c3 [NFC] Extract unifyTargetFeatures
  • Loading branch information
Sw authored and Sw committed Jun 26, 2020
2 parents 6f1c05b + ed398c3 commit a7ec3c4
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 22 deletions.
9 changes: 9 additions & 0 deletions clang/include/clang/Basic/BuiltinsPPC.def
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ BUILTIN(__builtin_altivec_vrldnm, "V2ULLiV2ULLiV2ULLi", "")
BUILTIN(__builtin_altivec_vpdepd, "V2ULLiV2ULLiV2ULLi", "")
BUILTIN(__builtin_altivec_vpextd, "V2ULLiV2ULLiV2ULLi", "")

// P10 Vector Centrifuge built-in.
BUILTIN(__builtin_altivec_vcfuged, "V2ULLiV2ULLiV2ULLi", "")

// P10 Vector Gather Every N-th Bit built-in.
BUILTIN(__builtin_altivec_vgnb, "ULLiV1ULLLiIi", "")

// P10 Vector Clear Bytes built-ins.
BUILTIN(__builtin_altivec_vclrlb, "V16cV16cUi", "")
BUILTIN(__builtin_altivec_vclrrb, "V16cV16cUi", "")
Expand Down Expand Up @@ -439,6 +445,8 @@ BUILTIN(__builtin_vsx_extractuword, "V2ULLiV16UcIi", "")
BUILTIN(__builtin_vsx_xxpermdi, "v.", "t")
BUILTIN(__builtin_vsx_xxsldwi, "v.", "t")

BUILTIN(__builtin_vsx_xxeval, "V2ULLiV2ULLiV2ULLiV2ULLiIi", "")

// Float 128 built-ins
BUILTIN(__builtin_sqrtf128_round_to_odd, "LLdLLd", "")
BUILTIN(__builtin_addf128_round_to_odd, "LLdLLdLLd", "")
Expand Down Expand Up @@ -489,6 +497,7 @@ BUILTIN(__builtin_divdeu, "ULLiULLiULLi", "")
BUILTIN(__builtin_bpermd, "SLLiSLLiSLLi", "")
BUILTIN(__builtin_pdepd, "ULLiULLiULLi", "")
BUILTIN(__builtin_pextd, "ULLiULLiULLi", "")
BUILTIN(__builtin_cfuged, "ULLiULLiULLi", "")
BUILTIN(__builtin_cntlzdm, "ULLiULLiULLi", "")
BUILTIN(__builtin_cnttzdm, "ULLiULLiULLi", "")

Expand Down
20 changes: 2 additions & 18 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,25 +374,9 @@ static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
ve::getVETargetFeatures(D, Args, Features);
}

// Find the last of each feature.
llvm::StringMap<unsigned> LastOpt;
for (unsigned I = 0, N = Features.size(); I < N; ++I) {
StringRef Name = Features[I];
assert(Name[0] == '-' || Name[0] == '+');
LastOpt[Name.drop_front(1)] = I;
}

for (unsigned I = 0, N = Features.size(); I < N; ++I) {
// If this feature was overridden, ignore it.
StringRef Name = Features[I];
llvm::StringMap<unsigned>::iterator LastI = LastOpt.find(Name.drop_front(1));
assert(LastI != LastOpt.end());
unsigned Last = LastI->second;
if (Last != I)
continue;

for (auto Feature : unifyTargetFeatures(Features)) {
CmdArgs.push_back(IsAux ? "-aux-target-feature" : "-target-feature");
CmdArgs.push_back(Name.data());
CmdArgs.push_back(Feature.data());
}
}

Expand Down
25 changes: 25 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,31 @@ void tools::handleTargetFeaturesGroup(const ArgList &Args,
}
}

std::vector<StringRef>
tools::unifyTargetFeatures(const std::vector<StringRef> &Features) {
std::vector<StringRef> UnifiedFeatures;
// Find the last of each feature.
llvm::StringMap<unsigned> LastOpt;
for (unsigned I = 0, N = Features.size(); I < N; ++I) {
StringRef Name = Features[I];
assert(Name[0] == '-' || Name[0] == '+');
LastOpt[Name.drop_front(1)] = I;
}

for (unsigned I = 0, N = Features.size(); I < N; ++I) {
// If this feature was overridden, ignore it.
StringRef Name = Features[I];
llvm::StringMap<unsigned>::iterator LastI = LastOpt.find(Name.drop_front(1));
assert(LastI != LastOpt.end());
unsigned Last = LastI->second;
if (Last != I)
continue;

UnifiedFeatures.push_back(Name);
}
return UnifiedFeatures;
}

void tools::addDirectoryList(const ArgList &Args, ArgStringList &CmdArgs,
const char *ArgName, const char *EnvVar) {
const char *DirList = ::getenv(EnvVar);
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,20 @@ void AddTargetFeature(const llvm::opt::ArgList &Args,
std::string getCPUName(const llvm::opt::ArgList &Args, const llvm::Triple &T,
bool FromAs = false);

/// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
/// append it to \p Features.
///
/// Note: Since \p Features may contain default values before calling
/// this function, or may be appended with entries to override arguments,
/// entries in \p Features are not unique.
void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args,
std::vector<StringRef> &Features,
llvm::opt::OptSpecifier Group);

/// If there are multiple +xxx or -xxx features, keep the last one.
std::vector<StringRef>
unifyTargetFeatures(const std::vector<StringRef> &Features);

/// Handles the -save-stats option and returns the filename to save statistics
/// to.
SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
Expand Down
36 changes: 36 additions & 0 deletions clang/lib/Headers/altivec.h
Original file line number Diff line number Diff line change
Expand Up @@ -16777,6 +16777,42 @@ vec_pext(vector unsigned long long __a, vector unsigned long long __b) {
return __builtin_altivec_vpextd(__a, __b);
}

/* vec_cfuge */

static __inline__ vector unsigned long long __ATTRS_o_ai
vec_cfuge(vector unsigned long long __a, vector unsigned long long __b) {
return __builtin_altivec_vcfuged(__a, __b);
}

/* vec_gnb */

#define vec_gnb(__a, __b) __builtin_altivec_vgnb(__a, __b)

/* vec_ternarylogic */
#ifdef __VSX__
#define vec_ternarylogic(__a, __b, __c, __imm) \
_Generic((__a), vector unsigned char \
: __builtin_vsx_xxeval((vector unsigned long long)(__a), \
(vector unsigned long long)(__b), \
(vector unsigned long long)(__c), (__imm)), \
vector unsigned short \
: __builtin_vsx_xxeval((vector unsigned long long)(__a), \
(vector unsigned long long)(__b), \
(vector unsigned long long)(__c), (__imm)), \
vector unsigned int \
: __builtin_vsx_xxeval((vector unsigned long long)(__a), \
(vector unsigned long long)(__b), \
(vector unsigned long long)(__c), (__imm)), \
vector unsigned long long \
: __builtin_vsx_xxeval((vector unsigned long long)(__a), \
(vector unsigned long long)(__b), \
(vector unsigned long long)(__c), (__imm)), \
vector unsigned __int128 \
: __builtin_vsx_xxeval((vector unsigned long long)(__a), \
(vector unsigned long long)(__b), \
(vector unsigned long long)(__c), (__imm)))
#endif /* __VSX__ */

/* vec_genpcvm */

#ifdef __VSX__
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3124,6 +3124,10 @@ bool Sema::CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
SemaBuiltinConstantArgRange(TheCall, 1, 0, 1);
case PPC::BI__builtin_pack_vector_int128:
return SemaVSXCheck(TheCall);
case PPC::BI__builtin_altivec_vgnb:
return SemaBuiltinConstantArgRange(TheCall, 1, 2, 7);
case PPC::BI__builtin_vsx_xxeval:
return SemaBuiltinConstantArgRange(TheCall, 3, 0, 255);
}
return SemaBuiltinConstantArgRange(TheCall, i, l, u);
}
Expand Down
5 changes: 5 additions & 0 deletions clang/test/CodeGen/builtins-ppc-p10.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ unsigned long long test_pextd(void) {
return __builtin_pextd(ulla, ullb);
}

unsigned long long test_cfuged(void) {
// CHECK: @llvm.ppc.cfuged
return __builtin_cfuged(ulla, ullb);
}

unsigned long long test_cntlzdm(void) {
// CHECK: @llvm.ppc.cntlzdm
return __builtin_cntlzdm(ulla, ullb);
Expand Down
63 changes: 59 additions & 4 deletions clang/test/CodeGen/builtins-ppc-p10vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include <altivec.h>

vector signed char vsca;
vector unsigned char vuca;
vector unsigned short vusa;
vector unsigned int vuia;
vector unsigned long long vulla, vullb;
vector unsigned char vuca, vucb, vucc;
vector unsigned short vusa, vusb, vusc;
vector unsigned int vuia, vuib, vuic;
vector unsigned long long vulla, vullb, vullc;
vector unsigned __int128 vui128a, vui128b, vui128c;
unsigned int uia;

vector unsigned long long test_vpdepd(void) {
Expand All @@ -24,6 +25,60 @@ vector unsigned long long test_vpextd(void) {
return vec_pext(vulla, vullb);
}

vector unsigned long long test_vcfuged(void) {
// CHECK: @llvm.ppc.altivec.vcfuged(<2 x i64>
// CHECK-NEXT: ret <2 x i64>
return vec_cfuge(vulla, vullb);
}

unsigned long long test_vgnb_1(void) {
// CHECK: @llvm.ppc.altivec.vgnb(<1 x i128> %{{.+}}, i32 2)
// CHECK-NEXT: ret i64
return vec_gnb(vui128a, 2);
}

unsigned long long test_vgnb_2(void) {
// CHECK: @llvm.ppc.altivec.vgnb(<1 x i128> %{{.+}}, i32 7)
// CHECK-NEXT: ret i64
return vec_gnb(vui128a, 7);
}

unsigned long long test_vgnb_3(void) {
// CHECK: @llvm.ppc.altivec.vgnb(<1 x i128> %{{.+}}, i32 5)
// CHECK-NEXT: ret i64
return vec_gnb(vui128a, 5);
}

vector unsigned char test_xxeval_uc(void) {
// CHECK: @llvm.ppc.vsx.xxeval(<2 x i64> %{{.+}}, <2 x i64> %{{.+}}, <2 x i64> %{{.+}}, i32 0)
// CHECK: ret <16 x i8>
return vec_ternarylogic(vuca, vucb, vucc, 0);
}

vector unsigned short test_xxeval_us(void) {
// CHECK: @llvm.ppc.vsx.xxeval(<2 x i64> %{{.+}}, <2 x i64> %{{.+}}, <2 x i64> %{{.+}}, i32 255)
// CHECK: ret <8 x i16>
return vec_ternarylogic(vusa, vusb, vusc, 255);
}

vector unsigned int test_xxeval_ui(void) {
// CHECK: @llvm.ppc.vsx.xxeval(<2 x i64> %{{.+}}, <2 x i64> %{{.+}}, <2 x i64> %{{.+}}, i32 150)
// CHECK: ret <4 x i32>
return vec_ternarylogic(vuia, vuib, vuic, 150);
}

vector unsigned long long test_xxeval_ull(void) {
// CHECK: @llvm.ppc.vsx.xxeval(<2 x i64> %{{.+}}, <2 x i64> %{{.+}}, <2 x i64> %{{.+}}, i32 1)
// CHECK: ret <2 x i64>
return vec_ternarylogic(vulla, vullb, vullc, 1);
}

vector unsigned __int128 test_xxeval_ui128(void) {
// CHECK: @llvm.ppc.vsx.xxeval(<2 x i64> %{{.+}}, <2 x i64> %{{.+}}, <2 x i64> %{{.+}}, i32 246)
// CHECK: ret <1 x i128>
return vec_ternarylogic(vui128a, vui128b, vui128c, 246);
}

vector unsigned char test_xxgenpcvbm(void) {
// CHECK: @llvm.ppc.vsx.xxgenpcvbm(<16 x i8> %{{.+}}, i32
// CHECK-NEXT: ret <16 x i8>
Expand Down
1 change: 1 addition & 0 deletions clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// REQUIRES: amdgpu-registered-target
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -emit-llvm -x hip %s -o - | FileCheck --check-prefixes=COMMON,CHECK %s
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -emit-llvm -x hip %s -disable-O0-optnone -o - | opt -S -O2 | FileCheck %s --check-prefixes=COMMON,OPT
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -x hip %s -o - | FileCheck -check-prefix=HOST %s
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Driver/hip-toolchain-features.hip
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@

// ALL3: {{.*}}clang{{.*}}"-target-feature" "+xnack" "-target-feature" "+sram-ecc"
// NOALL3: {{.*}}clang{{.*}}"-target-feature" "-xnack" "-target-feature" "-sram-ecc"

// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \
// RUN: --cuda-gpu-arch=gfx1010 %s \
// RUN: -mcumode -mcumode -mno-cumode -mwavefrontsize64 -mcumode \
// RUN: -mwavefrontsize64 -mno-wavefrontsize64 2>&1 \
// RUN: | FileCheck %s -check-prefix=DUP
// DUP: {{.*}}clang{{.*}} "-target-feature" "-wavefrontsize16"
// DUP-SAME: "-target-feature" "+wavefrontsize32"
// DUP-SAME: "-target-feature" "-wavefrontsize64"
// DUP-SAME: "-target-feature" "+cumode"
20 changes: 20 additions & 0 deletions llvm/include/llvm/IR/IntrinsicsPowerPC.td
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ let TargetPrefix = "ppc" in { // All intrinsics start with "llvm.ppc.".
: GCCBuiltin<"__builtin_pextd">,
Intrinsic <[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty], [IntrNoMem]>;

// Centrifuge Doubleword Builtin.
def int_ppc_cfuged
: GCCBuiltin<"__builtin_cfuged">,
Intrinsic <[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty], [IntrNoMem]>;

// Count Leading / Trailing Zeroes under bit Mask Builtins.
def int_ppc_cntlzdm
: GCCBuiltin<"__builtin_cntlzdm">,
Expand Down Expand Up @@ -426,6 +431,16 @@ let TargetPrefix = "ppc" in { // All intrinsics start with "llvm.ppc.".
Intrinsic<[llvm_v2i64_ty], [llvm_v2i64_ty, llvm_v2i64_ty],
[IntrNoMem]>;

// P10 Vector Centrifuge Builtin.
def int_ppc_altivec_vcfuged : GCCBuiltin<"__builtin_altivec_vcfuged">,
Intrinsic<[llvm_v2i64_ty], [llvm_v2i64_ty, llvm_v2i64_ty],
[IntrNoMem]>;

// P10 Vector Gather Every Nth Bit Builtin.
def int_ppc_altivec_vgnb : GCCBuiltin<"__builtin_altivec_vgnb">,
Intrinsic<[llvm_i64_ty], [llvm_v1i128_ty, llvm_i32_ty],
[IntrNoMem, ImmArg<ArgIndex<1>>]>;

// P10 Vector Clear Bytes
def int_ppc_altivec_vclrlb : GCCBuiltin<"__builtin_altivec_vclrlb">,
Intrinsic<[llvm_v16i8_ty], [llvm_v16i8_ty, llvm_i32_ty],
Expand Down Expand Up @@ -969,6 +984,11 @@ def int_ppc_vsx_xxinsertw :
PowerPC_VSX_Intrinsic<"xxinsertw",[llvm_v4i32_ty],
[llvm_v4i32_ty,llvm_v2i64_ty,llvm_i32_ty],
[IntrNoMem]>;
def int_ppc_vsx_xxeval :
PowerPC_VSX_Intrinsic<"xxeval", [llvm_v2i64_ty],
[llvm_v2i64_ty, llvm_v2i64_ty,
llvm_v2i64_ty, llvm_i32_ty],
[IntrNoMem, ImmArg<ArgIndex<3>>]>;
def int_ppc_vsx_xxgenpcvbm :
PowerPC_VSX_Intrinsic<"xxgenpcvbm", [llvm_v16i8_ty],
[llvm_v16i8_ty, llvm_i32_ty], [IntrNoMem]>;
Expand Down
65 changes: 65 additions & 0 deletions llvm/lib/Target/PowerPC/PPCInstrPrefix.td
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,54 @@ class XForm_XT6_IMM5_VB5<bits<6> opcode, bits<10> xo, dag OOL, dag IOL,
let Inst{31} = XT{5};
}

class 8RR_XX4Form_IMM8_XTAB6<bits<6> opcode, bits<2> xo,
dag OOL, dag IOL, string asmstr,
InstrItinClass itin, list<dag> pattern>
: PI<1, opcode, OOL, IOL, asmstr, itin> {
bits<6> XT;
bits<6> XA;
bits<6> XB;
bits<6> XC;
bits<8> IMM;

let Pattern = pattern;

// The prefix.
let Inst{6-7} = 1;
let Inst{8} = 0;
let Inst{9-11} = 0;
let Inst{12-13} = 0;
let Inst{14-23} = 0;
let Inst{24-31} = IMM;

// The instruction.
let Inst{38-42} = XT{4-0};
let Inst{43-47} = XA{4-0};
let Inst{48-52} = XB{4-0};
let Inst{53-57} = XC{4-0};
let Inst{58-59} = xo;
let Inst{60} = XC{5};
let Inst{61} = XA{5};
let Inst{62} = XB{5};
let Inst{63} = XT{5};
}

class VXForm_RD5_N3_VB5<bits<11> xo, dag OOL, dag IOL, string asmstr,
InstrItinClass itin, list<dag> pattern>
: I<4, OOL, IOL, asmstr, itin> {
bits<5> RD;
bits<5> VB;
bits<3> N;

let Pattern = pattern;

let Inst{6-10} = RD;
let Inst{11-12} = 0;
let Inst{13-15} = N;
let Inst{16-20} = VB;
let Inst{21-31} = xo;
}

multiclass MLS_DForm_R_SI34_RTA5_MEM_p<bits<6> opcode, dag OOL, dag IOL,
dag PCRel_IOL, string asmstr,
InstrItinClass itin> {
Expand Down Expand Up @@ -532,6 +580,23 @@ let Predicates = [IsISA3_1] in {
def PEXTD : XForm_6<31, 188, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
"pextd $rA, $rS, $rB", IIC_IntGeneral,
[(set i64:$rA, (int_ppc_pextd i64:$rS, i64:$rB))]>;
def VCFUGED : VXForm_1<1357, (outs vrrc:$vD), (ins vrrc:$vA, vrrc:$vB),
"vcfuged $vD, $vA, $vB", IIC_VecGeneral,
[(set v2i64:$vD,
(int_ppc_altivec_vcfuged v2i64:$vA, v2i64:$vB))]>;
def VGNB : VXForm_RD5_N3_VB5<1228, (outs g8rc:$rD), (ins vrrc:$vB, u3imm:$N),
"vgnb $rD, $vB, $N", IIC_VecGeneral,
[(set i64:$rD,
(int_ppc_altivec_vgnb v1i128:$vB, timm:$N))]>;
def CFUGED : XForm_6<31, 220, (outs g8rc:$rA), (ins g8rc:$rS, g8rc:$rB),
"cfuged $rA, $rS, $rB", IIC_IntGeneral,
[(set i64:$rA, (int_ppc_cfuged i64:$rS, i64:$rB))]>;
def XXEVAL :
8RR_XX4Form_IMM8_XTAB6<34, 1, (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB,
vsrc:$XC, u8imm:$IMM),
"xxeval $XT, $XA, $XB, $XC, $IMM", IIC_VecGeneral,
[(set v2i64:$XT, (int_ppc_vsx_xxeval v2i64:$XA,
v2i64:$XB, v2i64:$XC, timm:$IMM))]>;
def VCLZDM : VXForm_1<1924, (outs vrrc:$vD), (ins vrrc:$vA, vrrc:$vB),
"vclzdm $vD, $vA, $vB", IIC_VecGeneral,
[(set v2i64:$vD,
Expand Down
Loading

0 comments on commit a7ec3c4

Please sign in to comment.