Function *F = SCC[0]->getFunction();
- if (!F || !F->isDefinitionExact() ||
- F->hasFnAttribute(Attribute::OptimizeNone)) {
+ if (!F || !F->isDefinitionExact()) {
// Calls externally or not exact - can't say anything useful. Remove any
// existing function records (may have been created when scanning
// globals).
break;
}
- if (F->isDeclaration()) {
+ if (F->isDeclaration() || F->hasFnAttribute(Attribute::OptimizeNone)) {
// Try to get mod/ref behaviour from function attributes.
if (F->doesNotAccessMemory()) {
// Can't do better than that!
break; // The mod/ref lattice saturates here.
// Don't prove any properties based on the implementation of an optnone
- // function.
- if (Node->getFunction()->hasFnAttribute(Attribute::OptimizeNone)) {
- FI.addModRefInfo(MRI_Ref);
- FI.addModRefInfo(MRI_Mod);
+ // function. Function attributes were already used as a best approximation
+ // above.
+ if (Node->getFunction()->hasFnAttribute(Attribute::OptimizeNone))
continue;
- }
for (Instruction &I : instructions(Node->getFunction())) {
if (FI.getModRefInfo() == MRI_ModRef)
TEST(GlobalsModRef, OptNone) {
StringRef Assembly = R"(
- define void @f() optnone {
+ define void @f1() optnone {
+ ret void
+ }
+ define void @f2() optnone readnone {
+ ret void
+ }
+ define void @f3() optnone readonly {
ret void
}
)";
ASSERT_TRUE(M) << "Bad assembly?";
const auto &funcs = M->functions();
- ASSERT_NE(funcs.begin(), funcs.end());
- EXPECT_EQ(std::next(funcs.begin()), funcs.end());
- const Function &F = *funcs.begin();
+ auto I = funcs.begin();
+ ASSERT_NE(I, funcs.end());
+ const Function &F1 = *I;
+ ASSERT_NE(++I, funcs.end());
+ const Function &F2 = *I;
+ ASSERT_NE(++I, funcs.end());
+ const Function &F3 = *I;
+ EXPECT_EQ(++I, funcs.end());
Triple Trip(M->getTargetTriple());
TargetLibraryInfoImpl TLII(Trip);
llvm::CallGraph CG(*M);
auto AAR = GlobalsAAResult::analyzeModule(*M, TLI, CG);
- EXPECT_EQ(FMRB_UnknownModRefBehavior, AAR.getModRefBehavior(&F));
+
+ EXPECT_EQ(FMRB_UnknownModRefBehavior, AAR.getModRefBehavior(&F1));
+ EXPECT_EQ(FMRB_DoesNotAccessMemory, AAR.getModRefBehavior(&F2));
+ EXPECT_EQ(FMRB_OnlyReadsMemory, AAR.getModRefBehavior(&F3));
}