@@ -780,7 +780,8 @@ static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock,
780
780
// / When inlining a call site that has !llvm.mem.parallel_loop_access,
781
781
// / !llvm.access.group, !alias.scope or !noalias metadata, that metadata should
782
782
// / be propagated to all memory-accessing cloned instructions.
783
- static void PropagateCallSiteMetadata (CallBase &CB, ValueToValueMapTy &VMap) {
783
+ static void PropagateCallSiteMetadata (CallBase &CB, Function::iterator FStart,
784
+ Function::iterator FEnd) {
784
785
MDNode *MemParallelLoopAccess =
785
786
CB.getMetadata (LLVMContext::MD_mem_parallel_loop_access);
786
787
MDNode *AccessGroup = CB.getMetadata (LLVMContext::MD_access_group);
@@ -789,41 +790,33 @@ static void PropagateCallSiteMetadata(CallBase &CB, ValueToValueMapTy &VMap) {
789
790
if (!MemParallelLoopAccess && !AccessGroup && !AliasScope && !NoAlias)
790
791
return ;
791
792
792
- for (ValueToValueMapTy::iterator VMI = VMap.begin (), VMIE = VMap.end ();
793
- VMI != VMIE; ++VMI) {
794
- // Check that key is an instruction, to skip the Argument mapping, which
795
- // points to an instruction in the original function, not the inlined one.
796
- if (!VMI->second || !isa<Instruction>(VMI->first ))
797
- continue ;
798
-
799
- Instruction *NI = dyn_cast<Instruction>(VMI->second );
800
- if (!NI)
801
- continue ;
802
-
803
- // This metadata is only relevant for instructions that access memory.
804
- if (!NI->mayReadOrWriteMemory ())
805
- continue ;
793
+ for (BasicBlock &BB : make_range (FStart, FEnd)) {
794
+ for (Instruction &I : BB) {
795
+ // This metadata is only relevant for instructions that access memory.
796
+ if (!I.mayReadOrWriteMemory ())
797
+ continue ;
806
798
807
- if (MemParallelLoopAccess) {
808
- // TODO: This probably should not overwrite MemParalleLoopAccess.
809
- MemParallelLoopAccess = MDNode::concatenate (
810
- NI-> getMetadata (LLVMContext::MD_mem_parallel_loop_access),
811
- MemParallelLoopAccess);
812
- NI-> setMetadata (LLVMContext::MD_mem_parallel_loop_access,
799
+ if (MemParallelLoopAccess) {
800
+ // TODO: This probably should not overwrite MemParalleLoopAccess.
801
+ MemParallelLoopAccess = MDNode::concatenate (
802
+ I. getMetadata (LLVMContext::MD_mem_parallel_loop_access),
803
+ MemParallelLoopAccess);
804
+ I. setMetadata (LLVMContext::MD_mem_parallel_loop_access,
813
805
MemParallelLoopAccess);
814
- }
806
+ }
815
807
816
- if (AccessGroup)
817
- NI-> setMetadata (LLVMContext::MD_access_group, uniteAccessGroups (
818
- NI-> getMetadata (LLVMContext::MD_access_group), AccessGroup));
808
+ if (AccessGroup)
809
+ I. setMetadata (LLVMContext::MD_access_group, uniteAccessGroups (
810
+ I. getMetadata (LLVMContext::MD_access_group), AccessGroup));
819
811
820
- if (AliasScope)
821
- NI-> setMetadata (LLVMContext::MD_alias_scope, MDNode::concatenate (
822
- NI-> getMetadata (LLVMContext::MD_alias_scope), AliasScope));
812
+ if (AliasScope)
813
+ I. setMetadata (LLVMContext::MD_alias_scope, MDNode::concatenate (
814
+ I. getMetadata (LLVMContext::MD_alias_scope), AliasScope));
823
815
824
- if (NoAlias)
825
- NI->setMetadata (LLVMContext::MD_noalias, MDNode::concatenate (
826
- NI->getMetadata (LLVMContext::MD_noalias), NoAlias));
816
+ if (NoAlias)
817
+ I.setMetadata (LLVMContext::MD_noalias, MDNode::concatenate (
818
+ I.getMetadata (LLVMContext::MD_noalias), NoAlias));
819
+ }
827
820
}
828
821
}
829
822
@@ -844,9 +837,9 @@ class ScopedAliasMetadataDeepCloner {
844
837
// / subsequent remap() calls.
845
838
void clone ();
846
839
847
- // / Remap instructions in the given VMap from the original to the cloned
840
+ // / Remap instructions in the given range from the original to the cloned
848
841
// / metadata.
849
- void remap (ValueToValueMapTy &VMap );
842
+ void remap (Function::iterator FStart, Function::iterator FEnd );
850
843
};
851
844
852
845
ScopedAliasMetadataDeepCloner::ScopedAliasMetadataDeepCloner (
@@ -907,34 +900,27 @@ void ScopedAliasMetadataDeepCloner::clone() {
907
900
}
908
901
}
909
902
910
- void ScopedAliasMetadataDeepCloner::remap (ValueToValueMapTy &VMap) {
903
+ void ScopedAliasMetadataDeepCloner::remap (Function::iterator FStart,
904
+ Function::iterator FEnd) {
911
905
if (MDMap.empty ())
912
906
return ; // Nothing to do.
913
907
914
- for (auto Entry : VMap) {
915
- // Check that key is an instruction, to skip the Argument mapping, which
916
- // points to an instruction in the original function, not the inlined one.
917
- if (!Entry->second || !isa<Instruction>(Entry->first ))
918
- continue ;
919
-
920
- Instruction *I = dyn_cast<Instruction>(Entry->second );
921
- if (!I)
922
- continue ;
923
-
924
- // Only update scopes when we find them in the map. If they are not, it is
925
- // because we already handled that instruction before. This is faster than
926
- // tracking which instructions we already updated.
927
- if (MDNode *M = I->getMetadata (LLVMContext::MD_alias_scope))
928
- if (MDNode *MNew = MDMap.lookup (M))
929
- I->setMetadata (LLVMContext::MD_alias_scope, MNew);
930
-
931
- if (MDNode *M = I->getMetadata (LLVMContext::MD_noalias))
932
- if (MDNode *MNew = MDMap.lookup (M))
933
- I->setMetadata (LLVMContext::MD_noalias, MNew);
934
-
935
- if (auto *Decl = dyn_cast<NoAliasScopeDeclInst>(I))
936
- if (MDNode *MNew = MDMap.lookup (Decl->getScopeList ()))
937
- Decl->setScopeList (MNew);
908
+ for (BasicBlock &BB : make_range (FStart, FEnd)) {
909
+ for (Instruction &I : BB) {
910
+ // TODO: The null checks for the MDMap.lookup() results should no longer
911
+ // be necessary.
912
+ if (MDNode *M = I.getMetadata (LLVMContext::MD_alias_scope))
913
+ if (MDNode *MNew = MDMap.lookup (M))
914
+ I.setMetadata (LLVMContext::MD_alias_scope, MNew);
915
+
916
+ if (MDNode *M = I.getMetadata (LLVMContext::MD_noalias))
917
+ if (MDNode *MNew = MDMap.lookup (M))
918
+ I.setMetadata (LLVMContext::MD_noalias, MNew);
919
+
920
+ if (auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&I))
921
+ if (MDNode *MNew = MDMap.lookup (Decl->getScopeList ()))
922
+ Decl->setScopeList (MNew);
923
+ }
938
924
}
939
925
}
940
926
@@ -1926,7 +1912,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
1926
1912
1927
1913
// Now clone the inlined noalias scope metadata.
1928
1914
SAMetadataCloner.clone ();
1929
- SAMetadataCloner.remap (VMap );
1915
+ SAMetadataCloner.remap (FirstNewBlock, Caller-> end () );
1930
1916
1931
1917
// Add noalias metadata if necessary.
1932
1918
AddAliasScopeMetadata (CB, VMap, DL, CalleeAAR);
@@ -1936,7 +1922,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
1936
1922
AddReturnAttributes (CB, VMap);
1937
1923
1938
1924
// Propagate metadata on the callsite if necessary.
1939
- PropagateCallSiteMetadata (CB, VMap );
1925
+ PropagateCallSiteMetadata (CB, FirstNewBlock, Caller-> end () );
1940
1926
1941
1927
// Register any cloned assumptions.
1942
1928
if (IFI.GetAssumptionCache )
0 commit comments