@@ -524,9 +524,9 @@ void ModuleImport::addDebugIntrinsic(llvm::CallInst *intrinsic) {
524524 debugIntrinsics.insert (intrinsic);
525525}
526526
527- void ModuleImport::addDebugRecord (llvm::DbgRecord *dr ) {
528- if (!debugRecords.contains (dr ))
529- debugRecords.insert (dr );
527+ void ModuleImport::addDebugRecord (llvm::DbgRecord *debugRecord ) {
528+ if (!debugRecords.contains (debugRecord ))
529+ debugRecords.insert (debugRecord );
530530}
531531
532532static Attribute convertCGProfileModuleFlagValue (ModuleOp mlirModule,
@@ -2558,10 +2558,9 @@ LogicalResult ModuleImport::processInstruction(llvm::Instruction *inst) {
25582558 return convertIntrinsic (intrinsic);
25592559
25602560 // Capture instruction with attached debug markers for later processing.
2561- if (inst->DebugMarker ) {
2562- for (llvm::DbgRecord &dr : inst->DebugMarker ->getDbgRecordRange ())
2563- addDebugRecord (&dr);
2564- }
2561+ if (inst->DebugMarker )
2562+ for (llvm::DbgRecord &debugRecord : inst->DebugMarker ->getDbgRecordRange ())
2563+ addDebugRecord (&debugRecord);
25652564
25662565 // Convert all remaining LLVM instructions to MLIR operations.
25672566 return convertInstruction (inst);
@@ -3026,7 +3025,7 @@ LogicalResult ModuleImport::processFunction(llvm::Function *func) {
30263025 if (failed (processDebugIntrinsics ()))
30273026 return failure ();
30283027
3029- // Process the debug r that require a delayed conversion after
3028+ // Process the debug records that require a delayed conversion after
30303029 // everything else was converted.
30313030 if (failed (processDebugRecords ()))
30323031 return failure ();
@@ -3044,8 +3043,8 @@ static bool isMetadataKillLocation(bool isKillLocation, llvm::Value *value) {
30443043 return !isa<llvm::ValueAsMetadata>(nodeAsVal->getMetadata ());
30453044}
30463045
3047- // / Ensure that the debug intrinsic is inserted right after its operand is
3048- // / defined . Otherwise, the operand might not necessarily dominate the
3046+ // / Ensure that the debug intrinsic is inserted right after the operand
3047+ // / definition . Otherwise, the operand might not necessarily dominate the
30493048// / intrinsic. If the defining operation is a terminator, insert the intrinsic
30503049// / into a dominated block.
30513050static LogicalResult setDebugIntrinsicBuilderInsertionPoint (
@@ -3080,41 +3079,40 @@ static LogicalResult setDebugIntrinsicBuilderInsertionPoint(
30803079 return success ();
30813080}
30823081
3083- void ModuleImport::processDebugOpArgumentsAndInsertionPt (
3084- Location loc, DILocalVariableAttr &localVarAttr,
3085- DIExpressionAttr &localExprAttr, Value &locVal, bool hasArgList,
3086- bool isKillLocation,
3082+ std::tuple<DILocalVariableAttr, DIExpressionAttr, Value>
3083+ ModuleImport::processDebugOpArgumentsAndInsertionPt (
3084+ Location loc, bool hasArgList, bool isKillLocation,
30873085 llvm::function_ref<FailureOr<Value>()> convertArgOperandToValue,
30883086 llvm::Value *address,
30893087 llvm::PointerUnion<llvm::Value *, llvm::DILocalVariable *> variable,
30903088 llvm::DIExpression *expression, DominanceInfo &domInfo) {
30913089 // Drop debug intrinsics with arg lists.
30923090 // TODO: Support debug intrinsics that have arg lists.
30933091 if (hasArgList)
3094- return ;
3092+ return {} ;
30953093 // Kill locations can have metadata nodes as location operand. This
30963094 // cannot be converted to poison as the type cannot be reconstructed.
30973095 // TODO: find a way to support this case.
30983096 if (isMetadataKillLocation (isKillLocation, address))
3099- return ;
3097+ return {} ;
31003098 // Drop debug intrinsics if the associated variable information cannot be
31013099 // translated due to cyclic debug metadata.
31023100 // TODO: Support cyclic debug metadata.
3103- localVarAttr = matchLocalVariableAttr (variable);
3101+ DILocalVariableAttr localVarAttr = matchLocalVariableAttr (variable);
31043102 if (!localVarAttr)
3105- return ;
3103+ return {} ;
31063104 FailureOr<Value> argOperand = convertArgOperandToValue ();
31073105 if (failed (argOperand)) {
31083106 emitError (loc) << " failed to convert a debug operand: " << diag (*address);
3109- return ;
3107+ return {} ;
31103108 }
31113109
31123110 if (setDebugIntrinsicBuilderInsertionPoint (builder, domInfo, *argOperand)
31133111 .failed ())
3114- return ;
3112+ return {} ;
31153113
3116- localExprAttr = debugImporter->translateExpression (expression);
3117- locVal = *argOperand;
3114+ return {localVarAttr, debugImporter->translateExpression (expression),
3115+ *argOperand} ;
31183116}
31193117
31203118LogicalResult
@@ -3127,99 +3125,92 @@ ModuleImport::processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr,
31273125 return success ();
31283126 };
31293127
3130- DILocalVariableAttr localVariableAttr;
3131- DIExpressionAttr locationExprAttr;
3132- Value locVal;
31333128 OpBuilder::InsertionGuard guard (builder);
31343129 auto convertArgOperandToValue = [&]() {
31353130 return convertMetadataValue (dbgIntr->getArgOperand (0 ));
31363131 };
31373132
3138- processDebugOpArgumentsAndInsertionPt (
3139- loc, localVariableAttr, locationExprAttr, locVal, dbgIntr-> hasArgList (),
3140- dbgIntr->isKillLocation (), convertArgOperandToValue ,
3141- dbgIntr-> getArgOperand ( 0 ) , dbgIntr->getArgOperand (1 ),
3142- dbgIntr->getExpression (), domInfo);
3133+ auto [localVariableAttr, locationExprAttr, locVal] =
3134+ processDebugOpArgumentsAndInsertionPt (
3135+ loc, dbgIntr->hasArgList (), dbgIntr-> isKillLocation () ,
3136+ convertArgOperandToValue , dbgIntr->getArgOperand (0 ),
3137+ dbgIntr-> getArgOperand ( 1 ), dbgIntr->getExpression (), domInfo);
31433138
31443139 if (!localVariableAttr)
31453140 return emitUnsupportedWarning ();
31463141
31473142 if (!locVal) // Expected if localVariableAttr is present.
31483143 return failure ();
31493144
3150- Operation *op =
3151- llvm::TypeSwitch <llvm::DbgVariableIntrinsic *, Operation * >(dbgIntr)
3152- . Case ([&](llvm::DbgDeclareInst *) {
3153- return LLVM::DbgDeclareOp::create (
3154- builder, loc, locVal, localVariableAttr, locationExprAttr);
3155- })
3156- . Case ([&](llvm::DbgValueInst *) {
3157- return LLVM::DbgValueOp::create (
3158- builder, loc, locVal, localVariableAttr, locationExprAttr );
3159- });
3145+ Operation *op = nullptr ;
3146+ if (isa <llvm::DbgDeclareInst >(dbgIntr) )
3147+ op = LLVM::DbgDeclareOp::create (builder, loc, locVal, localVariableAttr,
3148+ locationExprAttr);
3149+ else if (isa<llvm::DbgValueInst>(dbgIntr))
3150+ op = LLVM::DbgValueOp::create (builder, loc, locVal, localVariableAttr,
3151+ locationExprAttr);
3152+ else
3153+ return emitUnsupportedWarning ( );
3154+
31603155 mapNoResultOp (dbgIntr, op);
31613156 setNonDebugMetadataAttrs (dbgIntr, op);
31623157 return success ();
31633158}
31643159
3165- LogicalResult ModuleImport::processDebugRecord (llvm::DbgRecord &dr ,
3160+ LogicalResult ModuleImport::processDebugRecord (llvm::DbgRecord &debugRecord ,
31663161 DominanceInfo &domInfo) {
3167- Location loc = translateLoc (dr .getDebugLoc ());
3162+ Location loc = translateLoc (debugRecord .getDebugLoc ());
31683163 auto emitUnsupportedWarning = [&]() {
31693164 if (!emitExpensiveWarnings)
31703165 return success ();
31713166 std::string options;
31723167 llvm::raw_string_ostream optionsStream (options);
3173- dr .print (optionsStream);
3168+ debugRecord .print (optionsStream);
31743169 emitWarning (loc) << " unhandled debug record " << optionsStream.str ();
31753170 return success ();
31763171 };
31773172
31783173 OpBuilder::InsertionGuard guard (builder);
3179- if (auto *dbgVar = dyn_cast<llvm::DbgVariableRecord>(&dr)) {
3180- DILocalVariableAttr localVariableAttr;
3181- DIExpressionAttr locationExprAttr;
3182- Value locVal;
3183- auto convertArgOperandToValue = [&]() -> FailureOr<Value> {
3184- llvm::Value *value = dbgVar->getAddress ();
3185-
3186- // Return the mapped value if it has been converted before.
3187- auto it = valueMapping.find (value);
3188- if (it != valueMapping.end ())
3189- return it->getSecond ();
3190-
3191- // Convert constants such as immediate values that have no mapping yet.
3192- if (auto *constant = dyn_cast<llvm::Constant>(value))
3193- return convertConstantExpr (constant);
3194- return failure ();
3195- };
3174+ auto *dbgVar = dyn_cast<llvm::DbgVariableRecord>(&debugRecord);
3175+ if (!dbgVar)
3176+ return emitUnsupportedWarning ();
31963177
3197- processDebugOpArgumentsAndInsertionPt (
3198- loc, localVariableAttr, locationExprAttr, locVal, dbgVar->hasArgList (),
3199- dbgVar->isKillLocation (), convertArgOperandToValue,
3200- dbgVar->getAddress (), dbgVar->getVariable (), dbgVar->getExpression (),
3201- domInfo);
3178+ auto convertArgOperandToValue = [&]() -> FailureOr<Value> {
3179+ llvm::Value *value = dbgVar->getAddress ();
32023180
3203- if (!localVariableAttr)
3204- return emitUnsupportedWarning ();
3181+ // Return the mapped value if it has been converted before.
3182+ auto it = valueMapping.find (value);
3183+ if (it != valueMapping.end ())
3184+ return it->getSecond ();
32053185
3206- if (!locVal) // Expected if localVariableAttr is present.
3207- return failure ();
3186+ // Convert constants such as immediate values that have no mapping yet.
3187+ if (auto *constant = dyn_cast<llvm::Constant>(value))
3188+ return convertConstantExpr (constant);
3189+ return failure ();
3190+ };
32083191
3209- if (dbgVar->isDbgDeclare ())
3210- LLVM::DbgDeclareOp::create (builder, loc, locVal, localVariableAttr,
3211- locationExprAttr);
3212- else if (dbgVar->isDbgValue ())
3213- LLVM::DbgValueOp::create (builder, loc, locVal, localVariableAttr,
3214- locationExprAttr);
3215- else // isDbgAssign
3216- return emitUnsupportedWarning ();
3192+ auto [localVariableAttr, locationExprAttr, locVal] =
3193+ processDebugOpArgumentsAndInsertionPt (
3194+ loc, dbgVar->hasArgList (), dbgVar->isKillLocation (),
3195+ convertArgOperandToValue, dbgVar->getAddress (), dbgVar->getVariable (),
3196+ dbgVar->getExpression (), domInfo);
32173197
3218- // FIXME: Nothing to map given the source is an LLVM attribute?
3219- return success ();
3220- }
3198+ if (!localVariableAttr)
3199+ return emitUnsupportedWarning ();
32213200
3222- return emitUnsupportedWarning ();
3201+ if (!locVal) // Expected if localVariableAttr is present.
3202+ return failure ();
3203+
3204+ if (dbgVar->isDbgDeclare ())
3205+ LLVM::DbgDeclareOp::create (builder, loc, locVal, localVariableAttr,
3206+ locationExprAttr);
3207+ else if (dbgVar->isDbgValue ())
3208+ LLVM::DbgValueOp::create (builder, loc, locVal, localVariableAttr,
3209+ locationExprAttr);
3210+ else // isDbgAssign
3211+ return emitUnsupportedWarning ();
3212+
3213+ return success ();
32233214}
32243215
32253216LogicalResult ModuleImport::processDebugIntrinsics () {
@@ -3234,8 +3225,8 @@ LogicalResult ModuleImport::processDebugIntrinsics() {
32343225
32353226LogicalResult ModuleImport::processDebugRecords () {
32363227 DominanceInfo domInfo;
3237- for (llvm::DbgRecord *dr : debugRecords) {
3238- if (failed (processDebugRecord (*dr , domInfo)))
3228+ for (llvm::DbgRecord *debugRecord : debugRecords) {
3229+ if (failed (processDebugRecord (*debugRecord , domInfo)))
32393230 return failure ();
32403231 }
32413232 debugRecords.clear ();
0 commit comments