Upgrade our copy of llvm/clang to 3.4 release. This version supports

all of the features in the current working draft of the upcoming C++
standard, provisionally named C++1y.

The code generator's performance is greatly increased, and the loop
auto-vectorizer is now enabled at -Os and -O2 in addition to -O3.  The
PowerPC backend has made several major improvements to code generation
quality and compile time, and the X86, SPARC, ARM32, Aarch64 and SystemZ
backends have all seen major feature work.

Release notes for llvm and clang can be found here:
<http://llvm.org/releases/3.4/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.4/tools/clang/docs/ReleaseNotes.html>

MFC after:	1 month
This commit is contained in:
Dimitry Andric 2014-02-16 19:44:07 +00:00
commit f785676f2a
2339 changed files with 260298 additions and 138917 deletions

View File

@ -38,6 +38,43 @@
# xargs -n1 | sort | uniq -d;
# done
# 20140216: new clang import which bumps version from 3.3 to 3.4.
OLD_FILES+=usr/bin/llvm-prof
OLD_FILES+=usr/bin/llvm-ranlib
OLD_FILES+=usr/include/clang/3.3/__wmmintrin_aes.h
OLD_FILES+=usr/include/clang/3.3/__wmmintrin_pclmul.h
OLD_FILES+=usr/include/clang/3.3/altivec.h
OLD_FILES+=usr/include/clang/3.3/ammintrin.h
OLD_FILES+=usr/include/clang/3.3/avx2intrin.h
OLD_FILES+=usr/include/clang/3.3/avxintrin.h
OLD_FILES+=usr/include/clang/3.3/bmi2intrin.h
OLD_FILES+=usr/include/clang/3.3/bmiintrin.h
OLD_FILES+=usr/include/clang/3.3/cpuid.h
OLD_FILES+=usr/include/clang/3.3/emmintrin.h
OLD_FILES+=usr/include/clang/3.3/f16cintrin.h
OLD_FILES+=usr/include/clang/3.3/fma4intrin.h
OLD_FILES+=usr/include/clang/3.3/fmaintrin.h
OLD_FILES+=usr/include/clang/3.3/immintrin.h
OLD_FILES+=usr/include/clang/3.3/lzcntintrin.h
OLD_FILES+=usr/include/clang/3.3/mm3dnow.h
OLD_FILES+=usr/include/clang/3.3/mm_malloc.h
OLD_FILES+=usr/include/clang/3.3/mmintrin.h
OLD_FILES+=usr/include/clang/3.3/module.map
OLD_FILES+=usr/include/clang/3.3/nmmintrin.h
OLD_FILES+=usr/include/clang/3.3/pmmintrin.h
OLD_FILES+=usr/include/clang/3.3/popcntintrin.h
OLD_FILES+=usr/include/clang/3.3/prfchwintrin.h
OLD_FILES+=usr/include/clang/3.3/rdseedintrin.h
OLD_FILES+=usr/include/clang/3.3/rtmintrin.h
OLD_FILES+=usr/include/clang/3.3/smmintrin.h
OLD_FILES+=usr/include/clang/3.3/tmmintrin.h
OLD_FILES+=usr/include/clang/3.3/wmmintrin.h
OLD_FILES+=usr/include/clang/3.3/x86intrin.h
OLD_FILES+=usr/include/clang/3.3/xmmintrin.h
OLD_FILES+=usr/include/clang/3.3/xopintrin.h
OLD_FILES+=usr/share/man/man1/llvm-prof.1.gz
OLD_FILES+=usr/share/man/man1/llvm-ranlib.1.gz
OLD_DIRS+=usr/include/clang/3.3
# 20140205: Open Firmware device moved
OLD_FILES+=usr/include/dev/ofw/ofw_nexus.h
# 20140128: libelf and libdwarf import

View File

@ -31,6 +31,9 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 11.x IS SLOW:
disable the most expensive debugging functionality run
"ln -s 'abort:false,junk:false' /etc/malloc.conf".)
20140216:
Clang and llvm have been upgraded to 3.4 release.
20140216:
The nve(4) driver has been removed. Please use the nfe(4) driver
for NVIDIA nForce MCP Ethernet adapters instead.

View File

@ -2007,8 +2007,8 @@ __eprintf (const char *string, const char *expression,
/* Clear part of an instruction cache. */
void
__clear_cache (char *beg __attribute__((__unused__)),
char *end __attribute__((__unused__)))
__clear_cache (void *beg __attribute__((__unused__)),
void *end __attribute__((__unused__)))
{
#ifdef CLEAR_INSN_CACHE
CLEAR_INSN_CACHE (beg, end);

View File

@ -35,7 +35,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
#endif
extern int __gcc_bcmp (const unsigned char *, const unsigned char *, size_t);
extern void __clear_cache (char *, char *);
extern void __clear_cache (void *, void *);
extern void __eprintf (const char *, const char *, unsigned int, const char *)
__attribute__ ((__noreturn__));

View File

@ -68,3 +68,4 @@ Google Test llvm/utils/unittest/googletest
OpenBSD regex llvm/lib/Support/{reg*, COPYRIGHT.regex}
pyyaml tests llvm/test/YAMLParser/{*.data, LICENSE.TXT}
ARM contributions llvm/lib/Target/ARM/LICENSE.TXT
md5 contributions llvm/lib/Support/MD5.cpp llvm/include/llvm/Support/MD5.h

View File

@ -34,7 +34,7 @@ extern "C" {
/* Builds a module from the bitcode in the specified memory buffer, returning a
reference to the module via the OutModule parameter. Returns 0 on success.
Optionally returns a human-readable error message via OutMessage. */
Optionally returns a human-readable error message via OutMessage. */
LLVMBool LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutModule, char **OutMessage);
@ -44,7 +44,7 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
/** Reads a module from the specified path, returning via the OutMP parameter
a module provider which performs lazy deserialization. Returns 0 on success.
Optionally returns a human-readable error message via OutMessage. */
Optionally returns a human-readable error message via OutMessage. */
LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutM,

View File

@ -34,7 +34,7 @@ extern "C" {
/*===-- Operations on modules ---------------------------------------------===*/
/** Writes a module to the specified path. Returns 0 on success. */
/** Writes a module to the specified path. Returns 0 on success. */
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path);
/** Writes a module to an open file descriptor. Returns 0 on success. */
@ -42,7 +42,7 @@ int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
int Unbuffered);
/** Deprecated for LLVMWriteBitcodeToFD. Writes a module to an open file
descriptor. Returns 0 on success. Closes the Handle. */
descriptor. Returns 0 on success. Closes the Handle. */
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int Handle);
/**

View File

@ -165,7 +165,9 @@ typedef enum {
a temporary measure until the API/ABI impact to the C API is understood
and the path forward agreed upon.
LLVMAddressSafety = 1ULL << 32,
LLVMStackProtectStrongAttribute = 1ULL<<33
LLVMStackProtectStrongAttribute = 1ULL<<33,
LLVMCold = 1ULL << 34,
LLVMOptimizeNone = 1ULL << 35
*/
} LLVMAttribute;
@ -220,6 +222,7 @@ typedef enum {
LLVMPtrToInt = 39,
LLVMIntToPtr = 40,
LLVMBitCast = 41,
LLVMAddrSpaceCast = 60,
/* Other Operators */
LLVMICmp = 42,
@ -272,7 +275,7 @@ typedef enum {
LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
equivalent. */
LLVMLinkOnceODRAutoHideLinkage, /**< Like LinkOnceODR, but possibly hidden. */
LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
LLVMWeakODRLinkage, /**< Same, but only replaced by something
equivalent. */
@ -299,6 +302,8 @@ typedef enum {
LLVMCCallConv = 0,
LLVMFastCallConv = 8,
LLVMColdCallConv = 9,
LLVMWebKitJSCallConv = 12,
LLVMAnyRegCallConv = 13,
LLVMX86StdcallCallConv = 64,
LLVMX86FastcallCallConv = 65
} LLVMCallConv;
@ -352,26 +357,26 @@ typedef enum {
LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
somewhat sane results, lock free. */
LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
operations affecting a specific address,
LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
operations affecting a specific address,
a consistent ordering exists */
LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
necessary to acquire a lock to access other
LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
necessary to acquire a lock to access other
memory with normal loads and stores. */
LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
a barrier of the sort necessary to release
LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
a barrier of the sort necessary to release
a lock. */
LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
Release barrier (for fences and
LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
Release barrier (for fences and
operations which both read and write
memory). */
LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
for loads and Release
semantics for stores.
Additionally, it guarantees
that a total ordering exists
between all
SequentiallyConsistent
LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
for loads and Release
semantics for stores.
Additionally, it guarantees
that a total ordering exists
between all
SequentiallyConsistent
operations. */
} LLVMAtomicOrdering;
@ -384,16 +389,16 @@ typedef enum {
LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
original using a signed comparison and return
original using a signed comparison and return
the old one */
LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
original using a signed comparison and return
original using a signed comparison and return
the old one */
LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
original using an unsigned comparison and return
original using an unsigned comparison and return
the old one */
LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
original using an unsigned comparison and return
original using an unsigned comparison and return
the old one */
} LLVMAtomicRMWBinOp;
@ -406,13 +411,37 @@ void LLVMInitializeCore(LLVMPassRegistryRef R);
/** Deallocate and destroy all ManagedStatic variables.
@see llvm::llvm_shutdown
@see ManagedStatic */
void LLVMShutdown();
void LLVMShutdown(void);
/*===-- Error handling ----------------------------------------------------===*/
char *LLVMCreateMessage(const char *Message);
void LLVMDisposeMessage(char *Message);
typedef void (*LLVMFatalErrorHandler)(const char *Reason);
/**
* Install a fatal error handler. By default, if LLVM detects a fatal error, it
* will call exit(1). This may not be appropriate in many contexts. For example,
* doing exit(1) will bypass many crash reporting/tracing system tools. This
* function allows you to install a callback that will be invoked prior to the
* call to exit(1).
*/
void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
/**
* Reset the fatal error handler. This resets LLVM's fatal error handling
* behavior to the default.
*/
void LLVMResetFatalErrorHandler(void);
/**
* Enable LLVM's built-in stack trace code. This intercepts the OS's crash
* signals and prints which component of LLVM you were in at the time if the
* crash.
*/
void LLVMEnablePrettyStackTrace(void);
/**
* @defgroup LLVMCCoreContext Contexts
@ -458,7 +487,7 @@ unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
/**
* @defgroup LLVMCCoreModule Modules
*
* Modules represent the top-level structure in a LLVM program. An LLVM
* Modules represent the top-level structure in an LLVM program. An LLVM
* module is effectively a translation unit or a collection of
* translation units merged together.
*
@ -537,6 +566,14 @@ void LLVMDumpModule(LLVMModuleRef M);
LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
char **ErrorMessage);
/**
* Return a string representation of the module. Use
* LLVMDisposeMessage to free the string.
*
* @see Module::print()
*/
char *LLVMPrintModuleToString(LLVMModuleRef M);
/**
* Set inline assembly for a module.
*
@ -688,6 +725,21 @@ LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
*/
LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
/**
* Dump a representation of a type to stderr.
*
* @see llvm::Type::dump()
*/
void LLVMDumpType(LLVMTypeRef Val);
/**
* Return a string representation of the type. Use
* LLVMDisposeMessage to free the string.
*
* @see llvm::Type::print()
*/
char *LLVMPrintTypeToString(LLVMTypeRef Val);
/**
* @defgroup LLVMCCoreTypeInt Integer Types
*
@ -1039,7 +1091,7 @@ LLVMTypeRef LLVMX86MMXType(void);
* hierarchy of classes within this type. Depending on the instance
* obtained, not all APIs are available.
*
* Callers can determine the type of a LLVMValueRef by calling the
* Callers can determine the type of an LLVMValueRef by calling the
* LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
* functions are defined by a macro, so it isn't obvious which are
* available by looking at the Doxygen source code. Instead, look at the
@ -1061,6 +1113,9 @@ LLVMTypeRef LLVMX86MMXType(void);
macro(BlockAddress) \
macro(ConstantAggregateZero) \
macro(ConstantArray) \
macro(ConstantDataSequential) \
macro(ConstantDataArray) \
macro(ConstantDataVector) \
macro(ConstantExpr) \
macro(ConstantFP) \
macro(ConstantInt) \
@ -1105,6 +1160,7 @@ LLVMTypeRef LLVMX86MMXType(void);
macro(UnaryInstruction) \
macro(AllocaInst) \
macro(CastInst) \
macro(AddrSpaceCastInst) \
macro(BitCastInst) \
macro(FPExtInst) \
macro(FPToSIInst) \
@ -1159,6 +1215,14 @@ void LLVMSetValueName(LLVMValueRef Val, const char *Name);
*/
void LLVMDumpValue(LLVMValueRef Val);
/**
* Return a string representation of the value. Use
* LLVMDisposeMessage to free the string.
*
* @see llvm::Value::print()
*/
char *LLVMPrintValueToString(LLVMValueRef Val);
/**
* Replace all uses of a value with another one.
*
@ -1179,7 +1243,7 @@ LLVMBool LLVMIsUndef(LLVMValueRef Val);
/**
* Convert value instances between types.
*
* Internally, a LLVMValueRef is "pinned" to a specific type. This
* Internally, an LLVMValueRef is "pinned" to a specific type. This
* series of functions allows you to cast an instance to a specific
* type.
*
@ -1201,7 +1265,7 @@ LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
* This module defines functions that allow you to inspect the uses of a
* LLVMValueRef.
*
* It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
* It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
* Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
* llvm::User and llvm::Value.
*
@ -1568,6 +1632,7 @@ LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
LLVMTypeRef ToType);
LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
@ -1623,8 +1688,33 @@ const char *LLVMGetSection(LLVMValueRef Global);
void LLVMSetSection(LLVMValueRef Global, const char *Section);
LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
unsigned LLVMGetAlignment(LLVMValueRef Global);
void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
/**
* @defgroup LLVMCCoreValueWithAlignment Values with alignment
*
* Functions in this group only apply to values with alignment, i.e.
* global variables, load and store instructions.
*/
/**
* Obtain the preferred alignment of the value.
* @see llvm::LoadInst::getAlignment()
* @see llvm::StoreInst::getAlignment()
* @see llvm::GlobalValue::getAlignment()
*/
unsigned LLVMGetAlignment(LLVMValueRef V);
/**
* Set the preferred alignment of the value.
* @see llvm::LoadInst::setAlignment()
* @see llvm::StoreInst::setAlignment()
* @see llvm::GlobalValue::setAlignment()
*/
void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
/**
* @}
*/
/**
* @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
@ -1804,7 +1894,7 @@ LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
/**
* Obtain the function to which this argument belongs.
*
* Unlike other functions in this group, this one takes a LLVMValueRef
* Unlike other functions in this group, this one takes an LLVMValueRef
* that corresponds to a llvm::Attribute.
*
* The returned LLVMValueRef is the llvm::Function to which this
@ -1829,7 +1919,7 @@ LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
/**
* Obtain the next parameter to a function.
*
* This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
* This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
* actually a wrapped iterator) and obtains the next parameter from the
* underlying iterator.
*/
@ -1978,12 +2068,12 @@ void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
/**
* Determine whether a LLVMValueRef is itself a basic block.
* Determine whether an LLVMValueRef is itself a basic block.
*/
LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
/**
* Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
* Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
*/
LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
@ -2140,7 +2230,7 @@ LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
/**
* Obtain the last instruction in a basic block.
*
* The returned LLVMValueRef corresponds to a LLVM:Instruction.
* The returned LLVMValueRef corresponds to an LLVM:Instruction.
*/
LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
@ -2322,12 +2412,12 @@ void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
/**
* Obtain an incoming value to a PHI node as a LLVMValueRef.
* Obtain an incoming value to a PHI node as an LLVMValueRef.
*/
LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
/**
* Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
* Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
*/
LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
@ -2518,6 +2608,8 @@ LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
LLVMTypeRef DestTy, const char *Name);
LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
LLVMTypeRef DestTy, const char *Name);
LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
LLVMTypeRef DestTy, const char *Name);
LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
LLVMTypeRef DestTy, const char *Name);
LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
@ -2571,9 +2663,9 @@ LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
const char *Name);
LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
LLVMValueRef RHS, const char *Name);
LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B,LLVMAtomicRMWBinOp op,
LLVMValueRef PTR, LLVMValueRef Val,
LLVMAtomicOrdering ordering,
LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B,LLVMAtomicRMWBinOp op,
LLVMValueRef PTR, LLVMValueRef Val,
LLVMAtomicOrdering ordering,
LLVMBool singleThread);
/**
@ -2706,16 +2798,16 @@ void LLVMDisposePassManager(LLVMPassManagerRef PM);
initialization succeeded. Must be executed in isolation from all
other LLVM api calls.
@see llvm::llvm_start_multithreaded */
LLVMBool LLVMStartMultithreaded();
LLVMBool LLVMStartMultithreaded(void);
/** Deallocate structures necessary to make LLVM safe for multithreading.
Must be executed in isolation from all other LLVM api calls.
@see llvm::llvm_stop_multithreaded */
void LLVMStopMultithreaded();
void LLVMStopMultithreaded(void);
/** Check whether LLVM is executing in thread-safe mode or not.
@see llvm::llvm_is_multithreaded */
LLVMBool LLVMIsMultithreaded();
LLVMBool LLVMIsMultithreaded(void);
/**
* @}

View File

@ -42,7 +42,7 @@ typedef void *LLVMDisasmContextRef;
* instruction are specified by the Offset parameter and its byte widith is the
* size parameter. For instructions sets with fixed widths and one symbolic
* operand per instruction, the Offset parameter will be zero and Size parameter
* will be the instruction width. The information is returned in TagBuf and is
* will be the instruction width. The information is returned in TagBuf and is
* Triple specific with its specific information defined by the value of
* TagType for that Triple. If symbolic information is returned the function
* returns 1, otherwise it returns 0.
@ -58,7 +58,7 @@ typedef int (*LLVMOpInfoCallback)(void *DisInfo, uint64_t PC,
* SubtractSymbol can be link edited independent of each other. Many other
* platforms only allow a relocatable expression of the form AddSymbol + Offset
* to be encoded.
*
*
* The LLVMOpInfoCallback() for the TagType value of 1 uses the struct
* LLVMOpInfo1. The value of the relocatable expression for the operand,
* including any PC adjustment, is passed in to the call back in the Value
@ -130,6 +130,17 @@ typedef const char *(*LLVMSymbolLookupCallback)(void *DisInfo,
/* The output reference is to a cstring address in a literal pool. */
#define LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr 3
/* The output reference is to a Objective-C CoreFoundation string. */
#define LLVMDisassembler_ReferenceType_Out_Objc_CFString_Ref 4
/* The output reference is to a Objective-C message. */
#define LLVMDisassembler_ReferenceType_Out_Objc_Message 5
/* The output reference is to a Objective-C message ref. */
#define LLVMDisassembler_ReferenceType_Out_Objc_Message_Ref 6
/* The output reference is to a Objective-C selector ref. */
#define LLVMDisassembler_ReferenceType_Out_Objc_Selector_Ref 7
/* The output reference is to a Objective-C class ref. */
#define LLVMDisassembler_ReferenceType_Out_Objc_Class_Ref 8
#ifdef __cplusplus
extern "C" {
#endif /* !defined(__cplusplus) */
@ -170,6 +181,10 @@ int LLVMSetDisasmOptions(LLVMDisasmContextRef DC, uint64_t Options);
#define LLVMDisassembler_Option_PrintImmHex 2
/* The option use the other assembler printer variant */
#define LLVMDisassembler_Option_AsmPrinterVariant 4
/* The option to set comment on instructions */
#define LLVMDisassembler_Option_SetInstrComments 8
/* The option to print latency information alongside instructions */
#define LLVMDisassembler_Option_PrintLatency 16
/**
* Dispose of a disassembler context.

View File

@ -40,12 +40,14 @@ void LLVMLinkInInterpreter(void);
typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
typedef struct LLVMOpaqueMCJITMemoryManager *LLVMMCJITMemoryManagerRef;
struct LLVMMCJITCompilerOptions {
unsigned OptLevel;
LLVMCodeModel CodeModel;
LLVMBool NoFramePointerElim;
LLVMBool EnableFastISel;
LLVMMCJITMemoryManagerRef MCJMM;
};
/*===-- Operations on generic values --------------------------------------===*/
@ -167,12 +169,44 @@ void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
/*===-- Operations on memory managers -------------------------------------===*/
typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(
void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
const char *SectionName);
typedef uint8_t *(*LLVMMemoryManagerAllocateDataSectionCallback)(
void *Opaque, uintptr_t Size, unsigned Alignment, unsigned SectionID,
const char *SectionName, LLVMBool IsReadOnly);
typedef LLVMBool (*LLVMMemoryManagerFinalizeMemoryCallback)(
void *Opaque, char **ErrMsg);
typedef void (*LLVMMemoryManagerDestroyCallback)(void *Opaque);
/**
* Create a simple custom MCJIT memory manager. This memory manager can
* intercept allocations in a module-oblivious way. This will return NULL
* if any of the passed functions are NULL.
*
* @param Opaque An opaque client object to pass back to the callbacks.
* @param AllocateCodeSection Allocate a block of memory for executable code.
* @param AllocateDataSection Allocate a block of memory for data.
* @param FinalizeMemory Set page permissions and flush cache. Return 0 on
* success, 1 on error.
*/
LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
void *Opaque,
LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
LLVMMemoryManagerDestroyCallback Destroy);
void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM);
/**
* @}
*/
#ifdef __cplusplus
}
}
#endif /* defined(__cplusplus) */
#endif

View File

@ -0,0 +1,40 @@
/*===-- llvm-c/IRReader.h - IR Reader C Interface -----------------*- C -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
|* This file is distributed under the University of Illinois Open Source *|
|* License. See LICENSE.TXT for details. *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
|* This file defines the C interface to the IR Reader. *|
|* *|
\*===----------------------------------------------------------------------===*/
#ifndef LLVM_C_IRREADER_H
#define LLVM_C_IRREADER_H
#include "llvm-c/Core.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Read LLVM IR from a memory buffer and convert it into an in-memory Module
* object. Returns 0 on success.
* Optionally returns a human-readable description of any errors that
* occured during parsing IR. OutMessage must be disposed with
* LLVMDisposeMessage.
*
* @see llvm::ParseIR()
*/
LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
char **OutMessage);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -4,7 +4,7 @@
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//
//===----------------------------------------------------------------------===//
//
// This header provides a C API to use the LLVM link time optimization
@ -46,7 +46,7 @@ extern "C" {
// Added C-specific error codes
LLVM_LTO_NULL_OBJECT
} llvm_lto_status_t;
/// This provides C interface to initialize link time optimizer. This allows
/// linker to use dlopen() interface to dynamically load LinkTimeOptimizer.
/// extern "C" helps, because dlopen() interface uses name to find the symbol.

View File

@ -100,4 +100,3 @@ const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI);
#endif /* defined(__cplusplus) */
#endif

View File

@ -0,0 +1,35 @@
/*===-- llvm-c/Support.h - Support C Interface --------------------*- C -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
|* This file is distributed under the University of Illinois Open Source *|
|* License. See LICENSE.TXT for details. *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
|* This file defines the C interface to the LLVM support library. *|
|* *|
\*===----------------------------------------------------------------------===*/
#ifndef LLVM_C_SUPPORT_H
#define LLVM_C_SUPPORT_H
#include "llvm-c/Core.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* This function permanently loads the dynamic library at the given path.
* It is safe to call this function multiple times for the same library.
*
* @see sys::DynamicLibrary::LoadLibraryPermanently()
*/
LLVMBool LLVMLoadLibraryPermanently(const char* Filename);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -22,6 +22,10 @@
#include "llvm-c/Core.h"
#include "llvm/Config/llvm-config.h"
#if defined(_MSC_VER) && !defined(inline)
#define inline __inline
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -37,14 +41,13 @@ enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
typedef struct LLVMStructLayout *LLVMStructLayoutRef;
/* Declare all of the target-initialization functions that are available. */
#define LLVM_TARGET(TargetName) \
void LLVMInitialize##TargetName##TargetInfo(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
@ -53,7 +56,7 @@ typedef struct LLVMStructLayout *LLVMStructLayoutRef;
void LLVMInitialize##TargetName##TargetMC(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
/* Declare all of the available assembly printer initialization functions. */
#define LLVM_ASM_PRINTER(TargetName) \
void LLVMInitialize##TargetName##AsmPrinter(void);
@ -71,7 +74,7 @@ typedef struct LLVMStructLayout *LLVMStructLayoutRef;
void LLVMInitialize##TargetName##Disassembler(void);
#include "llvm/Config/Disassemblers.def"
#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
/** LLVMInitializeAllTargetInfos - The main program should call this function if
it wants access to all available targets that LLVM is configured to
support. */
@ -98,7 +101,7 @@ static inline void LLVMInitializeAllTargetMCs(void) {
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
}
/** LLVMInitializeAllAsmPrinters - The main program should call this function if
it wants all asm printers that LLVM is configured to support, to make them
available via the TargetRegistry. */
@ -107,7 +110,7 @@ static inline void LLVMInitializeAllAsmPrinters(void) {
#include "llvm/Config/AsmPrinters.def"
#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
}
/** LLVMInitializeAllAsmParsers - The main program should call this function if
it wants all asm parsers that LLVM is configured to support, to make them
available via the TargetRegistry. */
@ -116,7 +119,7 @@ static inline void LLVMInitializeAllAsmParsers(void) {
#include "llvm/Config/AsmParsers.def"
#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
}
/** LLVMInitializeAllDisassemblers - The main program should call this function
if it wants all disassemblers that LLVM is configured to support, to make
them available via the TargetRegistry. */
@ -126,9 +129,9 @@ static inline void LLVMInitializeAllDisassemblers(void) {
#include "llvm/Config/Disassemblers.def"
#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
}
/** LLVMInitializeNativeTarget - The main program should call this function to
initialize the native target corresponding to the host. This is useful
initialize the native target corresponding to the host. This is useful
for JIT applications to ensure that the target gets linked in correctly. */
static inline LLVMBool LLVMInitializeNativeTarget(void) {
/* If we have a native target, initialize it to ensure it is linked in. */
@ -140,7 +143,43 @@ static inline LLVMBool LLVMInitializeNativeTarget(void) {
#else
return 1;
#endif
}
}
/** LLVMInitializeNativeTargetAsmParser - The main program should call this
function to initialize the parser for the native target corresponding to the
host. */
static inline LLVMBool LLVMInitializeNativeAsmParser(void) {
#ifdef LLVM_NATIVE_ASMPARSER
LLVM_NATIVE_ASMPARSER();
return 0;
#else
return 1;
#endif
}
/** LLVMInitializeNativeTargetAsmPrinter - The main program should call this
function to initialize the printer for the native target corresponding to
the host. */
static inline LLVMBool LLVMInitializeNativeAsmPrinter(void) {
#ifdef LLVM_NATIVE_ASMPRINTER
LLVM_NATIVE_ASMPRINTER();
return 0;
#else
return 1;
#endif
}
/** LLVMInitializeNativeTargetDisassembler - The main program should call this
function to initialize the disassembler for the native target corresponding
to the host. */
static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
#ifdef LLVM_NATIVE_DISASSEMBLER
LLVM_NATIVE_DISASSEMBLER();
return 0;
#else
return 1;
#endif
}
/*===-- Target Data -------------------------------------------------------===*/
@ -151,83 +190,94 @@ LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
/** Adds target data information to a pass manager. This does not take ownership
of the target data.
See the method llvm::PassManagerBase::add. */
void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM);
/** Adds target library information to a pass manager. This does not take
ownership of the target library info.
See the method llvm::PassManagerBase::add. */
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
LLVMPassManagerRef PM);
/** Converts target data to a target layout string. The string must be disposed
with LLVMDisposeMessage.
See the constructor llvm::DataLayout::DataLayout. */
char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
/** Returns the byte order of a target, either LLVMBigEndian or
LLVMLittleEndian.
See the method llvm::DataLayout::isLittleEndian. */
enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
/** Returns the pointer size in bytes for a target.
See the method llvm::DataLayout::getPointerSize. */
unsigned LLVMPointerSize(LLVMTargetDataRef);
unsigned LLVMPointerSize(LLVMTargetDataRef TD);
/** Returns the pointer size in bytes for a target for a specified
address space.
See the method llvm::DataLayout::getPointerSize. */
unsigned LLVMPointerSizeForAS(LLVMTargetDataRef, unsigned AS);
unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
/** Returns the integer type that is the same size as a pointer on a target.
See the method llvm::DataLayout::getIntPtrType. */
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
/** Returns the integer type that is the same size as a pointer on a target.
This version allows the address space to be specified.
See the method llvm::DataLayout::getIntPtrType. */
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef, unsigned AS);
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
/** Returns the integer type that is the same size as a pointer on a target.
See the method llvm::DataLayout::getIntPtrType. */
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
/** Returns the integer type that is the same size as a pointer on a target.
This version allows the address space to be specified.
See the method llvm::DataLayout::getIntPtrType. */
LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
unsigned AS);
/** Computes the size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeSizeInBits. */
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the storage size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeStoreSize. */
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the ABI size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeAllocSize. */
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the ABI alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. */
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the call frame alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. */
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the preferred alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. */
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
/** Computes the preferred alignment of a global variable in bytes for a target.
See the method llvm::DataLayout::getPreferredAlignment. */
unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
LLVMValueRef GlobalVar);
/** Computes the structure element that contains the byte offset for a target.
See the method llvm::StructLayout::getElementContainingOffset. */
unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
unsigned long long Offset);
/** Computes the byte offset of the indexed struct element for a target.
See the method llvm::StructLayout::getElementContainingOffset. */
unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
unsigned Element);
unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
LLVMTypeRef StructTy, unsigned Element);
/** Deallocates a TargetData.
See the destructor llvm::DataLayout::~DataLayout. */
void LLVMDisposeTargetData(LLVMTargetDataRef);
void LLVMDisposeTargetData(LLVMTargetDataRef TD);
/**
* @}

View File

@ -57,11 +57,21 @@ typedef enum {
} LLVMCodeGenFileType;
/** Returns the first llvm::Target in the registered targets list. */
LLVMTargetRef LLVMGetFirstTarget();
LLVMTargetRef LLVMGetFirstTarget(void);
/** Returns the next llvm::Target given a previous one (or null if there's none) */
LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
/*===-- Target ------------------------------------------------------------===*/
/** Finds the target corresponding to the given name and stores it in \p T.
Returns 0 on success. */
LLVMTargetRef LLVMGetTargetFromName(const char *Name);
/** Finds the target corresponding to the given triple and stores it in \p T.
Returns 0 on success. Optionally returns any error in ErrorMessage.
Use LLVMDisposeMessage to dispose the message. */
LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T,
char **ErrorMessage);
/** Returns the name of a target. See llvm::Target::getName */
const char *LLVMGetTargetName(LLVMTargetRef T);
@ -79,9 +89,9 @@ LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
/*===-- Target Machine ----------------------------------------------------===*/
/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, char *Triple,
char *CPU, char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
LLVMCodeModel CodeModel);
LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
const char *Triple, const char *CPU, const char *Features,
LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
/** Dispose the LLVMTargetMachineRef instance generated by
LLVMCreateTargetMachine. */
@ -108,6 +118,10 @@ char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
/** Returns the llvm::DataLayout used for this llvm:TargetMachine. */
LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);
/** Set the target machine's ASM verbosity. */
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
LLVMBool VerboseAsm);
/** Emits an asm or object file for the given module to the filename. This
wraps several c++ only classes (among them a file stream). Returns any
error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
@ -117,6 +131,12 @@ LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
/*===-- Triple ------------------------------------------------------------===*/
/** Get a triple for the host machine as a string. The result needs to be
disposed with LLVMDisposeMessage. */
char* LLVMGetDefaultTargetTriple(void);
#ifdef __cplusplus
}
#endif

