@@ -1473,18 +1473,20 @@ ModuleImport::convertBranchArgs(llvm::Instruction *branch,
1473
1473
return success ();
1474
1474
}
1475
1475
1476
- LogicalResult
1477
- ModuleImport::convertCallTypeAndOperands (llvm::CallBase *callInst,
1478
- SmallVectorImpl<Type> &types,
1479
- SmallVectorImpl<Value> &operands) {
1476
+ LogicalResult ModuleImport::convertCallTypeAndOperands (
1477
+ llvm::CallBase *callInst, SmallVectorImpl<Type> &types,
1478
+ SmallVectorImpl<Value> &operands, bool allowInlineAsm) {
1480
1479
if (!callInst->getType ()->isVoidTy ())
1481
1480
types.push_back (convertType (callInst->getType ()));
1482
1481
1483
1482
if (!callInst->getCalledFunction ()) {
1484
- FailureOr<Value> called = convertValue (callInst->getCalledOperand ());
1485
- if (failed (called))
1486
- return failure ();
1487
- operands.push_back (*called);
1483
+ if (!allowInlineAsm ||
1484
+ !isa<llvm::InlineAsm>(callInst->getCalledOperand ())) {
1485
+ FailureOr<Value> called = convertValue (callInst->getCalledOperand ());
1486
+ if (failed (called))
1487
+ return failure ();
1488
+ operands.push_back (*called);
1489
+ }
1488
1490
}
1489
1491
SmallVector<llvm::Value *> args (callInst->args ());
1490
1492
FailureOr<SmallVector<Value>> arguments = convertValues (args);
@@ -1579,53 +1581,68 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) {
1579
1581
1580
1582
SmallVector<Type> types;
1581
1583
SmallVector<Value> operands;
1582
- if (failed (convertCallTypeAndOperands (callInst, types, operands)))
1584
+ if (failed (convertCallTypeAndOperands (callInst, types, operands,
1585
+ /* allowInlineAsm=*/ true )))
1583
1586
return failure ();
1584
1587
1585
1588
auto funcTy =
1586
1589
dyn_cast<LLVMFunctionType>(convertType (callInst->getFunctionType ()));
1587
1590
if (!funcTy)
1588
1591
return failure ();
1589
1592
1590
- CallOp callOp;
1591
-
1592
- if (llvm::Function *callee = callInst->getCalledFunction ()) {
1593
- callOp = builder.create <CallOp>(
1594
- loc, funcTy, SymbolRefAttr::get (context, callee->getName ()),
1595
- operands);
1593
+ if (auto asmI = dyn_cast<llvm::InlineAsm>(callInst->getCalledOperand ())) {
1594
+ auto callOp = builder.create <InlineAsmOp>(
1595
+ loc, funcTy.getReturnType (), operands,
1596
+ builder.getStringAttr (asmI->getAsmString ()),
1597
+ builder.getStringAttr (asmI->getConstraintString ()),
1598
+ /* has_side_effects=*/ true ,
1599
+ /* is_align_stack=*/ false , /* asm_dialect=*/ nullptr ,
1600
+ /* operand_attrs=*/ nullptr );
1601
+ if (!callInst->getType ()->isVoidTy ())
1602
+ mapValue (inst, callOp.getResult (0 ));
1603
+ else
1604
+ mapNoResultOp (inst, callOp);
1596
1605
} else {
1597
- callOp = builder.create <CallOp>(loc, funcTy, operands);
1606
+ CallOp callOp;
1607
+
1608
+ if (llvm::Function *callee = callInst->getCalledFunction ()) {
1609
+ callOp = builder.create <CallOp>(
1610
+ loc, funcTy, SymbolRefAttr::get (context, callee->getName ()),
1611
+ operands);
1612
+ } else {
1613
+ callOp = builder.create <CallOp>(loc, funcTy, operands);
1614
+ }
1615
+ callOp.setCConv (convertCConvFromLLVM (callInst->getCallingConv ()));
1616
+ callOp.setTailCallKind (
1617
+ convertTailCallKindFromLLVM (callInst->getTailCallKind ()));
1618
+ setFastmathFlagsAttr (inst, callOp);
1619
+
1620
+ // Handle function attributes.
1621
+ if (callInst->hasFnAttr (llvm::Attribute::Convergent))
1622
+ callOp.setConvergent (true );
1623
+ if (callInst->hasFnAttr (llvm::Attribute::NoUnwind))
1624
+ callOp.setNoUnwind (true );
1625
+ if (callInst->hasFnAttr (llvm::Attribute::WillReturn))
1626
+ callOp.setWillReturn (true );
1627
+
1628
+ llvm::MemoryEffects memEffects = callInst->getMemoryEffects ();
1629
+ ModRefInfo othermem = convertModRefInfoFromLLVM (
1630
+ memEffects.getModRef (llvm::MemoryEffects::Location::Other));
1631
+ ModRefInfo argMem = convertModRefInfoFromLLVM (
1632
+ memEffects.getModRef (llvm::MemoryEffects::Location::ArgMem));
1633
+ ModRefInfo inaccessibleMem = convertModRefInfoFromLLVM (
1634
+ memEffects.getModRef (llvm::MemoryEffects::Location::InaccessibleMem));
1635
+ auto memAttr = MemoryEffectsAttr::get (callOp.getContext (), othermem,
1636
+ argMem, inaccessibleMem);
1637
+ // Only set the attribute when it does not match the default value.
1638
+ if (!memAttr.isReadWrite ())
1639
+ callOp.setMemoryEffectsAttr (memAttr);
1640
+
1641
+ if (!callInst->getType ()->isVoidTy ())
1642
+ mapValue (inst, callOp.getResult ());
1643
+ else
1644
+ mapNoResultOp (inst, callOp);
1598
1645
}
1599
- callOp.setCConv (convertCConvFromLLVM (callInst->getCallingConv ()));
1600
- callOp.setTailCallKind (
1601
- convertTailCallKindFromLLVM (callInst->getTailCallKind ()));
1602
- setFastmathFlagsAttr (inst, callOp);
1603
-
1604
- // Handle function attributes.
1605
- if (callInst->hasFnAttr (llvm::Attribute::Convergent))
1606
- callOp.setConvergent (true );
1607
- if (callInst->hasFnAttr (llvm::Attribute::NoUnwind))
1608
- callOp.setNoUnwind (true );
1609
- if (callInst->hasFnAttr (llvm::Attribute::WillReturn))
1610
- callOp.setWillReturn (true );
1611
-
1612
- llvm::MemoryEffects memEffects = callInst->getMemoryEffects ();
1613
- ModRefInfo othermem = convertModRefInfoFromLLVM (
1614
- memEffects.getModRef (llvm::MemoryEffects::Location::Other));
1615
- ModRefInfo argMem = convertModRefInfoFromLLVM (
1616
- memEffects.getModRef (llvm::MemoryEffects::Location::ArgMem));
1617
- ModRefInfo inaccessibleMem = convertModRefInfoFromLLVM (
1618
- memEffects.getModRef (llvm::MemoryEffects::Location::InaccessibleMem));
1619
- auto memAttr = MemoryEffectsAttr::get (callOp.getContext (), othermem, argMem,
1620
- inaccessibleMem);
1621
- // Only set the attribute when it does not match the default value.
1622
- if (!memAttr.isReadWrite ())
1623
- callOp.setMemoryEffectsAttr (memAttr);
1624
-
1625
- if (!callInst->getType ()->isVoidTy ())
1626
- mapValue (inst, callOp.getResult ());
1627
- else
1628
- mapNoResultOp (inst, callOp);
1629
1646
return success ();
1630
1647
}
1631
1648
if (inst->getOpcode () == llvm::Instruction::LandingPad) {
0 commit comments