|
31 | 31 | #include "llvm/IR/CallingConv.h"
|
32 | 32 | #include "llvm/IR/Constant.h"
|
33 | 33 | #include "llvm/IR/Constants.h"
|
| 34 | +#include "llvm/IR/DIBuilder.h" |
34 | 35 | #include "llvm/IR/DebugInfoMetadata.h"
|
35 | 36 | #include "llvm/IR/DerivedTypes.h"
|
36 | 37 | #include "llvm/IR/Function.h"
|
@@ -6498,10 +6499,41 @@ static Function *createOutlinedFunction(
|
6498 | 6499 | ParameterTypes.push_back(Arg->getType());
|
6499 | 6500 | }
|
6500 | 6501 |
|
| 6502 | + auto BB = Builder.GetInsertBlock(); |
| 6503 | + auto M = BB->getModule(); |
6501 | 6504 | auto FuncType = FunctionType::get(Builder.getVoidTy(), ParameterTypes,
|
6502 | 6505 | /*isVarArg*/ false);
|
6503 |
| - auto Func = Function::Create(FuncType, GlobalValue::InternalLinkage, FuncName, |
6504 |
| - Builder.GetInsertBlock()->getModule()); |
| 6506 | + auto Func = |
| 6507 | + Function::Create(FuncType, GlobalValue::InternalLinkage, FuncName, M); |
| 6508 | + |
| 6509 | + // If there's a DISubprogram associated with current function, then |
| 6510 | + // generate one for the outlined function. |
| 6511 | + if (Function *parentFunc = BB->getParent()) { |
| 6512 | + if (DISubprogram *SP = parentFunc->getSubprogram()) { |
| 6513 | + DICompileUnit *CU = SP->getUnit(); |
| 6514 | + DIBuilder DB(*M, true, CU); |
| 6515 | + DebugLoc DL = Builder.getCurrentDebugLocation(); |
| 6516 | + // TODO: We are using nullopt for arguments at the moment. This will need |
| 6517 | + // to be updated when debug data is being generated for variables. |
| 6518 | + DISubroutineType *Ty = |
| 6519 | + DB.createSubroutineType(DB.getOrCreateTypeArray(std::nullopt)); |
| 6520 | + DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagDefinition | |
| 6521 | + DISubprogram::SPFlagOptimized | |
| 6522 | + DISubprogram::SPFlagLocalToUnit; |
| 6523 | + |
| 6524 | + DISubprogram *OutlinedSP = DB.createFunction( |
| 6525 | + CU, FuncName, FuncName, SP->getFile(), DL.getLine(), Ty, DL.getLine(), |
| 6526 | + DINode::DIFlags::FlagArtificial, SPFlags); |
| 6527 | + |
| 6528 | + // Attach subprogram to the function. |
| 6529 | + Func->setSubprogram(OutlinedSP); |
| 6530 | + // Update the CurrentDebugLocation in the builder so that right scope |
| 6531 | + // is used for things inside outlined function. |
| 6532 | + Builder.SetCurrentDebugLocation( |
| 6533 | + DILocation::get(Func->getContext(), DL.getLine(), DL.getCol(), |
| 6534 | + OutlinedSP, DL.getInlinedAt())); |
| 6535 | + } |
| 6536 | + } |
6505 | 6537 |
|
6506 | 6538 | // Save insert point.
|
6507 | 6539 | auto OldInsertPoint = Builder.saveIP();
|
|
0 commit comments