[Mlir-commits] [mlir] 794b58b - [IR] Drop const in DILocation::getMergedLocation
Christian Ulmann
llvmlistbot at llvm.org
Mon May 15 00:22:34 PDT 2023
Author: Christian Ulmann
Date: 2023-05-15T07:21:43Z
New Revision: 794b58b467de9989fa68b7d23792512e2d338e7c
URL: https://github.com/llvm/llvm-project/commit/794b58b467de9989fa68b7d23792512e2d338e7c
DIFF: https://github.com/llvm/llvm-project/commit/794b58b467de9989fa68b7d23792512e2d338e7c.diff
LOG: [IR] Drop const in DILocation::getMergedLocation
This commit removes constness from DILocation::getMergedLocation and
fixes all its users accordingly.
Having constness on the parameters forced the return type to be const
as well, which does force usage of `const_cast` when the location needs
to be used in metadata nodes.
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D149942
Added:
Modified:
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/include/llvm/IR/Instruction.h
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
mlir/lib/Target/LLVMIR/DebugTranslation.cpp
mlir/lib/Target/LLVMIR/DebugTranslation.h
mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index 33bf2cd50db60..325592421ab9d 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2048,15 +2048,13 @@ class DILocation : public MDNode {
/// use the scope of any location.
///
/// \p LocA \p LocB: The locations to be merged.
- static const DILocation *getMergedLocation(const DILocation *LocA,
- const DILocation *LocB);
+ static DILocation *getMergedLocation(DILocation *LocA, DILocation *LocB);
/// Try to combine the vector of locations passed as input in a single one.
/// This function applies getMergedLocation() repeatedly left-to-right.
///
/// \p Locs: The locations to be merged.
- static const DILocation *
- getMergedLocations(ArrayRef<const DILocation *> Locs);
+ static DILocation *getMergedLocations(ArrayRef<DILocation *> Locs);
/// Return the masked discriminator value for an input discrimnator value D
/// (i.e. zero out the (B+1)-th and above bits for D (B is 0-base).
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 2128fe278e9bc..732f6df133576 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -521,7 +521,7 @@ class Instruction : public User,
/// applications, thus the N-way merging should be in code path.
/// The DebugLoc attached to this instruction will be overwritten by the
/// merged DebugLoc.
- void applyMergedLocation(const DILocation *LocA, const DILocation *LocB);
+ void applyMergedLocation(DILocation *LocA, DILocation *LocB);
/// Updates the debug location given that the instruction has been hoisted
/// from a block to a predecessor of that block.
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 9cef82e783743..d2229da31f4b4 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -868,8 +868,7 @@ unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
return 0;
}
-void Instruction::applyMergedLocation(const DILocation *LocA,
- const DILocation *LocB) {
+void Instruction::applyMergedLocation(DILocation *LocA, DILocation *LocB) {
setDebugLoc(DILocation::getMergedLocation(LocA, LocB));
}
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 667cca3fb5cfd..da0881ad1125d 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -95,14 +95,13 @@ DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
Storage, Context.pImpl->DILocations);
}
-const DILocation *
-DILocation::getMergedLocations(ArrayRef<const DILocation *> Locs) {
+DILocation *DILocation::getMergedLocations(ArrayRef<DILocation *> Locs) {
if (Locs.empty())
return nullptr;
if (Locs.size() == 1)
return Locs[0];
auto *Merged = Locs[0];
- for (const DILocation *L : llvm::drop_begin(Locs)) {
+ for (DILocation *L : llvm::drop_begin(Locs)) {
Merged = getMergedLocation(Merged, L);
if (Merged == nullptr)
break;
@@ -110,8 +109,7 @@ DILocation::getMergedLocations(ArrayRef<const DILocation *> Locs) {
return Merged;
}
-const DILocation *DILocation::getMergedLocation(const DILocation *LocA,
- const DILocation *LocB) {
+DILocation *DILocation::getMergedLocation(DILocation *LocA, DILocation *LocB) {
if (!LocA || !LocB)
return nullptr;
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index f184ff9aeea23..0f9fb864c9e12 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -2214,7 +2214,7 @@ bool llvm::promoteLoopAccessesToScalars(
});
// Look at all the loop uses, and try to merge their locations.
- std::vector<const DILocation *> LoopUsesLocs;
+ std::vector<DILocation *> LoopUsesLocs;
for (auto *U : LoopUses)
LoopUsesLocs.push_back(U->getDebugLoc().get());
auto DL = DebugLoc(DILocation::getMergedLocations(LoopUsesLocs));
diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
index 7e0000730fb17..0e8b3e8573abd 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -121,7 +121,7 @@ performBlockTailMerging(Function &F, ArrayRef<BasicBlock *> BBs,
// Now, go through each block (with the current terminator type)
// we've recorded, and rewrite it to branch to the new common block.
- const DILocation *CommonDebugLoc = nullptr;
+ DILocation *CommonDebugLoc = nullptr;
for (BasicBlock *BB : BBs) {
auto *Term = BB->getTerminator();
assert(Term->getOpcode() == CanonicalTerm->getOpcode() &&
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 2dfc16fecc880..665126cf83bbf 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2562,7 +2562,7 @@ static void MergeCompatibleInvokesImpl(ArrayRef<InvokeInst *> Invokes,
// And finally, replace the original `invoke`s with an unconditional branch
// to the block with the merged `invoke`. Also, give that merged `invoke`
// the merged debugloc of all the original `invoke`s.
- const DILocation *MergedDebugLoc = nullptr;
+ DILocation *MergedDebugLoc = nullptr;
for (InvokeInst *II : Invokes) {
// Compute the debug location common to all the original `invoke`s.
if (!MergedDebugLoc)
diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
index 9e3e05eec25ee..f09a9417151ce 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -168,7 +168,7 @@ class ModuleTranslation {
llvm::Module *getLLVMModule() { return llvmModule.get(); }
/// Translates the given location.
- const llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope);
+ llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope);
/// Translates the given LLVM debug info metadata.
llvm::Metadata *translateDebugInfo(LLVM::DINodeAttr attr);
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index 87d02f84e4b4c..3730ddfed238f 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -261,17 +261,17 @@ llvm::DINode *DebugTranslation::translate(DINodeAttr attr) {
//===----------------------------------------------------------------------===//
/// Translate the given location to an llvm debug location.
-const llvm::DILocation *
-DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope) {
+llvm::DILocation *DebugTranslation::translateLoc(Location loc,
+ llvm::DILocalScope *scope) {
if (!debugEmissionIsEnabled)
return nullptr;
return translateLoc(loc, scope, /*inlinedAt=*/nullptr);
}
/// Translate the given location to an llvm DebugLoc.
-const llvm::DILocation *
-DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope,
- const llvm::DILocation *inlinedAt) {
+llvm::DILocation *DebugTranslation::translateLoc(Location loc,
+ llvm::DILocalScope *scope,
+ llvm::DILocation *inlinedAt) {
// LLVM doesn't have a representation for unknown.
if (!scope || isa<UnknownLoc>(loc))
return nullptr;
@@ -281,10 +281,10 @@ DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope,
if (existingIt != locationToLoc.end())
return existingIt->second;
- const llvm::DILocation *llvmLoc = nullptr;
+ llvm::DILocation *llvmLoc = nullptr;
if (auto callLoc = dyn_cast<CallSiteLoc>(loc)) {
// For callsites, the caller is fed as the inlinedAt for the callee.
- const auto *callerLoc = translateLoc(callLoc.getCaller(), scope, inlinedAt);
+ auto *callerLoc = translateLoc(callLoc.getCaller(), scope, inlinedAt);
llvmLoc = translateLoc(callLoc.getCallee(), scope, callerLoc);
} else if (auto fileLoc = dyn_cast<FileLineColLoc>(loc)) {
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.h b/mlir/lib/Target/LLVMIR/DebugTranslation.h
index 3ea077a80bfa1..f654a4307cfbb 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.h
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.h
@@ -35,7 +35,7 @@ class DebugTranslation {
void finalize();
/// Translate the given location to an llvm debug location.
- const llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope);
+ llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope);
/// Translate the debug information for the given function.
void translate(LLVMFuncOp func, llvm::Function &llvmFunc);
@@ -54,8 +54,8 @@ class DebugTranslation {
private:
/// Translate the given location to an llvm debug location with the given
/// scope and inlinedAt parameters.
- const llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope,
- const llvm::DILocation *inlinedAt);
+ llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope,
+ llvm::DILocation *inlinedAt);
/// Create an llvm debug file for the given file path.
llvm::DIFile *translateFile(StringRef fileName);
@@ -85,7 +85,7 @@ class DebugTranslation {
/// A mapping between mlir location+scope and the corresponding llvm debug
/// metadata.
DenseMap<std::tuple<Location, llvm::DILocalScope *, const llvm::DILocation *>,
- const llvm::DILocation *>
+ llvm::DILocation *>
locationToLoc;
/// A mapping between debug attribute and the corresponding llvm debug
diff --git a/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp b/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
index d3c5bb4466392..fbbfa1fcdf1d1 100644
--- a/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
@@ -198,10 +198,10 @@ void LoopAnnotationConversion::convertLocation(FusedLoc location) {
localScopeAttr));
if (!localScope)
return;
- const llvm::Metadata *loc =
+ llvm::Metadata *loc =
loopAnnotationTranslation.moduleTranslation.translateLoc(location,
localScope);
- metadataNodes.push_back(const_cast<llvm::Metadata *>(loc));
+ metadataNodes.push_back(loc);
}
llvm::MDNode *LoopAnnotationConversion::convert() {
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 9d796c55cb14d..e4cd94026a59e 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1275,8 +1275,8 @@ llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() {
return ompBuilder.get();
}
-const llvm::DILocation *
-ModuleTranslation::translateLoc(Location loc, llvm::DILocalScope *scope) {
+llvm::DILocation *ModuleTranslation::translateLoc(Location loc,
+ llvm::DILocalScope *scope) {
return debugTranslation->translateLoc(loc, scope);
}
More information about the Mlir-commits
mailing list