Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaBase.h"
#include "clang/Sema/SemaConcept.h"
#include "clang/Sema/SemaRISCV.h"
#include "clang/Sema/TypoCorrection.h"
#include "clang/Sema/Weak.h"
#include "llvm/ADT/APInt.h"
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Serialization/ASTBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@ enum ASTRecordTypes {
UPDATE_MODULE_LOCAL_VISIBLE = 76,

UPDATE_TU_LOCAL_VISIBLE = 77,

/// Record code for #pragma clang riscv intrinsic vector.
RISCV_VECTOR_INTRINSICS_PRAGMA = 78,
};

/// Record types used within a source manager block.
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Serialization/ASTReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,9 @@ class ASTReader
/// The IDs of all decls with function effects to be checked.
SmallVector<GlobalDeclID> DeclsWithEffectsToVerify;

/// The RISC-V intrinsic pragma(including RVV, SiFive and Andes).
SmallVector<bool, 3> RISCVVecIntrinsicPragma;

private:
struct ImportedSubmodule {
serialization::SubmoduleID ID;
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Serialization/ASTWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ class ASTWriter : public ASTDeserializationListener,
void WriteDeclsWithEffectsToVerify(Sema &SemaRef);
void WriteModuleFileExtension(Sema &SemaRef,
ModuleFileExtensionWriter &Writer);
void WriteRISCVIntrinsicPragmas(Sema &SemaRef);

unsigned DeclParmVarAbbrev = 0;
unsigned DeclContextLexicalAbbrev = 0;
Expand Down
23 changes: 23 additions & 0 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4447,6 +4447,22 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
for (unsigned I = 0, N = Record.size(); I != N; /*in loop*/)
DeclsToCheckForDeferredDiags.insert(ReadDeclID(F, Record, I));
break;

case RISCV_VECTOR_INTRINSICS_PRAGMA: {
unsigned NumRecords = Record.front();
// Last record which is used to keep number of valid records.
if (Record.size() - 1 != NumRecords)
return llvm::createStringError(std::errc::illegal_byte_sequence,
"invalid rvv intrinsic pragma record");

if (RISCVVecIntrinsicPragma.empty())
RISCVVecIntrinsicPragma.append(NumRecords, 0);
// There might be multiple precompiled modules imported, we need to union
// them all.
for (unsigned i = 0; i < NumRecords; ++i)
RISCVVecIntrinsicPragma[i] |= Record[i + 1];
break;
}
}
}
}
Expand Down Expand Up @@ -9063,6 +9079,13 @@ void ASTReader::UpdateSema() {
PointersToMembersPragmaLocation);
}
SemaObj->CUDA().ForceHostDeviceDepth = ForceHostDeviceDepth;
if (!RISCVVecIntrinsicPragma.empty()) {
assert(RISCVVecIntrinsicPragma.size() == 3 &&
"Wrong number of RISCVVecIntrinsicPragma");
SemaObj->RISCV().DeclareRVVBuiltins = RISCVVecIntrinsicPragma[0];
SemaObj->RISCV().DeclareSiFiveVectorBuiltins = RISCVVecIntrinsicPragma[1];
SemaObj->RISCV().DeclareAndesVectorBuiltins = RISCVVecIntrinsicPragma[2];
}

if (PragmaAlignPackCurrentValue) {
// The bottom of the stack might have a default value. It must be adjusted
Expand Down
12 changes: 12 additions & 0 deletions clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ void ASTWriter::WriteBlockInfoBlock() {
RECORD(PP_ASSUME_NONNULL_LOC);
RECORD(PP_UNSAFE_BUFFER_USAGE);
RECORD(VTABLES_TO_EMIT);
RECORD(RISCV_VECTOR_INTRINSICS_PRAGMA);

// SourceManager Block.
BLOCK(SOURCE_MANAGER_BLOCK);
Expand Down Expand Up @@ -5232,6 +5233,16 @@ void ASTWriter::WriteModuleFileExtension(Sema &SemaRef,
Stream.ExitBlock();
}

void ASTWriter::WriteRISCVIntrinsicPragmas(Sema &SemaRef) {
RecordData Record;
// Need to update this when new intrinsic class is added.
Record.push_back(/*size*/ 3);
Record.push_back(SemaRef.RISCV().DeclareRVVBuiltins);
Record.push_back(SemaRef.RISCV().DeclareSiFiveVectorBuiltins);
Record.push_back(SemaRef.RISCV().DeclareAndesVectorBuiltins);
Stream.EmitRecord(RISCV_VECTOR_INTRINSICS_PRAGMA, Record);
}

//===----------------------------------------------------------------------===//
// General Serialization Routines
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -6130,6 +6141,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema *SemaPtr, StringRef isysroot,
WriteFPPragmaOptions(SemaPtr->CurFPFeatureOverrides());
WriteOpenCLExtensions(*SemaPtr);
WriteCUDAPragmas(*SemaPtr);
WriteRISCVIntrinsicPragmas(*SemaPtr);
}

// If we're emitting a module, write out the submodule information.
Expand Down
40 changes: 40 additions & 0 deletions clang/test/PCH/riscv-rvv-vectors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// RUN: rm -rf %t
// RUN: split-file %s %t


// Test precompiled header
// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +v -emit-pch -o %t/test_pch.pch %t/test_pch.h
// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +v -include-pch %t/test_pch.pch \
// RUN: -fsyntax-only -verify %t/test_pch_src.c
//
// Test precompiled module(only available after C++20)
// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +v -std=c++20 -xc++-user-header -emit-header-unit -o %t/test_module1.pcm %t/test_module1.h
// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +v -std=c++20 -xc++-user-header -emit-header-unit -o %t/test_module2.pcm %t/test_module2.h
// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +v -std=c++20 -fmodule-file=%t/test_module1.pcm -fmodule-file=%t/test_module2.pcm \
// RUN: -fsyntax-only %t/test_module_src.cpp

//--- test_pch.h
// expected-no-diagnostics
#include <riscv_vector.h>

//--- test_pch_src.c
// expected-no-diagnostics
vuint64m4_t v_add(vuint64m4_t a, vuint64m4_t b, size_t vl) {
return __riscv_vadd_vv_u64m4(a, b, vl);
}

//--- test_module1.h
// expected-no-diagnostics
#include <riscv_vector.h>

//--- test_module2.h
// expected-no-diagnostics
// empty header

//--- test_module_src.cpp
// expected-no-diagnostics
import "test_module1.h";
import "test_module2.h";
vuint64m4_t v_add(vuint64m4_t a, vuint64m4_t b, size_t vl) {
return __riscv_vadd_vv_u64m4(a, b, vl);
}