View File

@ -65,6 +65,9 @@ void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM);
/** See llvm::createLoopRotatePass function. */
void LLVMAddLoopRotatePass(LLVMPassManagerRef PM);
/** See llvm::createLoopRerollPass function. */
void LLVMAddLoopRerollPass(LLVMPassManagerRef PM);
/** See llvm::createLoopUnrollPass function. */
void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM);
@ -74,6 +77,9 @@ void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM);
/** See llvm::createMemCpyOptPass function. */
void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM);
/** See llvm::createPartiallyInlineLibCallsPass function. */
void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM);
/** See llvm::createPromoteMemoryToRegisterPass function. */
void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM);

View File

@ -16,9 +16,22 @@
#ifndef LLVM_C_LTO_H
#define LLVM_C_LTO_H
#include <stdbool.h>
#include <stddef.h>
#include <unistd.h>
#include <sys/types.h>
#ifndef __cplusplus
#if !defined(_MSC_VER)
#include <stdbool.h>
typedef bool lto_bool_t;
#else
/* MSVC in particular does not have anything like _Bool or bool in C, but we can
at least make sure the type is the same size. The implementation side will
use C++ bool. */
typedef unsigned char lto_bool_t;
#endif
#else
typedef bool lto_bool_t;
#endif
/**
* @defgroup LLVMCLTO LTO
@ -27,7 +40,7 @@
* @{
*/
#define LTO_API_VERSION 4
#define LTO_API_VERSION 5
typedef enum {
LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */
@ -87,14 +100,14 @@ lto_get_error_message(void);
/**
* Checks if a file is a loadable object file.
*/
extern bool
extern lto_bool_t
lto_module_is_object_file(const char* path);
/**
* Checks if a file is a loadable object compiled for requested target.
*/
extern bool
extern lto_bool_t
lto_module_is_object_file_for_target(const char* path,
const char* target_triple_prefix);
@ -102,14 +115,14 @@ lto_module_is_object_file_for_target(const char* path,
/**
* Checks if a buffer is a loadable object file.
*/
extern bool
extern lto_bool_t
lto_module_is_object_file_in_memory(const void* mem, size_t length);
/**
* Checks if a buffer is a loadable object compiled for requested target.
*/
extern bool
extern lto_bool_t
lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length,
const char* target_triple_prefix);
@ -208,7 +221,7 @@ lto_codegen_dispose(lto_code_gen_t);
* Add an object module to the set of modules for which code will be generated.
* Returns true on error (check lto_get_error_message() for details).
*/
extern bool
extern lto_bool_t
lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
@ -217,7 +230,7 @@ lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
* Sets if debug info should be generated.
* Returns true on error (check lto_get_error_message() for details).
*/
extern bool
extern lto_bool_t
lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
@ -225,7 +238,7 @@ lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
* Sets which PIC code model to generated.
* Returns true on error (check lto_get_error_message() for details).
*/
extern bool
extern lto_bool_t
lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
@ -251,9 +264,8 @@ lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
int nargs);
/**
* Adds to a list of all global symbols that must exist in the final
* generated code. If a function is not listed, it might be
* inlined into every usage and optimized away.
* Tells LTO optimization passes that this symbol must be preserved
* because it is referenced by native code or a command line option.
*/
extern void
lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
@ -263,7 +275,7 @@ lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
* merged contents of all modules added so far.
* Returns true on error (check lto_get_error_message() for details).
*/
extern bool
extern lto_bool_t
lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
/**
@ -281,7 +293,7 @@ lto_codegen_compile(lto_code_gen_t cg, size_t* length);
* Generates code for all added modules into one native object file.
* The name of the file is written to name. Returns true on error.
*/
extern bool
extern lto_bool_t
lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -68,18 +68,18 @@ public:
}
using APInt::toString;
APSInt trunc(uint32_t width) const {
APSInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(uint32_t width) const {
return APSInt(APInt::trunc(width), IsUnsigned);
}
APSInt extend(uint32_t width) const {
APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extend(uint32_t width) const {
if (IsUnsigned)
return APSInt(zext(width), IsUnsigned);
else
return APSInt(sext(width), IsUnsigned);
}
APSInt extOrTrunc(uint32_t width) const {
APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extOrTrunc(uint32_t width) const {
if (IsUnsigned)
return APSInt(zextOrTrunc(width), IsUnsigned);
else
@ -212,7 +212,7 @@ public:
assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
return APSInt(static_cast<const APInt&>(*this) & RHS, IsUnsigned);
}
APSInt And(const APSInt& RHS) const {
APSInt LLVM_ATTRIBUTE_UNUSED_RESULT And(const APSInt& RHS) const {
return this->operator&(RHS);
}
@ -220,7 +220,7 @@ public:
assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
return APSInt(static_cast<const APInt&>(*this) | RHS, IsUnsigned);
}
APSInt Or(const APSInt& RHS) const {
APSInt LLVM_ATTRIBUTE_UNUSED_RESULT Or(const APSInt& RHS) const {
return this->operator|(RHS);
}
@ -229,7 +229,7 @@ public:
assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
return APSInt(static_cast<const APInt&>(*this) ^ RHS, IsUnsigned);
}
APSInt Xor(const APSInt& RHS) const {
APSInt LLVM_ATTRIBUTE_UNUSED_RESULT Xor(const APSInt& RHS) const {
return this->operator^(RHS);
}

View File

@ -80,9 +80,16 @@ namespace llvm {
/// Construct an ArrayRef from a C array.
template <size_t N>
/*implicit*/ ArrayRef(const T (&Arr)[N])
/*implicit*/ LLVM_CONSTEXPR ArrayRef(const T (&Arr)[N])
: Data(Arr), Length(N) {}
#if LLVM_HAS_INITIALIZER_LISTS
/// Construct an ArrayRef from a std::initializer_list.
/*implicit*/ ArrayRef(const std::initializer_list<T> &Vec)
: Data(Vec.begin() == Vec.end() ? (T*)0 : Vec.begin()),
Length(Vec.size()) {}
#endif
/// @}
/// @name Simple Operations
/// @{
@ -178,6 +185,8 @@ namespace llvm {
public:
typedef T *iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
/// Construct an empty MutableArrayRef.
/*implicit*/ MutableArrayRef() : ArrayRef<T>() {}
@ -212,6 +221,9 @@ namespace llvm {
iterator begin() const { return data(); }
iterator end() const { return data() + this->size(); }
reverse_iterator rbegin() const { return reverse_iterator(end()); }
reverse_iterator rend() const { return reverse_iterator(begin()); }
/// front - Get the first element.
T &front() const {
assert(!this->empty());

View File

@ -138,8 +138,15 @@ public:
/// all - Returns true if all bits are set.
bool all() const {
// TODO: Optimize this.
return count() == size();
for (unsigned i = 0; i < Size / BITWORD_SIZE; ++i)
if (Bits[i] != ~0UL)
return false;
// If bits remain check that they are ones. The unused bits are always zero.
if (unsigned Remainder = Size % BITWORD_SIZE)
return Bits[Size / BITWORD_SIZE] == (1UL << Remainder) - 1;
return true;
}
/// none - Returns true if none of the bits are set.
@ -153,9 +160,9 @@ public:
for (unsigned i = 0; i < NumBitWords(size()); ++i)
if (Bits[i] != 0) {
if (sizeof(BitWord) == 4)
return i * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Bits[i]);
return i * BITWORD_SIZE + countTrailingZeros((uint32_t)Bits[i]);
if (sizeof(BitWord) == 8)
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
llvm_unreachable("Unsupported!");
}
return -1;
@ -176,9 +183,9 @@ public:
if (Copy != 0) {
if (sizeof(BitWord) == 4)
return WordPos * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Copy);
return WordPos * BITWORD_SIZE + countTrailingZeros((uint32_t)Copy);
if (sizeof(BitWord) == 8)
return WordPos * BITWORD_SIZE + CountTrailingZeros_64(Copy);
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
llvm_unreachable("Unsupported!");
}
@ -186,9 +193,9 @@ public:
for (unsigned i = WordPos+1; i < NumBitWords(size()); ++i)
if (Bits[i] != 0) {
if (sizeof(BitWord) == 4)
return i * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Bits[i]);
return i * BITWORD_SIZE + countTrailingZeros((uint32_t)Bits[i]);
if (sizeof(BitWord) == 8)
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
llvm_unreachable("Unsupported!");
}
return -1;

View File

@ -64,7 +64,9 @@ public:
return const_iterator(getBucketsEnd(), getBucketsEnd(), true);
}
bool empty() const { return getNumEntries() == 0; }
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {
return getNumEntries() == 0;
}
unsigned size() const { return getNumEntries(); }
/// Grow the densemap so that it has at least Size buckets. Does not shrink
@ -222,11 +224,11 @@ public:
if (LookupBucketFor(Key, TheBucket))
return *TheBucket;
return *InsertIntoBucket(Key, ValueT(), TheBucket);
return *InsertIntoBucket(std::move(Key), ValueT(), TheBucket);
}
ValueT &operator[](KeyT &&Key) {
return FindAndConstruct(Key).second;
return FindAndConstruct(std::move(Key)).second;
}
#endif
@ -436,9 +438,8 @@ private:
this->grow(NumBuckets * 2);
LookupBucketFor(Key, TheBucket);
NumBuckets = getNumBuckets();
}
if (NumBuckets-(NewNumEntries+getNumTombstones()) <= NumBuckets/8) {
this->grow(NumBuckets * 2);
} else if (NumBuckets-(NewNumEntries+getNumTombstones()) <= NumBuckets/8) {
this->grow(NumBuckets);
LookupBucketFor(Key, TheBucket);
}
assert(TheBucket);
@ -713,13 +714,13 @@ public:
init(NumInitBuckets);
}
SmallDenseMap(const SmallDenseMap &other) {
SmallDenseMap(const SmallDenseMap &other) : BaseT() {
init(0);
copyFrom(other);
}
#if LLVM_HAS_RVALUE_REFERENCES
SmallDenseMap(SmallDenseMap &&other) {
SmallDenseMap(SmallDenseMap &&other) : BaseT() {
init(0);
swap(other);
}

View File

@ -352,7 +352,8 @@ template<class T> class FoldingSetBucketIterator;
template<typename T>
inline bool
DefaultFoldingSetTrait<T>::Equals(T &X, const FoldingSetNodeID &ID,
unsigned IDHash, FoldingSetNodeID &TempID) {
unsigned /*IDHash*/,
FoldingSetNodeID &TempID) {
FoldingSetTrait<T>::Profile(X, TempID);
return TempID == ID;
}
@ -366,7 +367,7 @@ template<typename T, typename Ctx>
inline bool
DefaultContextualFoldingSetTrait<T, Ctx>::Equals(T &X,
const FoldingSetNodeID &ID,
unsigned IDHash,
unsigned /*IDHash*/,
FoldingSetNodeID &TempID,
Ctx Context) {
ContextualFoldingSetTrait<T, Ctx>::Profile(X, TempID, Context);

View File

@ -211,6 +211,7 @@ public:
friend class ImmutableMap;
public:
typedef ptrdiff_t difference_type;
typedef typename ImmutableMap<KeyT,ValT,ValInfo>::value_type value_type;
typedef typename ImmutableMap<KeyT,ValT,ValInfo>::value_type_ref reference;
typedef typename iterator::value_type *pointer;

View File

@ -851,6 +851,18 @@ PROFILE_INTEGER_INFO(unsigned long long)
#undef PROFILE_INTEGER_INFO
/// Profile traits for booleans.
template <>
struct ImutProfileInfo<bool> {
typedef const bool value_type;
typedef const bool& value_type_ref;
static inline void Profile(FoldingSetNodeID& ID, value_type_ref X) {
ID.AddBoolean(X);
}
};
/// Generic profile trait for pointer types. We treat pointers as
/// references to unique objects.
template <typename T>
@ -1060,6 +1072,7 @@ public:
friend class ImmutableSet<ValT,ValInfo>;
public:
typedef ptrdiff_t difference_type;
typedef typename ImmutableSet<ValT,ValInfo>::value_type value_type;
typedef typename ImmutableSet<ValT,ValInfo>::value_type_ref reference;
typedef typename iterator::value_type *pointer;

View File

@ -496,7 +496,7 @@ public:
NodeRef() {}
/// operator bool - Detect a null ref.
operator bool() const { return pip.getOpaqueValue(); }
LLVM_EXPLICIT operator bool() const { return pip.getOpaqueValue(); }
/// NodeRef - Create a reference to the node p with n elements.
template <typename NodeT>
@ -612,7 +612,7 @@ public:
/// insertFrom - Add mapping of [a;b] to y if possible, coalescing as much as
/// possible. This may cause the node to grow by 1, or it may cause the node
/// to shrink because of coalescing.
/// @param i Starting index = insertFrom(0, size, a)
/// @param Pos Starting index = insertFrom(0, size, a)
/// @param Size Number of elements in node.
/// @param a Interval start.
/// @param b Interval stop.
@ -1956,7 +1956,7 @@ iterator::eraseNode(unsigned Level) {
/// overflow - Distribute entries of the current node evenly among
/// its siblings and ensure that the current node is not full.
/// This may require allocating a new node.
/// @param NodeT The type of node at Level (Leaf or Branch).
/// @tparam NodeT The type of node at Level (Leaf or Branch).
/// @param Level path index of the overflowing node.
/// @return True when the tree height was changed.
template <typename KeyT, typename ValT, unsigned N, typename Traits>

View File

@ -1,52 +0,0 @@
//===- llvm/ADT/NullablePtr.h - A pointer that allows null ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines and implements the NullablePtr class.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_ADT_NULLABLEPTR_H
#define LLVM_ADT_NULLABLEPTR_H
#include <cassert>
#include <cstddef>
namespace llvm {
/// NullablePtr pointer wrapper - NullablePtr is used for APIs where a
/// potentially-null pointer gets passed around that must be explicitly handled
/// in lots of places. By putting a wrapper around the null pointer, it makes
/// it more likely that the null pointer case will be handled correctly.
template<class T>
class NullablePtr {
T *Ptr;
public:
NullablePtr(T *P = 0) : Ptr(P) {}
bool isNull() const { return Ptr == 0; }
bool isNonNull() const { return Ptr != 0; }
/// get - Return the pointer if it is non-null.
const T *get() const {
assert(Ptr && "Pointer wasn't checked for null!");
return Ptr;
}
/// get - Return the pointer if it is non-null.
T *get() {
assert(Ptr && "Pointer wasn't checked for null!");
return Ptr;
}
T *getPtrOrNull() { return Ptr; }
const T *getPtrOrNull() const { return Ptr; }
};
} // end namespace llvm
#endif

View File

@ -70,8 +70,9 @@ public:
T *operator->() const { return Ptr; }
T *get() const { return Ptr; }
operator bool() const { return Ptr != 0; }
LLVM_EXPLICIT operator bool() const { return Ptr != 0; }
bool operator!() const { return Ptr == 0; }
bool isValid() const { return Ptr != 0; }
void swap(OwningPtr &RHS) {
T *Tmp = RHS.Ptr;
@ -132,7 +133,7 @@ public:
}
T *get() const { return Ptr; }
operator bool() const { return Ptr != 0; }
LLVM_EXPLICIT operator bool() const { return Ptr != 0; }
bool operator!() const { return Ptr == 0; }
void swap(OwningArrayPtr &RHS) {

View File

@ -14,6 +14,7 @@
#ifndef LLVM_ADT_POINTERINTPAIR_H
#define LLVM_ADT_POINTERINTPAIR_H
#include "llvm/Support/Compiler.h"
#include "llvm/Support/PointerLikeTypeTraits.h"
#include <cassert>
@ -40,7 +41,7 @@ template <typename PointerTy, unsigned IntBits, typename IntType=unsigned,
typename PtrTraits = PointerLikeTypeTraits<PointerTy> >
class PointerIntPair {
intptr_t Value;
enum {
enum LLVM_ENUM_INT_TYPE(uintptr_t) {
/// PointerBitMask - The bits that come from the pointer.
PointerBitMask =
~(uintptr_t)(((intptr_t)1 << PtrTraits::NumLowBitsAvailable)-1),

View File

@ -15,6 +15,7 @@
#ifndef LLVM_ADT_POINTERUNION_H
#define LLVM_ADT_POINTERUNION_H
#include "llvm/Support/Compiler.h"
#include "llvm/ADT/PointerIntPair.h"
namespace llvm {
@ -71,7 +72,7 @@ namespace llvm {
/// printf("%d %d", P.is<int*>(), P.is<float*>()); // prints "1 0"
/// X = P.get<int*>(); // ok.
/// Y = P.get<float*>(); // runtime assertion failure.
/// Z = P.get<double*>(); // runtime assertion failure (regardless of tag)
/// Z = P.get<double*>(); // compile time failure.
/// P = (float*)0;
/// Y = P.get<float*>(); // ok.
/// X = P.get<int*>(); // runtime assertion failure.
@ -109,7 +110,7 @@ namespace llvm {
// we recursively strip off low bits if we have a nested PointerUnion.
return !PointerLikeTypeTraits<PT1>::getFromVoidPointer(Val.getPointer());
}
operator bool() const { return !isNull(); }
LLVM_EXPLICIT operator bool() const { return !isNull(); }
/// is<T>() return true if the Union currently holds the type matching T.
template<typename T>
@ -174,7 +175,19 @@ namespace llvm {
return V;
}
};
template<typename PT1, typename PT2>
static bool operator==(PointerUnion<PT1, PT2> lhs,
PointerUnion<PT1, PT2> rhs) {
return lhs.getOpaqueValue() == rhs.getOpaqueValue();
}
template<typename PT1, typename PT2>
static bool operator!=(PointerUnion<PT1, PT2> lhs,
PointerUnion<PT1, PT2> rhs) {
return lhs.getOpaqueValue() != rhs.getOpaqueValue();
}
// Teach SmallPtrSet that PointerUnion is "basically a pointer", that has
// # low bits available = min(PT1bits,PT2bits)-1.
template<typename PT1, typename PT2>
@ -251,7 +264,7 @@ namespace llvm {
/// isNull - Return true if the pointer held in the union is null,
/// regardless of which type it is.
bool isNull() const { return Val.isNull(); }
operator bool() const { return !isNull(); }
LLVM_EXPLICIT operator bool() const { return !isNull(); }
/// is<T>() return true if the Union currently holds the type matching T.
template<typename T>
@ -359,7 +372,7 @@ namespace llvm {
/// isNull - Return true if the pointer held in the union is null,
/// regardless of which type it is.
bool isNull() const { return Val.isNull(); }
operator bool() const { return !isNull(); }
LLVM_EXPLICIT operator bool() const { return !isNull(); }
/// is<T>() return true if the Union currently holds the type matching T.
template<typename T>

View File

@ -217,6 +217,22 @@ inline tier<T1, T2> tie(T1& f, T2& s) {
return tier<T1, T2>(f, s);
}
/// \brief Function object to check whether the first component of a std::pair
/// compares less than the first component of another std::pair.
struct less_first {
template <typename T> bool operator()(const T &lhs, const T &rhs) const {
return lhs.first < rhs.first;
}
};
/// \brief Function object to check whether the second component of a std::pair
/// compares less than the second component of another std::pair.
struct less_second {
template <typename T> bool operator()(const T &lhs, const T &rhs) const {
return lhs.second < rhs.second;
}
};
//===----------------------------------------------------------------------===//
// Extra additions for arrays
//===----------------------------------------------------------------------===//
@ -277,12 +293,16 @@ inline void array_pod_sort(IteratorTy Start, IteratorTy End) {
get_array_pod_sort_comparator(*Start));
}
template<class IteratorTy>
inline void array_pod_sort(IteratorTy Start, IteratorTy End,
int (*Compare)(const void*, const void*)) {
template <class IteratorTy>
inline void array_pod_sort(
IteratorTy Start, IteratorTy End,
int (*Compare)(
const typename std::iterator_traits<IteratorTy>::value_type *,
const typename std::iterator_traits<IteratorTy>::value_type *)) {
// Don't dereference start iterator of empty sequence.
if (Start == End) return;
qsort(&*Start, End-Start, sizeof(*Start), Compare);
qsort(&*Start, End - Start, sizeof(*Start),
reinterpret_cast<int (*)(const void *, const void *)>(Compare));
}
//===----------------------------------------------------------------------===//

View File

@ -170,7 +170,7 @@ public:
vector_.pop_back();
}
T pop_back_val() {
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val() {
T Ret = back();
pop_back();
return Ret;

View File

@ -216,9 +216,9 @@ public:
if (Bits == 0)
return -1;
if (NumBaseBits == 32)
return CountTrailingZeros_32(Bits);
return countTrailingZeros(Bits);
if (NumBaseBits == 64)
return CountTrailingZeros_64(Bits);
return countTrailingZeros(Bits);
llvm_unreachable("Unsupported!");
}
return getPointer()->find_first();
@ -234,9 +234,9 @@ public:
if (Bits == 0 || Prev + 1 >= getSmallSize())
return -1;
if (NumBaseBits == 32)
return CountTrailingZeros_32(Bits);
return countTrailingZeros(Bits);
if (NumBaseBits == 64)
return CountTrailingZeros_64(Bits);
return countTrailingZeros(Bits);
llvm_unreachable("Unsupported!");
}
return getPointer()->find_next(Prev);
@ -426,6 +426,40 @@ public:
return *this;
}
/// reset - Reset bits that are set in RHS. Same as *this &= ~RHS.
SmallBitVector &reset(const SmallBitVector &RHS) {
if (isSmall() && RHS.isSmall())
setSmallBits(getSmallBits() & ~RHS.getSmallBits());
else if (!isSmall() && !RHS.isSmall())
getPointer()->reset(*RHS.getPointer());
else
for (unsigned i = 0, e = std::min(size(), RHS.size()); i != e; ++i)
if (RHS.test(i))
reset(i);
return *this;
}
/// test - Check if (This - RHS) is zero.
/// This is the same as reset(RHS) and any().
bool test(const SmallBitVector &RHS) const {
if (isSmall() && RHS.isSmall())
return (getSmallBits() & ~RHS.getSmallBits()) != 0;
if (!isSmall() && !RHS.isSmall())
return getPointer()->test(*RHS.getPointer());
unsigned i, e;
for (i = 0, e = std::min(size(), RHS.size()); i != e; ++i)
if (test(i) && !RHS.test(i))
return true;
for (e = size(); i != e; ++i)
if (test(i))
return true;
return false;
}
SmallBitVector &operator|=(const SmallBitVector &RHS) {
resize(std::max(size(), RHS.size()));
if (isSmall())

View File

@ -71,7 +71,7 @@ protected:
~SmallPtrSetImpl();
public:
bool empty() const { return size() == 0; }
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const { return size() == 0; }
unsigned size() const { return NumElements; }
void clear() {

View File

@ -53,7 +53,7 @@ public:
return size_t((char*)CapacityX - (char*)BeginX);
}
bool empty() const { return BeginX == EndX; }
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const { return BeginX == EndX; }
};
template <typename T, unsigned N> struct SmallVectorStorage;
@ -427,7 +427,7 @@ public:
this->grow(N);
}
T pop_back_val() {
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val() {
#if LLVM_HAS_RVALUE_REFERENCES
T Result = ::std::move(this->back());
#else

View File

@ -137,9 +137,9 @@ public:
for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i)
if (Bits[i] != 0) {
if (sizeof(BitWord) == 4)
return i * BITWORD_SIZE + CountTrailingZeros_32(Bits[i]);
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
if (sizeof(BitWord) == 8)
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
llvm_unreachable("Unsupported!");
}
llvm_unreachable("Illegal empty element");
@ -162,9 +162,9 @@ public:
if (Copy != 0) {
if (sizeof(BitWord) == 4)
return WordPos * BITWORD_SIZE + CountTrailingZeros_32(Copy);
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
if (sizeof(BitWord) == 8)
return WordPos * BITWORD_SIZE + CountTrailingZeros_64(Copy);
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
llvm_unreachable("Unsupported!");
}
@ -172,9 +172,9 @@ public:
for (unsigned i = WordPos+1; i < BITWORDS_PER_ELEMENT; ++i)
if (Bits[i] != 0) {
if (sizeof(BitWord) == 4)
return i * BITWORD_SIZE + CountTrailingZeros_32(Bits[i]);
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
if (sizeof(BitWord) == 8)
return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
llvm_unreachable("Unsupported!");
}
return -1;

View File

@ -14,6 +14,7 @@
#ifndef LLVM_ADT_STRINGEXTRAS_H
#define LLVM_ADT_STRINGEXTRAS_H
#include <iterator>
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DataTypes.h"
@ -159,6 +160,48 @@ static inline StringRef getOrdinalSuffix(unsigned Val) {
}
}
template <typename IteratorT>
inline std::string join_impl(IteratorT Begin, IteratorT End,
StringRef Separator, std::input_iterator_tag) {
std::string S;
if (Begin == End)
return S;
S += (*Begin);
while (++Begin != End) {
S += Separator;
S += (*Begin);
}
return S;
}
template <typename IteratorT>
inline std::string join_impl(IteratorT Begin, IteratorT End,
StringRef Separator, std::forward_iterator_tag) {
std::string S;
if (Begin == End)
return S;
size_t Len = (std::distance(Begin, End) - 1) * Separator.size();
for (IteratorT I = Begin; I != End; ++I)
Len += (*Begin).size();
S.reserve(Len);
S += (*Begin);
while (++Begin != End) {
S += Separator;
S += (*Begin);
}
return S;
}
/// Joins the strings in the range [Begin, End), adding Separator between
/// the elements.
template <typename IteratorT>
inline std::string join(IteratorT Begin, IteratorT End, StringRef Separator) {
typedef typename std::iterator_traits<IteratorT>::iterator_category tag;
return join_impl(Begin, End, Separator, tag());
}
} // End llvm namespace
#endif

View File

@ -102,6 +102,13 @@ public:
bool empty() const { return NumItems == 0; }
unsigned size() const { return NumItems; }
void swap(StringMapImpl &Other) {
std::swap(TheTable, Other.TheTable);
std::swap(NumBuckets, Other.NumBuckets);
std::swap(NumItems, Other.NumItems);
std::swap(NumTombstones, Other.NumTombstones);
}
};
/// StringMapEntry - This is used to represent one value that is inserted into
@ -109,6 +116,7 @@ public:
/// and data.
template<typename ValueTy>
class StringMapEntry : public StringMapEntryBase {
StringMapEntry(StringMapEntry &E) LLVM_DELETED_FUNCTION;
public:
ValueTy second;
@ -409,6 +417,8 @@ protected:
public:
typedef StringMapEntry<ValueTy> value_type;
StringMapConstIterator() : Ptr(0) { }
explicit StringMapConstIterator(StringMapEntryBase **Bucket,
bool NoAdvance = false)
: Ptr(Bucket) {
@ -448,6 +458,7 @@ private:
template<typename ValueTy>
class StringMapIterator : public StringMapConstIterator<ValueTy> {
public:
StringMapIterator() {}
explicit StringMapIterator(StringMapEntryBase **Bucket,
bool NoAdvance = false)
: StringMapConstIterator<ValueTy>(Bucket, NoAdvance) {

View File

@ -19,7 +19,7 @@
#include <utility>
namespace llvm {
template<typename T>
template <typename T>
class SmallVectorImpl;
class APInt;
class hash_code;
@ -175,7 +175,7 @@ namespace llvm {
/// transform one of the given strings into the other. If zero,
/// the strings are identical.
unsigned edit_distance(StringRef Other, bool AllowReplacements = true,
unsigned MaxEditDistance = 0);
unsigned MaxEditDistance = 0) const;
/// str - Get the contents as an std::string.
std::string str() const {
@ -210,12 +210,18 @@ namespace llvm {
compareMemory(Data, Prefix.Data, Prefix.Length) == 0;
}
/// Check if this string starts with the given \p Prefix, ignoring case.
bool startswith_lower(StringRef Prefix) const;
/// Check if this string ends with the given \p Suffix.
bool endswith(StringRef Suffix) const {
return Length >= Suffix.Length &&
compareMemory(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
}
/// Check if this string ends with the given \p Suffix, ignoring case.
bool endswith_lower(StringRef Suffix) const;
/// @}
/// @name String Searching
/// @{
@ -548,6 +554,10 @@ namespace llvm {
template <typename T> struct isPodLike;
template <> struct isPodLike<StringRef> { static const bool value = true; };
/// Construct a string ref from a boolean.
inline StringRef toStringRef(bool B) {
return StringRef(B ? "true" : "false");
}
}
#endif

View File

@ -14,30 +14,33 @@
// Some system headers or GCC predefined macros conflict with identifiers in
// this file. Undefine them here.
#undef NetBSD
#undef mips
#undef sparc
namespace llvm {
/// Triple - Helper class for working with target triples.
/// Triple - Helper class for working with autoconf configuration names. For
/// historical reasons, we also call these 'triples' (they used to contain
/// exactly three fields).
///
/// Target triples are strings in the canonical form:
/// Configuration names are strings in the canonical form:
/// ARCHITECTURE-VENDOR-OPERATING_SYSTEM
/// or
/// ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
///
/// This class is used for clients which want to support arbitrary
/// target triples, but also want to implement certain special
/// behavior for particular targets. This class isolates the mapping
/// from the components of the target triple to well known IDs.
/// configuration names, but also want to implement certain special
/// behavior for particular configurations. This class isolates the mapping
/// from the components of the configuration name to well known IDs.
///
/// At its core the Triple class is designed to be a wrapper for a triple
/// string; the constructor does not change or normalize the triple string.
/// Clients that need to handle the non-canonical triples that users often
/// specify should use the normalize method.
///
/// See autoconf/config.guess for a glimpse into what triples look like in
/// practice.
/// See autoconf/config.guess for a glimpse into what configuration names
/// look like in practice.
class Triple {
public:
enum ArchType {
@ -53,6 +56,7 @@ public:
msp430, // MSP430: msp430
ppc, // PPC: powerpc
ppc64, // PPC64: powerpc64, ppu
ppc64le, // PPC64LE: powerpc64le
r600, // R600: AMD GPUs HD2XXX - HD6XXX
sparc, // Sparc: sparc
sparcv9, // Sparcv9: Sparcv9
@ -62,7 +66,6 @@ public:
x86, // X86: i[3-9]86
x86_64, // X86-64: amd64, x86_64
xcore, // XCore: xcore
mblaze, // MBlaze: mblaze
nvptx, // NVPTX: 32-bit
nvptx64, // NVPTX: 64-bit
le32, // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten)
@ -79,7 +82,8 @@ public:
BGP,
BGQ,
Freescale,
IBM
IBM,
NVIDIA
};
enum OSType {
UnknownOS,
@ -105,7 +109,9 @@ public:
NaCl, // Native Client
CNK, // BG/P Compute-Node Kernel
Bitrig,
AIX
AIX,
CUDA, // NVIDIA CUDA
NVCL // NVIDIA OpenCL
};
enum EnvironmentType {
UnknownEnvironment,
@ -313,7 +319,12 @@ public:
return getOS() == Triple::Cygwin || getOS() == Triple::MinGW32;
}
/// isOSWindows - Is this a "Windows" OS.
/// \brief Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
bool isOSMSVCRT() const {
return getOS() == Triple::Win32 || getOS() == Triple::MinGW32;
}
/// \brief Tests whether the OS is Windows.
bool isOSWindows() const {
return getOS() == Triple::Win32 || isOSCygMing();
}
@ -323,6 +334,11 @@ public:
return getOS() == Triple::NaCl;
}
/// \brief Tests whether the OS is Linux.
bool isOSLinux() const {
return getOS() == Triple::Linux;
}
/// \brief Tests whether the OS uses the ELF binary format.
bool isOSBinFormatELF() const {
return !isOSDarwin() && !isOSWindows();

View File

@ -382,7 +382,9 @@ public:
// Miscellaneous inspection routines.
size_type max_size() const { return size_type(-1); }
bool empty() const { return Head == 0 || Head == getTail(); }
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {
return Head == 0 || Head == getTail();
}
// Front and back accessor functions...
reference front() {
@ -534,7 +536,7 @@ public:
// Functionality derived from other functions defined above...
//
size_type size() const {
size_type LLVM_ATTRIBUTE_UNUSED_RESULT size() const {
if (Head == 0) return 0; // Don't require construction of sentinel if empty.
return std::distance(begin(), end());
}

View File

@ -0,0 +1,117 @@
//===- llvm/ADT/polymorphic_ptr.h - Smart copyable owned ptr ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
/// \file
/// This file provides a polymorphic_ptr class template. See the class comments
/// for details about this API, its intended use cases, etc.
///
/// The primary motivation here is to work around the necessity of copy
/// semantics in C++98. This is typically used where any actual copies are
/// incidental or unnecessary. As a consequence, it is expected to cease to be
/// useful and be removed when we can directly rely on move-only types.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_ADT_POLYMORPHIC_PTR_H
#define LLVM_ADT_POLYMORPHIC_PTR_H
#include "llvm/Support/Compiler.h"
namespace llvm {
/// \brief An owning, copyable polymorphic smart pointer.
///
/// This pointer exists to provide copyable owned smart pointer. Rather than
/// shared ownership semantics, it has unique ownership semantics and deep copy
/// semantics. It is copyable by requiring that the underlying type exposes
/// a method which can produce a (heap allocated) clone.
///
/// Note that in almost all scenarios use of this could be avoided if we could
/// build move-only containers of a std::unique_ptr, but until then this
/// provides an effective way to place polymorphic objects in a container.
template <typename T> class polymorphic_ptr {
T *ptr;
public:
polymorphic_ptr(T *ptr = 0) : ptr(ptr) {}
polymorphic_ptr(const polymorphic_ptr &arg) : ptr(arg ? arg->clone() : 0) {}
#if LLVM_HAS_RVALUE_REFERENCES
polymorphic_ptr(polymorphic_ptr &&arg) : ptr(arg.take()) {}
#endif
~polymorphic_ptr() { delete ptr; }
polymorphic_ptr &operator=(polymorphic_ptr arg) {
swap(arg);
return *this;
}
polymorphic_ptr &operator=(T *arg) {
if (arg != ptr) {
delete ptr;
ptr = arg;
}
return *this;
}
T &operator*() const { return *ptr; }
T *operator->() const { return ptr; }
LLVM_EXPLICIT operator bool() const { return ptr != 0; }
bool operator!() const { return ptr == 0; }
T *get() const { return ptr; }
T *take() {
T *tmp = ptr;
ptr = 0;
return tmp;
}
void swap(polymorphic_ptr &arg) {
T *tmp = ptr;
ptr = arg.ptr;
arg.ptr = tmp;
}
};
template <typename T>
void swap(polymorphic_ptr<T> &lhs, polymorphic_ptr<T> &rhs) {
lhs.swap(rhs);
}
template <typename T, typename U>
bool operator==(const polymorphic_ptr<T> &lhs, const polymorphic_ptr<U> &rhs) {
return lhs.get() == rhs.get();
}
template <typename T, typename U>
bool operator!=(const polymorphic_ptr<T> &lhs, const polymorphic_ptr<U> &rhs) {
return lhs.get() != rhs.get();
}
template <typename T, typename U>
bool operator==(const polymorphic_ptr<T> &lhs, U *rhs) {
return lhs.get() == rhs;
}
template <typename T, typename U>
bool operator!=(const polymorphic_ptr<T> &lhs, U *rhs) {
return lhs.get() != rhs;
}
template <typename T, typename U>
bool operator==(T *lhs, const polymorphic_ptr<U> &rhs) {
return lhs == rhs.get();
}
template <typename T, typename U>
bool operator!=(T *lhs, const polymorphic_ptr<U> &rhs) {
return lhs != rhs.get();
}
}
#endif

View File

@ -584,6 +584,10 @@ struct DenseMapInfo<AliasAnalysis::Location> {
/// function.
bool isNoAliasCall(const Value *V);
/// isNoAliasArgument - Return true if this is an argument with the noalias
/// attribute.
bool isNoAliasArgument(const Value *V);
/// isIdentifiedObject - Return true if this pointer refers to a distinct and
/// identifiable object. This returns true for:
/// Global Variables and Functions (but not Global Aliases)

View File

@ -1,4 +1,4 @@
//===---- BlockFrequencyImpl.h - Machine Block Frequency Implementation ---===//
//===-- BlockFrequencyImpl.h - Block Frequency Implementation --*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
@ -33,7 +33,7 @@ class BlockFrequencyInfo;
class MachineBlockFrequencyInfo;
/// BlockFrequencyImpl implements block frequency algorithm for IR and
/// Machine Instructions. Algorithm starts with value 1024 (START_FREQ)
/// Machine Instructions. Algorithm starts with value ENTRY_FREQ
/// for the entry block and then propagates frequencies using branch weights
/// from (Machine)BranchProbabilityInfo. LoopInfo is not required because
/// algorithm can find "backedges" by itself.
@ -85,31 +85,16 @@ class BlockFrequencyImpl {
<< " --> " << Freqs[BB] << "\n");
}
/// divBlockFreq - Divide BB block frequency by PROB. If Prob = 0 do nothing.
///
void divBlockFreq(BlockT *BB, BranchProbability Prob) {
uint64_t N = Prob.getNumerator();
assert(N && "Illegal division by zero!");
uint64_t D = Prob.getDenominator();
uint64_t Freq = (Freqs[BB].getFrequency() * D) / N;
// Should we assert it?
if (Freq > UINT32_MAX)
Freq = UINT32_MAX;
Freqs[BB] = BlockFrequency(Freq);
DEBUG(dbgs() << "Frequency(" << getBlockName(BB) << ") /= (" << Prob
<< ") --> " << Freqs[BB] << "\n");
}
// All blocks in postorder.
std::vector<BlockT *> POT;
// Map Block -> Position in reverse-postorder list.
DenseMap<BlockT *, unsigned> RPO;
// Cycle Probability for each bloch.
DenseMap<BlockT *, uint32_t> CycleProb;
// For each loop header, record the per-iteration probability of exiting the
// loop. This is the reciprocal of the expected number of loop iterations.
typedef DenseMap<BlockT*, BranchProbability> LoopExitProbMap;
LoopExitProbMap LoopExitProb;
// (reverse-)postorder traversal iterators.
typedef typename std::vector<BlockT *>::iterator pot_iterator;
@ -123,7 +108,7 @@ class BlockFrequencyImpl {
rpot_iterator rpot_at(BlockT *BB) {
rpot_iterator I = rpot_begin();
unsigned idx = RPO[BB];
unsigned idx = RPO.lookup(BB);
assert(idx);
std::advance(I, idx - 1);
@ -131,22 +116,14 @@ class BlockFrequencyImpl {
return I;
}
/// isReachable - Returns if BB block is reachable from the entry.
/// isBackedge - Return if edge Src -> Dst is a reachable backedge.
///
bool isReachable(BlockT *BB) {
return RPO.count(BB);
}
/// isBackedge - Return if edge Src -> Dst is a backedge.
///
bool isBackedge(BlockT *Src, BlockT *Dst) {
assert(isReachable(Src));
assert(isReachable(Dst));
unsigned a = RPO[Src];
unsigned b = RPO[Dst];
bool isBackedge(BlockT *Src, BlockT *Dst) const {
unsigned a = RPO.lookup(Src);
if (!a)
return false;
unsigned b = RPO.lookup(Dst);
assert(b && "Destination block should be reachable");
return a >= b;
}
@ -196,7 +173,7 @@ class BlockFrequencyImpl {
PI != PE; ++PI) {
BlockT *Pred = *PI;
if (isReachable(Pred) && isBackedge(Pred, BB)) {
if (isBackedge(Pred, BB)) {
isLoopHead = true;
} else if (BlocksInLoop.count(Pred)) {
incBlockFreq(BB, getEdgeFreq(Pred, BB));
@ -211,10 +188,13 @@ class BlockFrequencyImpl {
if (!isLoopHead)
return;
assert(EntryFreq >= CycleProb[BB]);
uint32_t CProb = CycleProb[BB];
uint32_t Numerator = EntryFreq - CProb ? EntryFreq - CProb : 1;
divBlockFreq(BB, BranchProbability(Numerator, EntryFreq));
// This block is a loop header, so boost its frequency by the expected
// number of loop iterations. The loop blocks will be revisited so they all
// get this boost.
typename LoopExitProbMap::const_iterator I = LoopExitProb.find(BB);
assert(I != LoopExitProb.end() && "Loop header missing from table");
Freqs[BB] /= I->second;
DEBUG(dbgs() << "Loop header scaled to " << Freqs[BB] << ".\n");
}
/// doLoop - Propagate block frequency down through the loop.
@ -234,24 +214,50 @@ class BlockFrequencyImpl {
}
// Compute loop's cyclic probability using backedges probabilities.
BlockFrequency BackFreq;
for (typename GT::ChildIteratorType
PI = GraphTraits< Inverse<BlockT *> >::child_begin(Head),
PE = GraphTraits< Inverse<BlockT *> >::child_end(Head);
PI != PE; ++PI) {
BlockT *Pred = *PI;
assert(Pred);
if (isReachable(Pred) && isBackedge(Pred, Head)) {
uint64_t N = getEdgeFreq(Pred, Head).getFrequency();
uint64_t D = getBlockFreq(Head).getFrequency();
assert(N <= EntryFreq && "Backedge frequency must be <= EntryFreq!");
uint64_t Res = (N * EntryFreq) / D;
assert(Res <= UINT32_MAX);
CycleProb[Head] += (uint32_t) Res;
DEBUG(dbgs() << " CycleProb[" << getBlockName(Head) << "] += " << Res
<< " --> " << CycleProb[Head] << "\n");
}
if (isBackedge(Pred, Head))
BackFreq += getEdgeFreq(Pred, Head);
}
// The cyclic probability is freq(BackEdges) / freq(Head), where freq(Head)
// only counts edges entering the loop, not the loop backedges.
// The probability of leaving the loop on each iteration is:
//
// ExitProb = 1 - CyclicProb
//
// The Expected number of loop iterations is:
//
// Iterations = 1 / ExitProb
//
uint64_t D = std::max(getBlockFreq(Head).getFrequency(), UINT64_C(1));
uint64_t N = std::max(BackFreq.getFrequency(), UINT64_C(1));
if (N < D)
N = D - N;
else
// We'd expect N < D, but rounding and saturation means that can't be
// guaranteed.
N = 1;
// Now ExitProb = N / D, make sure it fits in an i32/i32 fraction.
assert(N <= D);
if (D > UINT32_MAX) {
unsigned Shift = 32 - countLeadingZeros(D);
D >>= Shift;
N >>= Shift;
if (N == 0)
N = 1;
}
BranchProbability LEP = BranchProbability(N, D);
LoopExitProb.insert(std::make_pair(Head, LEP));
DEBUG(dbgs() << "LoopExitProb[" << getBlockName(Head) << "] = " << LEP
<< " from 1 - " << BackFreq << " / " << getBlockFreq(Head)
<< ".\n");
}
friend class BlockFrequencyInfo;
@ -266,7 +272,7 @@ class BlockFrequencyImpl {
// Clear everything.
RPO.clear();
POT.clear();
CycleProb.clear();
LoopExitProb.clear();
Freqs.clear();
BlockT *EntryBlock = fn->begin();
@ -292,8 +298,7 @@ class BlockFrequencyImpl {
PI != PE; ++PI) {
BlockT *Pred = *PI;
if (isReachable(Pred) && isBackedge(Pred, BB)
&& (!LastTail || RPO[Pred] > RPO[LastTail]))
if (isBackedge(Pred, BB) && (!LastTail || RPO[Pred] > RPO[LastTail]))
LastTail = Pred;
}

View File

@ -1,4 +1,4 @@
//========-------- BlockFrequencyInfo.h - Block Frequency Analysis -------========//
//===------- BlockFrequencyInfo.h - Block Frequency Analysis --*- C++ -*---===//
//
// The LLVM Compiler Infrastructure
//
@ -41,12 +41,14 @@ public:
bool runOnFunction(Function &F);
void print(raw_ostream &O, const Module *M) const;
const Function *getFunction() const;
void view() const;
/// getblockFreq - Return block frequency. Return 0 if we don't have the
/// information. Please note that initial frequency is equal to 1024. It means
/// that we should not rely on the value itself, but only on the comparison to
/// the other block frequencies. We do this to avoid using of floating points.
///
/// information. Please note that initial frequency is equal to ENTRY_FREQ. It
/// means that we should not rely on the value itself, but only on the
/// comparison to the other block frequencies. We do this to avoid using of
/// floating points.
BlockFrequency getBlockFreq(const BasicBlock *BB) const;
};

View File

@ -131,11 +131,15 @@ private:
/// \brief Track the set of blocks directly succeeded by a returning block.
SmallPtrSet<BasicBlock *, 16> PostDominatedByUnreachable;
/// \brief Track the set of blocks that always lead to a cold call.
SmallPtrSet<BasicBlock *, 16> PostDominatedByColdCall;
/// \brief Get sum of the block successors' weights.
uint32_t getSumForBlock(const BasicBlock *BB) const;
bool calcUnreachableHeuristics(BasicBlock *BB);
bool calcMetadataWeights(BasicBlock *BB);
bool calcColdCallHeuristics(BasicBlock *BB);
bool calcPointerHeuristics(BasicBlock *BB);
bool calcLoopBranchHeuristics(BasicBlock *BB);
bool calcZeroHeuristics(BasicBlock *BB);

View File

@ -0,0 +1,83 @@
//===-- Analysis/CFG.h - BasicBlock Analyses --------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This family of functions performs analyses on basic blocks, and instructions
// contained within basic blocks.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_CFG_H
#define LLVM_ANALYSIS_CFG_H
#include "llvm/IR/BasicBlock.h"
#include "llvm/Support/CFG.h"
namespace llvm {
class BasicBlock;
class DominatorTree;
class Function;
class Instruction;
class LoopInfo;
class TerminatorInst;
/// Analyze the specified function to find all of the loop backedges in the
/// function and return them. This is a relatively cheap (compared to
/// computing dominators and loop info) analysis.
///
/// The output is added to Result, as pairs of <from,to> edge info.
void FindFunctionBackedges(
const Function &F,
SmallVectorImpl<std::pair<const BasicBlock *, const BasicBlock *> > &
Result);
/// Search for the specified successor of basic block BB and return its position
/// in the terminator instruction's list of successors. It is an error to call
/// this with a block that is not a successor.
unsigned GetSuccessorNumber(BasicBlock *BB, BasicBlock *Succ);
/// Return true if the specified edge is a critical edge. Critical edges are
/// edges from a block with multiple successors to a block with multiple
/// predecessors.
///
bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum,
bool AllowIdenticalEdges = false);
/// \brief Determine whether instruction 'To' is reachable from 'From',
/// returning true if uncertain.
///
/// Determine whether there is a path from From to To within a single function.
/// Returns false only if we can prove that once 'From' has been executed then
/// 'To' can not be executed. Conservatively returns true.
///
/// This function is linear with respect to the number of blocks in the CFG,
/// walking down successors from From to reach To, with a fixed threshold.
/// Using DT or LI allows us to answer more quickly. LI reduces the cost of
/// an entire loop of any number of blocsk to be the same as the cost of a
/// single block. DT reduces the cost by allowing the search to terminate when
/// we find a block that dominates the block containing 'To'. DT is most useful
/// on branchy code but not loops, and LI is most useful on code with loops but
/// does not help on branchy code outside loops.
bool isPotentiallyReachable(const Instruction *From, const Instruction *To,
const DominatorTree *DT = 0,
const LoopInfo *LI = 0);
/// \brief Determine whether block 'To' is reachable from 'From', returning
/// true if uncertain.
///
/// Determine whether there is a path from From to To within a single function.
/// Returns false only if we can prove that once 'From' has been reached then
/// 'To' can not be executed. Conservatively returns true.
bool isPotentiallyReachable(const BasicBlock *From, const BasicBlock *To,
const DominatorTree *DT = 0,
const LoopInfo *LI = 0);
} // End llvm namespace
#endif

View File

@ -44,8 +44,9 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
return OS.str();
}
static std::string getCompleteNodeLabel(const BasicBlock *Node,
static std::string getCompleteNodeLabel(const BasicBlock *Node,
const Function *) {
enum { MaxColumns = 80 };
std::string Str;
raw_string_ostream OS(Str);
@ -59,16 +60,32 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
// Process string output to make it nicer...
for (unsigned i = 0; i != OutStr.length(); ++i)
unsigned ColNum = 0;
unsigned LastSpace = 0;
for (unsigned i = 0; i != OutStr.length(); ++i) {
if (OutStr[i] == '\n') { // Left justify
OutStr[i] = '\\';
OutStr.insert(OutStr.begin()+i+1, 'l');
ColNum = 0;
LastSpace = 0;
} else if (OutStr[i] == ';') { // Delete comments!
unsigned Idx = OutStr.find('\n', i+1); // Find end of line
OutStr.erase(OutStr.begin()+i, OutStr.begin()+Idx);
--i;
} else if (ColNum == MaxColumns) { // Wrap lines.
if (LastSpace) {
OutStr.insert(LastSpace, "\\l...");
ColNum = i - LastSpace;
LastSpace = 0;
i += 3; // The loop will advance 'i' again.
}
// Else keep trying to find a space.
}
else
++ColNum;
if (OutStr[i] == ' ')
LastSpace = i;
}
return OutStr;
}
@ -86,20 +103,20 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
if (const BranchInst *BI = dyn_cast<BranchInst>(Node->getTerminator()))
if (BI->isConditional())
return (I == succ_begin(Node)) ? "T" : "F";
// Label source of switch edges with the associated value.
if (const SwitchInst *SI = dyn_cast<SwitchInst>(Node->getTerminator())) {
unsigned SuccNo = I.getSuccessorIndex();
if (SuccNo == 0) return "def";
std::string Str;
raw_string_ostream OS(Str);
SwitchInst::ConstCaseIt Case =
SwitchInst::ConstCaseIt::fromSuccessorIndex(SI, SuccNo);
SwitchInst::ConstCaseIt::fromSuccessorIndex(SI, SuccNo);
OS << Case.getCaseValue()->getValue();
return OS.str();
}
}
return "";
}
};

View File

@ -69,13 +69,36 @@ class CallGraphNode;
//===----------------------------------------------------------------------===//
// CallGraph class definition
//
class CallGraph {
protected:
class CallGraph : public ModulePass {
Module *Mod; // The module this call graph represents
typedef std::map<const Function *, CallGraphNode *> FunctionMapTy;
FunctionMapTy FunctionMap; // Map from a function to its node
// Root is root of the call graph, or the external node if a 'main' function
// couldn't be found.
//
CallGraphNode *Root;
// ExternalCallingNode - This node has edges to all external functions and
// those internal functions that have their address taken.
CallGraphNode *ExternalCallingNode;
// CallsExternalNode - This node has edges to it from all functions making
// indirect calls or calling an external function.
CallGraphNode *CallsExternalNode;
/// Replace the function represented by this node by another.
/// This does not rescan the body of the function, so it is suitable when
/// splicing the body of one function to another while also updating all
/// callers from the old function to the new.
///
void spliceFunction(const Function *From, const Function *To);
// Add a function to the call graph, and link the node to all of the functions
// that it calls.
void addToCallGraph(Function *F);
public:
static char ID; // Class identification, replacement for typeinfo
//===---------------------------------------------------------------------
@ -107,15 +130,14 @@ public:
}
/// Returns the CallGraphNode which is used to represent undetermined calls
/// into the callgraph. Override this if you want behavioral inheritance.
virtual CallGraphNode* getExternalCallingNode() const { return 0; }
virtual CallGraphNode* getCallsExternalNode() const { return 0; }
/// into the callgraph.
CallGraphNode *getExternalCallingNode() const { return ExternalCallingNode; }
CallGraphNode *getCallsExternalNode() const { return CallsExternalNode; }
/// Return the root/main method in the module, or some other root node, such
/// as the externalcallingnode. Overload these if you behavioral
/// inheritance.
virtual CallGraphNode* getRoot() { return 0; }
virtual const CallGraphNode* getRoot() const { return 0; }
/// as the externalcallingnode.
CallGraphNode *getRoot() { return Root; }
const CallGraphNode *getRoot() const { return Root; }
//===---------------------------------------------------------------------
// Functions to keep a call graph up to date with a function that has been
@ -129,41 +151,20 @@ public:
/// do this is to dropAllReferences before calling this.
///
Function *removeFunctionFromModule(CallGraphNode *CGN);
Function *removeFunctionFromModule(Function *F) {
return removeFunctionFromModule((*this)[F]);
}
/// getOrInsertFunction - This method is identical to calling operator[], but
/// it will insert a new CallGraphNode for the specified function if one does
/// not already exist.
CallGraphNode *getOrInsertFunction(const Function *F);
/// spliceFunction - Replace the function represented by this node by another.
/// This does not rescan the body of the function, so it is suitable when
/// splicing the body of one function to another while also updating all
/// callers from the old function to the new.
///
void spliceFunction(const Function *From, const Function *To);
CallGraph();
virtual ~CallGraph() { releaseMemory(); }
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
virtual bool runOnModule(Module &M);
virtual void releaseMemory();
//===---------------------------------------------------------------------
// Pass infrastructure interface glue code.
//
protected:
CallGraph() {}
public:
virtual ~CallGraph() { destroy(); }
/// initialize - Call this method before calling other methods,
/// re/initializes the state of the CallGraph.
///
void initialize(Module &M);
void print(raw_ostream &o, Module *) const;
void print(raw_ostream &o, const Module *) const;
void dump() const;
protected:
// destroy - Release memory for the call graph
virtual void destroy();
};
//===----------------------------------------------------------------------===//

View File

@ -1,4 +1,4 @@
//===-- ConstantFolding.h - Fold instructions into constants --------------===//
//===-- ConstantFolding.h - Fold instructions into constants ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -48,8 +48,8 @@ Constant *ConstantFoldConstantExpression(const ConstantExpr *CE,
/// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
/// specified operands. If successful, the constant result is returned, if not,
/// null is returned. Note that this function can fail when attempting to
/// fold instructions like loads and stores, which have no constant expression
/// null is returned. Note that this function can fail when attempting to
/// fold instructions like loads and stores, which have no constant expression
/// form.
///
Constant *ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,

View File

@ -61,11 +61,20 @@ namespace llvm {
/// cases (for output, flow, and anti dependences), the dependence implies
/// an ordering, where the source must precede the destination; in contrast,
/// input dependences are unordered.
///
/// When a dependence graph is built, each Dependence will be a member of
/// the set of predecessor edges for its destination instruction and a set
/// if successor edges for its source instruction. These sets are represented
/// as singly-linked lists, with the "next" fields stored in the dependence
/// itelf.
class Dependence {
public:
Dependence(Instruction *Source,
Instruction *Destination) :
Src(Source), Dst(Destination) {}
Src(Source),
Dst(Destination),
NextPredecessor(NULL),
NextSuccessor(NULL) {}
virtual ~Dependence() {}
/// Dependence::DVEntry - Each level in the distance/direction vector
@ -164,11 +173,36 @@ namespace llvm {
/// variable associated with the loop at this level.
virtual bool isScalar(unsigned Level) const;
/// getNextPredecessor - Returns the value of the NextPredecessor
/// field.
const Dependence *getNextPredecessor() const {
return NextPredecessor;
}
/// getNextSuccessor - Returns the value of the NextSuccessor
/// field.
const Dependence *getNextSuccessor() const {
return NextSuccessor;
}
/// setNextPredecessor - Sets the value of the NextPredecessor
/// field.
void setNextPredecessor(const Dependence *pred) {
NextPredecessor = pred;
}
/// setNextSuccessor - Sets the value of the NextSuccessor
/// field.
void setNextSuccessor(const Dependence *succ) {
NextSuccessor = succ;
}
/// dump - For debugging purposes, dumps a dependence to OS.
///
void dump(raw_ostream &OS) const;
private:
Instruction *Src, *Dst;
const Dependence *NextPredecessor, *NextSuccessor;
friend class DependenceAnalysis;
};
@ -815,7 +849,7 @@ namespace llvm {
bool propagate(const SCEV *&Src,
const SCEV *&Dst,
SmallBitVector &Loops,
SmallVector<Constraint, 4> &Constraints,
SmallVectorImpl<Constraint> &Constraints,
bool &Consistent);
/// propagateDistance - Attempt to propagate a distance
@ -874,6 +908,10 @@ namespace llvm {
/// based on the current constraint.
void updateDirection(Dependence::DVEntry &Level,
const Constraint &CurConstraint) const;
bool tryDelinearize(const SCEV *SrcSCEV, const SCEV *DstSCEV,
SmallVectorImpl<Subscript> &Pair) const;
public:
static char ID; // Class identification, replacement for typeinfo
DependenceAnalysis() : FunctionPass(ID) {

View File

@ -346,6 +346,20 @@ public:
DomTreeNodeBase<NodeT> *getRootNode() { return RootNode; }
const DomTreeNodeBase<NodeT> *getRootNode() const { return RootNode; }
/// Get all nodes dominated by R, including R itself. Return true on success.
void getDescendants(NodeT *R, SmallVectorImpl<NodeT *> &Result) const {
const DomTreeNodeBase<NodeT> *RN = getNode(R);
SmallVector<const DomTreeNodeBase<NodeT> *, 8> WL;
WL.push_back(RN);
Result.clear();
while (!WL.empty()) {
const DomTreeNodeBase<NodeT> *N = WL.pop_back_val();
Result.push_back(N->getBlock());
WL.append(N->begin(), N->end());
}
}
/// properlyDominates - Returns true iff A dominates B and A != B.
/// Note that this is not a constant time operation!
///
@ -755,6 +769,12 @@ public:
return DT->getRootNode();
}
/// Get all nodes dominated by R, including R itself. Return true on success.
void getDescendants(BasicBlock *R,
SmallVectorImpl<BasicBlock *> &Result) const {
DT->getDescendants(R, Result);
}
/// compare - Return false if the other dominator tree matches this
/// dominator tree. Otherwise return true.
inline bool compare(DominatorTree &Other) const {

View File

@ -14,7 +14,6 @@
#ifndef LLVM_ANALYSIS_INLINECOST_H
#define LLVM_ANALYSIS_INLINECOST_H
#include "llvm/Analysis/CodeMetrics.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include <cassert>
#include <climits>
@ -77,7 +76,7 @@ public:
}
/// \brief Test whether the inline cost is low enough for inlining.
operator bool() const {
LLVM_EXPLICIT operator bool() const {
return Cost < Threshold;
}

View File

@ -1,4 +1,4 @@
//===-- InstructionSimplify.h - Fold instructions into simpler forms ------===//
//===-- InstructionSimplify.h - Fold instrs into simpler forms --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//

View File

@ -50,6 +50,7 @@ inline void RemoveFromVector(std::vector<T*> &V, T *N) {
class DominatorTree;
class LoopInfo;
class Loop;
class MDNode;
class PHINode;
class raw_ostream;
template<class N, class M> class LoopInfoBase;
@ -68,6 +69,8 @@ class LoopBase {
// Blocks - The list of blocks in this loop. First entry is the header node.
std::vector<BlockT*> Blocks;
SmallPtrSet<const BlockT*, 8> DenseBlockSet;
LoopBase(const LoopBase<BlockT, LoopT> &) LLVM_DELETED_FUNCTION;
const LoopBase<BlockT, LoopT>&
operator=(const LoopBase<BlockT, LoopT> &) LLVM_DELETED_FUNCTION;
@ -107,7 +110,7 @@ public:
/// contains - Return true if the specified basic block is in this loop.
///
bool contains(const BlockT *BB) const {
return std::find(block_begin(), block_end(), BB) != block_end();
return DenseBlockSet.count(BB);
}
/// contains - Return true if the specified instruction is in this loop.
@ -133,7 +136,6 @@ public:
/// getBlocks - Get a list of the basic blocks which make up this loop.
///
const std::vector<BlockT*> &getBlocks() const { return Blocks; }
std::vector<BlockT*> &getBlocksVector() { return Blocks; }
typedef typename std::vector<BlockT*>::const_iterator block_iterator;
block_iterator block_begin() const { return Blocks.begin(); }
block_iterator block_end() const { return Blocks.end(); }
@ -270,6 +272,17 @@ public:
/// transformations should use addBasicBlockToLoop.
void addBlockEntry(BlockT *BB) {
Blocks.push_back(BB);
DenseBlockSet.insert(BB);
}
/// reverseBlocks - interface to reverse Blocks[from, end of loop] in this loop
void reverseBlock(unsigned from) {
std::reverse(Blocks.begin() + from, Blocks.end());
}
/// reserveBlocks- interface to do reserve() for Blocks
void reserveBlocks(unsigned size) {
Blocks.reserve(size);
}
/// moveToHeader - This method is used to move BB (which must be part of this
@ -292,6 +305,7 @@ public:
/// the mapping in the LoopInfo class.
void removeBlockFromLoop(BlockT *BB) {
RemoveFromVector(Blocks, BB);
DenseBlockSet.erase(BB);
}
/// verifyLoop - Verify loop structure
@ -306,6 +320,7 @@ protected:
friend class LoopInfoBase<BlockT, LoopT>;
explicit LoopBase(BlockT *BB) : ParentLoop(0) {
Blocks.push_back(BB);
DenseBlockSet.insert(BB);
}
};
@ -391,6 +406,22 @@ public:
/// iterations.
bool isAnnotatedParallel() const;
/// Return the llvm.loop loop id metadata node for this loop if it is present.
///
/// If this loop contains the same llvm.loop metadata on each branch to the
/// header then the node is returned. If any latch instruction does not
/// contain llvm.loop or or if multiple latches contain different nodes then
/// 0 is returned.
MDNode *getLoopID() const;
/// Set the llvm.loop loop id metadata for this loop.
///
/// The LoopID metadata node will be added to each terminator instruction in
/// the loop that branches to the loop header.
///
/// The LoopID metadata node should have one or more operands and the first
/// operand should should be the node itself.
void setLoopID(MDNode *LoopID) const;
/// hasDedicatedExits - Return true if no exit block for the loop
/// has a predecessor that is outside the loop.
bool hasDedicatedExits() const;

View File

@ -31,17 +31,12 @@ namespace llvm {
template<class BlockT, class LoopT>
void LoopBase<BlockT, LoopT>::
getExitingBlocks(SmallVectorImpl<BlockT *> &ExitingBlocks) const {
// Sort the blocks vector so that we can use binary search to do quick
// lookups.
SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
std::sort(LoopBBs.begin(), LoopBBs.end());
typedef GraphTraits<BlockT*> BlockTraits;
for (block_iterator BI = block_begin(), BE = block_end(); BI != BE; ++BI)
for (typename BlockTraits::ChildIteratorType I =
BlockTraits::child_begin(*BI), E = BlockTraits::child_end(*BI);
I != E; ++I)
if (!std::binary_search(LoopBBs.begin(), LoopBBs.end(), *I)) {
if (!contains(*I)) {
// Not in current loop? It must be an exit block.
ExitingBlocks.push_back(*BI);
break;
@ -65,17 +60,12 @@ BlockT *LoopBase<BlockT, LoopT>::getExitingBlock() const {
template<class BlockT, class LoopT>
void LoopBase<BlockT, LoopT>::
getExitBlocks(SmallVectorImpl<BlockT*> &ExitBlocks) const {
// Sort the blocks vector so that we can use binary search to do quick
// lookups.
SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
std::sort(LoopBBs.begin(), LoopBBs.end());
typedef GraphTraits<BlockT*> BlockTraits;
for (block_iterator BI = block_begin(), BE = block_end(); BI != BE; ++BI)
for (typename BlockTraits::ChildIteratorType I =
BlockTraits::child_begin(*BI), E = BlockTraits::child_end(*BI);
I != E; ++I)
if (!std::binary_search(LoopBBs.begin(), LoopBBs.end(), *I))
if (!contains(*I))
// Not in current loop? It must be an exit block.
ExitBlocks.push_back(*I);
}
@ -95,17 +85,12 @@ BlockT *LoopBase<BlockT, LoopT>::getExitBlock() const {
template<class BlockT, class LoopT>
void LoopBase<BlockT, LoopT>::
getExitEdges(SmallVectorImpl<Edge> &ExitEdges) const {
// Sort the blocks vector so that we can use binary search to do quick
// lookups.
SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
array_pod_sort(LoopBBs.begin(), LoopBBs.end());
typedef GraphTraits<BlockT*> BlockTraits;
for (block_iterator BI = block_begin(), BE = block_end(); BI != BE; ++BI)
for (typename BlockTraits::ChildIteratorType I =
BlockTraits::child_begin(*BI), E = BlockTraits::child_end(*BI);
I != E; ++I)
if (!std::binary_search(LoopBBs.begin(), LoopBBs.end(), *I))
if (!contains(*I))
// Not in current loop? It must be an exit block.
ExitEdges.push_back(Edge(*BI, *I));
}
@ -210,7 +195,7 @@ addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase<BlockT, LoopT> &LIB) {
// Add the basic block to this loop and all parent loops...
while (L) {
L->Blocks.push_back(NewBB);
L->addBlockEntry(NewBB);
L = L->getParentLoop();
}
}
@ -250,11 +235,6 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
// Keep track of the number of BBs visited.
unsigned NumVisited = 0;
// Sort the blocks vector so that we can use binary search to do quick
// lookups.
SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
std::sort(LoopBBs.begin(), LoopBBs.end());
// Check the individual blocks.
for ( ; BI != BE; ++BI) {
BlockT *BB = *BI;
@ -266,7 +246,7 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
for (typename BlockTraits::ChildIteratorType SI =
BlockTraits::child_begin(BB), SE = BlockTraits::child_end(BB);
SI != SE; ++SI)
if (std::binary_search(LoopBBs.begin(), LoopBBs.end(), *SI)) {
if (contains(*SI)) {
HasInsideLoopSuccs = true;
break;
}
@ -275,7 +255,7 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
InvBlockTraits::child_begin(BB), PE = InvBlockTraits::child_end(BB);
PI != PE; ++PI) {
BlockT *N = *PI;
if (std::binary_search(LoopBBs.begin(), LoopBBs.end(), N))
if (contains(N))
HasInsideLoopPreds = true;
else
OutsideLoopPreds.push_back(N);
@ -309,7 +289,7 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
// Each block in each subloop should be contained within this loop.
for (block_iterator BI = (*I)->block_begin(), BE = (*I)->block_end();
BI != BE; ++BI) {
assert(std::binary_search(LoopBBs.begin(), LoopBBs.end(), *BI) &&
assert(contains(*BI) &&
"Loop does not contain all the blocks of a subloop!");
}
@ -418,7 +398,7 @@ static void discoverAndMapSubloop(LoopT *L, ArrayRef<BlockT*> Backedges,
}
}
L->getSubLoopsVector().reserve(NumSubloops);
L->getBlocksVector().reserve(NumBlocks);
L->reserveBlocks(NumBlocks);
}
namespace {
@ -489,15 +469,14 @@ void PopulateLoopsDFS<BlockT, LoopT>::insertIntoLoop(BlockT *Block) {
// For convenience, Blocks and Subloops are inserted in postorder. Reverse
// the lists, except for the loop header, which is always at the beginning.
std::reverse(Subloop->getBlocksVector().begin()+1,
Subloop->getBlocksVector().end());
Subloop->reverseBlock(1);
std::reverse(Subloop->getSubLoopsVector().begin(),
Subloop->getSubLoopsVector().end());
Subloop = Subloop->getParentLoop();
}
for (; Subloop; Subloop = Subloop->getParentLoop())
Subloop->getBlocksVector().push_back(Block);
Subloop->addBlockEntry(Block);
}
/// Analyze LoopInfo discovers loops during a postorder DominatorTree traversal

View File

@ -16,8 +16,8 @@
#define LLVM_ANALYSIS_LOOPPASS_H
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/LegacyPassManagers.h"
#include "llvm/Pass.h"
#include "llvm/PassManagers.h"
#include <deque>
namespace llvm {

View File

@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
//
// This family of functions identifies calls to builtin functions that allocate
// or free memory.
// or free memory.
//
//===----------------------------------------------------------------------===//
@ -64,6 +64,10 @@ bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
bool isReallocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
bool LookThroughBitCast = false);
/// \brief Tests if a value is a call or invoke to a library function that
/// allocates memory and never returns null (such as operator new).
bool isOperatorNewLikeFn(const Value *V, const TargetLibraryInfo *TLI,
bool LookThroughBitCast = false);
//===----------------------------------------------------------------------===//
// malloc Call Utility Functions.
@ -78,10 +82,10 @@ static inline CallInst *extractMallocCall(Value *I,
return const_cast<CallInst*>(extractMallocCall((const Value*)I, TLI));
}
/// isArrayMalloc - Returns the corresponding CallInst if the instruction
/// isArrayMalloc - Returns the corresponding CallInst if the instruction
/// is a call to malloc whose array size can be determined and the array size
/// is not constant 1. Otherwise, return NULL.
const CallInst *isArrayMalloc(const Value *I, const DataLayout *TD,
const CallInst *isArrayMalloc(const Value *I, const DataLayout *DL,
const TargetLibraryInfo *TLI);
/// getMallocType - Returns the PointerType resulting from the malloc call.
@ -98,12 +102,12 @@ PointerType *getMallocType(const CallInst *CI, const TargetLibraryInfo *TLI);
/// >1: Unique PointerType cannot be determined, return NULL.
Type *getMallocAllocatedType(const CallInst *CI, const TargetLibraryInfo *TLI);
/// getMallocArraySize - Returns the array size of a malloc call. If the
/// getMallocArraySize - Returns the array size of a malloc call. If the
/// argument passed to malloc is a multiple of the size of the malloced type,
/// then return that multiple. For non-array mallocs, the multiple is
/// constant 1. Otherwise, return NULL for mallocs whose array size cannot be
/// determined.
Value *getMallocArraySize(CallInst *CI, const DataLayout *TD,
Value *getMallocArraySize(CallInst *CI, const DataLayout *DL,
const TargetLibraryInfo *TLI,
bool LookThroughSExt = false);
@ -127,12 +131,12 @@ static inline CallInst *extractCallocCall(Value *I,
/// isFreeCall - Returns non-null if the value is a call to the builtin free()
const CallInst *isFreeCall(const Value *I, const TargetLibraryInfo *TLI);
static inline CallInst *isFreeCall(Value *I, const TargetLibraryInfo *TLI) {
return const_cast<CallInst*>(isFreeCall((const Value*)I, TLI));
}
//===----------------------------------------------------------------------===//
// Utility functions to compute size of objects.
//
@ -143,19 +147,19 @@ static inline CallInst *isFreeCall(Value *I, const TargetLibraryInfo *TLI) {
/// underlying object pointed to by Ptr.
/// If RoundToAlign is true, then Size is rounded up to the aligment of allocas,
/// byval arguments, and global variables.
bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout *TD,
bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout *DL,
const TargetLibraryInfo *TLI, bool RoundToAlign = false);
typedef std::pair<APInt, APInt> SizeOffsetType;
/// \brief Evaluate the size and offset of an object ponted by a Value*
/// \brief Evaluate the size and offset of an object pointed to by a Value*
/// statically. Fails if size or offset are not known at compile time.
class ObjectSizeOffsetVisitor
: public InstVisitor<ObjectSizeOffsetVisitor, SizeOffsetType> {
const DataLayout *TD;
const DataLayout *DL;
const TargetLibraryInfo *TLI;
bool RoundToAlign;
unsigned IntTyBits;
@ -169,7 +173,7 @@ class ObjectSizeOffsetVisitor
}
public:
ObjectSizeOffsetVisitor(const DataLayout *TD, const TargetLibraryInfo *TLI,
ObjectSizeOffsetVisitor(const DataLayout *DL, const TargetLibraryInfo *TLI,
LLVMContext &Context, bool RoundToAlign = false);
SizeOffsetType compute(Value *V);
@ -206,7 +210,7 @@ public:
typedef std::pair<Value*, Value*> SizeOffsetEvalType;
/// \brief Evaluate the size and offset of an object ponted by a Value*.
/// \brief Evaluate the size and offset of an object pointed to by a Value*.
/// May create code to compute the result at run-time.
class ObjectSizeOffsetEvaluator
: public InstVisitor<ObjectSizeOffsetEvaluator, SizeOffsetEvalType> {
@ -216,7 +220,7 @@ class ObjectSizeOffsetEvaluator
typedef DenseMap<const Value*, WeakEvalType> CacheMapTy;
typedef SmallPtrSet<const Value*, 8> PtrSetTy;
const DataLayout *TD;
const DataLayout *DL;
const TargetLibraryInfo *TLI;
LLVMContext &Context;
BuilderTy Builder;
@ -224,6 +228,7 @@ class ObjectSizeOffsetEvaluator
Value *Zero;
CacheMapTy CacheMap;
PtrSetTy SeenVals;
bool RoundToAlign;
SizeOffsetEvalType unknown() {
return std::make_pair((Value*)0, (Value*)0);
@ -231,8 +236,8 @@ class ObjectSizeOffsetEvaluator
SizeOffsetEvalType compute_(Value *V);
public:
ObjectSizeOffsetEvaluator(const DataLayout *TD, const TargetLibraryInfo *TLI,
LLVMContext &Context);
ObjectSizeOffsetEvaluator(const DataLayout *DL, const TargetLibraryInfo *TLI,
LLVMContext &Context, bool RoundToAlign = false);
SizeOffsetEvalType compute(Value *V);
bool knownSize(SizeOffsetEvalType SizeOffset) {

View File

@ -93,64 +93,6 @@ namespace llvm {
//
ImmutablePass *createObjCARCAliasAnalysisPass();
//===--------------------------------------------------------------------===//
//
// createProfileLoaderPass - This pass loads information from a profile dump
// file.
//
ModulePass *createProfileLoaderPass();
extern char &ProfileLoaderPassID;
//===--------------------------------------------------------------------===//
//
// createProfileMetadataLoaderPass - This pass loads information from a
// profile dump file and sets branch weight metadata.
//
ModulePass *createProfileMetadataLoaderPass();
extern char &ProfileMetadataLoaderPassID;
//===--------------------------------------------------------------------===//
//
// createNoProfileInfoPass - This pass implements the default "no profile".
//
ImmutablePass *createNoProfileInfoPass();
//===--------------------------------------------------------------------===//
//
// createProfileEstimatorPass - This pass estimates profiling information
// instead of loading it from a previous run.
//
FunctionPass *createProfileEstimatorPass();
extern char &ProfileEstimatorPassID;
//===--------------------------------------------------------------------===//
//
// createProfileVerifierPass - This pass verifies profiling information.
//
FunctionPass *createProfileVerifierPass();
//===--------------------------------------------------------------------===//
//
// createPathProfileLoaderPass - This pass loads information from a path
// profile dump file.
//
ModulePass *createPathProfileLoaderPass();
extern char &PathProfileLoaderPassID;
//===--------------------------------------------------------------------===//
//
// createNoPathProfileInfoPass - This pass implements the default
// "no path profile".
//
ImmutablePass *createNoPathProfileInfoPass();
//===--------------------------------------------------------------------===//
//
// createPathProfileVerifierPass - This pass verifies path profiling
// information.
//
ModulePass *createPathProfileVerifierPass();
//===--------------------------------------------------------------------===//
//
// createDSAAPass - This pass implements simple context sensitive alias
@ -192,6 +134,13 @@ namespace llvm {
//
FunctionPass *createCostModelAnalysisPass();
//===--------------------------------------------------------------------===//
//
// createDelinearizationPass - This pass implements attempts to restore
// multidimensional array indices from linearized expressions.
//
FunctionPass *createDelinearizationPass();
//===--------------------------------------------------------------------===//
//
// Minor pass prototypes, allowing us to expose them through bugpoint and

View File

@ -1,304 +0,0 @@
//===- PathNumbering.h ----------------------------------------*- C++ -*---===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Ball-Larus path numbers uniquely identify paths through a directed acyclic
// graph (DAG) [Ball96]. For a CFG backedges are removed and replaced by phony
// edges to obtain a DAG, and thus the unique path numbers [Ball96].
//
// The purpose of this analysis is to enumerate the edges in a CFG in order
// to obtain paths from path numbers in a convenient manner. As described in
// [Ball96] edges can be enumerated such that given a path number by following
// the CFG and updating the path number, the path is obtained.
//
// [Ball96]
// T. Ball and J. R. Larus. "Efficient Path Profiling."
// International Symposium on Microarchitecture, pages 46-57, 1996.
// http://portal.acm.org/citation.cfm?id=243857
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_PATHNUMBERING_H
#define LLVM_ANALYSIS_PATHNUMBERING_H
#include "llvm/Analysis/ProfileInfoTypes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Pass.h"
#include "llvm/Support/CFG.h"
#include <map>
#include <stack>
#include <vector>
namespace llvm {
class BallLarusNode;
class BallLarusEdge;
class BallLarusDag;
// typedefs for storage/ interators of various DAG components
typedef std::vector<BallLarusNode*> BLNodeVector;
typedef std::vector<BallLarusNode*>::iterator BLNodeIterator;
typedef std::vector<BallLarusEdge*> BLEdgeVector;
typedef std::vector<BallLarusEdge*>::iterator BLEdgeIterator;
typedef std::map<BasicBlock*, BallLarusNode*> BLBlockNodeMap;
typedef std::stack<BallLarusNode*> BLNodeStack;
// Represents a basic block with information necessary for the BallLarus
// algorithms.
class BallLarusNode {
public:
enum NodeColor { WHITE, GRAY, BLACK };
// Constructor: Initializes a new Node for the given BasicBlock
BallLarusNode(BasicBlock* BB) :
_basicBlock(BB), _numberPaths(0), _color(WHITE) {
static unsigned nextUID = 0;
_uid = nextUID++;
}
// Returns the basic block for the BallLarusNode
BasicBlock* getBlock();
// Get/set the number of paths to the exit starting at the node.
unsigned getNumberPaths();
void setNumberPaths(unsigned numberPaths);
// Get/set the NodeColor used in graph algorithms.
NodeColor getColor();
void setColor(NodeColor color);
// Iterator information for predecessor edges. Includes phony and
// backedges.
BLEdgeIterator predBegin();
BLEdgeIterator predEnd();
unsigned getNumberPredEdges();
// Iterator information for successor edges. Includes phony and
// backedges.
BLEdgeIterator succBegin();
BLEdgeIterator succEnd();
unsigned getNumberSuccEdges();
// Add an edge to the predecessor list.
void addPredEdge(BallLarusEdge* edge);
// Remove an edge from the predecessor list.
void removePredEdge(BallLarusEdge* edge);
// Add an edge to the successor list.
void addSuccEdge(BallLarusEdge* edge);
// Remove an edge from the successor list.
void removeSuccEdge(BallLarusEdge* edge);
// Returns the name of the BasicBlock being represented. If BasicBlock
// is null then returns "<null>". If BasicBlock has no name, then
// "<unnamed>" is returned. Intended for use with debug output.
std::string getName();
private:
// The corresponding underlying BB.
BasicBlock* _basicBlock;
// Holds the predecessor edges of this node.
BLEdgeVector _predEdges;
// Holds the successor edges of this node.
BLEdgeVector _succEdges;
// The number of paths from the node to the exit.
unsigned _numberPaths;
// 'Color' used by graph algorithms to mark the node.
NodeColor _color;
// Unique ID to ensure naming difference with dotgraphs
unsigned _uid;
// Removes an edge from an edgeVector. Used by removePredEdge and
// removeSuccEdge.
void removeEdge(BLEdgeVector& v, BallLarusEdge* e);
};
// Represents an edge in the Dag. For an edge, v -> w, v is the source, and
// w is the target.
class BallLarusEdge {
public:
enum EdgeType { NORMAL, BACKEDGE, SPLITEDGE,
BACKEDGE_PHONY, SPLITEDGE_PHONY, CALLEDGE_PHONY };
// Constructor: Initializes an BallLarusEdge with a source and target.
BallLarusEdge(BallLarusNode* source, BallLarusNode* target,
unsigned duplicateNumber)
: _source(source), _target(target), _weight(0), _edgeType(NORMAL),
_realEdge(NULL), _duplicateNumber(duplicateNumber) {}
// Returns the source/ target node of this edge.
BallLarusNode* getSource() const;
BallLarusNode* getTarget() const;
// Sets the type of the edge.
EdgeType getType() const;
// Gets the type of the edge.
void setType(EdgeType type);
// Returns the weight of this edge. Used to decode path numbers to
// sequences of basic blocks.
unsigned getWeight();
// Sets the weight of the edge. Used during path numbering.
void setWeight(unsigned weight);
// Gets/sets the phony edge originating at the root.
BallLarusEdge* getPhonyRoot();
void setPhonyRoot(BallLarusEdge* phonyRoot);
// Gets/sets the phony edge terminating at the exit.
BallLarusEdge* getPhonyExit();
void setPhonyExit(BallLarusEdge* phonyExit);
// Gets/sets the associated real edge if this is a phony edge.
BallLarusEdge* getRealEdge();
void setRealEdge(BallLarusEdge* realEdge);
// Returns the duplicate number of the edge.
unsigned getDuplicateNumber();
protected:
// Source node for this edge.
BallLarusNode* _source;
// Target node for this edge.
BallLarusNode* _target;
private:
// Edge weight cooresponding to path number increments before removing
// increments along a spanning tree. The sum over the edge weights gives
// the path number.
unsigned _weight;
// Type to represent for what this edge is intended
EdgeType _edgeType;
// For backedges and split-edges, the phony edge which is linked to the
// root node of the DAG. This contains a path number initialization.
BallLarusEdge* _phonyRoot;
// For backedges and split-edges, the phony edge which is linked to the
// exit node of the DAG. This contains a path counter increment, and
// potentially a path number increment.
BallLarusEdge* _phonyExit;
// If this is a phony edge, _realEdge is a link to the back or split
// edge. Otherwise, this is null.
BallLarusEdge* _realEdge;
// An ID to differentiate between those edges which have the same source
// and destination blocks.
unsigned _duplicateNumber;
};
// Represents the Ball Larus DAG for a given Function. Can calculate
// various properties required for instrumentation or analysis. E.g. the
// edge weights that determine the path number.
class BallLarusDag {
public:
// Initializes a BallLarusDag from the CFG of a given function. Must
// call init() after creation, since some initialization requires
// virtual functions.
BallLarusDag(Function &F)
: _root(NULL), _exit(NULL), _function(F) {}
// Initialization that requires virtual functions which are not fully
// functional in the constructor.
void init();
// Frees all memory associated with the DAG.
virtual ~BallLarusDag();
// Calculate the path numbers by assigning edge increments as prescribed
// in Ball-Larus path profiling.
void calculatePathNumbers();
// Returns the number of paths for the DAG.
unsigned getNumberOfPaths();
// Returns the root (i.e. entry) node for the DAG.
BallLarusNode* getRoot();
// Returns the exit node for the DAG.
BallLarusNode* getExit();
// Returns the function for the DAG.
Function& getFunction();
// Clears the node colors.
void clearColors(BallLarusNode::NodeColor color);
protected:
// All nodes in the DAG.
BLNodeVector _nodes;
// All edges in the DAG.
BLEdgeVector _edges;
// All backedges in the DAG.
BLEdgeVector _backEdges;
// Allows subclasses to determine which type of Node is created.
// Override this method to produce subclasses of BallLarusNode if
// necessary. The destructor of BallLarusDag will call free on each pointer
// created.
virtual BallLarusNode* createNode(BasicBlock* BB);
// Allows subclasses to determine which type of Edge is created.
// Override this method to produce subclasses of BallLarusEdge if
// necessary. Parameters source and target will have been created by
// createNode and can be cast to the subclass of BallLarusNode*
// returned by createNode. The destructor of BallLarusDag will call free
// on each pointer created.
virtual BallLarusEdge* createEdge(BallLarusNode* source, BallLarusNode*
target, unsigned duplicateNumber);
// Proxy to node's constructor. Updates the DAG state.
BallLarusNode* addNode(BasicBlock* BB);
// Proxy to edge's constructor. Updates the DAG state.
BallLarusEdge* addEdge(BallLarusNode* source, BallLarusNode* target,
unsigned duplicateNumber);
private:
// The root (i.e. entry) node for this DAG.
BallLarusNode* _root;
// The exit node for this DAG.
BallLarusNode* _exit;
// The function represented by this DAG.
Function& _function;
// Processes one node and its imediate edges for building the DAG.
void buildNode(BLBlockNodeMap& inDag, std::stack<BallLarusNode*>& dfsStack);
// Process an edge in the CFG for DAG building.
void buildEdge(BLBlockNodeMap& inDag, std::stack<BallLarusNode*>& dfsStack,
BallLarusNode* currentNode, BasicBlock* succBB,
unsigned duplicateNumber);
// The weight on each edge is the increment required along any path that
// contains that edge.
void calculatePathNumbersFrom(BallLarusNode* node);
// Adds a backedge with its phony edges. Updates the DAG state.
void addBackedge(BallLarusNode* source, BallLarusNode* target,
unsigned duplicateCount);
};
} // end namespace llvm
#endif

View File

@ -1,112 +0,0 @@
//===- PathProfileInfo.h --------------------------------------*- C++ -*---===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file outlines the interface used by optimizers to load path profiles.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_PATHPROFILEINFO_H
#define LLVM_ANALYSIS_PATHPROFILEINFO_H
#include "llvm/Analysis/PathNumbering.h"
#include "llvm/IR/BasicBlock.h"
namespace llvm {
class ProfilePath;
class ProfilePathEdge;
class PathProfileInfo;
typedef std::vector<ProfilePathEdge> ProfilePathEdgeVector;
typedef std::vector<ProfilePathEdge>::iterator ProfilePathEdgeIterator;
typedef std::vector<BasicBlock*> ProfilePathBlockVector;
typedef std::vector<BasicBlock*>::iterator ProfilePathBlockIterator;
typedef std::map<unsigned int,ProfilePath*> ProfilePathMap;
typedef std::map<unsigned int,ProfilePath*>::iterator ProfilePathIterator;
typedef std::map<Function*,unsigned int> FunctionPathCountMap;
typedef std::map<Function*,ProfilePathMap> FunctionPathMap;
typedef std::map<Function*,ProfilePathMap>::iterator FunctionPathIterator;
class ProfilePathEdge {
public:
ProfilePathEdge(BasicBlock* source, BasicBlock* target,
unsigned duplicateNumber);
inline unsigned getDuplicateNumber() { return _duplicateNumber; }
inline BasicBlock* getSource() { return _source; }
inline BasicBlock* getTarget() { return _target; }
protected:
BasicBlock* _source;
BasicBlock* _target;
unsigned _duplicateNumber;
};
class ProfilePath {
public:
ProfilePath(unsigned int number, unsigned int count,
double countStdDev, PathProfileInfo* ppi);
double getFrequency() const;
inline unsigned int getNumber() const { return _number; }
inline unsigned int getCount() const { return _count; }
inline double getCountStdDev() const { return _countStdDev; }
ProfilePathEdgeVector* getPathEdges() const;
ProfilePathBlockVector* getPathBlocks() const;
BasicBlock* getFirstBlockInPath() const;
private:
unsigned int _number;
unsigned int _count;
double _countStdDev;
// double pointer back to the profiling info
PathProfileInfo* _ppi;
};
// TODO: overload [] operator for getting path
// Add: getFunctionCallCount()
class PathProfileInfo {
public:
PathProfileInfo();
~PathProfileInfo();
void setCurrentFunction(Function* F);
Function* getCurrentFunction() const;
BasicBlock* getCurrentFunctionEntry();
ProfilePath* getPath(unsigned int number);
unsigned int getPotentialPathCount();
ProfilePathIterator pathBegin();
ProfilePathIterator pathEnd();
unsigned int pathsRun();
static char ID; // Pass identification
std::string argList;
protected:
FunctionPathMap _functionPaths;
FunctionPathCountMap _functionPathCounts;
private:
BallLarusDag* _currentDag;
Function* _currentFunction;
friend class ProfilePath;
};
} // end namespace llvm
#endif

View File

@ -74,6 +74,11 @@ struct PostDominatorTree : public FunctionPass {
return DT->findNearestCommonDominator(A, B);
}
inline const BasicBlock *findNearestCommonDominator(const BasicBlock *A,
const BasicBlock *B) {
return DT->findNearestCommonDominator(A, B);
}
virtual void releaseMemory() {
DT->releaseMemory();
}

View File

@ -1,140 +0,0 @@
//===- ProfileDataLoader.h - Load & convert profile info ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// The ProfileDataLoader class is used to load profiling data from a dump file.
// The ProfileDataT<FType, BType> class is used to store the mapping of this
// data to control flow edges.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_PROFILEDATALOADER_H
#define LLVM_ANALYSIS_PROFILEDATALOADER_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include <string>
namespace llvm {
class ModulePass;
class Function;
class BasicBlock;
// Helper for dumping edges to dbgs().
raw_ostream& operator<<(raw_ostream &O, std::pair<const BasicBlock *,
const BasicBlock *> E);
/// \brief The ProfileDataT<FType, BType> class is used to store the mapping of
/// profiling data to control flow edges.
///
/// An edge is defined by its source and sink basic blocks.
template<class FType, class BType>
class ProfileDataT {
public:
// The profiling information defines an Edge by its source and sink basic
// blocks.
typedef std::pair<const BType*, const BType*> Edge;
private:
typedef DenseMap<Edge, unsigned> EdgeWeights;
/// \brief Count the number of times a transition between two blocks is
/// executed.
///
/// As a special case, we also hold an edge from the null BasicBlock to the
/// entry block to indicate how many times the function was entered.
DenseMap<const FType*, EdgeWeights> EdgeInformation;
public:
/// getFunction() - Returns the Function for an Edge.
static const FType *getFunction(Edge e) {
// e.first may be NULL
assert(((!e.first) || (e.first->getParent() == e.second->getParent()))
&& "A ProfileData::Edge can not be between two functions");
assert(e.second && "A ProfileData::Edge must have a real sink");
return e.second->getParent();
}
/// getEdge() - Creates an Edge between two BasicBlocks.
static Edge getEdge(const BType *Src, const BType *Dest) {
return Edge(Src, Dest);
}
/// getEdgeWeight - Return the number of times that a given edge was
/// executed.
unsigned getEdgeWeight(Edge e) const {
const FType *f = getFunction(e);
assert((EdgeInformation.find(f) != EdgeInformation.end())
&& "No profiling information for function");
EdgeWeights weights = EdgeInformation.find(f)->second;
assert((weights.find(e) != weights.end())
&& "No profiling information for edge");
return weights.find(e)->second;
}
/// addEdgeWeight - Add 'weight' to the already stored execution count for
/// this edge.
void addEdgeWeight(Edge e, unsigned weight) {
EdgeInformation[getFunction(e)][e] += weight;
}
};
typedef ProfileDataT<Function, BasicBlock> ProfileData;
//typedef ProfileDataT<MachineFunction, MachineBasicBlock> MachineProfileData;
/// The ProfileDataLoader class is used to load raw profiling data from the
/// dump file.
class ProfileDataLoader {
private:
/// The name of the file where the raw profiling data is stored.
const std::string &Filename;
/// A vector of the command line arguments used when the target program was
/// run to generate profiling data. One entry per program run.
SmallVector<std::string, 1> CommandLines;
/// The raw values for how many times each edge was traversed, values from
/// multiple program runs are accumulated.
SmallVector<unsigned, 32> EdgeCounts;
public:
/// ProfileDataLoader ctor - Read the specified profiling data file, exiting
/// the program if the file is invalid or broken.
ProfileDataLoader(const char *ToolName, const std::string &Filename);
/// A special value used to represent the weight of an edge which has not
/// been counted yet.
static const unsigned Uncounted;
/// getNumExecutions - Return the number of times the target program was run
/// to generate this profiling data.
unsigned getNumExecutions() const { return CommandLines.size(); }
/// getExecution - Return the command line parameters used to generate the
/// i'th set of profiling data.
const std::string &getExecution(unsigned i) const { return CommandLines[i]; }
const std::string &getFileName() const { return Filename; }
/// getRawEdgeCounts - Return the raw profiling data, this is just a list of
/// numbers with no mappings to edges.
ArrayRef<unsigned> getRawEdgeCounts() const { return EdgeCounts; }
};
/// createProfileMetadataLoaderPass - This function returns a Pass that loads
/// the profiling information for the module from the specified filename.
ModulePass *createProfileMetadataLoaderPass(const std::string &Filename);
} // End llvm namespace
#endif

View File

@ -1,39 +0,0 @@
/*===-- ProfileDataTypes.h - Profiling info shared constants --------------===*\
|*
|* The LLVM Compiler Infrastructure
|*
|* This file is distributed under the University of Illinois Open Source
|* License. See LICENSE.TXT for details.
|*
|*===----------------------------------------------------------------------===*|
|*
|* This file defines constants shared by the various different profiling
|* runtime libraries and the LLVM C++ profile metadata loader. It must be a
|* C header because, at present, the profiling runtimes are written in C.
|*
\*===----------------------------------------------------------------------===*/
#ifndef LLVM_ANALYSIS_PROFILEDATATYPES_H
#define LLVM_ANALYSIS_PROFILEDATATYPES_H
/* Included by libprofile. */
#if defined(__cplusplus)
extern "C" {
#endif
/* TODO: Strip out unused entries once ProfileInfo etc has been removed. */
enum ProfilingType {
ArgumentInfo = 1, /* The command line argument block */
FunctionInfo = 2, /* Function profiling information */
BlockInfo = 3, /* Block profiling information */
EdgeInfo = 4, /* Edge profiling information */
PathInfo = 5, /* Path profiling information */
BBTraceInfo = 6, /* Basic block trace information */
OptEdgeInfo = 7 /* Edge profiling information, optimal version */
};
#if defined(__cplusplus)
}
#endif
#endif /* LLVM_ANALYSIS_PROFILEDATATYPES_H */

View File

@ -1,247 +0,0 @@
//===- llvm/Analysis/ProfileInfo.h - Profile Info Interface -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the generic ProfileInfo interface, which is used as the
// common interface used by all clients of profiling information, and
// implemented either by making static guestimations, or by actually reading in
// profiling information gathered by running the program.
//
// Note that to be useful, all profile-based optimizations should preserve
// ProfileInfo, which requires that they notify it when changes to the CFG are
// made. (This is not implemented yet.)
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_PROFILEINFO_H
#define LLVM_ANALYSIS_PROFILEINFO_H
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <map>
#include <set>
#include <string>
namespace llvm {
class Pass;
class raw_ostream;
class BasicBlock;
class Function;
class MachineBasicBlock;
class MachineFunction;
// Helper for dumping edges to dbgs().
raw_ostream& operator<<(raw_ostream &O, std::pair<const BasicBlock *, const BasicBlock *> E);
raw_ostream& operator<<(raw_ostream &O, std::pair<const MachineBasicBlock *, const MachineBasicBlock *> E);
raw_ostream& operator<<(raw_ostream &O, const BasicBlock *BB);
raw_ostream& operator<<(raw_ostream &O, const MachineBasicBlock *MBB);
raw_ostream& operator<<(raw_ostream &O, const Function *F);
raw_ostream& operator<<(raw_ostream &O, const MachineFunction *MF);
/// ProfileInfo Class - This class holds and maintains profiling
/// information for some unit of code.
template<class FType, class BType>
class ProfileInfoT {
public:
// Types for handling profiling information.
typedef std::pair<const BType*, const BType*> Edge;
typedef std::pair<Edge, double> EdgeWeight;
typedef std::map<Edge, double> EdgeWeights;
typedef std::map<const BType*, double> BlockCounts;
typedef std::map<const BType*, const BType*> Path;
protected:
// EdgeInformation - Count the number of times a transition between two
// blocks is executed. As a special case, we also hold an edge from the
// null BasicBlock to the entry block to indicate how many times the
// function was entered.
std::map<const FType*, EdgeWeights> EdgeInformation;
// BlockInformation - Count the number of times a block is executed.
std::map<const FType*, BlockCounts> BlockInformation;
// FunctionInformation - Count the number of times a function is executed.
std::map<const FType*, double> FunctionInformation;
ProfileInfoT<MachineFunction, MachineBasicBlock> *MachineProfile;
public:
static char ID; // Class identification, replacement for typeinfo
ProfileInfoT();
~ProfileInfoT(); // We want to be subclassed
// MissingValue - The value that is returned for execution counts in case
// no value is available.
static const double MissingValue;
// getFunction() - Returns the Function for an Edge, checking for validity.
static const FType* getFunction(Edge e) {
if (e.first)
return e.first->getParent();
if (e.second)
return e.second->getParent();
llvm_unreachable("Invalid ProfileInfo::Edge");
}
// getEdge() - Creates an Edge from two BasicBlocks.
static Edge getEdge(const BType *Src, const BType *Dest) {
return std::make_pair(Src, Dest);
}
//===------------------------------------------------------------------===//
/// Profile Information Queries
///
double getExecutionCount(const FType *F);
double getExecutionCount(const BType *BB);
void setExecutionCount(const BType *BB, double w);
void addExecutionCount(const BType *BB, double w);
double getEdgeWeight(Edge e) const {
typename std::map<const FType*, EdgeWeights>::const_iterator J =
EdgeInformation.find(getFunction(e));
if (J == EdgeInformation.end()) return MissingValue;
typename EdgeWeights::const_iterator I = J->second.find(e);
if (I == J->second.end()) return MissingValue;
return I->second;
}
void setEdgeWeight(Edge e, double w) {
DEBUG_WITH_TYPE("profile-info",
dbgs() << "Creating Edge " << e
<< " (weight: " << format("%.20g",w) << ")\n");
EdgeInformation[getFunction(e)][e] = w;
}
void addEdgeWeight(Edge e, double w);
EdgeWeights &getEdgeWeights (const FType *F) {
return EdgeInformation[F];
}
//===------------------------------------------------------------------===//
/// Analysis Update Methods
///
void removeBlock(const BType *BB);
void removeEdge(Edge e);
void replaceEdge(const Edge &, const Edge &);
enum GetPathMode {
GetPathToExit = 1,
GetPathToValue = 2,
GetPathToDest = 4,
GetPathWithNewEdges = 8
};
const BType *GetPath(const BType *Src, const BType *Dest,
Path &P, unsigned Mode);
void divertFlow(const Edge &, const Edge &);
void splitEdge(const BType *FirstBB, const BType *SecondBB,
const BType *NewBB, bool MergeIdenticalEdges = false);
void splitBlock(const BType *Old, const BType* New);
void splitBlock(const BType *BB, const BType* NewBB,
BType *const *Preds, unsigned NumPreds);
void replaceAllUses(const BType *RmBB, const BType *DestBB);
void transfer(const FType *Old, const FType *New);
void repair(const FType *F);
void dump(FType *F = 0, bool real = true) {
dbgs() << "**** This is ProfileInfo " << this << " speaking:\n";
if (!real) {
typename std::set<const FType*> Functions;
dbgs() << "Functions: \n";
if (F) {
dbgs() << F << "@" << format("%p", F) << ": " << format("%.20g",getExecutionCount(F)) << "\n";
Functions.insert(F);
} else {
for (typename std::map<const FType*, double>::iterator fi = FunctionInformation.begin(),
fe = FunctionInformation.end(); fi != fe; ++fi) {
dbgs() << fi->first << "@" << format("%p",fi->first) << ": " << format("%.20g",fi->second) << "\n";
Functions.insert(fi->first);
}
}
for (typename std::set<const FType*>::iterator FI = Functions.begin(), FE = Functions.end();
FI != FE; ++FI) {
const FType *F = *FI;
typename std::map<const FType*, BlockCounts>::iterator bwi = BlockInformation.find(F);
dbgs() << "BasicBlocks for Function " << F << ":\n";
for (typename BlockCounts::const_iterator bi = bwi->second.begin(), be = bwi->second.end(); bi != be; ++bi) {
dbgs() << bi->first << "@" << format("%p", bi->first) << ": " << format("%.20g",bi->second) << "\n";
}
}
for (typename std::set<const FType*>::iterator FI = Functions.begin(), FE = Functions.end();
FI != FE; ++FI) {
typename std::map<const FType*, EdgeWeights>::iterator ei = EdgeInformation.find(*FI);
dbgs() << "Edges for Function " << ei->first << ":\n";
for (typename EdgeWeights::iterator ewi = ei->second.begin(), ewe = ei->second.end();
ewi != ewe; ++ewi) {
dbgs() << ewi->first << ": " << format("%.20g",ewi->second) << "\n";
}
}
} else {
assert(F && "No function given, this is not supported!");
dbgs() << "Functions: \n";
dbgs() << F << "@" << format("%p", F) << ": " << format("%.20g",getExecutionCount(F)) << "\n";
dbgs() << "BasicBlocks for Function " << F << ":\n";
for (typename FType::const_iterator BI = F->begin(), BE = F->end();
BI != BE; ++BI) {
const BType *BB = &(*BI);
dbgs() << BB << "@" << format("%p", BB) << ": " << format("%.20g",getExecutionCount(BB)) << "\n";
}
}
dbgs() << "**** ProfileInfo " << this << ", over and out.\n";
}
bool CalculateMissingEdge(const BType *BB, Edge &removed, bool assumeEmptyExit = false);
bool EstimateMissingEdges(const BType *BB);
ProfileInfoT<MachineFunction, MachineBasicBlock> *MI() {
if (MachineProfile == 0)
MachineProfile = new ProfileInfoT<MachineFunction, MachineBasicBlock>();
return MachineProfile;
}
bool hasMI() const {
return (MachineProfile != 0);
}
};
typedef ProfileInfoT<Function, BasicBlock> ProfileInfo;
typedef ProfileInfoT<MachineFunction, MachineBasicBlock> MachineProfileInfo;
/// createProfileLoaderPass - This function returns a Pass that loads the
/// profiling information for the module from the specified filename, making
/// it available to the optimizers.
Pass *createProfileLoaderPass(const std::string &Filename);
} // End llvm namespace
#endif

View File

@ -1,81 +0,0 @@
//===- ProfileInfoLoader.h - Load & convert profile information -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// The ProfileInfoLoader class is used to load and represent profiling
// information read in from the dump file. If conversions between formats are
// needed, it can also do this.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_PROFILEINFOLOADER_H
#define LLVM_ANALYSIS_PROFILEINFOLOADER_H
#include <string>
#include <utility>
#include <vector>
namespace llvm {
class Module;
class Function;
class BasicBlock;
class ProfileInfoLoader {
const std::string &Filename;
std::vector<std::string> CommandLines;
std::vector<unsigned> FunctionCounts;
std::vector<unsigned> BlockCounts;
std::vector<unsigned> EdgeCounts;
std::vector<unsigned> OptimalEdgeCounts;
std::vector<unsigned> BBTrace;
public:
// ProfileInfoLoader ctor - Read the specified profiling data file, exiting
// the program if the file is invalid or broken.
ProfileInfoLoader(const char *ToolName, const std::string &Filename);
static const unsigned Uncounted;
unsigned getNumExecutions() const { return CommandLines.size(); }
const std::string &getExecution(unsigned i) const { return CommandLines[i]; }
const std::string &getFileName() const { return Filename; }
// getRawFunctionCounts - This method is used by consumers of function
// counting information.
//
const std::vector<unsigned> &getRawFunctionCounts() const {
return FunctionCounts;
}
// getRawBlockCounts - This method is used by consumers of block counting
// information.
//
const std::vector<unsigned> &getRawBlockCounts() const {
return BlockCounts;
}
// getEdgeCounts - This method is used by consumers of edge counting
// information.
//
const std::vector<unsigned> &getRawEdgeCounts() const {
return EdgeCounts;
}
// getEdgeOptimalCounts - This method is used by consumers of optimal edge
// counting information.
//
const std::vector<unsigned> &getRawOptimalEdgeCounts() const {
return OptimalEdgeCounts;
}
};
} // End llvm namespace
#endif

View File

@ -1,52 +0,0 @@
/*===-- ProfileInfoTypes.h - Profiling info shared constants --------------===*\
|*
|* The LLVM Compiler Infrastructure
|*
|* This file is distributed under the University of Illinois Open Source
|* License. See LICENSE.TXT for details.
|*
|*===----------------------------------------------------------------------===*|
|*
|* This file defines constants shared by the various different profiling
|* runtime libraries and the LLVM C++ profile info loader. It must be a
|* C header because, at present, the profiling runtimes are written in C.
|*
\*===----------------------------------------------------------------------===*/
#ifndef LLVM_ANALYSIS_PROFILEINFOTYPES_H
#define LLVM_ANALYSIS_PROFILEINFOTYPES_H
/* Included by libprofile. */
#if defined(__cplusplus)
extern "C" {
#endif
/* IDs to distinguish between those path counters stored in hashses vs arrays */
enum ProfilingStorageType {
ProfilingArray = 1,
ProfilingHash = 2
};
#include "llvm/Analysis/ProfileDataTypes.h"
/*
* The header for tables that map path numbers to path counters.
*/
typedef struct {
unsigned fnNumber; /* function number for these counters */
unsigned numEntries; /* number of entries stored */
} PathProfileHeader;
/*
* Describes an entry in a tagged table for path counters.
*/
typedef struct {
unsigned pathNumber;
unsigned pathCounter;
} PathProfileTableEntry;
#if defined(__cplusplus)
}
#endif
#endif /* LLVM_ANALYSIS_PROFILEINFOTYPES_H */

View File

@ -18,8 +18,8 @@
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/LegacyPassManagers.h"
#include "llvm/Pass.h"
#include "llvm/PassManagers.h"
#include <deque>
namespace llvm {
@ -51,7 +51,7 @@ public:
/// @brief Get a pass to print the LLVM IR in the region.
///
/// @param O The ouput stream to print the Region.
/// @param O The output stream to print the Region.
/// @param Banner The banner to separate different printed passes.
///
/// @return The pass to print the LLVM IR in the region.

View File

@ -189,15 +189,16 @@ namespace llvm {
/// Convenient NoWrapFlags manipulation that hides enum casts and is
/// visible in the ScalarEvolution name space.
static SCEV::NoWrapFlags maskFlags(SCEV::NoWrapFlags Flags, int Mask) {
static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT
maskFlags(SCEV::NoWrapFlags Flags, int Mask) {
return (SCEV::NoWrapFlags)(Flags & Mask);
}
static SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags,
SCEV::NoWrapFlags OnFlags) {
static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT
setFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OnFlags) {
return (SCEV::NoWrapFlags)(Flags | OnFlags);
}
static SCEV::NoWrapFlags clearFlags(SCEV::NoWrapFlags Flags,
SCEV::NoWrapFlags OffFlags) {
static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT
clearFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OffFlags) {
return (SCEV::NoWrapFlags)(Flags & ~OffFlags);
}
@ -361,18 +362,18 @@ namespace llvm {
/// that we attempt to compute getSCEVAtScope information for, which can
/// be expensive in extreme cases.
DenseMap<const SCEV *,
std::map<const Loop *, const SCEV *> > ValuesAtScopes;
SmallVector<std::pair<const Loop *, const SCEV *>, 2> > ValuesAtScopes;
/// LoopDispositions - Memoized computeLoopDisposition results.
DenseMap<const SCEV *,
std::map<const Loop *, LoopDisposition> > LoopDispositions;
SmallVector<std::pair<const Loop *, LoopDisposition>, 2> > LoopDispositions;
/// computeLoopDisposition - Compute a LoopDisposition value.
LoopDisposition computeLoopDisposition(const SCEV *S, const Loop *L);
/// BlockDispositions - Memoized computeBlockDisposition results.
DenseMap<const SCEV *,
std::map<const BasicBlock *, BlockDisposition> > BlockDispositions;
SmallVector<std::pair<const BasicBlock *, BlockDisposition>, 2> > BlockDispositions;
/// computeBlockDisposition - Compute a BlockDisposition value.
BlockDisposition computeBlockDisposition(const SCEV *S, const BasicBlock *BB);
@ -426,14 +427,6 @@ namespace llvm {
/// resolution.
void ForgetSymbolicName(Instruction *I, const SCEV *SymName);
/// getBECount - Subtract the end and start values and divide by the step,
/// rounding up, to get the number of times the backedge is executed. Return
/// CouldNotCompute if an intermediate computation overflows.
const SCEV *getBECount(const SCEV *Start,
const SCEV *End,
const SCEV *Step,
bool NoWrap);
/// getBackedgeTakenInfo - Return the BackedgeTakenInfo for the given
/// loop, lazily computing new values if the loop hasn't been analyzed
/// yet.
@ -498,6 +491,8 @@ namespace llvm {
/// less-than is signed.
ExitLimit HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
const Loop *L, bool isSigned, bool IsSubExpr);
ExitLimit HowManyGreaterThans(const SCEV *LHS, const SCEV *RHS,
const Loop *L, bool isSigned, bool IsSubExpr);
/// getPredecessorWithUniqueSuccessorForBB - Return a predecessor of BB
/// (which may not be an immediate predecessor) which has exactly one
@ -545,6 +540,10 @@ namespace llvm {
/// forgetMemoizedResults - Drop memoized information computed for S.
void forgetMemoizedResults(const SCEV *S);
/// Return false iff given SCEV contains a SCEVUnknown with NULL value-
/// pointer.
bool checkValidity(const SCEV *S) const;
public:
static char ID; // Pass identification, replacement for typeid
ScalarEvolution();
@ -632,21 +631,15 @@ namespace llvm {
const SCEV *getUnknown(Value *V);
const SCEV *getCouldNotCompute();
/// getSizeOfExpr - Return an expression for sizeof on the given type.
/// getSizeOfExpr - Return an expression for sizeof AllocTy that is type
/// IntTy
///
const SCEV *getSizeOfExpr(Type *AllocTy);
const SCEV *getSizeOfExpr(Type *IntTy, Type *AllocTy);
/// getAlignOfExpr - Return an expression for alignof on the given type.
/// getOffsetOfExpr - Return an expression for offsetof on the given field
/// with type IntTy
///
const SCEV *getAlignOfExpr(Type *AllocTy);
/// getOffsetOfExpr - Return an expression for offsetof on the given field.
///
const SCEV *getOffsetOfExpr(StructType *STy, unsigned FieldNo);
/// getOffsetOfExpr - Return an expression for offsetof on the given field.
///
const SCEV *getOffsetOfExpr(Type *CTy, Constant *FieldNo);
const SCEV *getOffsetOfExpr(Type *IntTy, StructType *STy, unsigned FieldNo);
/// getNegativeSCEV - Return the SCEV object corresponding to -V.
///
@ -881,6 +874,24 @@ namespace llvm {
virtual void print(raw_ostream &OS, const Module* = 0) const;
virtual void verifyAnalysis() const;
private:
/// Compute the backedge taken count knowing the interval difference, the
/// stride and presence of the equality in the comparison.
const SCEV *computeBECount(const SCEV *Delta, const SCEV *Stride,
bool Equality);
/// Verify if an linear IV with positive stride can overflow when in a
/// less-than comparison, knowing the invariant term of the comparison,
/// the stride and the knowledge of NSW/NUW flags on the recurrence.
bool doesIVOverflowOnLT(const SCEV *RHS, const SCEV *Stride,
bool IsSigned, bool NoWrap);
/// Verify if an linear IV with negative stride can overflow when in a
/// greater-than comparison, knowing the invariant term of the comparison,
/// the stride and the knowledge of NSW/NUW flags on the recurrence.
bool doesIVOverflowOnGT(const SCEV *RHS, const SCEV *Stride,
bool IsSigned, bool NoWrap);
private:
FoldingSet<SCEV> UniqueSCEVs;
BumpPtrAllocator SCEVAllocator;

View File

@ -26,7 +26,7 @@ namespace llvm {
/// Return true if the given expression is safe to expand in the sense that
/// all materialized values are safe to speculate.
bool isSafeToExpand(const SCEV *S);
bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE);
/// SCEVExpander - This class uses information about analyze scalars to
/// rewrite expressions in canonical form.
@ -252,8 +252,6 @@ namespace llvm {
void rememberInstruction(Value *I);
void restoreInsertPoint(BasicBlock *BB, BasicBlock::iterator I);
bool isNormalAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L);
bool isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L);

View File

@ -351,8 +351,14 @@ namespace llvm {
static inline bool classof(const SCEV *S) {
return S->getSCEVType() == scAddRecExpr;
}
};
/// Splits the SCEV into two vectors of SCEVs representing the subscripts
/// and sizes of an array access. Returns the remainder of the
/// delinearization that is the offset start of the array.
const SCEV *delinearize(ScalarEvolution &SE,
SmallVectorImpl<const SCEV *> &Subscripts,
SmallVectorImpl<const SCEV *> &Sizes) const;
};
//===--------------------------------------------------------------------===//
/// SCEVSMaxExpr - This class represents a signed maximum selection.
@ -549,53 +555,60 @@ namespace llvm {
T.visitAll(Root);
}
/// The SCEVRewriter takes a scalar evolution expression and copies all its
/// components. The result after a rewrite is an identical SCEV.
struct SCEVRewriter
: public SCEVVisitor<SCEVRewriter, const SCEV*> {
typedef DenseMap<const Value*, Value*> ValueToValueMap;
/// The SCEVParameterRewriter takes a scalar evolution expression and updates
/// the SCEVUnknown components following the Map (Value -> Value).
struct SCEVParameterRewriter
: public SCEVVisitor<SCEVParameterRewriter, const SCEV*> {
public:
SCEVRewriter(ScalarEvolution &S) : SE(S) {}
static const SCEV *rewrite(const SCEV *Scev, ScalarEvolution &SE,
ValueToValueMap &Map) {
SCEVParameterRewriter Rewriter(SE, Map);
return Rewriter.visit(Scev);
}
virtual ~SCEVRewriter() {}
SCEVParameterRewriter(ScalarEvolution &S, ValueToValueMap &M)
: SE(S), Map(M) {}
virtual const SCEV *visitConstant(const SCEVConstant *Constant) {
const SCEV *visitConstant(const SCEVConstant *Constant) {
return Constant;
}
virtual const SCEV *visitTruncateExpr(const SCEVTruncateExpr *Expr) {
const SCEV *visitTruncateExpr(const SCEVTruncateExpr *Expr) {
const SCEV *Operand = visit(Expr->getOperand());
return SE.getTruncateExpr(Operand, Expr->getType());
}
virtual const SCEV *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
const SCEV *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
const SCEV *Operand = visit(Expr->getOperand());
return SE.getZeroExtendExpr(Operand, Expr->getType());
}
virtual const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
const SCEV *Operand = visit(Expr->getOperand());
return SE.getSignExtendExpr(Operand, Expr->getType());
}
virtual const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {
const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getAddExpr(Operands);
}
virtual const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getMulExpr(Operands);
}
virtual const SCEV *visitUDivExpr(const SCEVUDivExpr *Expr) {
const SCEV *visitUDivExpr(const SCEVUDivExpr *Expr) {
return SE.getUDivExpr(visit(Expr->getLHS()), visit(Expr->getRHS()));
}
virtual const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
@ -603,54 +616,33 @@ namespace llvm {
Expr->getNoWrapFlags());
}
virtual const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getSMaxExpr(Operands);
}
virtual const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) {
const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getUMaxExpr(Operands);
}
virtual const SCEV *visitUnknown(const SCEVUnknown *Expr) {
return Expr;
}
virtual const SCEV *visitCouldNotCompute(const SCEVCouldNotCompute *Expr) {
return Expr;
}
protected:
ScalarEvolution &SE;
};
typedef DenseMap<const Value*, Value*> ValueToValueMap;
/// The SCEVParameterRewriter takes a scalar evolution expression and updates
/// the SCEVUnknown components following the Map (Value -> Value).
struct SCEVParameterRewriter: public SCEVRewriter {
public:
static const SCEV *rewrite(const SCEV *Scev, ScalarEvolution &SE,
ValueToValueMap &Map) {
SCEVParameterRewriter Rewriter(SE, Map);
return Rewriter.visit(Scev);
}
SCEVParameterRewriter(ScalarEvolution &S, ValueToValueMap &M)
: SCEVRewriter(S), Map(M) {}
virtual const SCEV *visitUnknown(const SCEVUnknown *Expr) {
const SCEV *visitUnknown(const SCEVUnknown *Expr) {
Value *V = Expr->getValue();
if (Map.count(V))
return SE.getUnknown(Map[V]);
return Expr;
}
const SCEV *visitCouldNotCompute(const SCEVCouldNotCompute *Expr) {
return Expr;
}
private:
ScalarEvolution &SE;
ValueToValueMap &Map;
};
@ -658,17 +650,56 @@ namespace llvm {
/// The SCEVApplyRewriter takes a scalar evolution expression and applies
/// the Map (Loop -> SCEV) to all AddRecExprs.
struct SCEVApplyRewriter: public SCEVRewriter {
struct SCEVApplyRewriter
: public SCEVVisitor<SCEVApplyRewriter, const SCEV*> {
public:
static const SCEV *rewrite(const SCEV *Scev, LoopToScevMapT &Map,
ScalarEvolution &SE) {
SCEVApplyRewriter Rewriter(SE, Map);
return Rewriter.visit(Scev);
}
SCEVApplyRewriter(ScalarEvolution &S, LoopToScevMapT &M)
: SCEVRewriter(S), Map(M) {}
virtual const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
SCEVApplyRewriter(ScalarEvolution &S, LoopToScevMapT &M)
: SE(S), Map(M) {}
const SCEV *visitConstant(const SCEVConstant *Constant) {
return Constant;
}
const SCEV *visitTruncateExpr(const SCEVTruncateExpr *Expr) {
const SCEV *Operand = visit(Expr->getOperand());
return SE.getTruncateExpr(Operand, Expr->getType());
}
const SCEV *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
const SCEV *Operand = visit(Expr->getOperand());
return SE.getZeroExtendExpr(Operand, Expr->getType());
}
const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
const SCEV *Operand = visit(Expr->getOperand());
return SE.getSignExtendExpr(Operand, Expr->getType());
}
const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getAddExpr(Operands);
}
const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getMulExpr(Operands);
}
const SCEV *visitUDivExpr(const SCEVUDivExpr *Expr) {
return SE.getUDivExpr(visit(Expr->getLHS()), visit(Expr->getRHS()));
}
const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
@ -683,7 +714,30 @@ namespace llvm {
return Rec->evaluateAtIteration(Map[L], SE);
}
const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getSMaxExpr(Operands);
}
const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getUMaxExpr(Operands);
}
const SCEV *visitUnknown(const SCEVUnknown *Expr) {
return Expr;
}
const SCEV *visitCouldNotCompute(const SCEVCouldNotCompute *Expr) {
return Expr;
}
private:
ScalarEvolution &SE;
LoopToScevMapT &Map;
};

View File

@ -29,6 +29,7 @@
namespace llvm {
class GlobalValue;
class Loop;
class Type;
class User;
class Value;
@ -171,6 +172,12 @@ public:
/// comments for a detailed explanation of the cost values.
virtual unsigned getUserCost(const User *U) const;
/// \brief hasBranchDivergence - Return true if branch divergence exists.
/// Branch divergence has a significantly negative impact on GPU performance
/// when threads in the same wavefront take different paths due to conditional
/// branches.
virtual bool hasBranchDivergence() const;
/// \brief Test whether calls to a function lower to actual program function
/// calls.
///
@ -185,6 +192,36 @@ public:
/// incurs significant execution cost.
virtual bool isLoweredToCall(const Function *F) const;
/// Parameters that control the generic loop unrolling transformation.
struct UnrollingPreferences {
/// The cost threshold for the unrolled loop, compared to
/// CodeMetrics.NumInsts aggregated over all basic blocks in the loop body.
/// The unrolling factor is set such that the unrolled loop body does not
/// exceed this cost. Set this to UINT_MAX to disable the loop body cost
/// restriction.
unsigned Threshold;
/// The cost threshold for the unrolled loop when optimizing for size (set
/// to UINT_MAX to disable).
unsigned OptSizeThreshold;
/// A forced unrolling factor (the number of concatenated bodies of the
/// original loop in the unrolled loop body). When set to 0, the unrolling
/// transformation will select an unrolling factor based on the current cost
/// threshold and other factors.
unsigned Count;
/// Allow partial unrolling (unrolling of loops to expand the size of the
/// loop body, not only to eliminate small constant-trip-count loops).
bool Partial;
/// Allow runtime unrolling (unrolling of loops to expand the size of the
/// loop body even when the number of loop iterations is not known at compile
/// time).
bool Runtime;
};
/// \brief Get target-customized preferences for the generic loop unrolling
/// transformation. The caller will initialize UP with the current
/// target-independent defaults.
virtual void getUnrollingPreferences(Loop *L, UnrollingPreferences &UP) const;
/// @}
/// \name Scalar Target Information
@ -225,6 +262,16 @@ public:
int64_t BaseOffset, bool HasBaseReg,
int64_t Scale) const;
/// \brief Return the cost of the scaling factor used in the addressing
/// mode represented by AM for this target, for a load/store
/// of the specified type.
/// If the AM is supported, the return value must be >= 0.
/// If the AM is not supported, it returns a negative value.
/// TODO: Handle pre/postinc as well.
virtual int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
int64_t BaseOffset, bool HasBaseReg,
int64_t Scale) const;
/// isTruncateFree - Return true if it's free to truncate a value of
/// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
/// register EAX to i16 by referencing its sub-register AX.
@ -246,6 +293,10 @@ public:
/// getPopcntSupport - Return hardware support for population count.
virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
/// haveFastSqrt -- Return true if the hardware has a fast square-root
/// instruction.
virtual bool haveFastSqrt(Type *Ty) const;
/// getIntImmCost - Return the expected cost of materializing the given
/// integer immediate of the specified type.
virtual unsigned getIntImmCost(const APInt &Imm, Type *Ty) const;
@ -263,7 +314,7 @@ public:
SK_ExtractSubvector ///< ExtractSubvector Index indicates start offset.
};
/// \brief Additonal information about an operand's possible values.
/// \brief Additional information about an operand's possible values.
enum OperandValueKind {
OK_AnyValue, // Operand can have any value.
OK_UniformValue, // Operand is uniform (splat of a value).
@ -317,6 +368,22 @@ public:
unsigned Alignment,
unsigned AddressSpace) const;
/// \brief Calculate the cost of performing a vector reduction.
///
/// This is the cost of reducing the vector value of type \p Ty to a scalar
/// value using the operation denoted by \p Opcode. The form of the reduction
/// can either be a pairwise reduction or a reduction that splits the vector
/// at every reduction level.
///
/// Pairwise:
/// (v0, v1, v2, v3)
/// ((v0+v1), (v2, v3), undef, undef)
/// Split:
/// (v0, v1, v2, v3)
/// ((v0+v2), (v1+v3), undef, undef)
virtual unsigned getReductionCost(unsigned Opcode, Type *Ty,
bool IsPairwiseForm) const;
/// \returns The cost of Intrinsic instructions.
virtual unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
ArrayRef<Type *> Tys) const;
@ -329,7 +396,11 @@ public:
/// merged into the instruction indexing mode. Some targets might want to
/// distinguish between address computation for memory operations on vector
/// types and scalar types. Such targets should override this function.
virtual unsigned getAddressComputationCost(Type *Ty) const;
/// The 'IsComplex' parameter is a hint that the address computation is likely
/// to involve multiple instructions and as such unlikely to be merged into
/// the address indexing mode.
virtual unsigned getAddressComputationCost(Type *Ty,
bool IsComplex = false) const;
/// @}

View File

@ -25,6 +25,7 @@ namespace llvm {
class DataLayout;
class StringRef;
class MDNode;
class TargetLibraryInfo;
/// ComputeMaskedBits - Determine which of the bits specified in Mask are
/// known to be either zero or one and return them in the KnownZero/KnownOne
@ -186,7 +187,7 @@ namespace llvm {
/// isKnownNonNull - Return true if this pointer couldn't possibly be null by
/// its definition. This returns true for allocas, non-extern-weak globals
/// and byval arguments.
bool isKnownNonNull(const Value *V);
bool isKnownNonNull(const Value *V, const TargetLibraryInfo *TLI = 0);
} // end namespace llvm

View File

@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
//
// These functions are implemented by lib/VMCore/AutoUpgrade.cpp.
// These functions are implemented by lib/IR/AutoUpgrade.cpp.
//
//===----------------------------------------------------------------------===//
@ -15,30 +15,52 @@
#define LLVM_AUTOUPGRADE_H
namespace llvm {
class CallInst;
class Constant;
class Function;
class Instruction;
class Module;
class GlobalVariable;
class Function;
class CallInst;
class Type;
class Value;
/// This is a more granular function that simply checks an intrinsic function
/// This is a more granular function that simply checks an intrinsic function
/// for upgrading, and returns true if it requires upgrading. It may return
/// null in NewFn if the all calls to the original intrinsic function
/// should be transformed to non-function-call instructions.
bool UpgradeIntrinsicFunction(Function *F, Function *&NewFn);
/// This is the complement to the above, replacing a specific call to an
/// This is the complement to the above, replacing a specific call to an
/// intrinsic function with a call to the specified new function.
void UpgradeIntrinsicCall(CallInst *CI, Function *NewFn);
/// This is an auto-upgrade hook for any old intrinsic function syntaxes
/// which need to have both the function updated as well as all calls updated
/// to the new function. This should only be run in a post-processing fashion
/// This is an auto-upgrade hook for any old intrinsic function syntaxes
/// which need to have both the function updated as well as all calls updated
/// to the new function. This should only be run in a post-processing fashion
/// so that it can update all calls to the old function.
void UpgradeCallsToIntrinsic(Function* F);
/// This checks for global variables which should be upgraded. It returns true
/// if it requires upgrading.
bool UpgradeGlobalVariable(GlobalVariable *GV);
/// If the TBAA tag for the given instruction uses the scalar TBAA format,
/// we upgrade it to the struct-path aware TBAA format.
void UpgradeInstWithTBAATag(Instruction *I);
/// This is an auto-upgrade for bitcast between pointers with different
/// address spaces: the instruction is replaced by a pair ptrtoint+inttoptr.
Instruction *UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy,
Instruction *&Temp);
/// This is an auto-upgrade for bitcast constant expression between pointers
/// with different address spaces: the instruction is replaced by a pair
/// ptrtoint+inttoptr.
Value *UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy);
/// Check the debug info version number, if it is out-dated, drop the debug
/// info. Return true if module is modified.
bool UpgradeDebugInfo(Module &M);
} // End llvm namespace
#endif

View File

@ -1,538 +0,0 @@
//===-- llvm/Bitcode/Archive.h - LLVM Bitcode Archive -----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This header file declares the Archive and ArchiveMember classes that provide
// manipulation of LLVM Archive files. The implementation is provided by the
// lib/Bitcode/Archive library. This library is used to read and write
// archive (*.a) files that contain LLVM bitcode files (or others).
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_BITCODE_ARCHIVE_H
#define LLVM_BITCODE_ARCHIVE_H
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/Support/Path.h"
#include <map>
#include <set>
namespace llvm {
class MemoryBuffer;
// Forward declare classes
class Module; // From VMCore
class Archive; // Declared below
class ArchiveMemberHeader; // Internal implementation class
class LLVMContext; // Global data
/// This class is the main class manipulated by users of the Archive class. It
/// holds information about one member of the Archive. It is also the element
/// stored by the Archive's ilist, the Archive's main abstraction. Because of
/// the special requirements of archive files, users are not permitted to
/// construct ArchiveMember instances. You should obtain them from the methods
/// of the Archive class instead.
/// @brief This class represents a single archive member.
class ArchiveMember : public ilist_node<ArchiveMember> {
/// @name Types
/// @{
public:
/// These flags are used internally by the archive member to specify various
/// characteristics of the member. The various "is" methods below provide
/// access to the flags. The flags are not user settable.
enum Flags {
SVR4SymbolTableFlag = 1, ///< Member is a SVR4 symbol table
BSD4SymbolTableFlag = 2, ///< Member is a BSD4 symbol table
LLVMSymbolTableFlag = 4, ///< Member is an LLVM symbol table
BitcodeFlag = 8, ///< Member is bitcode
HasPathFlag = 16, ///< Member has a full or partial path
HasLongFilenameFlag = 32, ///< Member uses the long filename syntax
StringTableFlag = 64 ///< Member is an ar(1) format string table
};
/// @}
/// @name Accessors
/// @{
public:
/// @returns the parent Archive instance
/// @brief Get the archive associated with this member
Archive* getArchive() const { return parent; }
/// @returns the path to the Archive's file
/// @brief Get the path to the archive member
const sys::Path& getPath() const { return path; }
/// The "user" is the owner of the file per Unix security. This may not
/// have any applicability on non-Unix systems but is a required component
/// of the "ar" file format.
/// @brief Get the user associated with this archive member.
unsigned getUser() const { return info.getUser(); }
/// The "group" is the owning group of the file per Unix security. This
/// may not have any applicability on non-Unix systems but is a required
/// component of the "ar" file format.
/// @brief Get the group associated with this archive member.
unsigned getGroup() const { return info.getGroup(); }
/// The "mode" specifies the access permissions for the file per Unix
/// security. This may not have any applicability on non-Unix systems but is
/// a required component of the "ar" file format.
/// @brief Get the permission mode associated with this archive member.
unsigned getMode() const { return info.getMode(); }
/// This method returns the time at which the archive member was last
/// modified when it was not in the archive.
/// @brief Get the time of last modification of the archive member.
sys::TimeValue getModTime() const { return info.getTimestamp(); }
/// @returns the size of the archive member in bytes.
/// @brief Get the size of the archive member.
uint64_t getSize() const { return info.getSize(); }
/// This method returns the total size of the archive member as it
/// appears on disk. This includes the file content, the header, the
/// long file name if any, and the padding.
/// @brief Get total on-disk member size.
unsigned getMemberSize() const;
/// This method will return a pointer to the in-memory content of the
/// archive member, if it is available. If the data has not been loaded
/// into memory, the return value will be null.
/// @returns a pointer to the member's data.
/// @brief Get the data content of the archive member
const char* getData() const { return data; }
/// @returns true iff the member is a SVR4 (non-LLVM) symbol table
/// @brief Determine if this member is a SVR4 symbol table.
bool isSVR4SymbolTable() const { return flags&SVR4SymbolTableFlag; }
/// @returns true iff the member is a BSD4.4 (non-LLVM) symbol table
/// @brief Determine if this member is a BSD4.4 symbol table.
bool isBSD4SymbolTable() const { return flags&BSD4SymbolTableFlag; }
/// @returns true iff the archive member is the LLVM symbol table
/// @brief Determine if this member is the LLVM symbol table.
bool isLLVMSymbolTable() const { return flags&LLVMSymbolTableFlag; }
/// @returns true iff the archive member is the ar(1) string table
/// @brief Determine if this member is the ar(1) string table.
bool isStringTable() const { return flags&StringTableFlag; }
/// @returns true iff the archive member is a bitcode file.
/// @brief Determine if this member is a bitcode file.
bool isBitcode() const { return flags&BitcodeFlag; }
/// @returns true iff the file name contains a path (directory) component.
/// @brief Determine if the member has a path
bool hasPath() const { return flags&HasPathFlag; }
/// Long filenames are an artifact of the ar(1) file format which allows
/// up to sixteen characters in its header and doesn't allow a path
/// separator character (/). To avoid this, a "long format" member name is
/// allowed that doesn't have this restriction. This method determines if
/// that "long format" is used for this member.
/// @returns true iff the file name uses the long form
/// @brief Determine if the member has a long file name
bool hasLongFilename() const { return flags&HasLongFilenameFlag; }
/// This method returns the status info (like Unix stat(2)) for the archive
/// member. The status info provides the file's size, permissions, and
/// modification time. The contents of the Path::StatusInfo structure, other
/// than the size and modification time, may not have utility on non-Unix
/// systems.
/// @returns the status info for the archive member
/// @brief Obtain the status info for the archive member
const sys::FileStatus &getFileStatus() const { return info; }
/// This method causes the archive member to be replaced with the contents
/// of the file specified by \p File. The contents of \p this will be
/// updated to reflect the new data from \p File. The \p File must exist and
/// be readable on entry to this method.
/// @returns true if an error occurred, false otherwise
/// @brief Replace contents of archive member with a new file.
bool replaceWith(const sys::Path &aFile, std::string* ErrMsg);
/// @}
/// @name Data
/// @{
private:
Archive* parent; ///< Pointer to parent archive
sys::PathWithStatus path; ///< Path of file containing the member
sys::FileStatus info; ///< Status info (size,mode,date)
unsigned flags; ///< Flags about the archive member
const char* data; ///< Data for the member
/// @}
/// @name Constructors
/// @{
public:
/// The default constructor is only used by the Archive's iplist when it
/// constructs the list's sentry node.
ArchiveMember();
private:
/// Used internally by the Archive class to construct an ArchiveMember.
/// The contents of the ArchiveMember are filled out by the Archive class.
explicit ArchiveMember(Archive *PAR);
// So Archive can construct an ArchiveMember
friend class llvm::Archive;
/// @}
};
/// This class defines the interface to LLVM Archive files. The Archive class
/// presents the archive file as an ilist of ArchiveMember objects. The members
/// can be rearranged in any fashion either by directly editing the ilist or by
/// using editing methods on the Archive class (recommended). The Archive
/// class also provides several ways of accessing the archive file for various
/// purposes such as editing and linking. Full symbol table support is provided
/// for loading only those files that resolve symbols. Note that read
/// performance of this library is _crucial_ for performance of JIT type
/// applications and the linkers. Consequently, the implementation of the class
/// is optimized for reading.
class Archive {
/// @name Types
/// @{
public:
/// This is the ilist type over which users may iterate to examine
/// the contents of the archive
/// @brief The ilist type of ArchiveMembers that Archive contains.
typedef iplist<ArchiveMember> MembersList;
/// @brief Forward mutable iterator over ArchiveMember
typedef MembersList::iterator iterator;
/// @brief Forward immutable iterator over ArchiveMember
typedef MembersList::const_iterator const_iterator;
/// @brief Reverse mutable iterator over ArchiveMember
typedef std::reverse_iterator<iterator> reverse_iterator;
/// @brief Reverse immutable iterator over ArchiveMember
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
/// @brief The in-memory version of the symbol table
typedef std::map<std::string,unsigned> SymTabType;
/// @}
/// @name ilist accessor methods
/// @{
public:
inline iterator begin() { return members.begin(); }
inline const_iterator begin() const { return members.begin(); }
inline iterator end () { return members.end(); }
inline const_iterator end () const { return members.end(); }
inline reverse_iterator rbegin() { return members.rbegin(); }
inline const_reverse_iterator rbegin() const { return members.rbegin(); }
inline reverse_iterator rend () { return members.rend(); }
inline const_reverse_iterator rend () const { return members.rend(); }
inline size_t size() const { return members.size(); }
inline bool empty() const { return members.empty(); }
inline const ArchiveMember& front() const { return members.front(); }
inline ArchiveMember& front() { return members.front(); }
inline const ArchiveMember& back() const { return members.back(); }
inline ArchiveMember& back() { return members.back(); }
/// @}
/// @name ilist mutator methods
/// @{
public:
/// This method splices a \p src member from an archive (possibly \p this),
/// to a position just before the member given by \p dest in \p this. When
/// the archive is written, \p src will be written in its new location.
/// @brief Move a member to a new location
inline void splice(iterator dest, Archive& arch, iterator src)
{ return members.splice(dest,arch.members,src); }
/// This method erases a \p target member from the archive. When the
/// archive is written, it will no longer contain \p target. The associated
/// ArchiveMember is deleted.
/// @brief Erase a member.
inline iterator erase(iterator target) { return members.erase(target); }
/// @}
/// @name Constructors
/// @{
public:
/// Create an empty archive file and associate it with the \p Filename. This
/// method does not actually create the archive disk file. It creates an
/// empty Archive object. If the writeToDisk method is called, the archive
/// file \p Filename will be created at that point, with whatever content
/// the returned Archive object has at that time.
/// @returns An Archive* that represents the new archive file.
/// @brief Create an empty Archive.
static Archive* CreateEmpty(
const sys::Path& Filename,///< Name of the archive to (eventually) create.
LLVMContext& C ///< Context to use for global information
);
/// Open an existing archive and load its contents in preparation for
/// editing. After this call, the member ilist is completely populated based
/// on the contents of the archive file. You should use this form of open if
/// you intend to modify the archive or traverse its contents (e.g. for
/// printing).
/// @brief Open and load an archive file
static Archive* OpenAndLoad(
const sys::Path& filePath, ///< The file path to open and load
LLVMContext& C, ///< The context to use for global information
std::string* ErrorMessage ///< An optional error string
);
/// This method opens an existing archive file from \p Filename and reads in
/// its symbol table without reading in any of the archive's members. This
/// reduces both I/O and cpu time in opening the archive if it is to be used
/// solely for symbol lookup (e.g. during linking). The \p Filename must
/// exist and be an archive file or an error will be returned. This form
/// of opening the archive is intended for read-only operations that need to
/// locate members via the symbol table for link editing. Since the archve
/// members are not read by this method, the archive will appear empty upon
/// return. If editing operations are performed on the archive, they will
/// completely replace the contents of the archive! It is recommended that
/// if this form of opening the archive is used that only the symbol table
/// lookup methods (getSymbolTable, findModuleDefiningSymbol, and
/// findModulesDefiningSymbols) be used.
/// @returns an Archive* that represents the archive file, or null on error.
/// @brief Open an existing archive and load its symbols.
static Archive* OpenAndLoadSymbols(
const sys::Path& Filename, ///< Name of the archive file to open
LLVMContext& C, ///< The context to use for global info
std::string* ErrorMessage=0 ///< An optional error string
);
/// This destructor cleans up the Archive object, releases all memory, and
/// closes files. It does nothing with the archive file on disk. If you
/// haven't used the writeToDisk method by the time the destructor is
/// called, all changes to the archive will be lost.
/// @brief Destruct in-memory archive
~Archive();
/// @}
/// @name Accessors
/// @{
public:
/// @returns the path to the archive file.
/// @brief Get the archive path.
const sys::Path& getPath() { return archPath; }
/// This method is provided so that editing methods can be invoked directly
/// on the Archive's iplist of ArchiveMember. However, it is recommended
/// that the usual STL style iterator interface be used instead.
/// @returns the iplist of ArchiveMember
/// @brief Get the iplist of the members
MembersList& getMembers() { return members; }
/// This method allows direct query of the Archive's symbol table. The
/// symbol table is a std::map of std::string (the symbol) to unsigned (the
/// file offset). Note that for efficiency reasons, the offset stored in
/// the symbol table is not the actual offset. It is the offset from the
/// beginning of the first "real" file member (after the symbol table). Use
/// the getFirstFileOffset() to obtain that offset and add this value to the
/// offset in the symbol table to obtain the real file offset. Note that
/// there is purposefully no interface provided by Archive to look up
/// members by their offset. Use the findModulesDefiningSymbols and
/// findModuleDefiningSymbol methods instead.
/// @returns the Archive's symbol table.
/// @brief Get the archive's symbol table
const SymTabType& getSymbolTable() { return symTab; }
/// This method returns the offset in the archive file to the first "real"
/// file member. Archive files, on disk, have a signature and might have a
/// symbol table that precedes the first actual file member. This method
/// allows you to determine what the size of those fields are.
/// @returns the offset to the first "real" file member in the archive.
/// @brief Get the offset to the first "real" file member in the archive.
unsigned getFirstFileOffset() { return firstFileOffset; }
/// This method will scan the archive for bitcode modules, interpret them
/// and return a vector of the instantiated modules in \p Modules. If an
/// error occurs, this method will return true. If \p ErrMessage is not null
/// and an error occurs, \p *ErrMessage will be set to a string explaining
/// the error that occurred.
/// @returns true if an error occurred
/// @brief Instantiate all the bitcode modules located in the archive
bool getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage);
/// This accessor looks up the \p symbol in the archive's symbol table and
/// returns the associated module that defines that symbol. This method can
/// be called as many times as necessary. This is handy for linking the
/// archive into another module based on unresolved symbols. Note that the
/// Module returned by this accessor should not be deleted by the caller. It
/// is managed internally by the Archive class. It is possible that multiple
/// calls to this accessor will return the same Module instance because the
/// associated module defines multiple symbols.
/// @returns The Module* found or null if the archive does not contain a
/// module that defines the \p symbol.
/// @brief Look up a module by symbol name.
Module* findModuleDefiningSymbol(
const std::string& symbol, ///< Symbol to be sought
std::string* ErrMessage ///< Error message storage, if non-zero
);
/// This method is similar to findModuleDefiningSymbol but allows lookup of
/// more than one symbol at a time. If \p symbols contains a list of
/// undefined symbols in some module, then calling this method is like
/// making one complete pass through the archive to resolve symbols but is
/// more efficient than looking at the individual members. Note that on
/// exit, the symbols resolved by this method will be removed from \p
/// symbols to ensure they are not re-searched on a subsequent call. If
/// you need to retain the list of symbols, make a copy.
/// @brief Look up multiple symbols in the archive.
bool findModulesDefiningSymbols(
std::set<std::string>& symbols, ///< Symbols to be sought
SmallVectorImpl<Module*>& modules, ///< The modules matching \p symbols
std::string* ErrMessage ///< Error msg storage, if non-zero
);
/// This method determines whether the archive is a properly formed llvm
/// bitcode archive. It first makes sure the symbol table has been loaded
/// and has a non-zero size. If it does, then it is an archive. If not,
/// then it tries to load all the bitcode modules of the archive. Finally,
/// it returns whether it was successful.
/// @returns true if the archive is a proper llvm bitcode archive
/// @brief Determine whether the archive is a proper llvm bitcode archive.
bool isBitcodeArchive();
/// @}
/// @name Mutators
/// @{
public:
/// This method is the only way to get the archive written to disk. It
/// creates or overwrites the file specified when \p this was created
/// or opened. The arguments provide options for writing the archive. If
/// \p CreateSymbolTable is true, the archive is scanned for bitcode files
/// and a symbol table of the externally visible function and global
/// variable names is created. If \p TruncateNames is true, the names of the
/// archive members will have their path component stripped and the file
/// name will be truncated at 15 characters. If \p Compress is specified,
/// all archive members will be compressed before being written. If
/// \p PrintSymTab is true, the symbol table will be printed to std::cout.
/// @returns true if an error occurred, \p error set to error message;
/// returns false if the writing succeeded.
/// @brief Write (possibly modified) archive contents to disk
bool writeToDisk(
bool CreateSymbolTable=false, ///< Create Symbol table
bool TruncateNames=false, ///< Truncate the filename to 15 chars
std::string* ErrMessage=0 ///< If non-null, where error msg is set
);
/// This method adds a new file to the archive. The \p filename is examined
/// to determine just enough information to create an ArchiveMember object
/// which is then inserted into the Archive object's ilist at the location
/// given by \p where.
/// @returns true if an error occurred, false otherwise
/// @brief Add a file to the archive.
bool addFileBefore(
const sys::Path& filename, ///< The file to be added
iterator where, ///< Insertion point
std::string* ErrMsg ///< Optional error message location
);
/// @}
/// @name Implementation
/// @{
protected:
/// @brief Construct an Archive for \p filename and optionally map it
/// into memory.
explicit Archive(const sys::Path& filename, LLVMContext& C);
/// @param data The symbol table data to be parsed
/// @param len The length of the symbol table data
/// @param error Set to address of a std::string to get error messages
/// @returns false on error
/// @brief Parse the symbol table at \p data.
bool parseSymbolTable(const void* data,unsigned len,std::string* error);
/// @returns A fully populated ArchiveMember or 0 if an error occurred.
/// @brief Parse the header of a member starting at \p At
ArchiveMember* parseMemberHeader(
const char*&At, ///< The pointer to the location we're parsing
const char*End, ///< The pointer to the end of the archive
std::string* error ///< Optional error message catcher
);
/// @param ErrMessage Set to address of a std::string to get error messages
/// @returns false on error
/// @brief Check that the archive signature is correct
bool checkSignature(std::string* ErrMessage);
/// @param ErrMessage Set to address of a std::string to get error messages
/// @returns false on error
/// @brief Load the entire archive.
bool loadArchive(std::string* ErrMessage);
/// @param ErrMessage Set to address of a std::string to get error messages
/// @returns false on error
/// @brief Load just the symbol table.
bool loadSymbolTable(std::string* ErrMessage);
/// @brief Write the symbol table to an ofstream.
void writeSymbolTable(std::ofstream& ARFile);
/// Writes one ArchiveMember to an ofstream. If an error occurs, returns
/// false, otherwise true. If an error occurs and error is non-null then
/// it will be set to an error message.
/// @returns false if writing member succeeded,
/// returns true if writing member failed, \p error set to error message.
bool writeMember(
const ArchiveMember& member, ///< The member to be written
std::ofstream& ARFile, ///< The file to write member onto
bool CreateSymbolTable, ///< Should symbol table be created?
bool TruncateNames, ///< Should names be truncated to 11 chars?
std::string* ErrMessage ///< If non-null, place were error msg is set
);
/// @brief Fill in an ArchiveMemberHeader from ArchiveMember.
bool fillHeader(const ArchiveMember&mbr,
ArchiveMemberHeader& hdr,int sz, bool TruncateNames) const;
/// @brief Maps archive into memory
bool mapToMemory(std::string* ErrMsg);
/// @brief Frees all the members and unmaps the archive file.
void cleanUpMemory();
/// This type is used to keep track of bitcode modules loaded from the
/// symbol table. It maps the file offset to a pair that consists of the
/// associated ArchiveMember and the Module.
/// @brief Module mapping type
typedef std::map<unsigned,std::pair<Module*,ArchiveMember*> >
ModuleMap;
/// @}
/// @name Data
/// @{
protected:
sys::Path archPath; ///< Path to the archive file we read/write
MembersList members; ///< The ilist of ArchiveMember
MemoryBuffer *mapfile; ///< Raw Archive contents mapped into memory
const char* base; ///< Base of the memory mapped file data
SymTabType symTab; ///< The symbol table
std::string strtab; ///< The string table for long file names
unsigned symTabSize; ///< Size in bytes of symbol table
unsigned firstFileOffset; ///< Offset to first normal file.
ModuleMap modules; ///< The modules loaded via symbol lookup.
ArchiveMember* foreignST; ///< This holds the foreign symbol table.
LLVMContext& Context; ///< This holds global data.
/// @}
/// @name Hidden
/// @{
private:
Archive() LLVM_DELETED_FUNCTION;
Archive(const Archive&) LLVM_DELETED_FUNCTION;
Archive& operator=(const Archive&) LLVM_DELETED_FUNCTION;
/// @}
};
} // End llvm namespace
#endif

View File

@ -244,7 +244,7 @@ public:
uint32_t getWord(size_t pos) {
uint8_t buf[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
BitStream->getBitcodeBytes().readBytes(pos, sizeof(buf), buf, NULL);
BitStream->getBitcodeBytes().readBytes(pos, sizeof(buf), buf);
return *reinterpret_cast<support::ulittle32_t *>(buf);
}
@ -366,8 +366,7 @@ public:
// Read the next word from the stream.
uint8_t Array[sizeof(word_t)] = {0};
BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(Array),
Array, NULL);
BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(Array), Array);
// Handle big-endian byte-swapping if necessary.
support::detail::packed_endian_specific_integral

View File

@ -381,7 +381,8 @@ private:
BlobData = 0;
} else {
for (unsigned e = Vals.size(); RecordIdx != e; ++RecordIdx) {
assert(Vals[RecordIdx] < 256 && "Value too large to emit as blob");
assert(isUInt<8>(Vals[RecordIdx]) &&
"Value too large to emit as blob");
WriteByte((unsigned char)Vals[RecordIdx]);
}
}

View File

@ -194,7 +194,8 @@ namespace bitc {
CAST_FPEXT = 8,
CAST_PTRTOINT = 9,
CAST_INTTOPTR = 10,
CAST_BITCAST = 11
CAST_BITCAST = 11,
CAST_ADDRSPACECAST = 12
};
/// BinaryOpcodes - These are values used in the bitcode files to encode which
@ -330,6 +331,48 @@ namespace bitc {
enum UseListCodes {
USELIST_CODE_ENTRY = 1 // USELIST_CODE_ENTRY: TBD.
};
enum AttributeKindCodes {
// = 0 is unused
ATTR_KIND_ALIGNMENT = 1,
ATTR_KIND_ALWAYS_INLINE = 2,
ATTR_KIND_BY_VAL = 3,
ATTR_KIND_INLINE_HINT = 4,
ATTR_KIND_IN_REG = 5,
ATTR_KIND_MIN_SIZE = 6,
ATTR_KIND_NAKED = 7,
ATTR_KIND_NEST = 8,
ATTR_KIND_NO_ALIAS = 9,
ATTR_KIND_NO_BUILTIN = 10,
ATTR_KIND_NO_CAPTURE = 11,
ATTR_KIND_NO_DUPLICATE = 12,
ATTR_KIND_NO_IMPLICIT_FLOAT = 13,
ATTR_KIND_NO_INLINE = 14,
ATTR_KIND_NON_LAZY_BIND = 15,
ATTR_KIND_NO_RED_ZONE = 16,
ATTR_KIND_NO_RETURN = 17,
ATTR_KIND_NO_UNWIND = 18,
ATTR_KIND_OPTIMIZE_FOR_SIZE = 19,
ATTR_KIND_READ_NONE = 20,
ATTR_KIND_READ_ONLY = 21,
ATTR_KIND_RETURNED = 22,
ATTR_KIND_RETURNS_TWICE = 23,
ATTR_KIND_S_EXT = 24,
ATTR_KIND_STACK_ALIGNMENT = 25,
ATTR_KIND_STACK_PROTECT = 26,
ATTR_KIND_STACK_PROTECT_REQ = 27,
ATTR_KIND_STACK_PROTECT_STRONG = 28,
ATTR_KIND_STRUCT_RET = 29,
ATTR_KIND_SANITIZE_ADDRESS = 30,
ATTR_KIND_SANITIZE_THREAD = 31,
ATTR_KIND_SANITIZE_MEMORY = 32,
ATTR_KIND_UW_TABLE = 33,
ATTR_KIND_Z_EXT = 34,
ATTR_KIND_BUILTIN = 35,
ATTR_KIND_COLD = 36,
ATTR_KIND_OPTIMIZE_NONE = 37
};
} // End bitc namespace
} // End llvm namespace

View File

@ -26,6 +26,7 @@ namespace llvm {
class GlobalVariable;
class TargetLowering;
class TargetLoweringBase;
class SDNode;
class SDValue;
class SelectionDAG;
@ -88,6 +89,14 @@ ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
/// This function only tests target-independent requirements.
bool isInTailCallPosition(ImmutableCallSite CS, const TargetLowering &TLI);
/// Test if given that the input instruction is in the tail call position if the
/// return type or any attributes of the function will inhibit tail call
/// optimization.
bool returnTypeIsEligibleForTailCall(const Function *F,
const Instruction *I,
const ReturnInst *Ret,
const TargetLoweringBase &TLI);
} // End llvm namespace
#endif

View File

@ -38,9 +38,10 @@ namespace llvm {
class MachineConstantPoolValue;
class MachineJumpTableInfo;
class MachineModuleInfo;
class MachineMove;
class MCAsmInfo;
class MCCFIInstruction;
class MCContext;
class MCInstrInfo;
class MCSection;
class MCStreamer;
class MCSymbol;
@ -64,6 +65,7 @@ namespace llvm {
///
const MCAsmInfo *MAI;
const MCInstrInfo *MII;
/// OutContext - This is the context for the output file that we are
/// streaming. This owns all of the global MC-related objects for the
/// generated translation unit.
@ -121,6 +123,8 @@ namespace llvm {
public:
virtual ~AsmPrinter();
const DwarfDebug *getDwarfDebug() const { return DD; }
/// isVerbose - Return true if assembly output should contain comments.
///
bool isVerbose() const { return VerboseAsm; }
@ -141,6 +145,7 @@ namespace llvm {
/// getCurrentSection() - Return the current section we are emitting to.
const MCSection *getCurrentSection() const;
MCSymbol *getSymbol(const GlobalValue *GV) const;
//===------------------------------------------------------------------===//
// MachineFunctionPass Implementation.
@ -233,8 +238,8 @@ namespace llvm {
/// it if appropriate.
void EmitBasicBlockStart(const MachineBasicBlock *MBB) const;
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
void EmitGlobalConstant(const Constant *CV, unsigned AddrSpace = 0);
/// \brief Print a general LLVM constant to the .s file.
void EmitGlobalConstant(const Constant *CV);
//===------------------------------------------------------------------===//
@ -282,6 +287,10 @@ namespace llvm {
virtual bool
isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const;
/// emitImplicitDef - Targets can override this to customize the output of
/// IMPLICIT_DEF instructions in verbose mode.
virtual void emitImplicitDef(const MachineInstr *MI) const;
//===------------------------------------------------------------------===//
// Symbol Lowering Routines.
//===------------------------------------------------------------------===//
@ -357,13 +366,15 @@ namespace llvm {
/// where the size in bytes of the directive is specified by Size and Label
/// specifies the label. This implicitly uses .set if it is available.
void EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset,
unsigned Size) const;
unsigned Size,
bool IsSectionRelative = false) const;
/// EmitLabelReference - Emit something like ".long Label"
/// where the size in bytes of the directive is specified by Size and Label
/// specifies the label.
void EmitLabelReference(const MCSymbol *Label, unsigned Size) const {
EmitLabelPlusOffset(Label, 0, Size);
void EmitLabelReference(const MCSymbol *Label, unsigned Size,
bool IsSectionRelative = false) const {
EmitLabelPlusOffset(Label, 0, Size, IsSectionRelative);
}
//===------------------------------------------------------------------===//
@ -371,10 +382,10 @@ namespace llvm {
//===------------------------------------------------------------------===//
/// EmitSLEB128 - emit the specified signed leb128 value.
void EmitSLEB128(int Value, const char *Desc = 0) const;
void EmitSLEB128(int64_t Value, const char *Desc = 0) const;
/// EmitULEB128 - emit the specified unsigned leb128 value.
void EmitULEB128(unsigned Value, const char *Desc = 0,
void EmitULEB128(uint64_t Value, const char *Desc = 0,
unsigned PadTo = 0) const;
/// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
@ -402,24 +413,20 @@ namespace llvm {
void EmitSectionOffset(const MCSymbol *Label,
const MCSymbol *SectionLabel) const;
/// getDebugValueLocation - Get location information encoded by DBG_VALUE
/// operands.
virtual MachineLocation getDebugValueLocation(const MachineInstr *MI) const;
/// getISAEncoding - Get the value for DW_AT_APPLE_isa. Zero if no isa
/// encoding specified.
virtual unsigned getISAEncoding() { return 0; }
/// EmitDwarfRegOp - Emit dwarf register operation.
virtual void EmitDwarfRegOp(const MachineLocation &MLoc) const;
virtual void EmitDwarfRegOp(const MachineLocation &MLoc,
bool Indirect) const;
//===------------------------------------------------------------------===//
// Dwarf Lowering Routines
//===------------------------------------------------------------------===//
/// EmitCFIFrameMove - Emit frame instruction to describe the layout of the
/// frame.
void EmitCFIFrameMove(const MachineMove &Move) const;
/// \brief Emit frame instruction to describe the layout of the frame.
void emitCFIInstruction(const MCCFIInstruction &Inst) const;
//===------------------------------------------------------------------===//
// Inline Asm Support
@ -451,8 +458,7 @@ namespace llvm {
/// return true if the operand is erroneous.
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
unsigned AsmVariant,
const char *ExtraCode,
raw_ostream &OS);
const char *ExtraCode, raw_ostream &OS);
private:
/// Private state for PrintSpecial()
@ -464,7 +470,8 @@ namespace llvm {
/// EmitInlineAsm - Emit a blob of inline asm to the output streamer.
void EmitInlineAsm(StringRef Str, const MDNode *LocMDNode = 0,
InlineAsm::AsmDialect AsmDialect = InlineAsm::AD_ATT) const;
InlineAsm::AsmDialect AsmDialect =
InlineAsm::AD_ATT) const;
/// EmitInlineAsm - This method formats and emits the specified machine
/// instruction that is an inline asm.
@ -479,12 +486,13 @@ namespace llvm {
void EmitVisibility(MCSymbol *Sym, unsigned Visibility,
bool IsDefinition = true) const;
void EmitLinkage(unsigned Linkage, MCSymbol *GVSym) const;
void EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const;
void EmitJumpTableEntry(const MachineJumpTableInfo *MJTI,
const MachineBasicBlock *MBB,
unsigned uid) const;
const MachineBasicBlock *MBB, unsigned uid) const;
void EmitLLVMUsedList(const ConstantArray *InitList);
/// Emit llvm.ident metadata in an '.ident' directive.
void EmitModuleIdents(Module &M);
void EmitXXStructorList(const Constant *List, bool isCtor);
GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
};

View File

@ -18,9 +18,12 @@ namespace llvm {
class LiveInterval;
class LiveIntervals;
class MachineBlockFrequencyInfo;
class MachineLoopInfo;
/// normalizeSpillWeight - The spill weight of a live interval is computed as:
/// \brief Normalize the spill weight of a live interval
///
/// The spill weight of a live interval is computed as:
///
/// (sum(use freq) + sum(def freq)) / (K + size)
///
@ -37,42 +40,38 @@ namespace llvm {
return UseDefFreq / (Size + 25*SlotIndex::InstrDist);
}
/// VirtRegAuxInfo - Calculate auxiliary information for a virtual
/// register such as its spill weight and allocation hint.
/// \brief Calculate auxiliary information for a virtual register such as its
/// spill weight and allocation hint.
class VirtRegAuxInfo {
public:
typedef float (*NormalizingFn)(float, unsigned);
private:
MachineFunction &MF;
LiveIntervals &LIS;
const MachineLoopInfo &Loops;
const MachineBlockFrequencyInfo &MBFI;
DenseMap<unsigned, float> Hint;
NormalizingFn normalize;
public:
VirtRegAuxInfo(MachineFunction &mf, LiveIntervals &lis,
const MachineLoopInfo &loops) :
MF(mf), LIS(lis), Loops(loops) {}
const MachineLoopInfo &loops,
const MachineBlockFrequencyInfo &mbfi,
NormalizingFn norm = normalizeSpillWeight)
: MF(mf), LIS(lis), Loops(loops), MBFI(mbfi), normalize(norm) {}
/// CalculateWeightAndHint - (re)compute li's spill weight and allocation
/// hint.
void CalculateWeightAndHint(LiveInterval &li);
/// \brief (re)compute li's spill weight and allocation hint.
void calculateSpillWeightAndHint(LiveInterval &li);
};
/// CalculateSpillWeights - Compute spill weights for all virtual register
/// \brief Compute spill weights and allocation hints for all virtual register
/// live intervals.
class CalculateSpillWeights : public MachineFunctionPass {
public:
static char ID;
CalculateSpillWeights() : MachineFunctionPass(ID) {
initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry());
}
virtual void getAnalysisUsage(AnalysisUsage &au) const;
virtual bool runOnMachineFunction(MachineFunction &fn);
private:
/// Returns true if the given live interval is zero length.
bool isZeroLengthInterval(LiveInterval *li) const;
};
void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF,
const MachineLoopInfo &MLI,
const MachineBlockFrequencyInfo &MBFI,
VirtRegAuxInfo::NormalizingFn norm =
normalizeSpillWeight);
}
#endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H

View File

@ -158,7 +158,7 @@ private:
MachineFunction &MF;
const TargetMachine &TM;
const TargetRegisterInfo &TRI;
SmallVector<CCValAssign, 16> &Locs;
SmallVectorImpl<CCValAssign> &Locs;
LLVMContext &Context;
unsigned StackOffset;
@ -219,7 +219,7 @@ protected:
public:
CCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF,
const TargetMachine &TM, SmallVector<CCValAssign, 16> &locs,
const TargetMachine &TM, SmallVectorImpl<CCValAssign> &locs,
LLVMContext &C);
void addLoc(const CCValAssign &V) {

View File

@ -109,11 +109,6 @@ DisableFPElim("disable-fp-elim",
cl::desc("Disable frame pointer elimination optimization"),
cl::init(false));
cl::opt<bool>
DisableFPElimNonLeaf("disable-non-leaf-fp-elim",
cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"),
cl::init(false));
cl::opt<bool>
EnableUnsafeFPMath("enable-unsafe-fp-math",
cl::desc("Enable optimizations that may decrease FP precision"),
@ -155,7 +150,7 @@ FloatABIForCalls("float-abi",
cl::opt<llvm::FPOpFusion::FPOpFusionMode>
FuseFPOps("fp-contract",
cl::desc("Enable aggresive formation of fused FP ops"),
cl::desc("Enable aggressive formation of fused FP ops"),
cl::init(FPOpFusion::Standard),
cl::values(
clEnumValN(FPOpFusion::Fast, "fast",
@ -186,11 +181,6 @@ OverrideStackAlignment("stack-alignment",
cl::desc("Override default stack alignment"),
cl::init(0));
cl::opt<bool>
EnableRealignStack("realign-stack",
cl::desc("Realign stack if needed"),
cl::init(true));
cl::opt<std::string>
TrapFuncName("trap-func", cl::Hidden,
cl::desc("Emit a call to trap function rather than a trap instruction"),
@ -220,8 +210,4 @@ cl::opt<std::string> StartAfter("start-after",
cl::value_desc("pass-name"),
cl::init(""));
cl::opt<unsigned>
SSPBufferSize("stack-protector-buffer-size", cl::init(8),
cl::desc("Lower bound for a buffer to be considered for "
"stack protection"));
#endif

View File

@ -1,4 +1,4 @@
//===-- FastISel.h - Definition of the FastISel class ---------------------===//
//===-- FastISel.h - Definition of the FastISel class ---*- C++ -*---------===//
//
// The LLVM Compiler Infrastructure
//
@ -6,9 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the FastISel class.
//
///
/// \file
/// This file defines the FastISel class.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_CODEGEN_FASTISEL_H
@ -26,7 +27,6 @@ class ConstantFP;
class FunctionLoweringInfo;
class Instruction;
class LoadInst;
class MachineBasicBlock;
class MachineConstantPool;
class MachineFunction;
class MachineInstr;
@ -42,9 +42,8 @@ class TargetRegisterInfo;
class User;
class Value;
/// FastISel - This is a fast-path instruction selection class that
/// generates poor code and doesn't support illegal types or non-trivial
/// lowering, but runs quickly.
/// This is a fast-path instruction selection class that generates poor code and
/// doesn't support illegal types or non-trivial lowering, but runs quickly.
class FastISel {
protected:
DenseMap<const Value *, unsigned> LocalValueMap;
@ -60,99 +59,92 @@ protected:
const TargetRegisterInfo &TRI;
const TargetLibraryInfo *LibInfo;
/// The position of the last instruction for materializing constants
/// for use in the current block. It resets to EmitStartPt when it
/// makes sense (for example, it's usually profitable to avoid function
/// calls between the definition and the use)
/// The position of the last instruction for materializing constants for use
/// in the current block. It resets to EmitStartPt when it makes sense (for
/// example, it's usually profitable to avoid function calls between the
/// definition and the use)
MachineInstr *LastLocalValue;
/// The top most instruction in the current block that is allowed for
/// emitting local variables. LastLocalValue resets to EmitStartPt when
/// it makes sense (for example, on function calls)
/// The top most instruction in the current block that is allowed for emitting
/// local variables. LastLocalValue resets to EmitStartPt when it makes sense
/// (for example, on function calls)
MachineInstr *EmitStartPt;
public:
/// getLastLocalValue - Return the position of the last instruction
/// emitted for materializing constants for use in the current block.
/// Return the position of the last instruction emitted for materializing
/// constants for use in the current block.
MachineInstr *getLastLocalValue() { return LastLocalValue; }
/// setLastLocalValue - Update the position of the last instruction
/// emitted for materializing constants for use in the current block.
/// Update the position of the last instruction emitted for materializing
/// constants for use in the current block.
void setLastLocalValue(MachineInstr *I) {
EmitStartPt = I;
LastLocalValue = I;
}
/// startNewBlock - Set the current block to which generated machine
/// instructions will be appended, and clear the local CSE map.
///
/// Set the current block to which generated machine instructions will be
/// appended, and clear the local CSE map.
void startNewBlock();
/// getCurDebugLoc() - Return current debug location information.
/// Return current debug location information.
DebugLoc getCurDebugLoc() const { return DL; }
/// LowerArguments - Do "fast" instruction selection for function arguments
/// and append machine instructions to the current block. Return true if
/// it is successful.
/// Do "fast" instruction selection for function arguments and append machine
/// instructions to the current block. Return true if it is successful.
bool LowerArguments();
/// SelectInstruction - Do "fast" instruction selection for the given
/// LLVM IR instruction, and append generated machine instructions to
/// the current block. Return true if selection was successful.
///
/// Do "fast" instruction selection for the given LLVM IR instruction, and
/// append generated machine instructions to the current block. Return true if
/// selection was successful.
bool SelectInstruction(const Instruction *I);
/// SelectOperator - Do "fast" instruction selection for the given
/// LLVM IR operator (Instruction or ConstantExpr), and append
/// generated machine instructions to the current block. Return true
/// if selection was successful.
///
/// Do "fast" instruction selection for the given LLVM IR operator
/// (Instruction or ConstantExpr), and append generated machine instructions
/// to the current block. Return true if selection was successful.
bool SelectOperator(const User *I, unsigned Opcode);
/// getRegForValue - Create a virtual register and arrange for it to
/// be assigned the value for the given LLVM value.
/// Create a virtual register and arrange for it to be assigned the value for
/// the given LLVM value.
unsigned getRegForValue(const Value *V);
/// lookUpRegForValue - Look up the value to see if its value is already
/// cached in a register. It may be defined by instructions across blocks or
/// defined locally.
/// Look up the value to see if its value is already cached in a register. It
/// may be defined by instructions across blocks or defined locally.
unsigned lookUpRegForValue(const Value *V);
/// getRegForGEPIndex - This is a wrapper around getRegForValue that also
/// takes care of truncating or sign-extending the given getelementptr
/// index value.
/// This is a wrapper around getRegForValue that also takes care of truncating
/// or sign-extending the given getelementptr index value.
std::pair<unsigned, bool> getRegForGEPIndex(const Value *V);
/// \brief We're checking to see if we can fold \p LI into \p FoldInst.
/// Note that we could have a sequence where multiple LLVM IR instructions
/// are folded into the same machineinstr. For example we could have:
/// \brief We're checking to see if we can fold \p LI into \p FoldInst. Note
/// that we could have a sequence where multiple LLVM IR instructions are
/// folded into the same machineinstr. For example we could have:
///
/// A: x = load i32 *P
/// B: y = icmp A, 42
/// C: br y, ...
///
/// In this scenario, \p LI is "A", and \p FoldInst is "C". We know
/// about "B" (and any other folded instructions) because it is between
/// A and C.
/// In this scenario, \p LI is "A", and \p FoldInst is "C". We know about "B"
/// (and any other folded instructions) because it is between A and C.
///
/// If we succeed folding, return true.
///
bool tryToFoldLoad(const LoadInst *LI, const Instruction *FoldInst);
/// \brief The specified machine instr operand is a vreg, and that
/// vreg is being provided by the specified load instruction. If possible,
/// try to fold the load as an operand to the instruction, returning true if
/// \brief The specified machine instr operand is a vreg, and that vreg is
/// being provided by the specified load instruction. If possible, try to
/// fold the load as an operand to the instruction, returning true if
/// possible.
///
/// This method should be implemented by targets.
virtual bool tryToFoldLoadIntoMI(MachineInstr * /*MI*/, unsigned /*OpNo*/,
const LoadInst * /*LI*/) {
return false;
}
/// recomputeInsertPt - Reset InsertPt to prepare for inserting instructions
/// into the current block.
/// Reset InsertPt to prepare for inserting instructions into the current
/// block.
void recomputeInsertPt();
/// removeDeadCode - Remove all dead instructions between the I and E.
/// Remove all dead instructions between the I and E.
void removeDeadCode(MachineBasicBlock::iterator I,
MachineBasicBlock::iterator E);
@ -161,11 +153,11 @@ public:
DebugLoc DL;
};
/// enterLocalValueArea - Prepare InsertPt to begin inserting instructions
/// into the local value area and return the old insert position.
/// Prepare InsertPt to begin inserting instructions into the local value area
/// and return the old insert position.
SavePoint enterLocalValueArea();
/// leaveLocalValueArea - Reset InsertPt to the given old insert position.
/// Reset InsertPt to the given old insert position.
void leaveLocalValueArea(SavePoint Old);
virtual ~FastISel();
@ -174,69 +166,59 @@ protected:
explicit FastISel(FunctionLoweringInfo &funcInfo,
const TargetLibraryInfo *libInfo);
/// TargetSelectInstruction - This method is called by target-independent
/// code when the normal FastISel process fails to select an instruction.
/// This gives targets a chance to emit code for anything that doesn't
/// fit into FastISel's framework. It returns true if it was successful.
///
/// This method is called by target-independent code when the normal FastISel
/// process fails to select an instruction. This gives targets a chance to
/// emit code for anything that doesn't fit into FastISel's framework. It
/// returns true if it was successful.
virtual bool
TargetSelectInstruction(const Instruction *I) = 0;
/// FastLowerArguments - This method is called by target-independent code to
/// do target specific argument lowering. It returns true if it was
/// successful.
/// This method is called by target-independent code to do target specific
/// argument lowering. It returns true if it was successful.
virtual bool FastLowerArguments();
/// FastEmit_r - This method is called by target-independent code
/// to request that an instruction with the given type and opcode
/// be emitted.
/// This method is called by target-independent code to request that an
/// instruction with the given type and opcode be emitted.
virtual unsigned FastEmit_(MVT VT,
MVT RetVT,
unsigned Opcode);
/// FastEmit_r - This method is called by target-independent code
/// to request that an instruction with the given type, opcode, and
/// register operand be emitted.
///
/// This method is called by target-independent code to request that an
/// instruction with the given type, opcode, and register operand be emitted.
virtual unsigned FastEmit_r(MVT VT,
MVT RetVT,
unsigned Opcode,
unsigned Op0, bool Op0IsKill);
/// FastEmit_rr - This method is called by target-independent code
/// to request that an instruction with the given type, opcode, and
/// register operands be emitted.
///
/// This method is called by target-independent code to request that an
/// instruction with the given type, opcode, and register operands be emitted.
virtual unsigned FastEmit_rr(MVT VT,
MVT RetVT,
unsigned Opcode,
unsigned Op0, bool Op0IsKill,
unsigned Op1, bool Op1IsKill);
/// FastEmit_ri - This method is called by target-independent code
/// to request that an instruction with the given type, opcode, and
/// register and immediate operands be emitted.
///
/// This method is called by target-independent code to request that an
/// instruction with the given type, opcode, and register and immediate
/// operands be emitted.
virtual unsigned FastEmit_ri(MVT VT,
MVT RetVT,
unsigned Opcode,
unsigned Op0, bool Op0IsKill,
uint64_t Imm);
/// FastEmit_rf - This method is called by target-independent code
/// to request that an instruction with the given type, opcode, and
/// register and floating-point immediate operands be emitted.
///
/// This method is called by target-independent code to request that an
/// instruction with the given type, opcode, and register and floating-point
/// immediate operands be emitted.
virtual unsigned FastEmit_rf(MVT VT,
MVT RetVT,
unsigned Opcode,
unsigned Op0, bool Op0IsKill,
const ConstantFP *FPImm);
/// FastEmit_rri - This method is called by target-independent code
/// to request that an instruction with the given type, opcode, and
/// register and immediate operands be emitted.
///
/// This method is called by target-independent code to request that an
/// instruction with the given type, opcode, and register and immediate
/// operands be emitted.
virtual unsigned FastEmit_rri(MVT VT,
MVT RetVT,
unsigned Opcode,
@ -244,142 +226,130 @@ protected:
unsigned Op1, bool Op1IsKill,
uint64_t Imm);
/// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries
/// to emit an instruction with an immediate operand using FastEmit_ri.
/// If that fails, it materializes the immediate into a register and try
/// FastEmit_rr instead.
/// \brief This method is a wrapper of FastEmit_ri.
///
/// It first tries to emit an instruction with an immediate operand using
/// FastEmit_ri. If that fails, it materializes the immediate into a register
/// and try FastEmit_rr instead.
unsigned FastEmit_ri_(MVT VT,
unsigned Opcode,
unsigned Op0, bool Op0IsKill,
uint64_t Imm, MVT ImmType);
/// FastEmit_i - This method is called by target-independent code
/// to request that an instruction with the given type, opcode, and
/// immediate operand be emitted.
/// This method is called by target-independent code to request that an
/// instruction with the given type, opcode, and immediate operand be emitted.
virtual unsigned FastEmit_i(MVT VT,
MVT RetVT,
unsigned Opcode,
uint64_t Imm);
/// FastEmit_f - This method is called by target-independent code
/// to request that an instruction with the given type, opcode, and
/// floating-point immediate operand be emitted.
/// This method is called by target-independent code to request that an
/// instruction with the given type, opcode, and floating-point immediate
/// operand be emitted.
virtual unsigned FastEmit_f(MVT VT,
MVT RetVT,
unsigned Opcode,
const ConstantFP *FPImm);
/// FastEmitInst_ - Emit a MachineInstr with no operands and a
/// result register in the given register class.
///
/// Emit a MachineInstr with no operands and a result register in the given
/// register class.
unsigned FastEmitInst_(unsigned MachineInstOpcode,
const TargetRegisterClass *RC);
/// FastEmitInst_r - Emit a MachineInstr with one register operand
/// and a result register in the given register class.
///
/// Emit a MachineInstr with one register operand and a result register in the
/// given register class.
unsigned FastEmitInst_r(unsigned MachineInstOpcode,
const TargetRegisterClass *RC,
unsigned Op0, bool Op0IsKill);
/// FastEmitInst_rr - Emit a MachineInstr with two register operands
/// and a result register in the given register class.
///
/// Emit a MachineInstr with two register operands and a result register in
/// the given register class.
unsigned FastEmitInst_rr(unsigned MachineInstOpcode,
const TargetRegisterClass *RC,
unsigned Op0, bool Op0IsKill,
unsigned Op1, bool Op1IsKill);
/// FastEmitInst_rrr - Emit a MachineInstr with three register operands
/// and a result register in the given register class.
///
/// Emit a MachineInstr with three register operands and a result register in
/// the given register class.
unsigned FastEmitInst_rrr(unsigned MachineInstOpcode,
const TargetRegisterClass *RC,
unsigned Op0, bool Op0IsKill,
unsigned Op1, bool Op1IsKill,
unsigned Op2, bool Op2IsKill);
/// FastEmitInst_ri - Emit a MachineInstr with a register operand,
/// an immediate, and a result register in the given register class.
///
/// Emit a MachineInstr with a register operand, an immediate, and a result
/// register in the given register class.
unsigned FastEmitInst_ri(unsigned MachineInstOpcode,
const TargetRegisterClass *RC,
unsigned Op0, bool Op0IsKill,
uint64_t Imm);
/// FastEmitInst_rii - Emit a MachineInstr with one register operand
/// and two immediate operands.
///
/// Emit a MachineInstr with one register operand and two immediate operands.
unsigned FastEmitInst_rii(unsigned MachineInstOpcode,
const TargetRegisterClass *RC,
unsigned Op0, bool Op0IsKill,
uint64_t Imm1, uint64_t Imm2);
/// FastEmitInst_rf - Emit a MachineInstr with two register operands
/// and a result register in the given register class.
///
/// Emit a MachineInstr with two register operands and a result register in
/// the given register class.
unsigned FastEmitInst_rf(unsigned MachineInstOpcode,
const TargetRegisterClass *RC,
unsigned Op0, bool Op0IsKill,
const ConstantFP *FPImm);
/// FastEmitInst_rri - Emit a MachineInstr with two register operands,
/// an immediate, and a result register in the given register class.
///
/// Emit a MachineInstr with two register operands, an immediate, and a result
/// register in the given register class.
unsigned FastEmitInst_rri(unsigned MachineInstOpcode,
const TargetRegisterClass *RC,
unsigned Op0, bool Op0IsKill,
unsigned Op1, bool Op1IsKill,
uint64_t Imm);
/// FastEmitInst_rrii - Emit a MachineInstr with two register operands,
/// two immediates operands, and a result register in the given register
/// class.
/// Emit a MachineInstr with two register operands, two immediates operands,
/// and a result register in the given register class.
unsigned FastEmitInst_rrii(unsigned MachineInstOpcode,
const TargetRegisterClass *RC,
unsigned Op0, bool Op0IsKill,
unsigned Op1, bool Op1IsKill,
uint64_t Imm1, uint64_t Imm2);
/// FastEmitInst_i - Emit a MachineInstr with a single immediate
/// operand, and a result register in the given register class.
/// Emit a MachineInstr with a single immediate operand, and a result register
/// in the given register class.
unsigned FastEmitInst_i(unsigned MachineInstrOpcode,
const TargetRegisterClass *RC,
uint64_t Imm);
/// FastEmitInst_ii - Emit a MachineInstr with a two immediate operands.
/// Emit a MachineInstr with a two immediate operands.
unsigned FastEmitInst_ii(unsigned MachineInstrOpcode,
const TargetRegisterClass *RC,
uint64_t Imm1, uint64_t Imm2);
/// FastEmitInst_extractsubreg - Emit a MachineInstr for an extract_subreg
/// from a specified index of a superregister to a specified type.
/// Emit a MachineInstr for an extract_subreg from a specified index of a
/// superregister to a specified type.
unsigned FastEmitInst_extractsubreg(MVT RetVT,
unsigned Op0, bool Op0IsKill,
uint32_t Idx);
/// FastEmitZExtFromI1 - Emit MachineInstrs to compute the value of Op
/// with all but the least significant bit set to zero.
/// Emit MachineInstrs to compute the value of Op with all but the least
/// significant bit set to zero.
unsigned FastEmitZExtFromI1(MVT VT,
unsigned Op0, bool Op0IsKill);
/// FastEmitBranch - Emit an unconditional branch to the given block,
/// unless it is the immediate (fall-through) successor, and update
/// the CFG.
/// Emit an unconditional branch to the given block, unless it is the
/// immediate (fall-through) successor, and update the CFG.
void FastEmitBranch(MachineBasicBlock *MBB, DebugLoc DL);
void UpdateValueMap(const Value* I, unsigned Reg, unsigned NumRegs = 1);
unsigned createResultReg(const TargetRegisterClass *RC);
/// TargetMaterializeConstant - Emit a constant in a register using
/// target-specific logic, such as constant pool loads.
/// Emit a constant in a register using target-specific logic, such as
/// constant pool loads.
virtual unsigned TargetMaterializeConstant(const Constant* C) {
return 0;
}
/// TargetMaterializeAlloca - Emit an alloca address in a register using
/// target-specific logic.
/// Emit an alloca address in a register using target-specific logic.
virtual unsigned TargetMaterializeAlloca(const AllocaInst* C) {
return 0;
}
@ -388,6 +358,15 @@ protected:
return 0;
}
/// \brief Check if \c Add is an add that can be safely folded into \c GEP.
///
/// \c Add can be folded into \c GEP if:
/// - \c Add is an add,
/// - \c Add's size matches \c GEP's,
/// - \c Add is in the same basic block as \c GEP, and
/// - \c Add has a constant operand.
bool canFoldAddIntoGEP(const User *GEP, const Value *Add);
private:
bool SelectBinaryOp(const User *I, unsigned ISDOpcode);
@ -405,25 +384,26 @@ private:
bool SelectInsertValue(const User *I);
/// HandlePHINodesInSuccessorBlocks - Handle PHI nodes in successor blocks.
/// \brief Handle PHI nodes in successor blocks.
///
/// Emit code to ensure constants are copied into registers when needed.
/// Remember the virtual registers that need to be added to the Machine PHI
/// nodes as input. We cannot just directly add them, because expansion
/// might result in multiple MBB's for one BB. As such, the start of the
/// BB might correspond to a different MBB than the end.
/// nodes as input. We cannot just directly add them, because expansion might
/// result in multiple MBB's for one BB. As such, the start of the BB might
/// correspond to a different MBB than the end.
bool HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB);
/// materializeRegForValue - Helper for getRegForVale. This function is
/// called when the value isn't already available in a register and must
/// be materialized with new instructions.
/// Helper for getRegForVale. This function is called when the value isn't
/// already available in a register and must be materialized with new
/// instructions.
unsigned materializeRegForValue(const Value *V, MVT VT);
/// flushLocalValueMap - clears LocalValueMap and moves the area for the
/// new local variables to the beginning of the block. It helps to avoid
/// spilling cached variables across heavy instructions like calls.
/// Clears LocalValueMap and moves the area for the new local variables to the
/// beginning of the block. It helps to avoid spilling cached variables across
/// heavy instructions like calls.
void flushLocalValueMap();
/// hasTrivialKill - Test whether the given value has exactly one use.
/// Test whether the given value has exactly one use.
bool hasTrivialKill(const Value *V) const;
};

View File

@ -49,8 +49,8 @@ class Value;
/// function that is used when lowering a region of the function.
///
class FunctionLoweringInfo {
const TargetMachine &TM;
public:
const TargetLowering &TLI;
const Function *Fn;
MachineFunction *MF;
MachineRegisterInfo *RegInfo;
@ -120,7 +120,7 @@ public:
/// SelectionDAGISel::PrepareEHLandingPad().
unsigned ExceptionPointerVirtReg, ExceptionSelectorVirtReg;
explicit FunctionLoweringInfo(const TargetLowering &TLI);
explicit FunctionLoweringInfo(const TargetMachine &TM) : TM(TM) {}
/// set - Initialize this FunctionLoweringInfo with the given Function
/// and its associated MachineFunction.

View File

@ -77,18 +77,6 @@ namespace ISD {
/// adjustment during unwind.
FRAME_TO_ARGS_OFFSET,
/// RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
/// address of the exception block on entry to an landing pad block.
EXCEPTIONADDR,
/// RESULT, OUTCHAIN = LSDAADDR(INCHAIN) - This node represents the
/// address of the Language Specific Data Area for the enclosing function.
LSDAADDR,
/// RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node
/// represents the selection index of the exception thrown.
EHSELECTION,
/// OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
/// 'eh_return' gcc dwarf builtin, which is used to return from
/// exception. The general meaning is: adjust stack by OFFSET and pass
@ -431,6 +419,10 @@ namespace ISD {
/// getNode().
BITCAST,
/// ADDRSPACECAST - This operator converts between pointers of different
/// address spaces.
ADDRSPACECAST,
/// CONVERT_RNDSAT - This operator is used to support various conversions
/// between various types (float, signed, unsigned and vectors of those
/// types) with rounding and saturation. NOTE: Avoid using this operator as
@ -452,11 +444,11 @@ namespace ISD {
/// FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
/// FLOG, FLOG2, FLOG10, FEXP, FEXP2,
/// FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary
/// FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR - Perform various unary
/// floating point operations. These are inspired by libm.
FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
FLOG, FLOG2, FLOG10, FEXP, FEXP2,
FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR,
FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR,
/// FSINCOS - Compute both fsin and fcos as a single operation.
FSINCOS,
@ -616,11 +608,17 @@ namespace ISD {
ATOMIC_STORE,
/// Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
/// For double-word atomic operations:
/// ValLo, ValHi, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmpLo, cmpHi,
/// swapLo, swapHi)
/// This corresponds to the cmpxchg instruction.
ATOMIC_CMP_SWAP,
/// Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
/// Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt)
/// For double-word atomic operations:
/// ValLo, ValHi, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amtLo, amtHi)
/// ValLo, ValHi, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amtLo, amtHi)
/// These correspond to the atomicrmw instruction.
ATOMIC_SWAP,
ATOMIC_LOAD_ADD,
@ -647,7 +645,7 @@ namespace ISD {
/// which do not reference a specific memory location should be less than
/// this value. Those that do must not be less than this value, and can
/// be used with SelectionDAG::getMemIntrinsicNode.
static const int FIRST_TARGET_MEMORY_OPCODE = BUILTIN_OP_END+150;
static const int FIRST_TARGET_MEMORY_OPCODE = BUILTIN_OP_END+180;
//===--------------------------------------------------------------------===//
/// MemIndexedMode enum - This enum defines the load / store indexed

View File

@ -141,8 +141,8 @@ private:
DenseMap<const MDNode *, LexicalScope *> AbstractScopeMap;
/// AbstractScopesList - Tracks abstract scopes constructed while processing
/// a function.
SmallVector<LexicalScope *, 4>AbstractScopesList;
/// a function.
SmallVector<LexicalScope *, 4> AbstractScopesList;
/// CurrentFnLexicalScope - Top level scope for the current function.
///
@ -166,13 +166,13 @@ public:
virtual ~LexicalScope() {}
// Accessors.
LexicalScope *getParent() const { return Parent; }
const MDNode *getDesc() const { return Desc; }
const MDNode *getInlinedAt() const { return InlinedAtLocation; }
const MDNode *getScopeNode() const { return Desc; }
bool isAbstractScope() const { return AbstractScope; }
SmallVector<LexicalScope *, 4> &getChildren() { return Children; }
SmallVector<InsnRange, 4> &getRanges() { return Ranges; }
LexicalScope *getParent() const { return Parent; }
const MDNode *getDesc() const { return Desc; }
const MDNode *getInlinedAt() const { return InlinedAtLocation; }
const MDNode *getScopeNode() const { return Desc; }
bool isAbstractScope() const { return AbstractScope; }
SmallVectorImpl<LexicalScope *> &getChildren() { return Children; }
SmallVectorImpl<InsnRange> &getRanges() { return Ranges; }
/// addChild - Add a child scope.
void addChild(LexicalScope *S) { Children.push_back(S); }

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,7 @@ namespace llvm {
class AliasAnalysis;
class BitVector;
class BlockFrequency;
class LiveRangeCalc;
class LiveVariables;
class MachineDominatorTree;
@ -89,9 +90,9 @@ namespace llvm {
/// block.
SmallVector<std::pair<unsigned, unsigned>, 8> RegMaskBlocks;
/// RegUnitIntervals - Keep a live interval for each register unit as a way
/// of tracking fixed physreg interference.
SmallVector<LiveInterval*, 0> RegUnitIntervals;
/// Keeps a live range set for each register unit to track fixed physreg
/// interference.
SmallVector<LiveRange*, 0> RegUnitRanges;
public:
static char ID; // Pass identification, replacement for typeid
@ -99,12 +100,13 @@ namespace llvm {
virtual ~LiveIntervals();
// Calculate the spill weight to assign to a single instruction.
static float getSpillWeight(bool isDef, bool isUse, unsigned loopDepth);
static float getSpillWeight(bool isDef, bool isUse, BlockFrequency freq);
LiveInterval &getInterval(unsigned Reg) {
LiveInterval *LI = VirtRegIntervals[Reg];
assert(LI && "Interval does not exist for virtual register");
return *LI;
if (hasInterval(Reg))
return *VirtRegIntervals[Reg];
else
return createAndComputeVirtRegInterval(Reg);
}
const LiveInterval &getInterval(unsigned Reg) const {
@ -116,12 +118,17 @@ namespace llvm {
}
// Interval creation.
LiveInterval &getOrCreateInterval(unsigned Reg) {
if (!hasInterval(Reg)) {
VirtRegIntervals.grow(Reg);
VirtRegIntervals[Reg] = createInterval(Reg);
}
return getInterval(Reg);
LiveInterval &createEmptyInterval(unsigned Reg) {
assert(!hasInterval(Reg) && "Interval already exists!");
VirtRegIntervals.grow(Reg);
VirtRegIntervals[Reg] = createInterval(Reg);
return *VirtRegIntervals[Reg];
}
LiveInterval &createAndComputeVirtRegInterval(unsigned Reg) {
LiveInterval &LI = createEmptyInterval(Reg);
computeVirtRegInterval(LI);
return LI;
}
// Interval removal.
@ -130,10 +137,10 @@ namespace llvm {
VirtRegIntervals[Reg] = 0;
}
/// addLiveRangeToEndOfBlock - Given a register and an instruction,
/// adds a live range from that instruction to the end of its MBB.
LiveRange addLiveRangeToEndOfBlock(unsigned reg,
MachineInstr* startInst);
/// Given a register and an instruction, adds a live segment from that
/// instruction to the end of its MBB.
LiveInterval::Segment addSegmentToEndOfBlock(unsigned reg,
MachineInstr* startInst);
/// shrinkToUses - After removing some uses of a register, shrink its live
/// range to just the remaining uses. This method does not compute reaching
@ -153,7 +160,7 @@ namespace llvm {
/// extended to be live out of the basic block.
///
/// See also LiveRangeCalc::extend().
void extendToIndices(LiveInterval *LI, ArrayRef<SlotIndex> Indices);
void extendToIndices(LiveRange &LR, ArrayRef<SlotIndex> Indices);
/// pruneValue - If an LI value is live at Kill, prune its live range by
/// removing any liveness reachable from Kill. Add live range end points to
@ -199,14 +206,14 @@ namespace llvm {
return Indexes->getMBBEndIdx(mbb);
}
bool isLiveInToMBB(const LiveInterval &li,
bool isLiveInToMBB(const LiveRange &LR,
const MachineBasicBlock *mbb) const {
return li.liveAt(getMBBStartIdx(mbb));
return LR.liveAt(getMBBStartIdx(mbb));
}
bool isLiveOutOfMBB(const LiveInterval &li,
bool isLiveOutOfMBB(const LiveRange &LR,
const MachineBasicBlock *mbb) const {
return li.liveAt(getMBBEndIdx(mbb).getPrevSlot());
return LR.liveAt(getMBBEndIdx(mbb).getPrevSlot());
}
MachineBasicBlock* getMBBFromIndex(SlotIndex index) const {
@ -224,6 +231,12 @@ namespace llvm {
return Indexes->insertMachineInstrInMaps(MI);
}
void InsertMachineInstrRangeInMaps(MachineBasicBlock::iterator B,
MachineBasicBlock::iterator E) {
for (MachineBasicBlock::iterator I = B; I != E; ++I)
Indexes->insertMachineInstrInMaps(I);
}
void RemoveMachineInstrFromMaps(MachineInstr *MI) {
Indexes->removeMachineInstrFromMaps(MI);
}
@ -351,24 +364,24 @@ namespace llvm {
/// getRegUnit - Return the live range for Unit.
/// It will be computed if it doesn't exist.
LiveInterval &getRegUnit(unsigned Unit) {
LiveInterval *LI = RegUnitIntervals[Unit];
if (!LI) {
LiveRange &getRegUnit(unsigned Unit) {
LiveRange *LR = RegUnitRanges[Unit];
if (!LR) {
// Compute missing ranges on demand.
RegUnitIntervals[Unit] = LI = new LiveInterval(Unit, HUGE_VALF);
computeRegUnitInterval(LI);
RegUnitRanges[Unit] = LR = new LiveRange();
computeRegUnitRange(*LR, Unit);
}
return *LI;
return *LR;
}
/// getCachedRegUnit - Return the live range for Unit if it has already
/// been computed, or NULL if it hasn't been computed yet.
LiveInterval *getCachedRegUnit(unsigned Unit) {
return RegUnitIntervals[Unit];
LiveRange *getCachedRegUnit(unsigned Unit) {
return RegUnitRanges[Unit];
}
const LiveInterval *getCachedRegUnit(unsigned Unit) const {
return RegUnitIntervals[Unit];
const LiveRange *getCachedRegUnit(unsigned Unit) const {
return RegUnitRanges[Unit];
}
private:
@ -384,8 +397,8 @@ namespace llvm {
void dumpInstrs() const;
void computeLiveInRegUnits();
void computeRegUnitInterval(LiveInterval*);
void computeVirtRegInterval(LiveInterval*);
void computeRegUnitRange(LiveRange&, unsigned Unit);
void computeVirtRegInterval(LiveInterval&);
class HMEditor;
};

View File

@ -32,7 +32,7 @@ typedef SparseBitVector<128> LiveVirtRegBitSet;
/// Compare a live virtual register segment to a LiveIntervalUnion segment.
inline bool
overlap(const LiveRange &VRSeg,
overlap(const LiveInterval::Segment &VRSeg,
const IntervalMap<SlotIndex, LiveInterval*>::const_iterator &LUSeg) {
return VRSeg.start < LUSeg.stop() && LUSeg.start() < VRSeg.end;
}

View File

@ -19,19 +19,21 @@
#define LLVM_CODEGEN_LIVERANGEEDIT_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/CodeGen/LiveInterval.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Target/TargetMachine.h"
namespace llvm {
class AliasAnalysis;
class LiveIntervals;
class MachineBlockFrequencyInfo;
class MachineLoopInfo;
class MachineRegisterInfo;
class VirtRegMap;
class LiveRangeEdit {
class LiveRangeEdit : private MachineRegisterInfo::Delegate {
public:
/// Callback methods for LiveRangeEdit owners.
class Delegate {
@ -56,7 +58,7 @@ public:
private:
LiveInterval *Parent;
SmallVectorImpl<LiveInterval*> &NewRegs;
SmallVectorImpl<unsigned> &NewRegs;
MachineRegisterInfo &MRI;
LiveIntervals &LIS;
VirtRegMap *VRM;
@ -89,6 +91,16 @@ private:
/// a load, eliminate the register by folding the def into the use.
bool foldAsLoad(LiveInterval *LI, SmallVectorImpl<MachineInstr*> &Dead);
typedef SetVector<LiveInterval*,
SmallVector<LiveInterval*, 8>,
SmallPtrSet<LiveInterval*, 8> > ToShrinkSet;
/// Helper for eliminateDeadDefs.
void eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink);
/// MachineRegisterInfo callback to notify when new virtual
/// registers are created.
void MRI_NoteNewVirtualRegister(unsigned VReg);
public:
/// Create a LiveRangeEdit for breaking down parent into smaller pieces.
/// @param parent The register being spilled or split.
@ -100,7 +112,7 @@ public:
/// function. If NULL, no virtual register map updates will
/// be done. This could be the case if called before Regalloc.
LiveRangeEdit(LiveInterval *parent,
SmallVectorImpl<LiveInterval*> &newRegs,
SmallVectorImpl<unsigned> &newRegs,
MachineFunction &MF,
LiveIntervals &lis,
VirtRegMap *vrm,
@ -110,7 +122,9 @@ public:
TII(*MF.getTarget().getInstrInfo()),
TheDelegate(delegate),
FirstNew(newRegs.size()),
ScannedRemattable(false) {}
ScannedRemattable(false) { MRI.setDelegate(this); }
~LiveRangeEdit() { MRI.resetDelegate(this); }
LiveInterval &getParent() const {
assert(Parent && "No parent LiveInterval");
@ -119,23 +133,30 @@ public:
unsigned getReg() const { return getParent().reg; }
/// Iterator for accessing the new registers added by this edit.
typedef SmallVectorImpl<LiveInterval*>::const_iterator iterator;
typedef SmallVectorImpl<unsigned>::const_iterator iterator;
iterator begin() const { return NewRegs.begin()+FirstNew; }
iterator end() const { return NewRegs.end(); }
unsigned size() const { return NewRegs.size()-FirstNew; }
bool empty() const { return size() == 0; }
LiveInterval *get(unsigned idx) const { return NewRegs[idx+FirstNew]; }
unsigned get(unsigned idx) const { return NewRegs[idx+FirstNew]; }
ArrayRef<LiveInterval*> regs() const {
ArrayRef<unsigned> regs() const {
return makeArrayRef(NewRegs).slice(FirstNew);
}
/// createEmptyIntervalFrom - Create a new empty interval based on OldReg.
LiveInterval &createEmptyIntervalFrom(unsigned OldReg);
/// createFrom - Create a new virtual register based on OldReg.
LiveInterval &createFrom(unsigned OldReg);
unsigned createFrom(unsigned OldReg);
/// create - Create a new register with the same class and original slot as
/// parent.
LiveInterval &create() {
LiveInterval &createEmptyInterval() {
return createEmptyIntervalFrom(getReg());
}
unsigned create() {
return createFrom(getReg());
}
@ -201,7 +222,8 @@ public:
/// calculateRegClassAndHint - Recompute register class and hint for each new
/// register.
void calculateRegClassAndHint(MachineFunction&,
const MachineLoopInfo&);
const MachineLoopInfo&,
const MachineBlockFrequencyInfo&);
};
}

View File

@ -0,0 +1,88 @@
//===-- llvm/CodeGen/LiveRegUnits.h - Live register unit set ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements a Set of live register units. This can be used for ad
// hoc liveness tracking after register allocation. You can start with the
// live-ins/live-outs at the beginning/end of a block and update the information
// while walking the instructions inside the block.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CODEGEN_LIVEREGUNITS_H
#define LLVM_CODEGEN_LIVEREGUNITS_H
#include "llvm/ADT/SparseSet.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include <cassert>
namespace llvm {
class MachineInstr;
/// A set of live register units with functions to track liveness when walking
/// backward/forward through a basic block.
class LiveRegUnits {
SparseSet<unsigned> LiveUnits;
LiveRegUnits(const LiveRegUnits&) LLVM_DELETED_FUNCTION;
LiveRegUnits &operator=(const LiveRegUnits&) LLVM_DELETED_FUNCTION;
public:
/// \brief Constructs a new empty LiveRegUnits set.
LiveRegUnits() {}
void init(const TargetRegisterInfo *TRI) {
LiveUnits.clear();
LiveUnits.setUniverse(TRI->getNumRegs());
}
void clear() { LiveUnits.clear(); }
bool empty() const { return LiveUnits.empty(); }
/// \brief Adds a register to the set.
void addReg(unsigned Reg, const MCRegisterInfo &MCRI) {
for (MCRegUnitIterator RUnits(Reg, &MCRI); RUnits.isValid(); ++RUnits)
LiveUnits.insert(*RUnits);
}
/// \brief Removes a register from the set.
void removeReg(unsigned Reg, const MCRegisterInfo &MCRI) {
for (MCRegUnitIterator RUnits(Reg, &MCRI); RUnits.isValid(); ++RUnits)
LiveUnits.erase(*RUnits);
}
/// \brief Removes registers clobbered by the regmask operand @p Op.
void removeRegsInMask(const MachineOperand &Op, const MCRegisterInfo &MCRI);
/// \brief Returns true if register @p Reg (or one of its super register) is
/// contained in the set.
bool contains(unsigned Reg, const MCRegisterInfo &MCRI) const {
for (MCRegUnitIterator RUnits(Reg, &MCRI); RUnits.isValid(); ++RUnits) {
if (LiveUnits.count(*RUnits))
return true;
}
return false;
}
/// \brief Simulates liveness when stepping backwards over an
/// instruction(bundle): Remove Defs, add uses.
void stepBackward(const MachineInstr &MI, const MCRegisterInfo &MCRI);
/// \brief Simulates liveness when stepping forward over an
/// instruction(bundle): Remove killed-uses, add defs.
void stepForward(const MachineInstr &MI, const MCRegisterInfo &MCRI);
/// \brief Adds all registers in the live-in list of block @p BB.
void addLiveIns(const MachineBasicBlock *MBB, const MCRegisterInfo &MCRI);
};
} // namespace llvm
#endif

View File

@ -157,8 +157,8 @@ private: // Intermediate data structures
void HandlePhysRegUse(unsigned Reg, MachineInstr *MI);
void HandlePhysRegDef(unsigned Reg, MachineInstr *MI,
SmallVector<unsigned, 4> &Defs);
void UpdatePhysRegDefs(MachineInstr *MI, SmallVector<unsigned, 4> &Defs);
SmallVectorImpl<unsigned> &Defs);
void UpdatePhysRegDefs(MachineInstr *MI, SmallVectorImpl<unsigned> &Defs);
/// FindLastRefOrPartRef - Return the last reference or partial reference of
/// the specified register.

View File

@ -410,8 +410,8 @@ public:
/// branch to do so (e.g., a table jump). True is a conservative answer.
bool canFallThrough();
/// Returns a pointer to the first instructon in this block that is not a
/// PHINode instruction. When adding instruction to the beginning of the
/// Returns a pointer to the first instruction in this block that is not a
/// PHINode instruction. When adding instructions to the beginning of the
/// basic block, they should be added before the returned value, not before
/// the first instruction, which might be PHI.
/// Returns end() is there's no non-PHI instruction.
@ -733,6 +733,31 @@ template <> struct GraphTraits<Inverse<const MachineBasicBlock*> > {
}
};
/// MachineInstrSpan provides an interface to get an iteration range
/// containing the instruction it was initialized with, along with all
/// those instructions inserted prior to or following that instruction
/// at some point after the MachineInstrSpan is constructed.
class MachineInstrSpan {
MachineBasicBlock &MBB;
MachineBasicBlock::iterator I, B, E;
public:
MachineInstrSpan(MachineBasicBlock::iterator I)
: MBB(*I->getParent()),
I(I),
B(I == MBB.begin() ? MBB.end() : llvm::prior(I)),
E(llvm::next(I)) {}
MachineBasicBlock::iterator begin() {
return B == MBB.end() ? MBB.begin() : llvm::next(B);
}
MachineBasicBlock::iterator end() { return E; }
bool empty() { return begin() == end(); }
MachineBasicBlock::iterator getInitial() { return I; }
};
} // End llvm namespace
#endif

View File

@ -1,4 +1,4 @@
//==- MachineBranchProbabilityInfo.h - Machine Branch Probability Analysis -==//
//=- MachineBranchProbabilityInfo.h - Branch Probability Analysis -*- C++ -*-=//
//
// The LLVM Compiler Infrastructure
//

View File

@ -132,15 +132,17 @@ public:
/// address of the function constant pool values.
/// @brief The machine constant pool.
class MachineConstantPool {
const DataLayout *TD; ///< The machine's DataLayout.
unsigned PoolAlignment; ///< The alignment for the pool.
const TargetMachine &TM; ///< The target machine.
unsigned PoolAlignment; ///< The alignment for the pool.
std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants.
/// MachineConstantPoolValues that use an existing MachineConstantPoolEntry.
DenseSet<MachineConstantPoolValue*> MachineCPVsSharingEntries;
const DataLayout *getDataLayout() const;
public:
/// @brief The only constructor.
explicit MachineConstantPool(const DataLayout *td)
: TD(td), PoolAlignment(1) {}
explicit MachineConstantPool(const TargetMachine &TM)
: TM(TM), PoolAlignment(1) {}
~MachineConstantPool();
/// getConstantPoolAlignment - Return the alignment required by

View File

@ -27,6 +27,7 @@ class Type;
class MachineFunction;
class MachineBasicBlock;
class TargetFrameLowering;
class TargetMachine;
class BitVector;
class Value;
class AllocaInst;
@ -119,6 +120,8 @@ class MachineFrameInfo {
isSpillSlot(isSS), MayNeedSP(NSP), Alloca(Val), PreAllocated(false) {}
};
const TargetMachine &TM;
/// Objects - The list of stack objects allocated...
///
std::vector<StackObject> Objects;
@ -201,10 +204,6 @@ class MachineFrameInfo {
/// CSIValid - Has CSInfo been set yet?
bool CSIValid;
/// TargetFrameLowering - Target information about frame layout.
///
const TargetFrameLowering &TFI;
/// LocalFrameObjects - References to frame indices which are mapped
/// into the local frame allocation block. <FrameIdx, LocalOffset>
SmallVector<std::pair<int, int64_t>, 32> LocalFrameObjects;
@ -223,9 +222,11 @@ class MachineFrameInfo {
/// Whether the "realign-stack" option is on.
bool RealignOption;
const TargetFrameLowering *getFrameLowering() const;
public:
explicit MachineFrameInfo(const TargetFrameLowering &tfi, bool RealignOpt)
: TFI(tfi), RealignOption(RealignOpt) {
explicit MachineFrameInfo(const TargetMachine &TM, bool RealignOpt)
: TM(TM), RealignOption(RealignOpt) {
StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0;
HasVarSizedObjects = false;
FrameAddressTaken = false;

View File

@ -397,8 +397,8 @@ public:
return isBranch(Type) & isBarrier(Type) & !isIndirectBranch(Type);
}
// isPredicable - Return true if this instruction has a predicate operand that
// controls execution. It may be set to 'always', or may be set to other
/// Return true if this instruction has a predicate operand that
/// controls execution. It may be set to 'always', or may be set to other
/// values. There are various methods in TargetInstrInfo that can be used to
/// control and modify the predicate in this instruction.
bool isPredicable(QueryType Type = AllInBundle) const {
@ -637,6 +637,13 @@ public:
bool isEHLabel() const { return getOpcode() == TargetOpcode::EH_LABEL; }
bool isGCLabel() const { return getOpcode() == TargetOpcode::GC_LABEL; }
bool isDebugValue() const { return getOpcode() == TargetOpcode::DBG_VALUE; }
/// A DBG_VALUE is indirect iff the first operand is a register and
/// the second operand is an immediate.
bool isIndirectDebugValue() const {
return isDebugValue()
&& getOperand(0).isReg()
&& getOperand(1).isImm();
}
bool isPHI() const { return getOpcode() == TargetOpcode::PHI; }
bool isKill() const { return getOpcode() == TargetOpcode::KILL; }
@ -886,13 +893,12 @@ public:
/// Look for the operand that defines it and mark it as IsDead. If
/// AddIfNotFound is true, add a implicit operand if it's not found. Returns
/// true if the operand exists / is added.
bool addRegisterDead(unsigned IncomingReg, const TargetRegisterInfo *RegInfo,
bool addRegisterDead(unsigned Reg, const TargetRegisterInfo *RegInfo,
bool AddIfNotFound = false);
/// addRegisterDefined - We have determined MI defines a register. Make sure
/// there is an operand defining Reg.
void addRegisterDefined(unsigned IncomingReg,
const TargetRegisterInfo *RegInfo = 0);
void addRegisterDefined(unsigned Reg, const TargetRegisterInfo *RegInfo = 0);
/// setPhysRegsDeadExcept - Mark every physreg used by this instruction as
/// dead except those in the UsedRegs list.
@ -908,11 +914,6 @@ public:
bool isSafeToMove(const TargetInstrInfo *TII, AliasAnalysis *AA,
bool &SawStore) const;
/// isSafeToReMat - Return true if it's safe to rematerialize the specified
/// instruction which defined the specified register instead of copying it.
bool isSafeToReMat(const TargetInstrInfo *TII, AliasAnalysis *AA,
unsigned DstReg) const;
/// hasOrderedMemoryRef - Return true if this instruction may have an ordered
/// or volatile memory reference, or if the information describing the memory
/// reference is not available. Return false if it is known to have no

Some files were not shown because too many files have changed in this diff Show More