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

[clang] Introduce SemaRISCV #92682

Merged
merged 8 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
65 changes: 25 additions & 40 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class SemaHLSL;
class SemaObjC;
class SemaOpenACC;
class SemaOpenMP;
class SemaRISCV;
class SemaSYCL;
class StandardConversionSequence;
class Stmt;
Expand Down Expand Up @@ -1015,6 +1016,11 @@ class Sema final : public SemaBase {
return *OpenMPPtr;
}

SemaRISCV &RISCV() {
assert(RISCVPtr);
return *RISCVPtr;
}

SemaSYCL &SYCL() {
assert(SYCLPtr);
return *SYCLPtr;
Expand Down Expand Up @@ -1056,6 +1062,7 @@ class Sema final : public SemaBase {
std::unique_ptr<SemaObjC> ObjCPtr;
std::unique_ptr<SemaOpenACC> OpenACCPtr;
std::unique_ptr<SemaOpenMP> OpenMPPtr;
std::unique_ptr<SemaRISCV> RISCVPtr;
std::unique_ptr<SemaSYCL> SYCLPtr;

///@}
Expand Down Expand Up @@ -2031,6 +2038,23 @@ class Sema final : public SemaBase {

void CheckConstrainedAuto(const AutoType *AutoT, SourceLocation Loc);

bool BuiltinConstantArg(CallExpr *TheCall, int ArgNum, llvm::APSInt &Result);
bool BuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, int High,
bool RangeIsError = true);
bool BuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum,
unsigned Multiple);
bool BuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum);
bool BuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum,
unsigned ArgBits);
bool BuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum,
unsigned ArgBits);

bool checkArgCountAtLeast(CallExpr *Call, unsigned MinArgCount);
bool checkArgCountAtMost(CallExpr *Call, unsigned MaxArgCount);
bool checkArgCountRange(CallExpr *Call, unsigned MinArgCount,
unsigned MaxArgCount);
bool checkArgCount(CallExpr *Call, unsigned DesiredArgCount);

private:
void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
const ArraySubscriptExpr *ASE = nullptr,
Expand Down Expand Up @@ -2099,11 +2123,7 @@ class Sema final : public SemaBase {
bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
CallExpr *TheCall);
bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
CallExpr *TheCall);
void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D,
const llvm::StringMap<bool> &FeatureMap);

bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI,
unsigned BuiltinID, CallExpr *TheCall);
bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI,
Expand Down Expand Up @@ -2133,16 +2153,6 @@ class Sema final : public SemaBase {
ExprResult BuiltinNontemporalOverloaded(ExprResult TheCallResult);
ExprResult AtomicOpsOverloaded(ExprResult TheCallResult,
AtomicExpr::AtomicOp Op);
bool BuiltinConstantArg(CallExpr *TheCall, int ArgNum, llvm::APSInt &Result);
bool BuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, int High,
bool RangeIsError = true);
bool BuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum,
unsigned Multiple);
bool BuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum);
bool BuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum,
unsigned ArgBits);
bool BuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum,
unsigned ArgBits);
bool BuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall, int ArgNum,
unsigned ExpectedFieldNum, bool AllowName);
bool BuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall);
Expand Down Expand Up @@ -5886,7 +5896,6 @@ class Sema final : public SemaBase {
SourceLocation Loc, bool IsCompAssign);

bool isValidSveBitcast(QualType srcType, QualType destType);
bool isValidRVVBitcast(QualType srcType, QualType destType);

bool areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy);

Expand Down Expand Up @@ -11700,27 +11709,6 @@ class Sema final : public SemaBase {
/// Triggered by declaration-attribute processing.
void ProcessAPINotes(Decl *D);

///@}
//
//
// -------------------------------------------------------------------------
//
//

/// \name Name Lookup for RISC-V Vector Intrinsic
/// Implementations are in SemaRISCVVectorLookup.cpp
///@{

public:
/// Indicate RISC-V vector builtin functions enabled or not.
bool DeclareRISCVVBuiltins = false;

/// Indicate RISC-V SiFive vector builtin functions enabled or not.
bool DeclareRISCVSiFiveVectorBuiltins = false;

private:
std::unique_ptr<sema::RISCVIntrinsicManager> RVIntrinsicManager;

///@}
};

Expand All @@ -11743,9 +11731,6 @@ void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation,
PragmaMsStackAction Action,
llvm::StringRef StackSlotLabel,
AlignPackInfo Value);

std::unique_ptr<sema::RISCVIntrinsicManager>
CreateRISCVIntrinsicManager(Sema &S);
} // end namespace clang

