@@ -962,13 +962,18 @@ ModuleImport::getOrCreateNamelessSymbolName(llvm::GlobalVariable *globalVar) {
962
962
return symbolRef;
963
963
}
964
964
965
- LogicalResult ModuleImport::convertAlias (llvm::GlobalAlias *alias) {
966
- // Insert the global after the last one or at the start of the module.
965
+ OpBuilder::InsertionGuard ModuleImport::setGlobalInsertionPoint () {
967
966
OpBuilder::InsertionGuard guard (builder);
968
- if (!aliasInsertionOp )
969
- builder.setInsertionPointToStart (mlirModule. getBody () );
967
+ if (globalInsertionOp )
968
+ builder.setInsertionPointAfter (globalInsertionOp );
970
969
else
971
- builder.setInsertionPointAfter (aliasInsertionOp);
970
+ builder.setInsertionPointToStart (mlirModule.getBody ());
971
+ return guard;
972
+ }
973
+
974
+ LogicalResult ModuleImport::convertAlias (llvm::GlobalAlias *alias) {
975
+ // Insert the alias after the last one or at the start of the module.
976
+ OpBuilder::InsertionGuard guard = setGlobalInsertionPoint ();
972
977
973
978
Type type = convertType (alias->getValueType ());
974
979
AliasOp aliasOp = builder.create <AliasOp>(
@@ -977,7 +982,7 @@ LogicalResult ModuleImport::convertAlias(llvm::GlobalAlias *alias) {
977
982
/* dso_local=*/ alias->isDSOLocal (),
978
983
/* thread_local=*/ alias->isThreadLocal (),
979
984
/* attrs=*/ ArrayRef<NamedAttribute>());
980
- aliasInsertionOp = aliasOp;
985
+ globalInsertionOp = aliasOp;
981
986
982
987
clearRegionState ();
983
988
Block *block = builder.createBlock (&aliasOp.getInitializerRegion ());
@@ -996,11 +1001,7 @@ LogicalResult ModuleImport::convertAlias(llvm::GlobalAlias *alias) {
996
1001
997
1002
LogicalResult ModuleImport::convertGlobal (llvm::GlobalVariable *globalVar) {
998
1003
// Insert the global after the last one or at the start of the module.
999
- OpBuilder::InsertionGuard guard (builder);
1000
- if (!globalInsertionOp)
1001
- builder.setInsertionPointToStart (mlirModule.getBody ());
1002
- else
1003
- builder.setInsertionPointAfter (globalInsertionOp);
1004
+ OpBuilder::InsertionGuard guard = setGlobalInsertionPoint ();
1004
1005
1005
1006
Attribute valueAttr;
1006
1007
if (globalVar->hasInitializer ())
@@ -1096,11 +1097,8 @@ ModuleImport::convertGlobalCtorsAndDtors(llvm::GlobalVariable *globalVar) {
1096
1097
priorities.push_back (priority->getValue ().getZExtValue ());
1097
1098
}
1098
1099
1099
- OpBuilder::InsertionGuard guard (builder);
1100
- if (!globalInsertionOp)
1101
- builder.setInsertionPointToStart (mlirModule.getBody ());
1102
- else
1103
- builder.setInsertionPointAfter (globalInsertionOp);
1100
+ // Insert the global after the last one or at the start of the module.
1101
+ OpBuilder::InsertionGuard guard = setGlobalInsertionPoint ();
1104
1102
1105
1103
if (globalVar->getName () == getGlobalCtorsVarName ()) {
1106
1104
globalInsertionOp = builder.create <LLVM::GlobalCtorsOp>(
0 commit comments