@@ -498,27 +498,13 @@ LLVM_Util::LLVM_Util(const PerThreadInfo& per_thread_info, int debuglevel,
498498 m_llvm_type_longlong = (llvm::Type*)llvm::Type::getInt64Ty (*m_llvm_context);
499499 m_llvm_type_void = (llvm::Type*)llvm::Type::getVoidTy (*m_llvm_context);
500500
501- m_llvm_type_int_ptr = llvm::PointerType::get (m_llvm_type_int, 0 );
502- m_llvm_type_int8_ptr = llvm::PointerType::get (m_llvm_type_int8, 0 );
503- m_llvm_type_int64_ptr = llvm::PointerType::get (m_llvm_type_int64, 0 );
504- m_llvm_type_bool_ptr = llvm::PointerType::get (m_llvm_type_bool, 0 );
505- m_llvm_type_char_ptr = llvm::PointerType::get (m_llvm_type_char, 0 );
506- m_llvm_type_void_ptr = m_llvm_type_char_ptr;
507- m_llvm_type_float_ptr = llvm::PointerType::get (m_llvm_type_float, 0 );
508- m_llvm_type_longlong_ptr = llvm::PointerType::get (m_llvm_type_int64, 0 );
509- m_llvm_type_double_ptr = llvm::PointerType::get (m_llvm_type_double, 0 );
510-
511501 // A triple is a struct composed of 3 floats
512502 std::vector<llvm::Type*> triplefields (3 , m_llvm_type_float);
513503 m_llvm_type_triple = type_struct (triplefields, " Vec3" );
514- m_llvm_type_triple_ptr
515- = (llvm::PointerType*)llvm::PointerType::get (m_llvm_type_triple, 0 );
516504
517505 // A matrix is a struct composed 16 floats
518506 std::vector<llvm::Type*> matrixfields (16 , m_llvm_type_float);
519507 m_llvm_type_matrix = type_struct (matrixfields, " Matrix4" );
520- m_llvm_type_matrix_ptr
521- = (llvm::PointerType*)llvm::PointerType::get (m_llvm_type_matrix, 0 );
522508
523509 // Setup up wide aliases
524510 // TODO: why are there casts to the base class llvm::Type *?
@@ -533,6 +519,48 @@ LLVM_Util::LLVM_Util(const PerThreadInfo& per_thread_info, int debuglevel,
533519 m_llvm_type_wide_longlong = llvm_vector_type (m_llvm_type_longlong,
534520 m_vector_width);
535521
522+ // A twide riple is a struct composed of 3 wide floats
523+ std::vector<llvm::Type*> triple_wide_fields (3 , m_llvm_type_wide_float);
524+ m_llvm_type_wide_triple = type_struct (triple_wide_fields, " WideVec3" );
525+
526+ // A wide matrix is a struct composed 16 wide floats
527+ std::vector<llvm::Type*> matrix_wide_fields (16 , m_llvm_type_wide_float);
528+ m_llvm_type_wide_matrix = type_struct (matrix_wide_fields, " WideMatrix4" );
529+
530+ #if OSL_LLVM_VERSION >= 210
531+ // All opaque pointers now. Eventually, all the typed ones can go away.
532+ m_llvm_type_void_ptr = llvm::PointerType::get (*m_llvm_context, 0 );
533+ m_llvm_type_int_ptr = m_llvm_type_void_ptr;
534+ m_llvm_type_int8_ptr = m_llvm_type_void_ptr;
535+ m_llvm_type_int64_ptr = m_llvm_type_void_ptr;
536+ m_llvm_type_bool_ptr = m_llvm_type_void_ptr;
537+ m_llvm_type_char_ptr = m_llvm_type_void_ptr;
538+ m_llvm_type_float_ptr = m_llvm_type_void_ptr;
539+ m_llvm_type_longlong_ptr = m_llvm_type_void_ptr;
540+ m_llvm_type_double_ptr = m_llvm_type_void_ptr;
541+ m_llvm_type_triple_ptr = m_llvm_type_void_ptr;
542+ m_llvm_type_matrix_ptr = m_llvm_type_void_ptr;
543+ m_llvm_type_wide_char_ptr = m_llvm_type_void_ptr;
544+ m_llvm_type_wide_void_ptr = m_llvm_type_void_ptr;
545+ m_llvm_type_wide_int_ptr = m_llvm_type_void_ptr;
546+ m_llvm_type_wide_bool_ptr = m_llvm_type_void_ptr;
547+ m_llvm_type_wide_float_ptr = m_llvm_type_void_ptr;
548+ #else
549+ // Old style typed pointers. These are marked as deprecated in LLVM 21,
550+ // and will be removed in some subsequent version.
551+ m_llvm_type_int_ptr = llvm::PointerType::get (m_llvm_type_int, 0 );
552+ m_llvm_type_int8_ptr = llvm::PointerType::get (m_llvm_type_int8, 0 );
553+ m_llvm_type_int64_ptr = llvm::PointerType::get (m_llvm_type_int64, 0 );
554+ m_llvm_type_bool_ptr = llvm::PointerType::get (m_llvm_type_bool, 0 );
555+ m_llvm_type_char_ptr = llvm::PointerType::get (m_llvm_type_char, 0 );
556+ m_llvm_type_void_ptr = m_llvm_type_char_ptr;
557+ m_llvm_type_float_ptr = llvm::PointerType::get (m_llvm_type_float, 0 );
558+ m_llvm_type_longlong_ptr = llvm::PointerType::get (m_llvm_type_int64, 0 );
559+ m_llvm_type_double_ptr = llvm::PointerType::get (m_llvm_type_double, 0 );
560+ m_llvm_type_triple_ptr
561+ = (llvm::PointerType*)llvm::PointerType::get (m_llvm_type_triple, 0 );
562+ m_llvm_type_matrix_ptr
563+ = (llvm::PointerType*)llvm::PointerType::get (m_llvm_type_matrix, 0 );
536564 m_llvm_type_wide_char_ptr = llvm::PointerType::get (m_llvm_type_wide_char,
537565 0 );
538566 m_llvm_type_wide_void_ptr = llvm_vector_type (m_llvm_type_void_ptr,
@@ -542,14 +570,7 @@ LLVM_Util::LLVM_Util(const PerThreadInfo& per_thread_info, int debuglevel,
542570 0 );
543571 m_llvm_type_wide_float_ptr = llvm::PointerType::get (m_llvm_type_wide_float,
544572 0 );
545-
546- // A triple is a struct composed of 3 floats
547- std::vector<llvm::Type*> triple_wide_fields (3 , m_llvm_type_wide_float);
548- m_llvm_type_wide_triple = type_struct (triple_wide_fields, " WideVec3" );
549-
550- // A matrix is a struct composed 16 floats
551- std::vector<llvm::Type*> matrix_wide_fields (16 , m_llvm_type_wide_float);
552- m_llvm_type_wide_matrix = type_struct (matrix_wide_fields, " WideMatrix4" );
573+ #endif
553574
554575 ustring_rep (m_ustring_rep); // setup ustring-related types
555576}
@@ -567,14 +588,20 @@ LLVM_Util::ustring_rep(UstringRep rep)
567588 OSL_ASSERT (m_ustring_rep == UstringRep::hash);
568589 m_llvm_type_ustring = llvm::Type::getInt64Ty (*m_llvm_context);
569590 }
570- m_llvm_type_ustring_ptr = llvm::PointerType::get (m_llvm_type_ustring, 0 );
571591
572592 // Batched versions haven't been updated to handle hash yet.
573593 // For now leave them using the real ustring regardless of UstringRep
574594 m_llvm_type_wide_ustring = llvm_vector_type (m_llvm_type_real_ustring,
575595 m_vector_width);
596+
597+ #if OSL_LLVM_VERSION >= 210
598+ m_llvm_type_ustring_ptr = m_llvm_type_void_ptr;
599+ m_llvm_type_wide_ustring_ptr = m_llvm_type_void_ptr;
600+ #else
601+ m_llvm_type_ustring_ptr = llvm::PointerType::get (m_llvm_type_ustring, 0 );
576602 m_llvm_type_wide_ustring_ptr
577603 = llvm::PointerType::get (m_llvm_type_wide_ustring, 0 );
604+ #endif
578605}
579606
580607
@@ -1840,8 +1867,13 @@ LLVM_Util::nvptx_target_machine()
18401867 && " PTX compile error: LLVM Target is not initialized" );
18411868
18421869 m_nvptx_target_machine = llvm_target->createTargetMachine (
1843- ModuleTriple.str (), CUDA_TARGET_ARCH, " +ptx50" , options,
1844- llvm::Reloc::Static, llvm::CodeModel::Small,
1870+ #if OSL_LLVM_VERSION >= 210
1871+ llvm::Triple (ModuleTriple.str ()),
1872+ #else
1873+ ModuleTriple.str (),
1874+ #endif
1875+ CUDA_TARGET_ARCH, " +ptx50" , options, llvm::Reloc::Static,
1876+ llvm::CodeModel::Small,
18451877#if OSL_LLVM_VERSION >= 180
18461878 llvm::CodeGenOptLevel::Default
18471879#else
@@ -3287,7 +3319,11 @@ LLVM_Util::type_struct_field_at_index(llvm::Type* type, int index)
32873319llvm::PointerType*
32883320LLVM_Util::type_ptr (llvm::Type* type)
32893321{
3322+ #if OSL_LLVM_VERSION >= 210
3323+ return m_llvm_type_void_ptr;
3324+ #else
32903325 return llvm::PointerType::get (type, 0 );
3326+ #endif
32913327}
32923328
32933329llvm::Type*
@@ -3335,8 +3371,12 @@ llvm::PointerType*
33353371LLVM_Util::type_function_ptr (llvm::Type* rettype, cspan<llvm::Type*> params,
33363372 bool varargs)
33373373{
3374+ #if OSL_LLVM_VERSION >= 210
3375+ return m_llvm_type_void_ptr;
3376+ #else
33383377 llvm::FunctionType* functype = type_function (rettype, params, varargs);
33393378 return llvm::PointerType::getUnqual (functype);
3379+ #endif
33403380}
33413381
33423382
@@ -4160,8 +4200,7 @@ llvm::Value*
41604200LLVM_Util::ptr_to_cast (llvm::Value* val, llvm::Type* type,
41614201 const std::string& llname)
41624202{
4163- return builder ().CreatePointerCast (val, llvm::PointerType::get (type, 0 ),
4164- llname);
4203+ return builder ().CreatePointerCast (val, type_ptr (type), llname);
41654204}
41664205
41674206
@@ -4179,14 +4218,22 @@ llvm::Value*
41794218LLVM_Util::ptr_cast (llvm::Value* val, const TypeDesc& type,
41804219 const std::string& llname)
41814220{
4221+ #if OSL_LLVM_VERSION >= 210
4222+ return ptr_cast (val, m_llvm_type_void_ptr, llname);
4223+ #else
41824224 return ptr_cast (val, llvm::PointerType::get (llvm_type (type), 0 ), llname);
4225+ #endif
41834226}
41844227
41854228
41864229llvm::Value*
41874230LLVM_Util::wide_ptr_cast (llvm::Value* val, const TypeDesc& type)
41884231{
4232+ #if OSL_LLVM_VERSION >= 210
4233+ return ptr_cast (val, m_llvm_type_void_ptr);
4234+ #else
41894235 return ptr_cast (val, llvm::PointerType::get (llvm_vector_type (type), 0 ));
4236+ #endif
41904237}
41914238
41924239
0 commit comments