#endif
52 changes: 52 additions & 0 deletions clang/include/clang/Sema/SemaRISCV.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===----- SemaRISCV.h ------- RISC-V target-specific routines ------------===//
Endilll marked this conversation as resolved.
Show resolved Hide resolved
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
/// \file
/// This file declares semantic analysis functions specific to RISC-V.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_SEMA_SEMARISCV_H
#define LLVM_CLANG_SEMA_SEMARISCV_H

#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Type.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/RISCVIntrinsicManager.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/StringMap.h"
#include <memory>

namespace clang {
class SemaRISCV : public SemaBase {
public:
SemaRISCV(Sema &S);

bool CheckLMUL(CallExpr *TheCall, unsigned ArgNum);
bool CheckBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
CallExpr *TheCall);
void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D,
const llvm::StringMap<bool> &FeatureMap);

bool isValidRVVBitcast(QualType srcType, QualType destType);

/// Indicate RISC-V vector builtin functions enabled or not.
bool DeclareRVVBuiltins = false;

/// Indicate RISC-V SiFive vector builtin functions enabled or not.
bool DeclareSiFiveVectorBuiltins = false;

std::unique_ptr<sema::RISCVIntrinsicManager> IntrinsicManager;
};

std::unique_ptr<sema::RISCVIntrinsicManager>
CreateRISCVIntrinsicManager(Sema &S);
} // namespace clang

#endif // LLVM_CLANG_SEMA_SEMARISCV_H
5 changes: 3 additions & 2 deletions clang/lib/Parse/ParsePragma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaCUDA.h"
#include "clang/Sema/SemaCodeCompletion.h"
#include "clang/Sema/SemaRISCV.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringSwitch.h"
#include <optional>
Expand Down Expand Up @@ -4154,7 +4155,7 @@ void PragmaRISCVHandler::HandlePragma(Preprocessor &PP,
}

if (II->isStr("vector"))
Actions.DeclareRISCVVBuiltins = true;
Actions.RISCV().DeclareRVVBuiltins = true;
else if (II->isStr("sifive_vector"))
Actions.DeclareRISCVSiFiveVectorBuiltins = true;
Actions.RISCV().DeclareSiFiveVectorBuiltins = true;
}
4 changes: 3 additions & 1 deletion clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "clang/Sema/SemaObjC.h"
#include "clang/Sema/SemaOpenACC.h"
#include "clang/Sema/SemaOpenMP.h"
#include "clang/Sema/SemaRISCV.h"
#include "clang/Sema/SemaSYCL.h"
#include "clang/Sema/TemplateDeduction.h"
#include "clang/Sema/TemplateInstCallback.h"
Expand Down Expand Up @@ -210,6 +211,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
ObjCPtr(std::make_unique<SemaObjC>(*this)),
OpenACCPtr(std::make_unique<SemaOpenACC>(*this)),
OpenMPPtr(std::make_unique<SemaOpenMP>(*this)),
RISCVPtr(std::make_unique<SemaRISCV>(*this)),
SYCLPtr(std::make_unique<SemaSYCL>(*this)),
MSPointerToMemberRepresentationMethod(
LangOpts.getMSPointerToMemberRepresentationMethod()),
Expand Down Expand Up @@ -2049,7 +2051,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType() && FD) {
llvm::StringMap<bool> CallerFeatureMap;
Context.getFunctionFeatureMap(CallerFeatureMap, FD);
checkRVVTypeSupport(Ty, Loc, D, CallerFeatureMap);
RISCV().checkRVVTypeSupport(Ty, Loc, D, CallerFeatureMap);
}

// Don't allow SVE types in functions without a SVE target.
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Sema/SemaCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "clang/Sema/Initialization.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/SemaObjC.h"
#include "clang/Sema/SemaRISCV.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include <set>
Expand Down Expand Up @@ -2391,7 +2392,7 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr,
}

// Allow bitcasting between SVE VLATs and VLSTs, and vice-versa.
if (Self.isValidRVVBitcast(SrcType, DestType)) {
if (Self.RISCV().isValidRVVBitcast(SrcType, DestType)) {
Kind = CK_BitCast;
return TC_Success;
}
Expand Down Expand Up @@ -3002,7 +3003,7 @@ void CastOperation::CheckCStyleCast() {

// Allow bitcasting between compatible RVV vector types.
if ((SrcType->isVectorType() || DestType->isVectorType()) &&
Self.isValidRVVBitcast(SrcType, DestType)) {
Self.RISCV().isValidRVVBitcast(SrcType, DestType)) {
Kind = CK_BitCast;
return;
}
Expand Down
Loading
Loading