diff options
Diffstat (limited to 'mlir/lib/Target/LLVMIR/ModuleImport.cpp')
-rw-r--r-- | mlir/lib/Target/LLVMIR/ModuleImport.cpp | 141 |
1 files changed, 71 insertions, 70 deletions
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp index c807985..94db7f8 100644 --- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp @@ -185,7 +185,7 @@ ComdatOp ModuleImport::getGlobalComdatOp() { OpBuilder::InsertionGuard guard(builder); builder.setInsertionPointToEnd(mlirModule.getBody()); globalComdatOp = - builder.create<ComdatOp>(mlirModule.getLoc(), getGlobalComdatOpName()); + ComdatOp::create(builder, mlirModule.getLoc(), getGlobalComdatOpName()); globalInsertionOp = globalComdatOp; return globalComdatOp; } @@ -864,8 +864,8 @@ LogicalResult ModuleImport::convertModuleFlagsMetadata() { } if (!moduleFlags.empty()) - builder.create<LLVM::ModuleFlagsOp>(mlirModule.getLoc(), - builder.getArrayAttr(moduleFlags)); + LLVM::ModuleFlagsOp::create(builder, mlirModule.getLoc(), + builder.getArrayAttr(moduleFlags)); return success(); } @@ -880,8 +880,8 @@ LogicalResult ModuleImport::convertLinkerOptionsMetadata() { options.reserve(node->getNumOperands()); for (const llvm::MDOperand &option : node->operands()) options.push_back(cast<llvm::MDString>(option)->getString()); - builder.create<LLVM::LinkerOptionsOp>(mlirModule.getLoc(), - builder.getStrArrayAttr(options)); + LLVM::LinkerOptionsOp::create(builder, mlirModule.getLoc(), + builder.getStrArrayAttr(options)); } } return success(); @@ -984,8 +984,8 @@ void ModuleImport::processComdat(const llvm::Comdat *comdat) { ComdatOp comdatOp = getGlobalComdatOp(); OpBuilder::InsertionGuard guard(builder); builder.setInsertionPointToEnd(&comdatOp.getBody().back()); - auto selectorOp = builder.create<ComdatSelectorOp>( - mlirModule.getLoc(), comdat->getName(), + auto selectorOp = ComdatSelectorOp::create( + builder, mlirModule.getLoc(), comdat->getName(), convertComdatFromLLVM(comdat->getSelectionKind())); auto symbolRef = SymbolRefAttr::get(builder.getContext(), getGlobalComdatOpName(), @@ -1356,12 +1356,12 @@ LogicalResult ModuleImport::convertAlias(llvm::GlobalAlias *alias) { OpBuilder::InsertionGuard guard = setGlobalInsertionPoint(); Type type = convertType(alias->getValueType()); - AliasOp aliasOp = builder.create<AliasOp>( - mlirModule.getLoc(), type, convertLinkageFromLLVM(alias->getLinkage()), - alias->getName(), - /*dso_local=*/alias->isDSOLocal(), - /*thread_local=*/alias->isThreadLocal(), - /*attrs=*/ArrayRef<NamedAttribute>()); + AliasOp aliasOp = AliasOp::create(builder, mlirModule.getLoc(), type, + convertLinkageFromLLVM(alias->getLinkage()), + alias->getName(), + /*dso_local=*/alias->isDSOLocal(), + /*thread_local=*/alias->isThreadLocal(), + /*attrs=*/ArrayRef<NamedAttribute>()); globalInsertionOp = aliasOp; clearRegionState(); @@ -1370,7 +1370,7 @@ LogicalResult ModuleImport::convertAlias(llvm::GlobalAlias *alias) { FailureOr<Value> initializer = convertConstantExpr(alias->getAliasee()); if (failed(initializer)) return failure(); - builder.create<ReturnOp>(aliasOp.getLoc(), *initializer); + ReturnOp::create(builder, aliasOp.getLoc(), *initializer); if (alias->hasAtLeastLocalUnnamedAddr()) aliasOp.setUnnamedAddr(convertUnnamedAddrFromLLVM(alias->getUnnamedAddr())); @@ -1385,12 +1385,12 @@ LogicalResult ModuleImport::convertIFunc(llvm::GlobalIFunc *ifunc) { Type type = convertType(ifunc->getValueType()); llvm::Constant *resolver = ifunc->getResolver(); Type resolverType = convertType(resolver->getType()); - builder.create<IFuncOp>(mlirModule.getLoc(), ifunc->getName(), type, - resolver->getName(), resolverType, - convertLinkageFromLLVM(ifunc->getLinkage()), - ifunc->isDSOLocal(), ifunc->getAddressSpace(), - convertUnnamedAddrFromLLVM(ifunc->getUnnamedAddr()), - convertVisibilityFromLLVM(ifunc->getVisibility())); + IFuncOp::create(builder, mlirModule.getLoc(), ifunc->getName(), type, + resolver->getName(), resolverType, + convertLinkageFromLLVM(ifunc->getLinkage()), + ifunc->isDSOLocal(), ifunc->getAddressSpace(), + convertUnnamedAddrFromLLVM(ifunc->getUnnamedAddr()), + convertVisibilityFromLLVM(ifunc->getVisibility())); return success(); } @@ -1428,8 +1428,8 @@ LogicalResult ModuleImport::convertGlobal(llvm::GlobalVariable *globalVar) { if (globalName.empty()) globalName = getOrCreateNamelessSymbolName(globalVar).getValue(); - GlobalOp globalOp = builder.create<GlobalOp>( - mlirModule.getLoc(), type, globalVar->isConstant(), + GlobalOp globalOp = GlobalOp::create( + builder, mlirModule.getLoc(), type, globalVar->isConstant(), convertLinkageFromLLVM(globalVar->getLinkage()), StringRef(globalName), valueAttr, alignment, /*addr_space=*/globalVar->getAddressSpace(), /*dso_local=*/globalVar->isDSOLocal(), @@ -1445,7 +1445,7 @@ LogicalResult ModuleImport::convertGlobal(llvm::GlobalVariable *globalVar) { convertConstantExpr(globalVar->getInitializer()); if (failed(initializer)) return failure(); - builder.create<ReturnOp>(globalOp.getLoc(), *initializer); + ReturnOp::create(builder, globalOp.getLoc(), *initializer); } if (globalVar->hasAtLeastLocalUnnamedAddr()) { globalOp.setUnnamedAddr( @@ -1513,13 +1513,13 @@ ModuleImport::convertGlobalCtorsAndDtors(llvm::GlobalVariable *globalVar) { OpBuilder::InsertionGuard guard = setGlobalInsertionPoint(); if (globalVar->getName() == getGlobalCtorsVarName()) { - globalInsertionOp = builder.create<LLVM::GlobalCtorsOp>( - mlirModule.getLoc(), builder.getArrayAttr(funcs), + globalInsertionOp = LLVM::GlobalCtorsOp::create( + builder, mlirModule.getLoc(), builder.getArrayAttr(funcs), builder.getI32ArrayAttr(priorities), builder.getArrayAttr(dataList)); return success(); } - globalInsertionOp = builder.create<LLVM::GlobalDtorsOp>( - mlirModule.getLoc(), builder.getArrayAttr(funcs), + globalInsertionOp = LLVM::GlobalDtorsOp::create( + builder, mlirModule.getLoc(), builder.getArrayAttr(funcs), builder.getI32ArrayAttr(priorities), builder.getArrayAttr(dataList)); return success(); } @@ -1594,33 +1594,33 @@ FailureOr<Value> ModuleImport::convertConstant(llvm::Constant *constant) { if (Attribute attr = getConstantAsAttr(constant)) { Type type = convertType(constant->getType()); if (auto symbolRef = dyn_cast<FlatSymbolRefAttr>(attr)) { - return builder.create<AddressOfOp>(loc, type, symbolRef.getValue()) + return AddressOfOp::create(builder, loc, type, symbolRef.getValue()) .getResult(); } - return builder.create<ConstantOp>(loc, type, attr).getResult(); + return ConstantOp::create(builder, loc, type, attr).getResult(); } // Convert null pointer constants. if (auto *nullPtr = dyn_cast<llvm::ConstantPointerNull>(constant)) { Type type = convertType(nullPtr->getType()); - return builder.create<ZeroOp>(loc, type).getResult(); + return ZeroOp::create(builder, loc, type).getResult(); } // Convert none token constants. if (isa<llvm::ConstantTokenNone>(constant)) { - return builder.create<NoneTokenOp>(loc).getResult(); + return NoneTokenOp::create(builder, loc).getResult(); } // Convert poison. if (auto *poisonVal = dyn_cast<llvm::PoisonValue>(constant)) { Type type = convertType(poisonVal->getType()); - return builder.create<PoisonOp>(loc, type).getResult(); + return PoisonOp::create(builder, loc, type).getResult(); } // Convert undef. if (auto *undefVal = dyn_cast<llvm::UndefValue>(constant)) { Type type = convertType(undefVal->getType()); - return builder.create<UndefOp>(loc, type).getResult(); + return UndefOp::create(builder, loc, type).getResult(); } // Convert dso_local_equivalent. @@ -1646,7 +1646,7 @@ FailureOr<Value> ModuleImport::convertConstant(llvm::Constant *constant) { getOrCreateNamelessSymbolName(cast<llvm::GlobalVariable>(globalObj)); else symbolRef = FlatSymbolRefAttr::get(context, globalName); - return builder.create<AddressOfOp>(loc, type, symbolRef).getResult(); + return AddressOfOp::create(builder, loc, type, symbolRef).getResult(); } // Convert global alias accesses. @@ -1654,7 +1654,7 @@ FailureOr<Value> ModuleImport::convertConstant(llvm::Constant *constant) { Type type = convertType(globalAliasObj->getType()); StringRef aliaseeName = globalAliasObj->getName(); FlatSymbolRefAttr symbolRef = FlatSymbolRefAttr::get(context, aliaseeName); - return builder.create<AddressOfOp>(loc, type, symbolRef).getResult(); + return AddressOfOp::create(builder, loc, type, symbolRef).getResult(); } // Convert constant expressions. @@ -1705,16 +1705,17 @@ FailureOr<Value> ModuleImport::convertConstant(llvm::Constant *constant) { bool isArrayOrStruct = isa<LLVMArrayType, LLVMStructType>(rootType); assert((isArrayOrStruct || LLVM::isCompatibleVectorType(rootType)) && "unrecognized aggregate type"); - Value root = builder.create<UndefOp>(loc, rootType); + Value root = UndefOp::create(builder, loc, rootType); for (const auto &it : llvm::enumerate(elementValues)) { if (isArrayOrStruct) { - root = builder.create<InsertValueOp>(loc, root, it.value(), it.index()); + root = + InsertValueOp::create(builder, loc, root, it.value(), it.index()); } else { Attribute indexAttr = builder.getI32IntegerAttr(it.index()); Value indexValue = - builder.create<ConstantOp>(loc, builder.getI32Type(), indexAttr); - root = builder.create<InsertElementOp>(loc, rootType, root, it.value(), - indexValue); + ConstantOp::create(builder, loc, builder.getI32Type(), indexAttr); + root = InsertElementOp::create(builder, loc, rootType, root, it.value(), + indexValue); } } return root; @@ -1727,7 +1728,7 @@ FailureOr<Value> ModuleImport::convertConstant(llvm::Constant *constant) { "target extension type does not support zero-initialization"); // Create llvm.mlir.zero operation to represent zero-initialization of // target extension type. - return builder.create<LLVM::ZeroOp>(loc, targetExtType).getRes(); + return LLVM::ZeroOp::create(builder, loc, targetExtType).getRes(); } if (auto *blockAddr = dyn_cast<llvm::BlockAddress>(constant)) { @@ -2158,16 +2159,16 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) { } if (!brInst->isConditional()) { - auto brOp = builder.create<LLVM::BrOp>(loc, succBlockArgs.front(), - succBlocks.front()); + auto brOp = LLVM::BrOp::create(builder, loc, succBlockArgs.front(), + succBlocks.front()); mapNoResultOp(inst, brOp); return success(); } FailureOr<Value> condition = convertValue(brInst->getCondition()); if (failed(condition)) return failure(); - auto condBrOp = builder.create<LLVM::CondBrOp>( - loc, *condition, succBlocks.front(), succBlockArgs.front(), + auto condBrOp = LLVM::CondBrOp::create( + builder, loc, *condition, succBlocks.front(), succBlockArgs.front(), succBlocks.back(), succBlockArgs.back()); mapNoResultOp(inst, condBrOp); return success(); @@ -2200,9 +2201,9 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) { caseBlocks[it.index()] = lookupBlock(succBB); } - auto switchOp = builder.create<SwitchOp>( - loc, *condition, lookupBlock(defaultBB), defaultBlockArgs, caseValues, - caseBlocks, caseOperandRefs); + auto switchOp = SwitchOp::create(builder, loc, *condition, + lookupBlock(defaultBB), defaultBlockArgs, + caseValues, caseBlocks, caseOperandRefs); mapNoResultOp(inst, switchOp); return success(); } @@ -2252,14 +2253,14 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) { // IR). Build the indirect call by passing an empty `callee` operand and // insert into `operands` to include the indirect call target. FlatSymbolRefAttr calleeSym = convertCalleeName(callInst); - Value indirectCallVal = builder.create<LLVM::AddressOfOp>( - loc, LLVM::LLVMPointerType::get(context), calleeSym); + Value indirectCallVal = LLVM::AddressOfOp::create( + builder, loc, LLVM::LLVMPointerType::get(context), calleeSym); operands->insert(operands->begin(), indirectCallVal); } else { // Regular direct call using callee name. callee = convertCalleeName(callInst); } - CallOp callOp = builder.create<CallOp>(loc, *funcTy, callee, *operands); + CallOp callOp = CallOp::create(builder, loc, *funcTy, callee, *operands); if (failed(convertCallAttributes(callInst, callOp))) return failure(); @@ -2294,7 +2295,7 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) { Type type = convertType(lpInst->getType()); auto lpOp = - builder.create<LandingpadOp>(loc, type, lpInst->isCleanup(), operands); + LandingpadOp::create(builder, loc, type, lpInst->isCleanup(), operands); mapValue(inst, lpOp); return success(); } @@ -2344,8 +2345,8 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) { // IR). Build the indirect invoke by passing an empty `callee` operand and // insert into `operands` to include the indirect invoke target. FlatSymbolRefAttr calleeSym = convertCalleeName(invokeInst); - Value indirectInvokeVal = builder.create<LLVM::AddressOfOp>( - loc, LLVM::LLVMPointerType::get(context), calleeSym); + Value indirectInvokeVal = LLVM::AddressOfOp::create( + builder, loc, LLVM::LLVMPointerType::get(context), calleeSym); operands->insert(operands->begin(), indirectInvokeVal); } else { // Regular direct invoke using callee name. @@ -2354,9 +2355,9 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) { // Create the invoke operation. Normal destination block arguments will be // added later on to handle the case in which the operation result is // included in this list. - auto invokeOp = builder.create<InvokeOp>( - loc, *funcTy, calleeName, *operands, directNormalDest, ValueRange(), - lookupBlock(invokeInst->getUnwindDest()), unwindArgs); + auto invokeOp = InvokeOp::create( + builder, loc, *funcTy, calleeName, *operands, directNormalDest, + ValueRange(), lookupBlock(invokeInst->getUnwindDest()), unwindArgs); if (failed(convertInvokeAttributes(invokeInst, invokeOp))) return failure(); @@ -2382,7 +2383,7 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) { // arguments (including the invoke operation's result). OpBuilder::InsertionGuard g(builder); builder.setInsertionPointToStart(directNormalDest); - builder.create<LLVM::BrOp>(loc, normalArgs, normalDest); + LLVM::BrOp::create(builder, loc, normalArgs, normalDest); } else { // If the invoke operation's result is not a block argument to the normal // destination block, just add the block arguments as usual. @@ -2416,8 +2417,8 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) { } Type type = convertType(inst->getType()); - auto gepOp = builder.create<GEPOp>( - loc, type, sourceElementType, *basePtr, indices, + auto gepOp = GEPOp::create( + builder, loc, type, sourceElementType, *basePtr, indices, static_cast<GEPNoWrapFlags>(gepInst->getNoWrapFlags().getRaw())); mapValue(inst, gepOp); return success(); @@ -2443,8 +2444,8 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) { SmallVector<ValueRange> succBlockArgsRange = llvm::to_vector_of<ValueRange>(succBlockArgs); Location loc = translateLoc(inst->getDebugLoc()); - auto indBrOp = builder.create<LLVM::IndirectBrOp>( - loc, *basePtr, succBlockArgsRange, succBlocks); + auto indBrOp = LLVM::IndirectBrOp::create(builder, loc, *basePtr, + succBlockArgsRange, succBlocks); mapNoResultOp(inst, indBrOp); return success(); @@ -2888,8 +2889,8 @@ LogicalResult ModuleImport::processFunction(llvm::Function *func) { builder.setInsertionPointToEnd(mlirModule.getBody()); Location loc = debugImporter->translateFuncLocation(func); - LLVMFuncOp funcOp = builder.create<LLVMFuncOp>( - loc, func->getName(), functionType, + LLVMFuncOp funcOp = LLVMFuncOp::create( + builder, loc, func->getName(), functionType, convertLinkageFromLLVM(func->getLinkage()), dsoLocal, cconv); convertParameterAttributes(func, funcOp, builder); @@ -3066,12 +3067,12 @@ ModuleImport::processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr, Operation *op = llvm::TypeSwitch<llvm::DbgVariableIntrinsic *, Operation *>(dbgIntr) .Case([&](llvm::DbgDeclareInst *) { - return builder.create<LLVM::DbgDeclareOp>( - loc, *argOperand, localVariableAttr, locationExprAttr); + return LLVM::DbgDeclareOp::create( + builder, loc, *argOperand, localVariableAttr, locationExprAttr); }) .Case([&](llvm::DbgValueInst *) { - return builder.create<LLVM::DbgValueOp>( - loc, *argOperand, localVariableAttr, locationExprAttr); + return LLVM::DbgValueOp::create( + builder, loc, *argOperand, localVariableAttr, locationExprAttr); }); mapNoResultOp(dbgIntr, op); setNonDebugMetadataAttrs(dbgIntr, op); @@ -3116,8 +3117,8 @@ LogicalResult ModuleImport::processBasicBlock(llvm::BasicBlock *bb, if (bb->hasAddressTaken()) { OpBuilder::InsertionGuard guard(builder); builder.setInsertionPointToStart(block); - builder.create<BlockTagOp>(block->getParentOp()->getLoc(), - BlockTagAttr::get(context, bb->getNumber())); + BlockTagOp::create(builder, block->getParentOp()->getLoc(), + BlockTagAttr::get(context, bb->getNumber())); } return success(); } |