Skip to content

Commit

Permalink
[RISCV][Clang] Implement XcvElw Clang Builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
realqhc authored and PaoloS02 committed Dec 12, 2023
1 parent 48d6907 commit 4535d99
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/BuiltinsRISCVCOREV.def
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ TARGET_BUILTIN(alu_subuN, "UZiUZiUZiUc", "nc", "xcvalu")
TARGET_BUILTIN(alu_subRN, "ZiZiZiUc", "nc", "xcvalu")
TARGET_BUILTIN(alu_subuRN, "UZiUZiUZiUc", "nc", "xcvalu")

TARGET_BUILTIN(elw_elw, "iv*", "nc", "xcvelw")

#undef BUILTIN
#undef TARGET_BUILTIN
#undef PSEUDO_BUILTIN
7 changes: 4 additions & 3 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19363,12 +19363,13 @@ static Value *EmitCoreVIntrinsic(CodeGenFunction &CGF, unsigned BuiltinID,
for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
if (Ops[i]->getType() != MachineType) {
QualType type = E->getArg(i)->getType();
assert((type->isSignedIntegerType() || type->isUnsignedIntegerType()) &&
assert((type->isSignedIntegerType() || type->isUnsignedIntegerType() ||
type->isPointerType()) &&
"Argument of Core-V builtin must have signed or unsigned integer "
"type");
"or Pointer type");
if (type->isSignedIntegerType()) {
Ops[i] = CGF.Builder.CreateSExt(Ops[i], MachineType);
} else {
} else if ((type->isUnsignedIntegerType())) {
Ops[i] = CGF.Builder.CreateZExt(Ops[i], MachineType);
}
}
Expand Down
17 changes: 17 additions & 0 deletions clang/test/CodeGen/RISCV/corev-intrinsics/elw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang_cc1 -triple riscv32 -target-feature +xcvelw -emit-llvm %s -o - \
// RUN: | FileCheck %s


// CHECK-LABEL: @test_elw(
// CHECK-NEXT: entry:
// CHECK-NEXT: [[B_ADDR:%.*]] = alloca ptr, align 4
// CHECK-NEXT: store ptr [[B:%.*]], ptr [[B_ADDR]], align 4
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[B_ADDR]], align 4
// CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr i8, ptr [[TMP0]], i32 8
// CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.riscv.cv.elw.elw(ptr [[ADD_PTR]])
// CHECK-NEXT: ret i32 [[TMP1]]
//
int test_elw(void *b) {
return __builtin_riscv_cv_elw_elw(b + 8);
}

0 comments on commit 4535d99

Please sign in to comment.