@@ -42,15 +42,13 @@ static llvm::StructType *makeImportTableType(llvm::LLVMContext &context) {
4242 return existingType;
4343 }
4444 auto *i32Type = llvm::IntegerType::getInt32Ty (context);
45- auto *i8PtrType = llvm::PointerType::getUnqual (context);
46- auto *type =
47- llvm::StructType::create (context,
48- {
49- i32Type,
50- llvm::PointerType::get (i8PtrType, 0 ),
51- },
52- " iree_hal_executable_import_table_v0_t" ,
53- /* isPacked=*/ false );
45+ auto *type = llvm::StructType::create (context,
46+ {
47+ i32Type,
48+ llvm::PointerType::get (context, 0 ),
49+ },
50+ " iree_hal_executable_import_table_v0_t" ,
51+ /* isPacked=*/ false );
5452 return type;
5553}
5654
@@ -98,18 +96,15 @@ static llvm::StructType *makeWorkgroupStateType(llvm::LLVMContext &context) {
9896// i8*)
9997static llvm::FunctionType *
10098makeDispatchFunctionType (llvm::LLVMContext &context) {
101- auto *environmentType = makeEnvironmentType (context);
102- auto *dispatchStateType = makeDispatchStateType (context);
103- auto *workgroupStateType = makeWorkgroupStateType (context);
10499 auto *i32Type = llvm::IntegerType::getInt32Ty (context);
105- return llvm::FunctionType ::get (
106- i32Type,
107- {
108- llvm::PointerType::get (environmentType, 0 ) ,
109- llvm::PointerType::get (dispatchStateType, 0 ) ,
110- llvm::PointerType::get (workgroupStateType, 0 ) ,
111- },
112- /* isVarArg=*/ false );
100+ auto *ptrType = llvm::PointerType ::get (context, 0 );
101+ return llvm::FunctionType::get ( i32Type,
102+ {
103+ ptrType ,
104+ ptrType ,
105+ ptrType ,
106+ },
107+ /* isVarArg=*/ false );
113108}
114109
115110// %struct.iree_hal_executable_dispatch_attrs_v0_t = type {
@@ -182,17 +177,15 @@ makeStageLocationTableType(llvm::LLVMContext &context) {
182177 return existingType;
183178 }
184179 auto *i32Type = llvm::IntegerType::getInt32Ty (context);
185- auto *i8PtrType = llvm::PointerType::getUnqual (context);
186- auto *sourceLocationType = makeSourceLocationType (context);
187- auto *type = llvm::StructType::create (
188- context,
189- {
190- i32Type,
191- llvm::PointerType::get (i8PtrType, 0 ),
192- llvm::PointerType::get (sourceLocationType, 0 ),
193- },
194- " iree_hal_executable_stage_location_table_v0_t" ,
195- /* isPacked=*/ false );
180+ auto *type =
181+ llvm::StructType::create (context,
182+ {
183+ i32Type,
184+ llvm::PointerType::get (context, 0 ),
185+ llvm::PointerType::get (context, 0 ),
186+ },
187+ " iree_hal_executable_stage_location_table_v0_t" ,
188+ /* isPacked=*/ false );
196189 return type;
197190}
198191
@@ -211,26 +204,19 @@ static llvm::StructType *makeExportTableType(llvm::LLVMContext &context) {
211204 return existingType;
212205 }
213206 auto *i32Type = llvm::IntegerType::getInt32Ty (context);
214- auto *dispatchFunctionType = makeDispatchFunctionType (context);
215- auto *dispatchFunctionPointerType =
216- llvm::PointerType::get (dispatchFunctionType, 0 );
217- auto *dispatchAttrsType = makeDispatchAttrsType (context);
218- auto *i8PtrType = llvm::PointerType::getUnqual (context);
219- auto *sourceLocationType = makeSourceLocationType (context);
220- auto *stageLocationTableType = makeStageLocationTableType (context);
221- auto *type = llvm::StructType::create (
222- context,
223- {
224- i32Type,
225- llvm::PointerType::get (dispatchFunctionPointerType, 0 ),
226- llvm::PointerType::get (dispatchAttrsType, 0 ),
227- llvm::PointerType::get (i8PtrType, 0 ),
228- llvm::PointerType::get (i8PtrType, 0 ),
229- llvm::PointerType::get (sourceLocationType, 0 ),
230- llvm::PointerType::get (stageLocationTableType, 0 ),
231- },
232- " iree_hal_executable_export_table_v0_t" ,
233- /* isPacked=*/ false );
207+ auto *ptrType = llvm::PointerType::get (context, 0 );
208+ auto *type = llvm::StructType::create (context,
209+ {
210+ i32Type,
211+ ptrType,
212+ ptrType,
213+ ptrType,
214+ ptrType,
215+ ptrType,
216+ ptrType,
217+ },
218+ " iree_hal_executable_export_table_v0_t" ,
219+ /* isPacked=*/ false );
234220 return type;
235221}
236222
@@ -288,12 +274,11 @@ static llvm::StructType *makeSourceTableType(llvm::LLVMContext &context) {
288274 return existingType;
289275 }
290276 auto *i32Type = llvm::IntegerType::getInt32Ty (context);
291- auto *sourceFileType = makeSourceFileType (context);
292277 auto *type =
293278 llvm::StructType::create (context,
294279 {
295280 i32Type,
296- llvm::PointerType::get (sourceFileType , 0 ),
281+ llvm::PointerType::get (context , 0 ),
297282 },
298283 " iree_hal_executable_source_file_table_v0_t" ,
299284 /* isPacked=*/ false );
@@ -340,17 +325,16 @@ static llvm::StructType *makeLibraryType(llvm::StructType *libraryHeaderType) {
340325 auto *exportTableType = makeExportTableType (context);
341326 auto *constantTableType = makeConstantTableType (context);
342327 auto *sourceTableType = makeSourceTableType (context);
343- auto *type =
344- llvm::StructType::create (context,
345- {
346- llvm::PointerType::get (libraryHeaderType, 0 ),
347- importTableType,
348- exportTableType,
349- constantTableType,
350- sourceTableType,
351- },
352- " iree_hal_executable_library_v0_t" ,
353- /* isPacked=*/ false );
328+ auto *type = llvm::StructType::create (context,
329+ {
330+ llvm::PointerType::get (context, 0 ),
331+ importTableType,
332+ exportTableType,
333+ constantTableType,
334+ sourceTableType,
335+ },
336+ " iree_hal_executable_library_v0_t" ,
337+ /* isPacked=*/ false );
354338 return type;
355339}
356340
@@ -384,8 +368,8 @@ static llvm::Constant *createStringConstant(StringRef value,
384368static llvm::Constant *createStringConstantOrNull (StringRef value,
385369 llvm::Module *module ) {
386370 if (value.empty ()) {
387- auto i8Type = llvm::IntegerType::getInt8Ty ( module -> getContext ());
388- return llvm::ConstantPointerNull::get ( llvm:: PointerType::get (i8Type , 0 ));
371+ return llvm::ConstantPointerNull::get (
372+ llvm::PointerType::get (module -> getContext () , 0 ));
389373 }
390374 return createStringConstant (value, module );
391375}
@@ -433,19 +417,16 @@ static llvm::Constant *createArrayConstant(StringRef name,
433417llvm::Function *LibraryBuilder::build (StringRef queryFuncName) {
434418 auto &context = module ->getContext ();
435419 auto *i32Type = llvm::IntegerType::getInt32Ty (context);
436- auto *environmentStructType = makeEnvironmentType (context);
437- auto *environmentType = llvm::PointerType::get (environmentStructType, 0 );
438- auto *libraryHeaderType = makeLibraryHeaderType (context);
420+ auto *ptrType = llvm::PointerType::get (context, 0 );
439421
440422 // %struct.iree_hal_executable_library_header_t**
441423 // @iree_hal_library_query(i32, %struct.iree_hal_executable_environment_v0_t*)
442- auto *queryFuncType =
443- llvm::FunctionType::get (llvm::PointerType::get (libraryHeaderType, 0 ),
444- {
445- i32Type,
446- environmentType,
447- },
448- /* isVarArg=*/ false );
424+ auto *queryFuncType = llvm::FunctionType::get (ptrType,
425+ {
426+ i32Type,
427+ ptrType,
428+ },
429+ /* isVarArg=*/ false );
449430 auto *func =
450431 llvm::Function::Create (queryFuncType, llvm::GlobalValue::InternalLinkage,
451432 queryFuncName, *module );
@@ -461,10 +442,8 @@ llvm::Function *LibraryBuilder::build(StringRef queryFuncName) {
461442 builder.CreateICmpEQ (func->getArg (0 ),
462443 llvm::ConstantInt::get (
463444 i32Type, static_cast <int64_t >(Version::LATEST))),
464- builder.CreatePointerCast (v0,
465- llvm::PointerType::get (libraryHeaderType, 0 )),
466- llvm::ConstantPointerNull::get (
467- llvm::PointerType::get (libraryHeaderType, 0 ))));
445+ builder.CreatePointerCast (v0, ptrType),
446+ llvm::ConstantPointerNull::get (ptrType)));
468447
469448 return func;
470449}
@@ -473,10 +452,9 @@ llvm::Constant *
473452LibraryBuilder::buildLibraryV0ImportTable (std::string libraryName) {
474453 auto &context = module ->getContext ();
475454 auto *importTableType = makeImportTableType (context);
476- auto *i8Type = llvm::IntegerType::getInt8Ty (context);
477455 auto *i32Type = llvm::IntegerType::getInt32Ty (context);
478456 llvm::Constant *symbolNames =
479- llvm::Constant::getNullValue (llvm::PointerType::get (i8Type , 0 ));
457+ llvm::Constant::getNullValue (llvm::PointerType::get (context , 0 ));
480458 if (!imports.empty ()) {
481459 SmallVector<llvm::Constant *> symbolNameValues;
482460 for (auto &import : imports) {
@@ -486,7 +464,7 @@ LibraryBuilder::buildLibraryV0ImportTable(std::string libraryName) {
486464 symbolNameValues.push_back (createStringConstant (symbolName, module ));
487465 }
488466 symbolNames = createArrayConstant (libraryName + " _import_names" ,
489- llvm::PointerType::get (i8Type , 0 ),
467+ llvm::PointerType::get (context , 0 ),
490468 symbolNameValues, module );
491469 }
492470 return llvm::ConstantStruct::get (
@@ -502,26 +480,24 @@ llvm::Constant *
502480LibraryBuilder::buildLibraryV0ExportTable (std::string libraryName) {
503481 auto &context = module ->getContext ();
504482 auto *exportTableType = makeExportTableType (context);
505- auto *dispatchFunctionType = makeDispatchFunctionType (context);
506483 auto *dispatchAttrsType = makeDispatchAttrsType (context);
507484 auto *sourceLocationType = makeSourceLocationType (context);
508485 auto *stageLocationTableType = makeStageLocationTableType (context);
509486 auto *i8Type = llvm::IntegerType::getInt8Ty (context);
510487 auto *i16Type = llvm::IntegerType::getInt16Ty (context);
511488 auto *i32Type = llvm::IntegerType::getInt32Ty (context);
512489 auto *i64Type = llvm::IntegerType::getInt64Ty (context);
490+ auto *ptrType = llvm::PointerType::get (context, 0 );
513491
514492 // iree_hal_executable_export_table_v0_t::ptrs
515493 SmallVector<llvm::Constant *> exportPtrValues;
516494 for (auto dispatch : exports)
517495 exportPtrValues.push_back (dispatch.func );
518496 llvm::Constant *exportPtrs = createArrayConstant (
519- libraryName + " _funcs" , llvm::PointerType::get (dispatchFunctionType, 0 ),
520- exportPtrValues, module );
497+ libraryName + " _funcs" , ptrType, exportPtrValues, module );
521498
522499 // iree_hal_executable_export_table_v0_t::attrs
523- llvm::Constant *exportAttrs =
524- llvm::Constant::getNullValue (llvm::PointerType::get (i32Type, 0 ));
500+ llvm::Constant *exportAttrs = llvm::Constant::getNullValue (ptrType);
525501 bool hasNonDefaultAttrs = llvm::any_of (exports, [](const auto &dispatch) {
526502 return !dispatch.attrs .isDefault ();
527503 });
@@ -565,36 +541,30 @@ LibraryBuilder::buildLibraryV0ExportTable(std::string libraryName) {
565541 }
566542
567543 // iree_hal_executable_export_table_v0_t::names
568- llvm::Constant *exportNames =
569- llvm::Constant::getNullValue (llvm::PointerType::get (i8Type, 0 ));
544+ llvm::Constant *exportNames = llvm::Constant::getNullValue (ptrType);
570545 if (mode == Mode::INCLUDE_REFLECTION_ATTRS) {
571546 SmallVector<llvm::Constant *> exportNameValues;
572547 for (auto dispatch : exports)
573548 exportNameValues.push_back (createStringConstant (dispatch.name , module ));
574- exportNames = createArrayConstant (libraryName + " _names" ,
575- llvm::PointerType::get (i8Type, 0 ),
549+ exportNames = createArrayConstant (libraryName + " _names" , ptrType,
576550 exportNameValues, module );
577551 }
578552
579553 // iree_hal_executable_export_table_v0_t::tags
580- auto *i8PtrType = llvm::PointerType::get (i8Type, 0 );
581- llvm::Constant *exportTags =
582- llvm::Constant::getNullValue (llvm::PointerType::get (i8PtrType, 0 ));
554+ llvm::Constant *exportTags = llvm::Constant::getNullValue (ptrType);
583555 bool hasAnyTags = llvm::any_of (
584556 exports, [](auto &dispatch) { return !dispatch.tag .empty (); });
585557 if (mode == Mode::INCLUDE_REFLECTION_ATTRS && hasAnyTags) {
586558 SmallVector<llvm::Constant *> exportTagValues;
587559 for (auto dispatch : exports)
588560 exportTagValues.push_back (
589561 createStringConstantOrNull (dispatch.tag , module ));
590- exportTags = createArrayConstant (libraryName + " _tags" ,
591- llvm::PointerType::get (i8Type, 0 ),
562+ exportTags = createArrayConstant (libraryName + " _tags" , ptrType,
592563 exportTagValues, module );
593564 }
594565
595566 // iree_hal_executable_export_table_v0_t::source_locations
596- llvm::Constant *exportSourceLocations = llvm::Constant::getNullValue (
597- llvm::PointerType::get (sourceLocationType, 0 ));
567+ llvm::Constant *exportSourceLocations = llvm::Constant::getNullValue (ptrType);
598568 if (mode == Mode::INCLUDE_REFLECTION_ATTRS) {
599569 SmallVector<llvm::Constant *> exportSourceLocationValues;
600570 for (auto dispatch : exports) {
@@ -616,8 +586,7 @@ LibraryBuilder::buildLibraryV0ExportTable(std::string libraryName) {
616586 }
617587
618588 // iree_hal_executable_export_table_v0_t::stage_locations
619- llvm::Constant *exportStageLocations = llvm::Constant::getNullValue (
620- llvm::PointerType::get (stageLocationTableType, 0 ));
589+ llvm::Constant *exportStageLocations = llvm::Constant::getNullValue (ptrType);
621590 if (mode == Mode::INCLUDE_REFLECTION_ATTRS) {
622591 SmallVector<llvm::Constant *> exportStageTableValues;
623592 for (auto dispatch : exports) {
@@ -638,8 +607,8 @@ LibraryBuilder::buildLibraryV0ExportTable(std::string libraryName) {
638607 }));
639608 }
640609 llvm::Constant *stageNamesPtr = createArrayConstant (
641- libraryName + " _" + dispatch.name + " _stage_names" ,
642- llvm::PointerType::get (i8Type, 0 ), exportStageNameValues, module );
610+ libraryName + " _" + dispatch.name + " _stage_names" , ptrType,
611+ exportStageNameValues, module );
643612 llvm::Constant *sourceLocationsPtr = createArrayConstant (
644613 libraryName + " _" + dispatch.name + " _stage_source_locations" ,
645614 sourceLocationType, exportSourceLocationValues, module );
@@ -699,7 +668,7 @@ LibraryBuilder::buildLibraryV0SourceTable(std::string libraryName) {
699668 auto *sourceTableType = makeSourceTableType (context);
700669 auto *i32Type = llvm::IntegerType::getInt32Ty (context);
701670 llvm::Constant *sourceFilesValue =
702- llvm::Constant::getNullValue (llvm::PointerType::get (sourceFileType , 0 ));
671+ llvm::Constant::getNullValue (llvm::PointerType::get (context , 0 ));
703672 if (!sourceFiles.empty ()) {
704673 SmallVector<llvm::Constant *> sourceFileValues;
705674 for (auto &sourceFile : sourceFiles) {
0 commit comments