mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
[optnone] Make the optnone attribute effective at suppressing function
attribute and function argument attribute synthesizing and propagating. As with the other uses of this attribute, the goal remains a best-effort (no guarantees) attempt to not optimize the function or assume things about the function when optimizing. This is particularly useful for compiler testing, bisecting miscompiles, triaging things, etc. I was hitting specific issues using optnone to isolate test code from a test driver for my fuzz testing, and this is one step of fixing that. llvm-svn: 215538
This commit is contained in:
parent
2ae3eb4c49
commit
5652971ecf
@ -161,8 +161,9 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
|
||||
for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
|
||||
Function *F = (*I)->getFunction();
|
||||
|
||||
if (!F)
|
||||
// External node - may write memory. Just give up.
|
||||
if (!F || F->hasFnAttribute(Attribute::OptimizeNone))
|
||||
// External node or node we don't want to optimize - assume it may write
|
||||
// memory and give up.
|
||||
return false;
|
||||
|
||||
AliasAnalysis::ModRefBehavior MRB = AA->getModRefBehavior(F);
|
||||
@ -527,7 +528,8 @@ bool FunctionAttrs::AddArgumentAttrs(const CallGraphSCC &SCC) {
|
||||
// looking up whether a given CallGraphNode is in this SCC.
|
||||
for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
|
||||
Function *F = (*I)->getFunction();
|
||||
if (F && !F->isDeclaration() && !F->mayBeOverridden())
|
||||
if (F && !F->isDeclaration() && !F->mayBeOverridden() &&
|
||||
!F->hasFnAttribute(Attribute::OptimizeNone))
|
||||
SCCNodes.insert(F);
|
||||
}
|
||||
|
||||
@ -541,8 +543,9 @@ bool FunctionAttrs::AddArgumentAttrs(const CallGraphSCC &SCC) {
|
||||
for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
|
||||
Function *F = (*I)->getFunction();
|
||||
|
||||
if (!F)
|
||||
// External node - only a problem for arguments that we pass to it.
|
||||
if (!F || F->hasFnAttribute(Attribute::OptimizeNone))
|
||||
// External node or function we're trying not to optimize - only a problem
|
||||
// for arguments that we pass to it.
|
||||
continue;
|
||||
|
||||
// Definitions with weak linkage may be overridden at linktime with
|
||||
@ -794,8 +797,8 @@ bool FunctionAttrs::AddNoAliasAttrs(const CallGraphSCC &SCC) {
|
||||
for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
|
||||
Function *F = (*I)->getFunction();
|
||||
|
||||
if (!F)
|
||||
// External node - skip it;
|
||||
if (!F || F->hasFnAttribute(Attribute::OptimizeNone))
|
||||
// External node or node we don't want to optimize - skip it;
|
||||
return false;
|
||||
|
||||
// Already noalias.
|
||||
@ -834,6 +837,9 @@ bool FunctionAttrs::AddNoAliasAttrs(const CallGraphSCC &SCC) {
|
||||
/// given function and set any applicable attributes. Returns true
|
||||
/// if any attributes were set and false otherwise.
|
||||
bool FunctionAttrs::inferPrototypeAttributes(Function &F) {
|
||||
if (F.hasFnAttribute(Attribute::OptimizeNone))
|
||||
return false;
|
||||
|
||||
FunctionType *FTy = F.getFunctionType();
|
||||
LibFunc::Func TheLibFunc;
|
||||
if (!(TLI->getLibFunc(F.getName(), TheLibFunc) && TLI->has(TheLibFunc)))
|
||||
|
24
test/Transforms/FunctionAttrs/optnone.ll
Normal file
24
test/Transforms/FunctionAttrs/optnone.ll
Normal file
@ -0,0 +1,24 @@
|
||||
; RUN: opt < %s -functionattrs -S | FileCheck %s
|
||||
|
||||
@x = global i32 0
|
||||
|
||||
define void @test_opt(i8* %p) {
|
||||
; CHECK-LABEL: @test_opt
|
||||
; CHECK: (i8* nocapture readnone %p) #0 {
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @test_optnone(i8* %p) noinline optnone {
|
||||
; CHECK-LABEL: @test_optnone
|
||||
; CHECK: (i8* %p) #1 {
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i8 @strlen(i8*) noinline optnone
|
||||
; CHECK-LABEL: @strlen
|
||||
; CHECK: (i8*) #1
|
||||
|
||||
; CHECK-LABEL: attributes #0
|
||||
; CHECK: = { readnone }
|
||||
; CHECK-LABEL: attributes #1
|
||||
; CHECK: = { noinline optnone }
|
Loading…
Reference in New Issue
Block a user