Multiple changes ...

* Use getVoidPtrType helper
* Replace #define with constexpr
This commit is contained in:
liushuyu 2024-03-26 14:48:36 -06:00
parent 8ae2634fae
commit fc4d884d2d
No known key found for this signature in database
GPG key ID: 23D1CE4534419437
9 changed files with 20 additions and 23 deletions

View file

@ -32,7 +32,8 @@
# We also want an user-specified LLVM_ROOT_DIR to take precedence over the # We also want an user-specified LLVM_ROOT_DIR to take precedence over the
# system default locations such as /usr/local/bin. Executing find_program() # system default locations such as /usr/local/bin. Executing find_program()
# multiples times is the approach recommended in the docs. # multiples times is the approach recommended in the docs.
set(llvm_config_names llvm-config-17.0 llvm-config170 llvm-config-17 set(llvm_config_names llvm-config-18.1 llvm-config181 llvm-config-18
llvm-config-17.0 llvm-config170 llvm-config-17
llvm-config-16.0 llvm-config160 llvm-config-16 llvm-config-16.0 llvm-config160 llvm-config-16
llvm-config-15.0 llvm-config150 llvm-config-15 llvm-config-15.0 llvm-config150 llvm-config-15
llvm-config-14.0 llvm-config140 llvm-config-14 llvm-config-14.0 llvm-config140 llvm-config-14
@ -49,12 +50,12 @@ if(APPLE)
# extra fallbacks for MacPorts & Homebrew # extra fallbacks for MacPorts & Homebrew
find_program(LLVM_CONFIG find_program(LLVM_CONFIG
NAMES ${llvm_config_names} NAMES ${llvm_config_names}
PATHS /opt/local/libexec/llvm-17/bin PATHS /opt/local/libexec/llvm-18/bin /opt/local/libexec/llvm-17/bin
/opt/local/libexec/llvm-16/bin /opt/local/libexec/llvm-15/bin /opt/local/libexec/llvm-16/bin /opt/local/libexec/llvm-15/bin
/opt/local/libexec/llvm-14/bin /opt/local/libexec/llvm-13/bin /opt/local/libexec/llvm-14/bin /opt/local/libexec/llvm-13/bin
/opt/local/libexec/llvm-12/bin /opt/local/libexec/llvm-11/bin /opt/local/libexec/llvm-12/bin /opt/local/libexec/llvm-11/bin
/opt/local/libexec/llvm/bin /opt/local/libexec/llvm/bin
/usr/local/opt/llvm@17/bin /usr/local/opt/llvm@18/bin /usr/local/opt/llvm@17/bin
/usr/local/opt/llvm@16/bin /usr/local/opt/llvm@15/bin /usr/local/opt/llvm@16/bin /usr/local/opt/llvm@15/bin
/usr/local/opt/llvm@14/bin /usr/local/opt/llvm@13/bin /usr/local/opt/llvm@14/bin /usr/local/opt/llvm@13/bin
/usr/local/opt/llvm@12/bin /usr/local/opt/llvm@11/bin /usr/local/opt/llvm@12/bin /usr/local/opt/llvm@11/bin

View file

@ -115,7 +115,7 @@ void emitLLVMUsedArray(IRState &irs) {
return; return;
} }
auto *i8PtrType = LDC_getInt8PtrTy(irs.context()); auto *i8PtrType = getVoidPtrType(irs.context());
// Convert all elements to i8* (the expected type for llvm.used) // Convert all elements to i8* (the expected type for llvm.used)
for (auto &elem : irs.usedArray) { for (auto &elem : irs.usedArray) {

View file

@ -48,9 +48,9 @@
using CodeGenFileType = llvm::CodeGenFileType; using CodeGenFileType = llvm::CodeGenFileType;
#if LDC_LLVM_VER >= 1800 #if LDC_LLVM_VER >= 1800
#define CGFT_AssemblyFile CodeGenFileType::AssemblyFile constexpr llvm::CodeGenFileType CGFT_AssemblyFile = CodeGenFileType::AssemblyFile;
#define CGFT_ObjectFile CodeGenFileType::ObjectFile constexpr llvm::CodeGenFileType CGFT_ObjectFile = CodeGenFileType::ObjectFile;
#define CGFT_Null CodeGenFileType::Null constexpr llvm::CodeGenFileType CGFT_Null = CodeGenFileType::Null;
#endif #endif
#if LDC_LLVM_VER < 1700 #if LDC_LLVM_VER < 1700

View file

@ -185,9 +185,8 @@ llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd) {
// Declare and initialize the TypeDescriptor. // Declare and initialize the TypeDescriptor.
llvm::Constant *Fields[] = { llvm::Constant *Fields[] = {
classInfoPtr, // VFPtr classInfoPtr, // VFPtr
llvm::ConstantPointerNull::get( llvm::ConstantPointerNull::get(getVoidPtrType()), // Runtime data
LDC_getInt8PtrTy(gIR->context())), // Runtime data
llvm::ConstantDataArray::getString(gIR->context(), TypeNameString)}; llvm::ConstantDataArray::getString(gIR->context(), TypeNameString)};
llvm::StructType *TypeDescriptorType = llvm::StructType *TypeDescriptorType =
getTypeDescriptorType(irs, classInfoPtr, TypeNameString); getTypeDescriptorType(irs, classInfoPtr, TypeNameString);

View file

@ -910,7 +910,7 @@ void CodeGenPGO::emitCounterIncrement(const RootObject *S) const {
assert(counter_it != (*RegionCounterMap).end() && assert(counter_it != (*RegionCounterMap).end() &&
"Statement not found in PGO counter map!"); "Statement not found in PGO counter map!");
unsigned counter = counter_it->second; unsigned counter = counter_it->second;
auto *I8PtrTy = LDC_getInt8PtrTy(gIR->context()); auto *I8PtrTy = getVoidPtrType();
gIR->ir->CreateCall(GET_INTRINSIC_DECL(instrprof_increment), gIR->ir->CreateCall(GET_INTRINSIC_DECL(instrprof_increment),
{llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy), {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
gIR->ir->getInt64(FunctionHash), gIR->ir->getInt64(FunctionHash),
@ -1118,7 +1118,7 @@ void CodeGenPGO::valueProfile(uint32_t valueKind, llvm::Instruction *valueSite,
if (ptrCastNeeded) if (ptrCastNeeded)
value = gIR->ir->CreatePtrToInt(value, gIR->ir->getInt64Ty()); value = gIR->ir->CreatePtrToInt(value, gIR->ir->getInt64Ty());
auto *i8PtrTy = LDC_getInt8PtrTy(gIR->context()); auto *i8PtrTy = getVoidPtrType();
llvm::Value *Args[5] = { llvm::Value *Args[5] = {
llvm::ConstantExpr::getBitCast(FuncNameVar, i8PtrTy), llvm::ConstantExpr::getBitCast(FuncNameVar, i8PtrTy),
gIR->ir->getInt64(FunctionHash), value, gIR->ir->getInt32(valueKind), gIR->ir->getInt64(FunctionHash), value, gIR->ir->getInt32(valueKind),

View file

@ -271,7 +271,7 @@ static LLType *getPtrToAtomicType(LLType *type) {
#if LDC_LLVM_VER < 1800 #if LDC_LLVM_VER < 1800
return LLType::getIntNPtrTy(gIR->context(), static_cast<unsigned>(N)); return LLType::getIntNPtrTy(gIR->context(), static_cast<unsigned>(N));
#else #else
return llvm::PointerType::get(gIR->context(), static_cast<unsigned>(N)); return LLPointerType::getIntNPtrTy(gIR->context(), static_cast<unsigned>(N));
#endif #endif
default: default:
return nullptr; return nullptr;

View file

@ -738,7 +738,11 @@ LLPointerType *getPtrToType(LLType *t) {
} }
LLPointerType *getVoidPtrType() { LLPointerType *getVoidPtrType() {
return LLType::getInt8Ty(gIR->context())->getPointerTo(); return getVoidPtrType(gIR->context());
}
LLPointerType *getVoidPtrType(llvm::LLVMContext &C) {
return LLType::getInt8Ty(C)->getPointerTo();
} }
llvm::ConstantPointerNull *getNullPtr(LLType *t) { llvm::ConstantPointerNull *getNullPtr(LLType *t) {

View file

@ -152,6 +152,7 @@ LLGlobalVariable *isaGlobalVar(LLValue *v);
LLType *getI8Type(); LLType *getI8Type();
LLPointerType *getPtrToType(LLType *t); LLPointerType *getPtrToType(LLType *t);
LLPointerType *getVoidPtrType(); LLPointerType *getVoidPtrType();
LLPointerType *getVoidPtrType(llvm::LLVMContext &C);
llvm::ConstantPointerNull *getNullPtr(LLType *t); llvm::ConstantPointerNull *getNullPtr(LLType *t);
LLConstant *getNullValue(LLType *t); LLConstant *getNullValue(LLType *t);
@ -218,11 +219,3 @@ void DtoMemCpy(LLType *type, LLValue *dst, LLValue *src, bool withPadding = fals
* Generates a call to C memcmp. * Generates a call to C memcmp.
*/ */
LLValue *DtoMemCmp(LLValue *lhs, LLValue *rhs, LLValue *nbytes); LLValue *DtoMemCmp(LLValue *lhs, LLValue *rhs, LLValue *nbytes);
inline auto *LDC_getInt8PtrTy(llvm::LLVMContext &C) {
#if LDC_LLVM_VER < 1800
return llvm::Type::getInt8PtrTy(C);
#else
return llvm::PointerType::getUnqual(C);
#endif
}

View file

@ -663,7 +663,7 @@ TryCatchFinallyScopes::getLandingPadRef(CleanupCursor scope) {
namespace { namespace {
llvm::LandingPadInst *createLandingPadInst(IRState &irs) { llvm::LandingPadInst *createLandingPadInst(IRState &irs) {
LLType *retType = LLStructType::get(LDC_getInt8PtrTy(irs.context()), LLType *retType = LLStructType::get(getVoidPtrType(irs.context()),
LLType::getInt32Ty(irs.context())); LLType::getInt32Ty(irs.context()));
if (!irs.func()->hasLLVMPersonalityFn()) { if (!irs.func()->hasLLVMPersonalityFn()) {
irs.func()->setLLVMPersonalityFn( irs.func()->setLLVMPersonalityFn(