From 73247d2edc860c4c4ca6f2d5b3fef38d6ac0f68a Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Sat, 14 Feb 2009 10:56:35 +0000 Subject: [PATCH] Generalize some alias analysis logic from atomic intrinsics to any IntrWriteArgMem intrinsics. llvm-svn: 64551 --- llvm/lib/Analysis/AliasAnalysis.cpp | 7 +++- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 51 ------------------------ llvm/utils/TableGen/IntrinsicEmitter.cpp | 34 ++++++++++++++++ llvm/utils/TableGen/IntrinsicEmitter.h | 2 + 4 files changed, 42 insertions(+), 52 deletions(-) diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp index 67b2faac55dc..c5523ec4634d 100644 --- a/llvm/lib/Analysis/AliasAnalysis.cpp +++ b/llvm/lib/Analysis/AliasAnalysis.cpp @@ -124,8 +124,13 @@ AliasAnalysis::getModRefBehavior(Function *F, if (F->doesNotAccessMemory()) // Can't do better than this. return DoesNotAccessMemory; - else if (F->onlyReadsMemory()) + if (F->onlyReadsMemory()) return OnlyReadsMemory; + if (unsigned id = F->getIntrinsicID()) { +#define GET_INTRINSIC_MODREF_BEHAVIOR +#include "llvm/Intrinsics.gen" +#undef GET_INTRINSIC_MODREF_BEHAVIOR + } } return UnknownModRefBehavior; } diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index ef918507b770..fe71f04098b1 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -201,13 +201,7 @@ namespace { ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size); ModRefResult getModRefInfo(CallSite CS1, CallSite CS2); - - virtual ModRefBehavior getModRefBehavior(CallSite CS, - std::vector *Info = 0); - virtual ModRefBehavior getModRefBehavior(Function *F, - std::vector *Info = 0); - /// hasNoModRefInfoForCalls - We can provide mod/ref information against /// non-escaping allocations. virtual bool hasNoModRefInfoForCalls() const { return false; } @@ -251,51 +245,6 @@ bool BasicAliasAnalysis::pointsToConstantMemory(const Value *P) { } -static bool isAtomicRMW(Function* F) { - if (!F) return false; - if (F->isIntrinsic()) { - switch (F->getIntrinsicID()) { - case Intrinsic::atomic_cmp_swap: - case Intrinsic::atomic_load_add: - case Intrinsic::atomic_load_and: - case Intrinsic::atomic_load_max: - case Intrinsic::atomic_load_min: - case Intrinsic::atomic_load_nand: - case Intrinsic::atomic_load_or: - case Intrinsic::atomic_load_sub: - case Intrinsic::atomic_load_umax: - case Intrinsic::atomic_load_umin: - case Intrinsic::atomic_load_xor: - case Intrinsic::atomic_swap: - return true; - default: - return false; - } - } - - return false; -} - -AliasAnalysis::ModRefBehavior -BasicAliasAnalysis::getModRefBehavior(CallSite CS, - std::vector *Info) { - if (isAtomicRMW(CS.getCalledFunction())) - // CAS and related intrinsics only access their arguments. - return AliasAnalysis::AccessesArguments; - - return AliasAnalysis::getModRefBehavior(CS, Info); -} - -AliasAnalysis::ModRefBehavior -BasicAliasAnalysis::getModRefBehavior(Function *F, - std::vector *Info) { - if (isAtomicRMW(F)) - // CAS and related intrinsics only access their arguments. - return AliasAnalysis::AccessesArguments; - - return AliasAnalysis::getModRefBehavior(F, Info); -} - // getModRefInfo - Check to see if the specified callsite can clobber the // specified memory object. Since we only look at local properties of this // function, we really can't say much about this query. We do, however, use diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp index 53081ffb65f2..37fc6702ede6 100644 --- a/llvm/utils/TableGen/IntrinsicEmitter.cpp +++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp @@ -48,6 +48,9 @@ void IntrinsicEmitter::run(std::ostream &OS) { // Emit the intrinsic parameter attributes. EmitAttributes(Ints, OS); + // Emit intrinsic alias analysis mod/ref behavior. + EmitModRefBehavior(Ints, OS); + // Emit a list of intrinsics with corresponding GCC builtins. EmitGCCBuiltinList(Ints, OS); @@ -481,6 +484,37 @@ EmitAttributes(const std::vector &Ints, std::ostream &OS) { OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n"; } +/// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior. +void IntrinsicEmitter:: +EmitModRefBehavior(const std::vector &Ints, std::ostream &OS){ + OS << "// Determine intrinsic alias analysis mod/ref behavior.\n"; + OS << "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n"; + OS << "switch (id) {\n"; + OS << "default:\n return UnknownModRefBehavior;\n"; + for (unsigned i = 0, e = Ints.size(); i != e; ++i) { + if (Ints[i].ModRef == CodeGenIntrinsic::WriteMem) + continue; + OS << "case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName + << ":\n"; + switch (Ints[i].ModRef) { + default: + assert(false && "Unknown Mod/Ref type!"); + case CodeGenIntrinsic::NoMem: + OS << " return DoesNotAccessMemory;\n"; + break; + case CodeGenIntrinsic::ReadArgMem: + case CodeGenIntrinsic::ReadMem: + OS << " return OnlyReadsMemory;\n"; + break; + case CodeGenIntrinsic::WriteArgMem: + OS << " return AccessesArguments;\n"; + break; + } + } + OS << "}\n"; + OS << "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n"; +} + void IntrinsicEmitter:: EmitGCCBuiltinList(const std::vector &Ints, std::ostream &OS){ OS << "// Get the GCC builtin that corresponds to an LLVM intrinsic.\n"; diff --git a/llvm/utils/TableGen/IntrinsicEmitter.h b/llvm/utils/TableGen/IntrinsicEmitter.h index 0f3f0e72b6fa..4a169ffd6470 100644 --- a/llvm/utils/TableGen/IntrinsicEmitter.h +++ b/llvm/utils/TableGen/IntrinsicEmitter.h @@ -42,6 +42,8 @@ namespace llvm { std::ostream &OS); void EmitAttributes(const std::vector &Ints, std::ostream &OS); + void EmitModRefBehavior(const std::vector &Ints, + std::ostream &OS); void EmitGCCBuiltinList(const std::vector &Ints, std::ostream &OS); void EmitIntrinsicToGCCBuiltinMap(const std::vector &Ints,