[llvm-branch-commits] [llvm-branch] r85763 - in /llvm/branches/Apple/Leela: ./ autoconf/ cmake/ docs/ include/llvm-c/ include/llvm/ include/llvm/ADT/ include/llvm/Analysis/ include/llvm/Bitcode/ include/llvm/CodeGen/ include/llvm/ExecutionEngine/ include/llvm/MC/ include/llvm/Support/ include/llvm/System/ include/llvm/Target/ include/llvm/Transforms/Utils/ lib/Analysis/ lib/AsmParser/ lib/Bitcode/Reader/ lib/Bitcode/Writer/ lib/CodeGen/ lib/CodeGen/AsmPrinter/ lib/CodeGen/SelectionDAG/ lib/ExecutionEngine/ lib/ExecutionEngine...

Bill Wendling isanbard at gmail.com
Sun Nov 1 16:01:11 PST 2009


Author: void
Date: Sun Nov  1 18:01:08 2009
New Revision: 85763

URL: http://llvm.org/viewvc/llvm-project?rev=85763&view=rev
Log:
$ svn merge -c 85086 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85086 into '.':

$ svn merge -c 85344 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85344 into '.':

$ svn merge -c 85349 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85349 into '.':

$ svn merge -c 85351 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85351 into '.':

$ svn merge -c 85355 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85355 into '.':

$ svn merge -c 85365 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85365 into '.':

$ svn merge -c 85366 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85366 into '.':

$ svn merge -c 85367 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85367 into '.':

$ svn merge -c 85368 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85368 into '.':

$ svn merge -c 85370 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85370 into '.':

$ svn merge -c 85375 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85375 into '.':

$ svn merge -c 85376 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85376 into '.':

$ svn merge -c 85377 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85377 into '.':

$ svn merge -c 85445 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85445 into '.':

$ svn merge -c 85449 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85449 into '.':

$ svn merge -c 85457 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85457 into '.':

$ svn merge -c 85458 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85458 into '.':

$ svn merge -c 85465 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85465 into '.':

$ svn merge -c 85488 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85488 into '.':

$ svn merge -c 85495 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85495 into '.':

$ svn merge -c 85496 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85496 into '.':

$ svn merge -c 85556 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85556 into '.':

$ svn merge -c 85557 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85557 into '.':

$ svn merge -c 85558 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85558 into '.':

$ svn merge -c 85559 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85559 into '.':

$ svn merge -c 85562 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85562 into '.':

$ svn merge -c 85571 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85571 into '.':

$ svn merge -c 85572 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85572 into '.':

$ svn merge -c 85621 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85621 into '.':

$ svn merge -c 85625 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85625 into '.':

$ svn merge -c 85627 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85627 into '.':

$ svn merge -c 85678 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85678 into '.':

$ svn merge -c 85680 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85680 into '.':

$ svn merge -c 85688 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85688 into '.':

$ svn merge -c 85690 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85690 into '.':

$ svn merge -c 85692 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85692 into '.':

$ svn merge -c 85699 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85699 into '.':

$ svn merge -c 85700 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85700 into '.':

$ svn merge -c 85701 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85701 into '.':

$ svn merge -c 85702 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85702 into '.':

$ svn merge -c 85703 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85703 into '.':

$ svn merge -c 85704 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85704 into '.':

$ svn merge -c 85705 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85705 into '.':

$ svn merge -c 85706 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85706 into '.':

$ svn merge -c 85707 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85707 into '.':

$ svn merge -c 85708 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85708 into '.':

$ svn merge -c 85722 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85722 into '.':

$ svn merge -c 85724 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85724 into '.':

$ svn merge -c 85725 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85725 into '.':

$ svn merge -c 84192 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84192 into '.':

$ svn merge -c 84193 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84193 into '.':

$ svn merge -c 84295 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84295 into '.':

$ svn merge -c 84364 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84364 into '.':

$ svn merge -c 84367 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84367 into '.':

$ svn merge -c 84368 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84368 into '.':

$ svn merge -c 84661 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84661 into '.':

$ svn merge -c 85020 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85020 into '.':

$ svn merge -c 85549 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85549 into '.':

$ svn merge -c 85551 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r85551 into '.':

$ svn merge -c 84013 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84013 into '.':

$ svn merge -c 83987 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r83987 into '.':

$ svn merge -c 84975 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84975 into '.':

$ svn merge -c 84522 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84522 into '.':

$ svn merge -c 84651 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r84651 into '.':


Added:
    llvm/branches/Apple/Leela/include/llvm/System/AIXDataTypesFix.h
      - copied unchanged from r85086, llvm/trunk/include/llvm/System/AIXDataTypesFix.h
    llvm/branches/Apple/Leela/include/llvm/System/DataTypes.h.cmake
      - copied unchanged from r85086, llvm/trunk/include/llvm/System/DataTypes.h.cmake
    llvm/branches/Apple/Leela/include/llvm/System/DataTypes.h.in
      - copied unchanged from r85086, llvm/trunk/include/llvm/System/DataTypes.h.in
    llvm/branches/Apple/Leela/test/CodeGen/X86/loop_blocks.ll
      - copied unchanged from r84295, llvm/trunk/test/CodeGen/X86/loop_blocks.ll
    llvm/branches/Apple/Leela/test/CodeGen/X86/x86-64-jumps.ll
      - copied unchanged from r85703, llvm/trunk/test/CodeGen/X86/x86-64-jumps.ll
    llvm/branches/Apple/Leela/test/Transforms/ConstProp/constant-expr.ll
      - copied, changed from r84364, llvm/trunk/test/Transforms/ConstProp/constant-expr.ll
Removed:
    llvm/branches/Apple/Leela/include/llvm/Support/AIXDataTypesFix.h
    llvm/branches/Apple/Leela/include/llvm/Support/DataTypes.h.cmake
    llvm/branches/Apple/Leela/include/llvm/Support/DataTypes.h.in
    llvm/branches/Apple/Leela/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll
Modified:
    llvm/branches/Apple/Leela/Makefile
    llvm/branches/Apple/Leela/autoconf/configure.ac
    llvm/branches/Apple/Leela/cmake/config-ix.cmake
    llvm/branches/Apple/Leela/configure
    llvm/branches/Apple/Leela/docs/LangRef.html
    llvm/branches/Apple/Leela/include/llvm-c/Core.h
    llvm/branches/Apple/Leela/include/llvm/ADT/EquivalenceClasses.h
    llvm/branches/Apple/Leela/include/llvm/ADT/FoldingSet.h
    llvm/branches/Apple/Leela/include/llvm/ADT/ImmutableList.h
    llvm/branches/Apple/Leela/include/llvm/ADT/ImmutableSet.h
    llvm/branches/Apple/Leela/include/llvm/ADT/SmallPtrSet.h
    llvm/branches/Apple/Leela/include/llvm/ADT/SparseBitVector.h
    llvm/branches/Apple/Leela/include/llvm/ADT/StringExtras.h
    llvm/branches/Apple/Leela/include/llvm/ADT/Twine.h
    llvm/branches/Apple/Leela/include/llvm/Analysis/ScalarEvolution.h
    llvm/branches/Apple/Leela/include/llvm/Analysis/ValueTracking.h
    llvm/branches/Apple/Leela/include/llvm/BasicBlock.h
    llvm/branches/Apple/Leela/include/llvm/Bitcode/BitCodes.h
    llvm/branches/Apple/Leela/include/llvm/Bitcode/Deserialize.h
    llvm/branches/Apple/Leela/include/llvm/Bitcode/LLVMBitCodes.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/AsmPrinter.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/BinaryObject.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/ELFRelocation.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/JITCodeEmitter.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineBasicBlock.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineCodeEmitter.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineFrameInfo.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineInstrBuilder.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineModuleInfo.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineOperand.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineRelocation.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/SelectionDAG.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/SelectionDAGNodes.h
    llvm/branches/Apple/Leela/include/llvm/CodeGen/ValueTypes.h
    llvm/branches/Apple/Leela/include/llvm/Constant.h
    llvm/branches/Apple/Leela/include/llvm/Constants.h
    llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/ExecutionEngine.h
    llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/GenericValue.h
    llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/JITEventListener.h
    llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/JITMemoryManager.h
    llvm/branches/Apple/Leela/include/llvm/Instruction.def
    llvm/branches/Apple/Leela/include/llvm/Instructions.h
    llvm/branches/Apple/Leela/include/llvm/MC/MCAsmLexer.h
    llvm/branches/Apple/Leela/include/llvm/MC/MCAsmParser.h
    llvm/branches/Apple/Leela/include/llvm/MC/MCAssembler.h
    llvm/branches/Apple/Leela/include/llvm/MC/MCDisassembler.h
    llvm/branches/Apple/Leela/include/llvm/MC/MCExpr.h
    llvm/branches/Apple/Leela/include/llvm/MC/MCInst.h
    llvm/branches/Apple/Leela/include/llvm/MC/MCStreamer.h
    llvm/branches/Apple/Leela/include/llvm/MC/MCSymbol.h
    llvm/branches/Apple/Leela/include/llvm/MC/MCValue.h
    llvm/branches/Apple/Leela/include/llvm/Module.h
    llvm/branches/Apple/Leela/include/llvm/Pass.h
    llvm/branches/Apple/Leela/include/llvm/Support/Allocator.h
    llvm/branches/Apple/Leela/include/llvm/Support/ConstantRange.h
    llvm/branches/Apple/Leela/include/llvm/Support/ELF.h
    llvm/branches/Apple/Leela/include/llvm/Support/IRBuilder.h
    llvm/branches/Apple/Leela/include/llvm/Support/InstVisitor.h
    llvm/branches/Apple/Leela/include/llvm/Support/MathExtras.h
    llvm/branches/Apple/Leela/include/llvm/Support/MemoryBuffer.h
    llvm/branches/Apple/Leela/include/llvm/Support/MemoryObject.h
    llvm/branches/Apple/Leela/include/llvm/Support/PointerLikeTypeTraits.h
    llvm/branches/Apple/Leela/include/llvm/Support/SlowOperationInformer.h
    llvm/branches/Apple/Leela/include/llvm/Support/Timer.h
    llvm/branches/Apple/Leela/include/llvm/Support/ValueHandle.h
    llvm/branches/Apple/Leela/include/llvm/Support/raw_ostream.h
    llvm/branches/Apple/Leela/include/llvm/System/Atomic.h
    llvm/branches/Apple/Leela/include/llvm/System/Disassembler.h
    llvm/branches/Apple/Leela/include/llvm/System/Memory.h
    llvm/branches/Apple/Leela/include/llvm/System/TimeValue.h
    llvm/branches/Apple/Leela/include/llvm/Target/SubtargetFeature.h
    llvm/branches/Apple/Leela/include/llvm/Target/TargetData.h
    llvm/branches/Apple/Leela/include/llvm/Target/TargetIntrinsicInfo.h
    llvm/branches/Apple/Leela/include/llvm/Target/TargetJITInfo.h
    llvm/branches/Apple/Leela/include/llvm/Target/TargetSelectionDAG.td
    llvm/branches/Apple/Leela/include/llvm/Transforms/Utils/BasicBlockUtils.h
    llvm/branches/Apple/Leela/include/llvm/Transforms/Utils/ValueMapper.h
    llvm/branches/Apple/Leela/include/llvm/Type.h
    llvm/branches/Apple/Leela/include/llvm/Value.h
    llvm/branches/Apple/Leela/include/llvm/ValueSymbolTable.h
    llvm/branches/Apple/Leela/lib/Analysis/InlineCost.cpp
    llvm/branches/Apple/Leela/lib/Analysis/SparsePropagation.cpp
    llvm/branches/Apple/Leela/lib/AsmParser/LLLexer.cpp
    llvm/branches/Apple/Leela/lib/AsmParser/LLParser.cpp
    llvm/branches/Apple/Leela/lib/AsmParser/LLParser.h
    llvm/branches/Apple/Leela/lib/AsmParser/LLToken.h
    llvm/branches/Apple/Leela/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/branches/Apple/Leela/lib/Bitcode/Reader/BitcodeReader.h
    llvm/branches/Apple/Leela/lib/Bitcode/Writer/BitcodeWriter.cpp
    llvm/branches/Apple/Leela/lib/Bitcode/Writer/ValueEnumerator.cpp
    llvm/branches/Apple/Leela/lib/Bitcode/Writer/ValueEnumerator.h
    llvm/branches/Apple/Leela/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/branches/Apple/Leela/lib/CodeGen/BranchFolding.cpp
    llvm/branches/Apple/Leela/lib/CodeGen/ELF.h
    llvm/branches/Apple/Leela/lib/CodeGen/MachineBasicBlock.cpp
    llvm/branches/Apple/Leela/lib/CodeGen/MachineInstr.cpp
    llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
    llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.h
    llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
    llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h
    llvm/branches/Apple/Leela/lib/ExecutionEngine/ExecutionEngine.cpp
    llvm/branches/Apple/Leela/lib/ExecutionEngine/Interpreter/Execution.cpp
    llvm/branches/Apple/Leela/lib/ExecutionEngine/Interpreter/Interpreter.h
    llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JIT.h
    llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITDebugRegisterer.h
    llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITEmitter.cpp
    llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
    llvm/branches/Apple/Leela/lib/Linker/LinkModules.cpp
    llvm/branches/Apple/Leela/lib/MC/MCAsmInfo.cpp
    llvm/branches/Apple/Leela/lib/Support/Allocator.cpp
    llvm/branches/Apple/Leela/lib/System/Unix/Memory.inc
    llvm/branches/Apple/Leela/lib/System/Win32/Memory.inc
    llvm/branches/Apple/Leela/lib/Target/CBackend/CBackend.cpp
    llvm/branches/Apple/Leela/lib/Target/CellSPU/SPU.h
    llvm/branches/Apple/Leela/lib/Target/CppBackend/CPPBackend.cpp
    llvm/branches/Apple/Leela/lib/Target/MSIL/MSILWriter.cpp
    llvm/branches/Apple/Leela/lib/Target/TargetIntrinsicInfo.cpp
    llvm/branches/Apple/Leela/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp
    llvm/branches/Apple/Leela/lib/Target/X86/X86ISelDAGToDAG.cpp
    llvm/branches/Apple/Leela/lib/Target/X86/X86ISelLowering.cpp
    llvm/branches/Apple/Leela/lib/Target/X86/X86ISelLowering.h
    llvm/branches/Apple/Leela/lib/Target/X86/X86Instr64bit.td
    llvm/branches/Apple/Leela/lib/Target/X86/X86InstrInfo.td
    llvm/branches/Apple/Leela/lib/Transforms/IPO/GlobalDCE.cpp
    llvm/branches/Apple/Leela/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/branches/Apple/Leela/lib/Transforms/IPO/StripSymbols.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Scalar/CodeGenPrepare.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Scalar/CondPropagate.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Scalar/GVN.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Scalar/LoopUnswitch.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Scalar/SCCP.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Utils/BasicBlockUtils.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Utils/BreakCriticalEdges.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Utils/CloneFunction.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Utils/CloneModule.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Utils/Local.cpp
    llvm/branches/Apple/Leela/lib/Transforms/Utils/ValueMapper.cpp
    llvm/branches/Apple/Leela/lib/VMCore/AsmWriter.cpp
    llvm/branches/Apple/Leela/lib/VMCore/BasicBlock.cpp
    llvm/branches/Apple/Leela/lib/VMCore/ConstantFold.cpp
    llvm/branches/Apple/Leela/lib/VMCore/Constants.cpp
    llvm/branches/Apple/Leela/lib/VMCore/ConstantsContext.h
    llvm/branches/Apple/Leela/lib/VMCore/Function.cpp
    llvm/branches/Apple/Leela/lib/VMCore/Globals.cpp
    llvm/branches/Apple/Leela/lib/VMCore/Instruction.cpp
    llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp
    llvm/branches/Apple/Leela/lib/VMCore/LLVMContextImpl.h
    llvm/branches/Apple/Leela/lib/VMCore/Verifier.cpp
    llvm/branches/Apple/Leela/projects/sample/lib/sample/sample.c
    llvm/branches/Apple/Leela/test/Feature/terminators.ll
    llvm/branches/Apple/Leela/test/Transforms/SimplifyCFG/basictest.ll
    llvm/branches/Apple/Leela/tools/llvm-mc/AsmLexer.h
    llvm/branches/Apple/Leela/unittests/ADT/StringMapTest.cpp
    llvm/branches/Apple/Leela/unittests/ExecutionEngine/ExecutionEngineTest.cpp
    llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp
    llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/JITTest.cpp
    llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/Makefile
    llvm/branches/Apple/Leela/utils/TableGen/CodeGenDAGPatterns.h
    llvm/branches/Apple/Leela/utils/TableGen/DAGISelEmitter.cpp
    llvm/branches/Apple/Leela/utils/TableGen/Record.cpp
    llvm/branches/Apple/Leela/utils/TableGen/Record.h
    llvm/branches/Apple/Leela/utils/TableGen/TGLexer.h

Modified: llvm/branches/Apple/Leela/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/Makefile?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/Makefile (original)
+++ llvm/branches/Apple/Leela/Makefile Sun Nov  1 18:01:08 2009
@@ -136,8 +136,7 @@
 	$(Echo) Eliminating files constructed by configure
 	$(Verb) $(RM) -f \
 	  $(TopDistDir)/include/llvm/Config/config.h  \
-	  $(TopDistDir)/include/llvm/Support/DataTypes.h  \
-	  $(TopDistDir)/include/llvm/Support/ThreadSupport.h
+	  $(TopDistDir)/include/llvm/System/DataTypes.h
 
 clang-only: all
 tools-only: all
@@ -153,7 +152,7 @@
   include/llvm/Config/config.h \
   include/llvm/Config/Targets.def \
 	include/llvm/Config/AsmPrinters.def \
-  include/llvm/Support/DataTypes.h \
+  include/llvm/System/DataTypes.h \
 	tools/llvmc/plugins/Base/Base.td
 FilesToConfigPATH  := $(addprefix $(LLVM_OBJ_ROOT)/,$(FilesToConfig))
 

Modified: llvm/branches/Apple/Leela/autoconf/configure.ac
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/autoconf/configure.ac?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/autoconf/configure.ac (original)
+++ llvm/branches/Apple/Leela/autoconf/configure.ac Sun Nov  1 18:01:08 2009
@@ -1344,7 +1344,7 @@
 AC_CONFIG_FILES([include/llvm/Config/Targets.def])
 AC_CONFIG_FILES([include/llvm/Config/AsmPrinters.def])
 AC_CONFIG_FILES([include/llvm/Config/AsmParsers.def])
-AC_CONFIG_HEADERS([include/llvm/Support/DataTypes.h])
+AC_CONFIG_HEADERS([include/llvm/System/DataTypes.h])
 
 dnl Configure the makefile's configuration data
 AC_CONFIG_FILES([Makefile.config])

Modified: llvm/branches/Apple/Leela/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/cmake/config-ix.cmake?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/cmake/config-ix.cmake (original)
+++ llvm/branches/Apple/Leela/cmake/config-ix.cmake Sun Nov  1 18:01:08 2009
@@ -229,7 +229,7 @@
   )
 
 configure_file(
-  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
-  ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h
+  ${LLVM_MAIN_INCLUDE_DIR}/llvm/System/DataTypes.h.cmake
+  ${LLVM_BINARY_DIR}/include/llvm/System/DataTypes.h
   )
 

Modified: llvm/branches/Apple/Leela/configure
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/configure?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/configure (original)
+++ llvm/branches/Apple/Leela/configure Sun Nov  1 18:01:08 2009
@@ -35269,7 +35269,7 @@
 
 ac_config_files="$ac_config_files include/llvm/Config/AsmParsers.def"
 
-ac_config_headers="$ac_config_headers include/llvm/Support/DataTypes.h"
+ac_config_headers="$ac_config_headers include/llvm/System/DataTypes.h"
 
 
 ac_config_files="$ac_config_files Makefile.config"
@@ -35896,7 +35896,7 @@
     "include/llvm/Config/Targets.def") CONFIG_FILES="$CONFIG_FILES include/llvm/Config/Targets.def" ;;
     "include/llvm/Config/AsmPrinters.def") CONFIG_FILES="$CONFIG_FILES include/llvm/Config/AsmPrinters.def" ;;
     "include/llvm/Config/AsmParsers.def") CONFIG_FILES="$CONFIG_FILES include/llvm/Config/AsmParsers.def" ;;
-    "include/llvm/Support/DataTypes.h") CONFIG_HEADERS="$CONFIG_HEADERS include/llvm/Support/DataTypes.h" ;;
+    "include/llvm/System/DataTypes.h") CONFIG_HEADERS="$CONFIG_HEADERS include/llvm/System/DataTypes.h" ;;
     "Makefile.config") CONFIG_FILES="$CONFIG_FILES Makefile.config" ;;
     "llvm.spec") CONFIG_FILES="$CONFIG_FILES llvm.spec" ;;
     "docs/doxygen.cfg") CONFIG_FILES="$CONFIG_FILES docs/doxygen.cfg" ;;

Modified: llvm/branches/Apple/Leela/docs/LangRef.html
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/docs/LangRef.html?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/docs/LangRef.html (original)
+++ llvm/branches/Apple/Leela/docs/LangRef.html Sun Nov  1 18:01:08 2009
@@ -111,7 +111,7 @@
           <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
           <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
           <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
-          <li><a href="#i_indbr">'<tt>indbr</tt>' Instruction</a></li>
+          <li><a href="#i_indirectbr">'<tt>indirectbr</tt>' Instruction</a></li>
           <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
           <li><a href="#i_unwind">'<tt>unwind</tt>'  Instruction</a></li>
           <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
@@ -2177,13 +2177,13 @@
    the address of the entry block is illegal.</p>
      
 <p>This value only has defined behavior when used as an operand to the
-   '<a href="#i_indbr"><tt>indbr</tt></a>' instruction or for comparisons
+   '<a href="#i_indirectbr"><tt>indirectbr</tt></a>' instruction or for comparisons
    against null.  Pointer equality tests between labels addresses is undefined
    behavior - though, again, comparison against null is ok, and no label is
    equal to the null pointer.  This may also be passed around as an opaque
    pointer sized value as long as the bits are not inspected.  This allows
    <tt>ptrtoint</tt> and arithmetic to be performed on these values so long as
-   the original value is reconstituted before the <tt>indbr</tt>.</p>
+   the original value is reconstituted before the <tt>indirectbr</tt>.</p>
    
 <p>Finally, some targets may provide defined semantics when
    using the value as the operand to an inline assembly, but that is target
@@ -2517,7 +2517,7 @@
    '<a href="#i_ret"><tt>ret</tt></a>' instruction, the
    '<a href="#i_br"><tt>br</tt></a>' instruction, the
    '<a href="#i_switch"><tt>switch</tt></a>' instruction, the
-   '<a href="#i_indbr">'<tt>indbr</tt>' Instruction, the
+   '<a href="#i_indirectbr">'<tt>indirectbr</tt>' Instruction, the
    '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the
    '<a href="#i_unwind"><tt>unwind</tt></a>' instruction, and the
    '<a href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
@@ -2679,19 +2679,19 @@
 
 <!-- _______________________________________________________________________ -->
 <div class="doc_subsubsection">
-   <a name="i_indbr">'<tt>indbr</tt>' Instruction</a>
+   <a name="i_indirectbr">'<tt>indirectbr</tt>' Instruction</a>
 </div>
 
 <div class="doc_text">
 
 <h5>Syntax:</h5>
 <pre>
-  indbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
+  indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
 </pre>
 
 <h5>Overview:</h5>
 
-<p>The '<tt>indbr</tt>' instruction implements an indirect branch to a label
+<p>The '<tt>indirectbr</tt>' instruction implements an indirect branch to a label
    within the current function, whose address is specified by
    "<tt>address</tt>".  Address must be derived from a <a
    href="#blockaddress">blockaddress</a> constant.</p>
@@ -2719,7 +2719,7 @@
 
 <h5>Example:</h5>
 <pre>
- indbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ]
+ indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ]
 </pre>
 
 </div>

Modified: llvm/branches/Apple/Leela/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm-c/Core.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm-c/Core.h (original)
+++ llvm/branches/Apple/Leela/include/llvm-c/Core.h Sun Nov  1 18:01:08 2009
@@ -33,7 +33,7 @@
 #ifndef LLVM_C_CORE_H
 #define LLVM_C_CORE_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 #ifdef __cplusplus
 

Modified: llvm/branches/Apple/Leela/include/llvm/ADT/EquivalenceClasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ADT/EquivalenceClasses.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ADT/EquivalenceClasses.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ADT/EquivalenceClasses.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #ifndef LLVM_ADT_EQUIVALENCECLASSES_H
 #define LLVM_ADT_EQUIVALENCECLASSES_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <set>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/ADT/FoldingSet.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ADT/FoldingSet.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ADT/FoldingSet.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ADT/FoldingSet.h Sun Nov  1 18:01:08 2009
@@ -16,7 +16,7 @@
 #ifndef LLVM_ADT_FOLDINGSET_H
 #define LLVM_ADT_FOLDINGSET_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include <iterator>

Modified: llvm/branches/Apple/Leela/include/llvm/ADT/ImmutableList.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ADT/ImmutableList.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ADT/ImmutableList.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ADT/ImmutableList.h Sun Nov  1 18:01:08 2009
@@ -16,7 +16,7 @@
 
 #include "llvm/Support/Allocator.h"
 #include "llvm/ADT/FoldingSet.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cassert>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/ADT/ImmutableSet.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ADT/ImmutableSet.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ADT/ImmutableSet.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ADT/ImmutableSet.h Sun Nov  1 18:01:08 2009
@@ -16,7 +16,7 @@
 
 #include "llvm/Support/Allocator.h"
 #include "llvm/ADT/FoldingSet.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cassert>
 #include <functional>
 

Modified: llvm/branches/Apple/Leela/include/llvm/ADT/SmallPtrSet.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ADT/SmallPtrSet.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ADT/SmallPtrSet.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ADT/SmallPtrSet.h Sun Nov  1 18:01:08 2009
@@ -18,7 +18,7 @@
 #include <cassert>
 #include <cstring>
 #include <iterator>
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/PointerLikeTypeTraits.h"
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/ADT/SparseBitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ADT/SparseBitVector.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ADT/SparseBitVector.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ADT/SparseBitVector.h Sun Nov  1 18:01:08 2009
@@ -17,7 +17,7 @@
 
 #include "llvm/ADT/ilist.h"
 #include "llvm/ADT/ilist_node.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cassert>

Modified: llvm/branches/Apple/Leela/include/llvm/ADT/StringExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ADT/StringExtras.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ADT/StringExtras.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ADT/StringExtras.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #ifndef LLVM_ADT_STRINGEXTRAS_H
 #define LLVM_ADT_STRINGEXTRAS_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/ADT/APFloat.h"
 #include <cctype>
 #include <cstdio>

Modified: llvm/branches/Apple/Leela/include/llvm/ADT/Twine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ADT/Twine.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ADT/Twine.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ADT/Twine.h Sun Nov  1 18:01:08 2009
@@ -11,7 +11,7 @@
 #define LLVM_ADT_TWINE_H
 
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cassert>
 #include <string>
 

Modified: llvm/branches/Apple/Leela/include/llvm/Analysis/ScalarEvolution.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Analysis/ScalarEvolution.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Analysis/ScalarEvolution.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Analysis/ScalarEvolution.h Sun Nov  1 18:01:08 2009
@@ -24,7 +24,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Instructions.h"
 #include "llvm/Function.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/ConstantRange.h"

Modified: llvm/branches/Apple/Leela/include/llvm/Analysis/ValueTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Analysis/ValueTracking.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Analysis/ValueTracking.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Analysis/ValueTracking.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #ifndef LLVM_ANALYSIS_VALUETRACKING_H
 #define LLVM_ANALYSIS_VALUETRACKING_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <string>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/BasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/BasicBlock.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/BasicBlock.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/BasicBlock.h Sun Nov  1 18:01:08 2009
@@ -17,12 +17,13 @@
 #include "llvm/Instruction.h"
 #include "llvm/SymbolTableListTraits.h"
 #include "llvm/ADT/ilist.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
 
 class TerminatorInst;
 class LLVMContext;
+class BlockAddress;
 
 template<> struct ilist_traits<Instruction>
   : public SymbolTableListTraits<Instruction, BasicBlock> {
@@ -66,7 +67,7 @@
 /// @brief LLVM Basic Block Representation
 class BasicBlock : public Value, // Basic blocks are data objects also
                    public ilist_node<BasicBlock> {
-
+  friend class BlockAddress;
 public:
   typedef iplist<Instruction> InstListType;
 private:
@@ -108,10 +109,10 @@
         Function *getParent()       { return Parent; }
 
   /// use_back - Specialize the methods defined in Value, as we know that an
-  /// BasicBlock can only be used by Instructions (specifically PHI nodes and
-  /// terminators).
-  Instruction       *use_back()       { return cast<Instruction>(*use_begin());}
-  const Instruction *use_back() const { return cast<Instruction>(*use_begin());}
+  /// BasicBlock can only be used by Users (specifically PHI nodes, terminators,
+  /// and BlockAddress's).
+  User       *use_back()       { return cast<User>(*use_begin());}
+  const User *use_back() const { return cast<User>(*use_begin());}
   
   /// getTerminator() - If this is a well formed basic block, then this returns
   /// a pointer to the terminator instruction.  If it is not, then you get a
@@ -235,6 +236,19 @@
   /// keeping loop information consistent, use the SplitBlock utility function.
   ///
   BasicBlock *splitBasicBlock(iterator I, const Twine &BBName = "");
+
+  /// hasAddressTaken - returns true if there are any uses of this basic block
+  /// other than direct branches, switches, etc. to it.
+  bool hasAddressTaken() const { return SubclassData != 0; }
+                     
+private:
+  /// AdjustBlockAddressRefCount - BasicBlock stores the number of BlockAddress
+  /// objects using it.  This is almost always 0, sometimes one, possibly but
+  /// almost never 2, and inconceivably 3 or more.
+  void AdjustBlockAddressRefCount(int Amt) {
+    SubclassData += Amt;
+    assert((int)(char)SubclassData >= 0 && "Refcount wrap-around");
+  }
 };
 
 } // End llvm namespace

Modified: llvm/branches/Apple/Leela/include/llvm/Bitcode/BitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Bitcode/BitCodes.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Bitcode/BitCodes.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Bitcode/BitCodes.h Sun Nov  1 18:01:08 2009
@@ -19,7 +19,7 @@
 #define LLVM_BITCODE_BITCODES_H
 
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cassert>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/Bitcode/Deserialize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Bitcode/Deserialize.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Bitcode/Deserialize.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Bitcode/Deserialize.h Sun Nov  1 18:01:08 2009
@@ -20,7 +20,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Allocator.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <vector>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Bitcode/LLVMBitCodes.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Bitcode/LLVMBitCodes.h Sun Nov  1 18:01:08 2009
@@ -138,7 +138,8 @@
     CST_CODE_CE_CMP        = 17,  // CE_CMP:        [opty, opval, opval, pred]
     CST_CODE_INLINEASM     = 18,  // INLINEASM:     [sideeffect,asmstr,conststr]
     CST_CODE_CE_SHUFVEC_EX = 19,  // SHUFVEC_EX:    [opty, opval, opval, opval]
-    CST_CODE_CE_INBOUNDS_GEP = 20 // INBOUNDS_GEP:  [n x operands]
+    CST_CODE_CE_INBOUNDS_GEP = 20,// INBOUNDS_GEP:  [n x operands]
+    CST_CODE_BLOCKADDRESS  = 21   // CST_CODE_BLOCKADDRESS [fnty, fnval, bb#]
   };
 
   /// CastOpcodes - These are values used in the bitcode files to encode which
@@ -237,7 +238,7 @@
     // new select on i1 or [N x i1]
     FUNC_CODE_INST_VSELECT     = 29, // VSELECT:    [ty,opval,opval,predty,pred]
     FUNC_CODE_INST_INBOUNDS_GEP= 30, // INBOUNDS_GEP: [n x operands]
-    FUNC_CODE_INST_INDBR       = 31  // INDBR:      [opty, op0, op1, ...]
+    FUNC_CODE_INST_INDIRECTBR  = 31  // INDIRECTBR: [opty, op0, op1, ...]
   };
 } // End bitc namespace
 } // End llvm namespace

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/AsmPrinter.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/AsmPrinter.h Sun Nov  1 18:01:08 2009
@@ -22,6 +22,7 @@
 #include "llvm/ADT/DenseMap.h"
 
 namespace llvm {
+  class BlockAddress;
   class GCStrategy;
   class Constant;
   class ConstantArray;
@@ -334,6 +335,12 @@
     /// block label.
     MCSymbol *GetMBBSymbol(unsigned MBBID) const;
     
+    /// GetBlockAddressSymbol - Return the MCSymbol used to satisfy BlockAddress
+    /// uses of the specified basic block.
+    MCSymbol *GetBlockAddressSymbol(const BlockAddress *BA) const;
+    MCSymbol *GetBlockAddressSymbol(const Function *F,
+                                    const BasicBlock *BB) const;
+
     /// EmitBasicBlockStart - This method prints the label for the specified
     /// MachineBasicBlock, an alignment (if present) and a comment describing
     /// it if appropriate.

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/BinaryObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/BinaryObject.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/BinaryObject.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/BinaryObject.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #ifndef LLVM_CODEGEN_BINARYOBJECT_H
 #define LLVM_CODEGEN_BINARYOBJECT_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 #include <string>
 #include <vector>

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/ELFRelocation.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/ELFRelocation.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/ELFRelocation.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/ELFRelocation.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #ifndef LLVM_CODEGEN_ELF_RELOCATION_H
 #define LLVM_CODEGEN_ELF_RELOCATION_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
 

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/JITCodeEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/JITCodeEmitter.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/JITCodeEmitter.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/JITCodeEmitter.h Sun Nov  1 18:01:08 2009
@@ -18,7 +18,7 @@
 #define LLVM_CODEGEN_JITCODEEMITTER_H
 
 #include <string>
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/CodeGen/MachineCodeEmitter.h"
 

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineBasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineBasicBlock.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineBasicBlock.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineBasicBlock.h Sun Nov  1 18:01:08 2009
@@ -76,6 +76,10 @@
   /// exception handler.
   bool IsLandingPad;
 
+  /// AddressTaken - Indicate that this basic block is potentially the
+  /// target of an indirect branch.
+  bool AddressTaken;
+
   // Intrusive list support
   MachineBasicBlock() {}
 
@@ -92,6 +96,14 @@
   ///
   const BasicBlock *getBasicBlock() const { return BB; }
 
+  /// hasAddressTaken - Test whether this block is potentially the target
+  /// of an indirect branch.
+  bool hasAddressTaken() const { return AddressTaken; }
+
+  /// setHasAddressTaken - Set this block to reflect that it potentially
+  /// is the target of an indirect branch.
+  void setHasAddressTaken() { AddressTaken = true; }
+
   /// getParent - Return the MachineFunction containing this basic block.
   ///
   const MachineFunction *getParent() const { return xParent; }

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineCodeEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineCodeEmitter.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineCodeEmitter.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineCodeEmitter.h Sun Nov  1 18:01:08 2009
@@ -17,7 +17,7 @@
 #ifndef LLVM_CODEGEN_MACHINECODEEMITTER_H
 #define LLVM_CODEGEN_MACHINECODEEMITTER_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/DebugLoc.h"
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineFrameInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineFrameInfo.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineFrameInfo.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineFrameInfo.h Sun Nov  1 18:01:08 2009
@@ -16,7 +16,7 @@
 
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cassert>
 #include <vector>
 

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineInstrBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineInstrBuilder.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineInstrBuilder.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineInstrBuilder.h Sun Nov  1 18:01:08 2009
@@ -108,13 +108,6 @@
     return *this;
   }
 
-  const MachineInstrBuilder &addMetadata(MDNode *N,
-                                         int64_t Offset = 0,
-                                         unsigned char TargetFlags = 0) const {
-    MI->addOperand(MachineOperand::CreateMDNode(N, Offset, TargetFlags));
-    return *this;
-  }
-
   const MachineInstrBuilder &addExternalSymbol(const char *FnName,
                                           unsigned char TargetFlags = 0) const {
     MI->addOperand(MachineOperand::CreateES(FnName, TargetFlags));

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineModuleInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineModuleInfo.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineModuleInfo.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineModuleInfo.h Sun Nov  1 18:01:08 2009
@@ -32,7 +32,7 @@
 #define LLVM_CODEGEN_MACHINEMODULEINFO_H
 
 #include "llvm/Support/Dwarf.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/UniqueVector.h"

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineOperand.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineOperand.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineOperand.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineOperand.h Sun Nov  1 18:01:08 2009
@@ -14,15 +14,15 @@
 #ifndef LLVM_CODEGEN_MACHINEOPERAND_H
 #define LLVM_CODEGEN_MACHINEOPERAND_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cassert>
 
 namespace llvm {
   
 class ConstantFP;
+class BlockAddress;
 class MachineBasicBlock;
 class GlobalValue;
-class MDNode;
 class MachineInstr;
 class TargetMachine;
 class MachineRegisterInfo;
@@ -42,7 +42,7 @@
     MO_JumpTableIndex,         ///< Address of indexed Jump Table for switch
     MO_ExternalSymbol,         ///< Name of external global symbol
     MO_GlobalAddress,          ///< Address of a global value
-    MO_Metadata                ///< Metadata info
+    MO_BlockAddress            ///< Address of a basic block
   };
 
 private:
@@ -108,7 +108,7 @@
         int Index;                // For MO_*Index - The index itself.
         const char *SymbolName;   // For MO_ExternalSymbol.
         GlobalValue *GV;          // For MO_GlobalAddress.
-        MDNode *Node;             // For MO_Metadata.
+        BlockAddress *BA;         // For MO_BlockAddress.
       } Val;
       int64_t Offset;             // An offset from the object.
     } OffsetedInfo;
@@ -156,8 +156,8 @@
   bool isGlobal() const { return OpKind == MO_GlobalAddress; }
   /// isSymbol - Tests if this is a MO_ExternalSymbol operand.
   bool isSymbol() const { return OpKind == MO_ExternalSymbol; }
-  /// isMetadata - Tests if this is a MO_Metadata operand.
-  bool isMetadata() const { return OpKind == MO_Metadata; }
+  /// isBlockAddress - Tests if this is a MO_BlockAddress operand.
+  bool isBlockAddress() const { return OpKind == MO_BlockAddress; }
 
   //===--------------------------------------------------------------------===//
   // Accessors for Register Operands
@@ -293,15 +293,16 @@
     assert(isGlobal() && "Wrong MachineOperand accessor");
     return Contents.OffsetedInfo.Val.GV;
   }
-  
-  MDNode *getMDNode() const {
-    return Contents.OffsetedInfo.Val.Node;
+
+  BlockAddress *getBlockAddress() const {
+    assert(isBlockAddress() && "Wrong MachineOperand accessor");
+    return Contents.OffsetedInfo.Val.BA;
   }
   
   /// getOffset - Return the offset from the symbol in this operand. This always
   /// returns 0 for ExternalSymbol operands.
   int64_t getOffset() const {
-    assert((isGlobal() || isSymbol() || isCPI()) &&
+    assert((isGlobal() || isSymbol() || isCPI() || isBlockAddress()) &&
            "Wrong MachineOperand accessor");
     return Contents.OffsetedInfo.Offset;
   }
@@ -321,7 +322,7 @@
   }
 
   void setOffset(int64_t Offset) {
-    assert((isGlobal() || isSymbol() || isCPI() || isMetadata()) &&
+    assert((isGlobal() || isSymbol() || isCPI() || isBlockAddress()) &&
         "Wrong MachineOperand accessor");
     Contents.OffsetedInfo.Offset = Offset;
   }
@@ -426,14 +427,6 @@
     Op.setTargetFlags(TargetFlags);
     return Op;
   }
-  static MachineOperand CreateMDNode(MDNode *N, int64_t Offset,
-                                     unsigned char TargetFlags = 0) {
-    MachineOperand Op(MachineOperand::MO_Metadata);
-    Op.Contents.OffsetedInfo.Val.Node = N;
-    Op.setOffset(Offset);
-    Op.setTargetFlags(TargetFlags);
-    return Op;
-  }
   static MachineOperand CreateES(const char *SymName,
                                  unsigned char TargetFlags = 0) {
     MachineOperand Op(MachineOperand::MO_ExternalSymbol);
@@ -442,6 +435,12 @@
     Op.setTargetFlags(TargetFlags);
     return Op;
   }
+  static MachineOperand CreateBA(BlockAddress *BA) {
+    MachineOperand Op(MachineOperand::MO_BlockAddress);
+    Op.Contents.OffsetedInfo.Val.BA = BA;
+    Op.setOffset(0); // Offset is always 0.
+    return Op;
+  }
 
   friend class MachineInstr;
   friend class MachineRegisterInfo;

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineRelocation.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineRelocation.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineRelocation.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/MachineRelocation.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #ifndef LLVM_CODEGEN_MACHINERELOCATION_H
 #define LLVM_CODEGEN_MACHINERELOCATION_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cassert>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/SelectionDAG.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/SelectionDAG.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/SelectionDAG.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/SelectionDAG.h Sun Nov  1 18:01:08 2009
@@ -326,6 +326,8 @@
                           unsigned Line, unsigned Col, MDNode *CU);
   SDValue getLabel(unsigned Opcode, DebugLoc dl, SDValue Root,
                    unsigned LabelID);
+  SDValue getBlockAddress(BlockAddress *BA, DebugLoc dl,
+                          bool isTarget = false);
 
   SDValue getCopyToReg(SDValue Chain, DebugLoc dl, unsigned Reg, SDValue N) {
     return getNode(ISD::CopyToReg, dl, MVT::Other, Chain,

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/SelectionDAGNodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/SelectionDAGNodes.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/SelectionDAGNodes.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/SelectionDAGNodes.h Sun Nov  1 18:01:08 2009
@@ -28,7 +28,7 @@
 #include "llvm/CodeGen/ValueTypes.h"
 #include "llvm/CodeGen/MachineMemOperand.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/DebugLoc.h"
 #include <cassert>
 
@@ -97,7 +97,7 @@
     BasicBlock, VALUETYPE, CONDCODE, Register,
     Constant, ConstantFP,
     GlobalAddress, GlobalTLSAddress, FrameIndex,
-    JumpTable, ConstantPool, ExternalSymbol,
+    JumpTable, ConstantPool, ExternalSymbol, BlockAddress,
 
     // The address of the GOT
     GLOBAL_OFFSET_TABLE,
@@ -146,6 +146,7 @@
     TargetJumpTable,
     TargetConstantPool,
     TargetExternalSymbol,
+    TargetBlockAddress,
 
     /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
     /// This node represents a target intrinsic function with no side effects.
@@ -2026,11 +2027,27 @@
   }
 };
 
+class BlockAddressSDNode : public SDNode {
+  BlockAddress *BA;
+  friend class SelectionDAG;
+  BlockAddressSDNode(unsigned NodeTy, DebugLoc dl, EVT VT, BlockAddress *ba)
+    : SDNode(NodeTy, dl, getSDVTList(VT)), BA(ba) {
+  }
+public:
+  BlockAddress *getBlockAddress() const { return BA; }
+
+  static bool classof(const BlockAddressSDNode *) { return true; }
+  static bool classof(const SDNode *N) {
+    return N->getOpcode() == ISD::BlockAddress ||
+           N->getOpcode() == ISD::TargetBlockAddress;
+  }
+};
+
 class LabelSDNode : public SDNode {
   SDUse Chain;
   unsigned LabelID;
   friend class SelectionDAG;
-LabelSDNode(unsigned NodeTy, DebugLoc dl, SDValue ch, unsigned id)
+  LabelSDNode(unsigned NodeTy, DebugLoc dl, SDValue ch, unsigned id)
     : SDNode(NodeTy, dl, getSDVTList(MVT::Other)), LabelID(id) {
     InitOperands(&Chain, ch);
   }

Modified: llvm/branches/Apple/Leela/include/llvm/CodeGen/ValueTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/CodeGen/ValueTypes.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/CodeGen/ValueTypes.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/CodeGen/ValueTypes.h Sun Nov  1 18:01:08 2009
@@ -18,7 +18,7 @@
 
 #include <cassert>
 #include <string>
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/MathExtras.h"
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/Constant.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Constant.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Constant.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Constant.h Sun Nov  1 18:01:08 2009
@@ -48,6 +48,10 @@
     : User(ty, vty, Ops, NumOps) {}
 
   void destroyConstantImpl();
+  
+  void setOperand(unsigned i, Value *V) {
+    User::setOperand(i, V);
+  }
 public:
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
@@ -61,6 +65,10 @@
   /// true for things like constant expressions that could divide by zero.
   bool canTrap() const;
 
+  /// isConstantUsed - Return true if the constant has users other than constant
+  /// exprs and other dangling things.
+  bool isConstantUsed() const;
+  
   enum PossibleRelocationsTy {
     NoRelocation = 0,
     LocalRelocation = 1,
@@ -83,16 +91,13 @@
   /// FIXME: This really should not be in VMCore.
   PossibleRelocationsTy getRelocationInfo() const;
   
-  // Specialize get/setOperand for Constants as their operands are always
-  // constants as well.
-  Constant *getOperand(unsigned i) {
-    return static_cast<Constant*>(User::getOperand(i));
-  }
-  const Constant *getOperand(unsigned i) const {
-    return static_cast<const Constant*>(User::getOperand(i));
+  // Specialize get/setOperand for Users as their operands are always
+  // constants or BasicBlocks as well.
+  User *getOperand(unsigned i) {
+    return static_cast<User*>(User::getOperand(i));
   }
-  void setOperand(unsigned i, Constant *C) {
-    User::setOperand(i, C);
+  const User *getOperand(unsigned i) const {
+    return static_cast<const User*>(User::getOperand(i));
   }
   
   /// getVectorElements - This method, which is only valid on constant of vector

Modified: llvm/branches/Apple/Leela/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Constants.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Constants.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Constants.h Sun Nov  1 18:01:08 2009
@@ -548,7 +548,47 @@
   }
 };
 
+/// BlockAddress - The address of a basic block.
+///
+class BlockAddress : public Constant {
+  void *operator new(size_t, unsigned);                  // DO NOT IMPLEMENT
+  void *operator new(size_t s) { return User::operator new(s, 2); }
+  BlockAddress(Function *F, BasicBlock *BB);
+public:
+  /// get - Return a BlockAddress for the specified function and basic block.
+  static BlockAddress *get(Function *F, BasicBlock *BB);
+  
+  /// get - Return a BlockAddress for the specified basic block.  The basic
+  /// block must be embedded into a function.
+  static BlockAddress *get(BasicBlock *BB);
+  
+  /// Transparently provide more efficient getOperand methods.
+  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+  
+  Function *getFunction() const { return (Function*)Op<0>().get(); }
+  BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
+  
+  /// isNullValue - Return true if this is the value that would be returned by
+  /// getNullValue.
+  virtual bool isNullValue() const { return false; }
+  
+  virtual void destroyConstant();
+  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
+  
+  /// Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const BlockAddress *) { return true; }
+  static inline bool classof(const Value *V) {
+    return V->getValueID() == BlockAddressVal;
+  }
+};
 
+template <>
+struct OperandTraits<BlockAddress> : public FixedNumOperandTraits<2> {
+};
+
+DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(BlockAddress, Value)
+  
+//===----------------------------------------------------------------------===//
 /// ConstantExpr - a constant value that is initialized with an expression using
 /// other constant values.
 ///

Modified: llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/ExecutionEngine.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/ExecutionEngine.h Sun Nov  1 18:01:08 2009
@@ -19,6 +19,8 @@
 #include <map>
 #include <string>
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/ValueMap.h"
+#include "llvm/Support/ValueHandle.h"
 #include "llvm/System/Mutex.h"
 #include "llvm/Target/TargetMachine.h"
 
@@ -26,6 +28,7 @@
 
 struct GenericValue;
 class Constant;
+class ExecutionEngine;
 class Function;
 class GlobalVariable;
 class GlobalValue;
@@ -37,13 +40,26 @@
 class MutexGuard;
 class TargetData;
 class Type;
-template<typename> class AssertingVH;
 
 class ExecutionEngineState {
+public:
+  struct AddressMapConfig : public ValueMapConfig<const GlobalValue*> {
+    typedef ExecutionEngineState *ExtraData;
+    static sys::Mutex *getMutex(ExecutionEngineState *EES);
+    static void onDelete(ExecutionEngineState *EES, const GlobalValue *Old);
+    static void onRAUW(ExecutionEngineState *, const GlobalValue *,
+                       const GlobalValue *);
+  };
+
+  typedef ValueMap<const GlobalValue *, void *, AddressMapConfig>
+      GlobalAddressMapTy;
+
 private:
+  ExecutionEngine &EE;
+
   /// GlobalAddressMap - A mapping between LLVM global values and their
   /// actualized version...
-  std::map<AssertingVH<const GlobalValue>, void *> GlobalAddressMap;
+  GlobalAddressMapTy GlobalAddressMap;
 
   /// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap,
   /// used to convert raw addresses into the LLVM global value that is emitted
@@ -52,7 +68,9 @@
   std::map<void *, AssertingVH<const GlobalValue> > GlobalAddressReverseMap;
 
 public:
-  std::map<AssertingVH<const GlobalValue>, void *> &
+  ExecutionEngineState(ExecutionEngine &EE);
+
+  GlobalAddressMapTy &
   getGlobalAddressMap(const MutexGuard &) {
     return GlobalAddressMap;
   }
@@ -69,7 +87,7 @@
 
 class ExecutionEngine {
   const TargetData *TD;
-  ExecutionEngineState state;
+  ExecutionEngineState EEState;
   bool LazyCompilationDisabled;
   bool GVCompilationDisabled;
   bool SymbolSearchingDisabled;
@@ -213,8 +231,8 @@
   /// at the specified location.  This is used internally as functions are JIT'd
   /// and as global variables are laid out in memory.  It can and should also be
   /// used by clients of the EE that want to have an LLVM global overlay
-  /// existing data in memory.  After adding a mapping for GV, you must not
-  /// destroy it until you've removed the mapping.
+  /// existing data in memory.  Mappings are automatically removed when their
+  /// GlobalValue is destroyed.
   void addGlobalMapping(const GlobalValue *GV, void *Addr);
   
   /// clearAllGlobalMappings - Clear all global mappings and start over again
@@ -238,29 +256,29 @@
   void *getPointerToGlobalIfAvailable(const GlobalValue *GV);
 
   /// getPointerToGlobal - This returns the address of the specified global
-  /// value.  This may involve code generation if it's a function.  After
-  /// getting a pointer to GV, it and all globals it transitively refers to have
-  /// been passed to addGlobalMapping.  You must clear the mapping for each
-  /// referred-to global before destroying it.  If a referred-to global RTG is a
-  /// function and this ExecutionEngine is a JIT compiler, calling
-  /// updateGlobalMapping(RTG, 0) will leak the function's machine code, so you
-  /// should call freeMachineCodeForFunction(RTG) instead.  Note that
-  /// optimizations can move and delete non-external GlobalValues without
-  /// notifying the ExecutionEngine.
+  /// value.  This may involve code generation if it's a function.
   ///
   void *getPointerToGlobal(const GlobalValue *GV);
 
   /// getPointerToFunction - The different EE's represent function bodies in
   /// different ways.  They should each implement this to say what a function
-  /// pointer should look like.  See getPointerToGlobal for the requirements on
-  /// destroying F and any GlobalValues it refers to.
+  /// pointer should look like.  When F is destroyed, the ExecutionEngine will
+  /// remove its global mapping but will not yet free its machine code.  Call
+  /// freeMachineCodeForFunction(F) explicitly to do that.  Note that global
+  /// optimizations can destroy Functions without notifying the ExecutionEngine.
   ///
   virtual void *getPointerToFunction(Function *F) = 0;
 
+  /// getPointerToBasicBlock - The different EE's represent basic blocks in
+  /// different ways.  Return the representation for a blockaddress of the
+  /// specified block.
+  ///
+  virtual void *getPointerToBasicBlock(BasicBlock *BB) = 0;
+  
   /// getPointerToFunctionOrStub - If the specified function has been
   /// code-gen'd, return a pointer to the function.  If not, compile it, or use
-  /// a stub to implement lazy compilation if available.  See getPointerToGlobal
-  /// for the requirements on destroying F and any GlobalValues it refers to.
+  /// a stub to implement lazy compilation if available.  See
+  /// getPointerToFunction for the requirements on destroying F.
   ///
   virtual void *getPointerToFunctionOrStub(Function *F) {
     // Default implementation, just codegen the function.
@@ -296,8 +314,7 @@
 
   /// getOrEmitGlobalVariable - Return the address of the specified global
   /// variable, possibly emitting it to memory if needed.  This is used by the
-  /// Emitter.  See getPointerToGlobal for the requirements on destroying GV and
-  /// any GlobalValues it refers to.
+  /// Emitter.
   virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
     return getPointerToGlobal((GlobalValue*)GV);
   }
@@ -468,7 +485,6 @@
   }
 
   ExecutionEngine *create();
-
 };
 
 } // End llvm namespace

Modified: llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/GenericValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/GenericValue.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/GenericValue.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/GenericValue.h Sun Nov  1 18:01:08 2009
@@ -16,7 +16,7 @@
 #define GENERIC_VALUE_H
 
 #include "llvm/ADT/APInt.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
 

Modified: llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/JITEventListener.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/JITEventListener.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/JITEventListener.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/JITEventListener.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #ifndef LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H
 #define LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/DebugLoc.h"
 
 #include <vector>

Modified: llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/JITMemoryManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/JITMemoryManager.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/JITMemoryManager.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ExecutionEngine/JITMemoryManager.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #ifndef LLVM_EXECUTION_ENGINE_JIT_MEMMANAGER_H
 #define LLVM_EXECUTION_ENGINE_JIT_MEMMANAGER_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <string>
 
 namespace llvm {
@@ -132,9 +132,11 @@
   ///
   virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) = 0;
 
-  /// deallocateMemForFunction - Free JIT memory for the specified function.
-  /// This is never called when the JIT is currently emitting a function.
-  virtual void deallocateMemForFunction(const Function *F) = 0;
+  /// deallocateFunctionBody - Free the specified function body.  The argument
+  /// must be the return value from a call to startFunctionBody() that hasn't
+  /// been deallocated yet.  This is never called when the JIT is currently
+  /// emitting a function.
+  virtual void deallocateFunctionBody(void *Body) = 0;
   
   /// startExceptionTable - When we finished JITing the function, if exception
   /// handling is set, we emit the exception table.
@@ -146,6 +148,12 @@
   virtual void endExceptionTable(const Function *F, uint8_t *TableStart,
                                  uint8_t *TableEnd, uint8_t* FrameRegister) = 0;
 
+  /// deallocateExceptionTable - Free the specified exception table's memory.
+  /// The argument must be the return value from a call to startExceptionTable()
+  /// that hasn't been deallocated yet.  This is never called when the JIT is
+  /// currently emitting an exception table.
+  virtual void deallocateExceptionTable(void *ET) = 0;
+
   /// CheckInvariants - For testing only.  Return true if all internal
   /// invariants are preserved, or return false and set ErrorStr to a helpful
   /// error message.

Modified: llvm/branches/Apple/Leela/include/llvm/Instruction.def
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Instruction.def?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Instruction.def (original)
+++ llvm/branches/Apple/Leela/include/llvm/Instruction.def Sun Nov  1 18:01:08 2009
@@ -97,7 +97,7 @@
 HANDLE_TERM_INST  ( 1, Ret        , ReturnInst)
 HANDLE_TERM_INST  ( 2, Br         , BranchInst)
 HANDLE_TERM_INST  ( 3, Switch     , SwitchInst)
-HANDLE_TERM_INST  ( 4, IndBr      , IndBrInst)
+HANDLE_TERM_INST  ( 4, IndirectBr , IndirectBrInst)
 HANDLE_TERM_INST  ( 5, Invoke     , InvokeInst)
 HANDLE_TERM_INST  ( 6, Unwind     , UnwindInst)
 HANDLE_TERM_INST  ( 7, Unreachable, UnreachableInst)

Modified: llvm/branches/Apple/Leela/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Instructions.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Instructions.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Instructions.h Sun Nov  1 18:01:08 2009
@@ -2357,61 +2357,61 @@
 
 
 //===----------------------------------------------------------------------===//
-//                               IndBrInst Class
+//                             IndirectBrInst Class
 //===----------------------------------------------------------------------===//
 
 //===---------------------------------------------------------------------------
-/// IndBrInst - Indirect Branch Instruction.
+/// IndirectBrInst - Indirect Branch Instruction.
 ///
-class IndBrInst : public TerminatorInst {
+class IndirectBrInst : public TerminatorInst {
   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
   unsigned ReservedSpace;
   // Operand[0]    = Value to switch on
   // Operand[1]    = Default basic block destination
   // Operand[2n  ] = Value to match
   // Operand[2n+1] = BasicBlock to go to on match
-  IndBrInst(const IndBrInst &IBI);
+  IndirectBrInst(const IndirectBrInst &IBI);
   void init(Value *Address, unsigned NumDests);
   void resizeOperands(unsigned No);
   // allocate space for exactly zero operands
   void *operator new(size_t s) {
     return User::operator new(s, 0);
   }
-  /// IndBrInst ctor - Create a new indbr instruction, specifying an Address to
-  /// jump to.  The number of expected destinations can be specified here to
-  /// make memory allocation more efficient.  This constructor can also
+  /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
+  /// Address to jump to.  The number of expected destinations can be specified
+  /// here to make memory allocation more efficient.  This constructor can also
   /// autoinsert before another instruction.
-  IndBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
+  IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
   
-  /// IndBrInst ctor - Create a new indbr instruction, specifying an Address to
-  /// jump to.  The number of expected destinations can be specified here to
-  /// make memory allocation more efficient.  This constructor also autoinserts
-  /// at the end of the specified BasicBlock.
-  IndBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
+  /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
+  /// Address to jump to.  The number of expected destinations can be specified
+  /// here to make memory allocation more efficient.  This constructor also
+  /// autoinserts at the end of the specified BasicBlock.
+  IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
 protected:
-  virtual IndBrInst *clone_impl() const;
+  virtual IndirectBrInst *clone_impl() const;
 public:
-  static IndBrInst *Create(Value *Address, unsigned NumDests,
-                           Instruction *InsertBefore = 0) {
-    return new IndBrInst(Address, NumDests, InsertBefore);
+  static IndirectBrInst *Create(Value *Address, unsigned NumDests,
+                                Instruction *InsertBefore = 0) {
+    return new IndirectBrInst(Address, NumDests, InsertBefore);
   }
-  static IndBrInst *Create(Value *Address, unsigned NumDests,
-                           BasicBlock *InsertAtEnd) {
-    return new IndBrInst(Address, NumDests, InsertAtEnd);
+  static IndirectBrInst *Create(Value *Address, unsigned NumDests,
+                                BasicBlock *InsertAtEnd) {
+    return new IndirectBrInst(Address, NumDests, InsertAtEnd);
   }
-  ~IndBrInst();
+  ~IndirectBrInst();
   
   /// Provide fast operand accessors.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
   
-  // Accessor Methods for IndBr instruction.
+  // Accessor Methods for IndirectBrInst instruction.
   Value *getAddress() { return getOperand(0); }
   const Value *getAddress() const { return getOperand(0); }
   void setAddress(Value *V) { setOperand(0, V); }
   
   
   /// getNumDestinations - return the number of possible destinations in this
-  /// indbr instruction.
+  /// indirectbr instruction.
   unsigned getNumDestinations() const { return getNumOperands()-1; }
   
   /// getDestination - Return the specified destination.
@@ -2423,7 +2423,7 @@
   void addDestination(BasicBlock *Dest);
   
   /// removeDestination - This method removes the specified successor from the
-  /// indbr instruction.
+  /// indirectbr instruction.
   void removeDestination(unsigned i);
   
   unsigned getNumSuccessors() const { return getNumOperands()-1; }
@@ -2435,9 +2435,9 @@
   }
   
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool classof(const IndBrInst *) { return true; }
+  static inline bool classof(const IndirectBrInst *) { return true; }
   static inline bool classof(const Instruction *I) {
-    return I->getOpcode() == Instruction::IndBr;
+    return I->getOpcode() == Instruction::IndirectBr;
   }
   static inline bool classof(const Value *V) {
     return isa<Instruction>(V) && classof(cast<Instruction>(V));
@@ -2449,10 +2449,10 @@
 };
 
 template <>
-struct OperandTraits<IndBrInst> : public HungoffOperandTraits<1> {
+struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
 };
 
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndBrInst, Value)
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
   
   
 //===----------------------------------------------------------------------===//

Modified: llvm/branches/Apple/Leela/include/llvm/MC/MCAsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/MC/MCAsmLexer.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/MC/MCAsmLexer.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/MC/MCAsmLexer.h Sun Nov  1 18:01:08 2009
@@ -11,7 +11,7 @@
 #define LLVM_MC_MCASMLEXER_H
 
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
 class MCAsmLexer;

Modified: llvm/branches/Apple/Leela/include/llvm/MC/MCAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/MC/MCAsmParser.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/MC/MCAsmParser.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/MC/MCAsmParser.h Sun Nov  1 18:01:08 2009
@@ -10,7 +10,7 @@
 #ifndef LLVM_MC_MCASMPARSER_H
 #define LLVM_MC_MCASMPARSER_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
 class MCAsmLexer;

Modified: llvm/branches/Apple/Leela/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/MC/MCAssembler.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/MC/MCAssembler.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/MC/MCAssembler.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #include "llvm/ADT/ilist_node.h"
 #include "llvm/MC/MCValue.h"
 #include "llvm/Support/Casting.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <vector> // FIXME: Shouldn't be needed.
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/MC/MCDisassembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/MC/MCDisassembler.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/MC/MCDisassembler.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/MC/MCDisassembler.h Sun Nov  1 18:01:08 2009
@@ -9,7 +9,7 @@
 #ifndef MCDISASSEMBLER_H
 #define MCDISASSEMBLER_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   

Modified: llvm/branches/Apple/Leela/include/llvm/MC/MCExpr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/MC/MCExpr.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/MC/MCExpr.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/MC/MCExpr.h Sun Nov  1 18:01:08 2009
@@ -11,7 +11,7 @@
 #define LLVM_MC_MCEXPR_H
 
 #include "llvm/Support/Casting.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
 class MCAsmInfo;

Modified: llvm/branches/Apple/Leela/include/llvm/MC/MCInst.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/MC/MCInst.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/MC/MCInst.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/MC/MCInst.h Sun Nov  1 18:01:08 2009
@@ -17,7 +17,7 @@
 #define LLVM_MC_MCINST_H
 
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
 class raw_ostream;

Modified: llvm/branches/Apple/Leela/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/MC/MCStreamer.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/MC/MCStreamer.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/MC/MCStreamer.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #ifndef LLVM_MC_MCSTREAMER_H
 #define LLVM_MC_MCSTREAMER_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   class MCAsmInfo;

Modified: llvm/branches/Apple/Leela/include/llvm/MC/MCSymbol.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/MC/MCSymbol.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/MC/MCSymbol.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/MC/MCSymbol.h Sun Nov  1 18:01:08 2009
@@ -16,7 +16,7 @@
 
 #include <string>
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   class MCAsmInfo;

Modified: llvm/branches/Apple/Leela/include/llvm/MC/MCValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/MC/MCValue.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/MC/MCValue.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/MC/MCValue.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #ifndef LLVM_MC_MCVALUE_H
 #define LLVM_MC_MCVALUE_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/MC/MCSymbol.h"
 #include <cassert>
 

Modified: llvm/branches/Apple/Leela/include/llvm/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Module.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Module.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Module.h Sun Nov  1 18:01:08 2009
@@ -19,7 +19,7 @@
 #include "llvm/GlobalVariable.h"
 #include "llvm/GlobalAlias.h"
 #include "llvm/Metadata.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <vector>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/Pass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Pass.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Pass.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Pass.h Sun Nov  1 18:01:08 2009
@@ -29,7 +29,7 @@
 #ifndef LLVM_PASS_H
 #define LLVM_PASS_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cassert>
 #include <utility>
 #include <vector>

Removed: llvm/branches/Apple/Leela/include/llvm/Support/AIXDataTypesFix.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/AIXDataTypesFix.h?rev=85762&view=auto

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/AIXDataTypesFix.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/AIXDataTypesFix.h (removed)
@@ -1,25 +0,0 @@
-//===-- llvm/Support/AIXDataTypesFix.h - Fix datatype defs ------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file overrides default system-defined types and limits which cannot be
-// done in DataTypes.h.in because it is processed by autoheader first, which
-// comments out any #undef statement
-//
-//===----------------------------------------------------------------------===//
-
-// No include guards desired!
-
-#ifndef SUPPORT_DATATYPES_H
-#error "AIXDataTypesFix.h must only be included via DataTypes.h!"
-#endif
-
-// GCC is strict about defining large constants: they must have LL modifier.
-// These will be defined properly at the end of DataTypes.h
-#undef INT64_MAX
-#undef INT64_MIN

Modified: llvm/branches/Apple/Leela/include/llvm/Support/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/Allocator.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/Allocator.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/Allocator.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #define LLVM_SUPPORT_ALLOCATOR_H
 
 #include "llvm/Support/AlignOf.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cassert>
 #include <cstdlib>
 

Modified: llvm/branches/Apple/Leela/include/llvm/Support/ConstantRange.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/ConstantRange.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/ConstantRange.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/ConstantRange.h Sun Nov  1 18:01:08 2009
@@ -33,7 +33,7 @@
 #define LLVM_SUPPORT_CONSTANT_RANGE_H
 
 #include "llvm/ADT/APInt.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
 

Removed: llvm/branches/Apple/Leela/include/llvm/Support/DataTypes.h.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/DataTypes.h.cmake?rev=85762&view=auto

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/DataTypes.h.cmake (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/DataTypes.h.cmake (removed)
@@ -1,152 +0,0 @@
-/*===-- include/Support/DataTypes.h - Define fixed size types -----*- C -*-===*\
-|*                                                                            *|
-|*                     The LLVM Compiler Infrastructure                       *|
-|*                                                                            *|
-|* This file is distributed under the University of Illinois Open Source      *|
-|* License. See LICENSE.TXT for details.                                      *|
-|*                                                                            *|
-|*===----------------------------------------------------------------------===*|
-|*                                                                            *|
-|* This file contains definitions to figure out the size of _HOST_ data types.*|
-|* This file is important because different host OS's define different macros,*|
-|* which makes portability tough.  This file exports the following            *|
-|* definitions:                                                               *|
-|*                                                                            *|
-|*   [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types*|
-|*   [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values.     *|
-|*                                                                            *|
-|* No library is required when using these functinons.                        *|
-|*                                                                            *|
-|*===----------------------------------------------------------------------===*/
-
-/* Please leave this file C-compatible. */
-
-#ifndef SUPPORT_DATATYPES_H
-#define SUPPORT_DATATYPES_H
-
-#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
-#cmakedefine HAVE_INTTYPES_H ${HAVE_INTTYPES_H}
-#cmakedefine HAVE_STDINT_H ${HAVE_STDINT_H}
-#cmakedefine HAVE_UINT64_T ${HAVE_UINT64_T}
-#cmakedefine HAVE_U_INT64_T ${HAVE_U_INT64_T}
-
-#ifdef __cplusplus
-#include <cmath>
-#else
-#include <math.h>
-#endif
-
-#ifndef _MSC_VER
-
-/* Note that this header's correct operation depends on __STDC_LIMIT_MACROS
-   being defined.  We would define it here, but in order to prevent Bad Things
-   happening when system headers or C++ STL headers include stdint.h before we
-   define it here, we define it on the g++ command line (in Makefile.rules). */
-#if !defined(__STDC_LIMIT_MACROS)
-# error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
-#endif
-
-#if !defined(__STDC_CONSTANT_MACROS)
-# error "Must #define __STDC_CONSTANT_MACROS before " \
-        "#including Support/DataTypes.h"
-#endif
-
-/* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
-#endif
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
-
-#ifdef _AIX
-#include "llvm/Support/AIXDataTypesFix.h"
-#endif
-
-/* Handle incorrect definition of uint64_t as u_int64_t */
-#ifndef HAVE_UINT64_T
-#ifdef HAVE_U_INT64_T
-typedef u_int64_t uint64_t;
-#else
-# error "Don't have a definition for uint64_t on this platform"
-#endif
-#endif
-
-#ifdef _OpenBSD_
-#define INT8_MAX 127
-#define INT8_MIN -128
-#define UINT8_MAX 255
-#define INT16_MAX 32767
-#define INT16_MIN -32768
-#define UINT16_MAX 65535
-#define INT32_MAX 2147483647
-#define INT32_MIN -2147483648
-#define UINT32_MAX 4294967295U
-#endif
-
-#else /* _MSC_VER */
-/* Visual C++ doesn't provide standard integer headers, but it does provide
-   built-in data types. */
-#include <stdlib.h>
-#include <stddef.h>
-#include <sys/types.h>
-#ifdef __cplusplus
-#include <cmath>
-#else
-#include <math.h>
-#endif
-typedef __int64 int64_t;
-typedef unsigned __int64 uint64_t;
-typedef signed int int32_t;
-typedef unsigned int uint32_t;
-typedef short int16_t;
-typedef unsigned short uint16_t;
-typedef signed char int8_t;
-typedef unsigned char uint8_t;
-typedef signed int ssize_t;
-#define INT8_MAX 127
-#define INT8_MIN -128
-#define UINT8_MAX 255
-#define INT16_MAX 32767
-#define INT16_MIN -32768
-#define UINT16_MAX 65535
-#define INT32_MAX 2147483647
-#define INT32_MIN -2147483648
-#define UINT32_MAX 4294967295U
-#define INT8_C(C)   C
-#define UINT8_C(C)  C
-#define INT16_C(C)  C
-#define UINT16_C(C) C
-#define INT32_C(C)  C
-#define UINT32_C(C) C ## U
-#define INT64_C(C)  ((int64_t) C ## LL)
-#define UINT64_C(C) ((uint64_t) C ## ULL)
-#endif /* _MSC_VER */
-
-/* Set defaults for constants which we cannot find. */
-#if !defined(INT64_MAX)
-# define INT64_MAX 9223372036854775807LL
-#endif
-#if !defined(INT64_MIN)
-# define INT64_MIN ((-INT64_MAX)-1)
-#endif
-#if !defined(UINT64_MAX)
-# define UINT64_MAX 0xffffffffffffffffULL
-#endif
-
-#if __GNUC__ > 3
-#define END_WITH_NULL __attribute__((sentinel))
-#else
-#define END_WITH_NULL
-#endif
-
-#ifndef HUGE_VALF
-#define HUGE_VALF (float)HUGE_VAL
-#endif
-
-#endif  /* SUPPORT_DATATYPES_H */

Removed: llvm/branches/Apple/Leela/include/llvm/Support/DataTypes.h.in
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/DataTypes.h.in?rev=85762&view=auto

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/DataTypes.h.in (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/DataTypes.h.in (removed)
@@ -1,147 +0,0 @@
-/*===-- include/Support/DataTypes.h - Define fixed size types -----*- C -*-===*\
-|*                                                                            *|
-|*                     The LLVM Compiler Infrastructure                       *|
-|*                                                                            *|
-|* This file is distributed under the University of Illinois Open Source      *|
-|* License. See LICENSE.TXT for details.                                      *|
-|*                                                                            *|
-|*===----------------------------------------------------------------------===*|
-|*                                                                            *|
-|* This file contains definitions to figure out the size of _HOST_ data types.*|
-|* This file is important because different host OS's define different macros,*|
-|* which makes portability tough.  This file exports the following            *|
-|* definitions:                                                               *|
-|*                                                                            *|
-|*   [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types*|
-|*   [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values.     *|
-|*                                                                            *|
-|* No library is required when using these functinons.                        *|
-|*                                                                            *|
-|*===----------------------------------------------------------------------===*/
-
-/* Please leave this file C-compatible. */
-
-#ifndef SUPPORT_DATATYPES_H
-#define SUPPORT_DATATYPES_H
-
-#undef HAVE_SYS_TYPES_H
-#undef HAVE_INTTYPES_H
-#undef HAVE_STDINT_H
-#undef HAVE_UINT64_T
-#undef HAVE_U_INT64_T
-
-#ifdef __cplusplus
-#include <cmath>
-#else
-#include <math.h>
-#endif
-
-#ifndef _MSC_VER
-
-/* Note that this header's correct operation depends on __STDC_LIMIT_MACROS
-   being defined.  We would define it here, but in order to prevent Bad Things
-   happening when system headers or C++ STL headers include stdint.h before we
-   define it here, we define it on the g++ command line (in Makefile.rules). */
-#if !defined(__STDC_LIMIT_MACROS)
-# error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
-#endif
-
-#if !defined(__STDC_CONSTANT_MACROS)
-# error "Must #define __STDC_CONSTANT_MACROS before " \
-        "#including Support/DataTypes.h"
-#endif
-
-/* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
-#endif
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
-
-#ifdef _AIX
-#include "llvm/Support/AIXDataTypesFix.h"
-#endif
-
-/* Handle incorrect definition of uint64_t as u_int64_t */
-#ifndef HAVE_UINT64_T
-#ifdef HAVE_U_INT64_T
-typedef u_int64_t uint64_t;
-#else
-# error "Don't have a definition for uint64_t on this platform"
-#endif
-#endif
-
-#ifdef _OpenBSD_
-#define INT8_MAX 127
-#define INT8_MIN -128
-#define UINT8_MAX 255
-#define INT16_MAX 32767
-#define INT16_MIN -32768
-#define UINT16_MAX 65535
-#define INT32_MAX 2147483647
-#define INT32_MIN -2147483648
-#define UINT32_MAX 4294967295U
-#endif
-
-#else /* _MSC_VER */
-/* Visual C++ doesn't provide standard integer headers, but it does provide
-   built-in data types. */
-#include <stdlib.h>
-#include <stddef.h>
-#include <sys/types.h>
-typedef __int64 int64_t;
-typedef unsigned __int64 uint64_t;
-typedef signed int int32_t;
-typedef unsigned int uint32_t;
-typedef short int16_t;
-typedef unsigned short uint16_t;
-typedef signed char int8_t;
-typedef unsigned char uint8_t;
-typedef signed int ssize_t;
-#define INT8_MAX 127
-#define INT8_MIN -128
-#define UINT8_MAX 255
-#define INT16_MAX 32767
-#define INT16_MIN -32768
-#define UINT16_MAX 65535
-#define INT32_MAX 2147483647
-#define INT32_MIN -2147483648
-#define UINT32_MAX 4294967295U
-#define INT8_C(C)   C
-#define UINT8_C(C)  C
-#define INT16_C(C)  C
-#define UINT16_C(C) C
-#define INT32_C(C)  C
-#define UINT32_C(C) C ## U
-#define INT64_C(C)  ((int64_t) C ## LL)
-#define UINT64_C(C) ((uint64_t) C ## ULL)
-#endif /* _MSC_VER */
-
-/* Set defaults for constants which we cannot find. */
-#if !defined(INT64_MAX)
-# define INT64_MAX 9223372036854775807LL
-#endif
-#if !defined(INT64_MIN)
-# define INT64_MIN ((-INT64_MAX)-1)
-#endif
-#if !defined(UINT64_MAX)
-# define UINT64_MAX 0xffffffffffffffffULL
-#endif
-
-#if __GNUC__ > 3
-#define END_WITH_NULL __attribute__((sentinel))
-#else
-#define END_WITH_NULL
-#endif
-
-#ifndef HUGE_VALF
-#define HUGE_VALF (float)HUGE_VAL
-#endif
-
-#endif  /* SUPPORT_DATATYPES_H */

Modified: llvm/branches/Apple/Leela/include/llvm/Support/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/ELF.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/ELF.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/ELF.h Sun Nov  1 18:01:08 2009
@@ -21,7 +21,7 @@
 #ifndef LLVM_SUPPORT_ELF_H
 #define LLVM_SUPPORT_ELF_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cstring>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/IRBuilder.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/IRBuilder.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/IRBuilder.h Sun Nov  1 18:01:08 2009
@@ -253,6 +253,13 @@
     return Insert(SwitchInst::Create(V, Dest, NumCases));
   }
 
+  /// CreateIndirectBr - Create an indirect branch instruction with the
+  /// specified address operand, with an optional hint for the number of
+  /// destinations that will be added (for efficient allocation).
+  IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
+    return Insert(IndirectBrInst::Create(Addr, NumDests));
+  }
+
   /// CreateInvoke - Create an invoke instruction.
   template<typename InputIterator>
   InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,

Modified: llvm/branches/Apple/Leela/include/llvm/Support/InstVisitor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/InstVisitor.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/InstVisitor.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/InstVisitor.h Sun Nov  1 18:01:08 2009
@@ -160,7 +160,7 @@
   RetTy visitReturnInst(ReturnInst &I)              { DELEGATE(TerminatorInst);}
   RetTy visitBranchInst(BranchInst &I)              { DELEGATE(TerminatorInst);}
   RetTy visitSwitchInst(SwitchInst &I)              { DELEGATE(TerminatorInst);}
-  RetTy visitIndBrInst(IndBrInst &I)                { DELEGATE(TerminatorInst);}
+  RetTy visitIndirectBrInst(IndirectBrInst &I)      { DELEGATE(TerminatorInst);}
   RetTy visitInvokeInst(InvokeInst &I)              { DELEGATE(TerminatorInst);}
   RetTy visitUnwindInst(UnwindInst &I)              { DELEGATE(TerminatorInst);}
   RetTy visitUnreachableInst(UnreachableInst &I)    { DELEGATE(TerminatorInst);}

Modified: llvm/branches/Apple/Leela/include/llvm/Support/MathExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/MathExtras.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/MathExtras.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/MathExtras.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #ifndef LLVM_SUPPORT_MATHEXTRAS_H
 #define LLVM_SUPPORT_MATHEXTRAS_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
 

Modified: llvm/branches/Apple/Leela/include/llvm/Support/MemoryBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/MemoryBuffer.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/MemoryBuffer.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/MemoryBuffer.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #define LLVM_SUPPORT_MEMORYBUFFER_H
 
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <string>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/Support/MemoryObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/MemoryObject.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/MemoryObject.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/MemoryObject.h Sun Nov  1 18:01:08 2009
@@ -10,7 +10,7 @@
 #ifndef MEMORYOBJECT_H
 #define MEMORYOBJECT_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
 

Modified: llvm/branches/Apple/Leela/include/llvm/Support/PointerLikeTypeTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/PointerLikeTypeTraits.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/PointerLikeTypeTraits.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/PointerLikeTypeTraits.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #ifndef LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
 #define LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   

Modified: llvm/branches/Apple/Leela/include/llvm/Support/SlowOperationInformer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/SlowOperationInformer.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/SlowOperationInformer.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/SlowOperationInformer.h Sun Nov  1 18:01:08 2009
@@ -31,7 +31,7 @@
 
 #include <string>
 #include <cassert>
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   class SlowOperationInformer {

Modified: llvm/branches/Apple/Leela/include/llvm/Support/Timer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/Timer.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/Timer.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/Timer.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #ifndef LLVM_SUPPORT_TIMER_H
 #define LLVM_SUPPORT_TIMER_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/System/Mutex.h"
 #include <string>
 #include <vector>

Modified: llvm/branches/Apple/Leela/include/llvm/Support/ValueHandle.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/ValueHandle.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/ValueHandle.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/ValueHandle.h Sun Nov  1 18:01:08 2009
@@ -238,6 +238,31 @@
 template<> struct simplify_type<AssertingVH<Value> >
   : public simplify_type<const AssertingVH<Value> > {};
 
+// Specialize DenseMapInfo to allow AssertingVH to participate in DenseMap.
+template<typename T>
+struct DenseMapInfo<AssertingVH<T> > {
+  typedef DenseMapInfo<T*> PointerInfo;
+  static inline AssertingVH<T> getEmptyKey() {
+    return AssertingVH<T>(PointerInfo::getEmptyKey());
+  }
+  static inline T* getTombstoneKey() {
+    return AssertingVH<T>(PointerInfo::getTombstoneKey());
+  }
+  static unsigned getHashValue(const AssertingVH<T> &Val) {
+    return PointerInfo::getHashValue(Val);
+  }
+  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
+    return LHS == RHS;
+  }
+  static bool isPod() {
+#ifdef NDEBUG
+    return true;
+#else
+    return false;
+#endif
+  }
+};
+
 /// TrackingVH - This is a value handle that tracks a Value (or Value subclass),
 /// even across RAUW operations.
 ///

Modified: llvm/branches/Apple/Leela/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Support/raw_ostream.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Support/raw_ostream.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Support/raw_ostream.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #define LLVM_SUPPORT_RAW_OSTREAM_H
 
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   class format_object_base;

Modified: llvm/branches/Apple/Leela/include/llvm/System/Atomic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/System/Atomic.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/System/Atomic.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/System/Atomic.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #ifndef LLVM_SYSTEM_ATOMIC_H
 #define LLVM_SYSTEM_ATOMIC_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   namespace sys {

Modified: llvm/branches/Apple/Leela/include/llvm/System/Disassembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/System/Disassembler.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/System/Disassembler.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/System/Disassembler.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #ifndef LLVM_SYSTEM_DISASSEMBLER_H
 #define LLVM_SYSTEM_DISASSEMBLER_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <string>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/System/Memory.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/System/Memory.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/System/Memory.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/System/Memory.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #ifndef LLVM_SYSTEM_MEMORY_H
 #define LLVM_SYSTEM_MEMORY_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <string>
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/include/llvm/System/TimeValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/System/TimeValue.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/System/TimeValue.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/System/TimeValue.h Sun Nov  1 18:01:08 2009
@@ -11,7 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <string>
 
 #ifndef LLVM_SYSTEM_TIMEVALUE_H

Modified: llvm/branches/Apple/Leela/include/llvm/Target/SubtargetFeature.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Target/SubtargetFeature.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Target/SubtargetFeature.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Target/SubtargetFeature.h Sun Nov  1 18:01:08 2009
@@ -21,7 +21,7 @@
 #include <string>
 #include <vector>
 #include <cstring>
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   class raw_ostream;

Modified: llvm/branches/Apple/Leela/include/llvm/Target/TargetData.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Target/TargetData.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Target/TargetData.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Target/TargetData.h Sun Nov  1 18:01:08 2009
@@ -21,7 +21,7 @@
 #define LLVM_TARGET_TARGETDATA_H
 
 #include "llvm/Pass.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/ADT/SmallVector.h"
 #include <string>

Modified: llvm/branches/Apple/Leela/include/llvm/Target/TargetIntrinsicInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Target/TargetIntrinsicInfo.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Target/TargetIntrinsicInfo.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Target/TargetIntrinsicInfo.h Sun Nov  1 18:01:08 2009
@@ -25,35 +25,21 @@
 /// TargetIntrinsicInfo - Interface to description of machine instruction set
 ///
 class TargetIntrinsicInfo {
-  
-  const char **Intrinsics;               // Raw array to allow static init'n
-  unsigned NumIntrinsics;                // Number of entries in the desc array
-
-  TargetIntrinsicInfo(const TargetIntrinsicInfo &);  // DO NOT IMPLEMENT
-  void operator=(const TargetIntrinsicInfo &);   // DO NOT IMPLEMENT
+  TargetIntrinsicInfo(const TargetIntrinsicInfo &); // DO NOT IMPLEMENT
+  void operator=(const TargetIntrinsicInfo &);      // DO NOT IMPLEMENT
 public:
-  TargetIntrinsicInfo(const char **desc, unsigned num);
+  TargetIntrinsicInfo();
   virtual ~TargetIntrinsicInfo();
 
-  unsigned getNumIntrinsics() const { return NumIntrinsics; }
-
-  virtual Function *getDeclaration(Module *M, const char *BuiltinName) const {
-    return 0;
-  }
-
-  // Returns the Function declaration for intrinsic BuiltinName.  If the
-  // intrinsic can be overloaded, uses Tys to return the correct function.
-  virtual Function *getDeclaration(Module *M, const char *BuiltinName,
-                                   const Type **Tys, unsigned numTys) const {
-    return 0;
-  }
+  /// Return the name of a target intrinsic, e.g. "llvm.bfin.ssync".
+  virtual const char *getName(unsigned IntrID) const =0;
 
-  // Returns true if the Builtin can be overloaded.
-  virtual bool isOverloaded(Module *M, const char *BuiltinName) const {
-    return false;
-  }
+  /// Look up target intrinsic by name. Return intrinsic ID or 0 for unknown
+  /// names.
+  virtual unsigned lookupName(const char *Name, unsigned Len) const =0;
 
-  virtual unsigned getIntrinsicID(Function *F) const { return 0; }
+  /// Return the target intrinsic ID of a function, or 0.
+  virtual unsigned getIntrinsicID(Function *F) const;
 };
 
 } // End llvm namespace

Modified: llvm/branches/Apple/Leela/include/llvm/Target/TargetJITInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Target/TargetJITInfo.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Target/TargetJITInfo.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Target/TargetJITInfo.h Sun Nov  1 18:01:08 2009
@@ -18,7 +18,7 @@
 #define LLVM_TARGET_TARGETJITINFO_H
 
 #include <cassert>
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   class Function;

Modified: llvm/branches/Apple/Leela/include/llvm/Target/TargetSelectionDAG.td
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Target/TargetSelectionDAG.td?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Target/TargetSelectionDAG.td (original)
+++ llvm/branches/Apple/Leela/include/llvm/Target/TargetSelectionDAG.td Sun Nov  1 18:01:08 2009
@@ -269,6 +269,10 @@
                          "ExternalSymbolSDNode">;
 def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
                          "ExternalSymbolSDNode">;
+def blockaddress : SDNode<"ISD::BlockAddress",        SDTPtrLeaf, [],
+                         "BlockAddressSDNode">;
+def tblockaddress: SDNode<"ISD::TargetBlockAddress",  SDTPtrLeaf, [],
+                         "BlockAddressSDNode">;
 
 def add        : SDNode<"ISD::ADD"       , SDTIntBinOp   ,
                         [SDNPCommutative, SDNPAssociative]>;

Modified: llvm/branches/Apple/Leela/include/llvm/Transforms/Utils/BasicBlockUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Transforms/Utils/BasicBlockUtils.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Transforms/Utils/BasicBlockUtils.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Transforms/Utils/BasicBlockUtils.h Sun Nov  1 18:01:08 2009
@@ -116,8 +116,8 @@
 /// SplitCriticalEdge - If this edge is a critical edge, insert a new node to
 /// split the critical edge.  This will update DominatorTree and
 /// DominatorFrontier information if it is available, thus calling this pass
-/// will not invalidate either of them. This returns true if the edge was split,
-/// false otherwise.  
+/// will not invalidate either of them. This returns the new block if the edge
+/// was split, null otherwise.
 ///
 /// If MergeIdenticalEdges is true (not the default), *all* edges from TI to the
 /// specified successor will be merged into the same critical edge block.  
@@ -126,10 +126,16 @@
 /// dest go to one block instead of each going to a different block, but isn't 
 /// the standard definition of a "critical edge".
 ///
+/// It is invalid to call this function on a critical edge that starts at an
+/// IndirectBrInst.  Splitting these edges will almost always create an invalid
+/// program because the addr of the new block won't be the one that is jumped
+/// to.
+///
 BasicBlock *SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
                               Pass *P = 0, bool MergeIdenticalEdges = false);
 
-inline BasicBlock *SplitCriticalEdge(BasicBlock *BB, succ_iterator SI, Pass *P = 0) {
+inline BasicBlock *SplitCriticalEdge(BasicBlock *BB, succ_iterator SI,
+                                     Pass *P = 0) {
   return SplitCriticalEdge(BB->getTerminator(), SI.getSuccessorIndex(), P);
 }
 

Modified: llvm/branches/Apple/Leela/include/llvm/Transforms/Utils/ValueMapper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Transforms/Utils/ValueMapper.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Transforms/Utils/ValueMapper.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Transforms/Utils/ValueMapper.h Sun Nov  1 18:01:08 2009
@@ -20,10 +20,9 @@
 namespace llvm {
   class Value;
   class Instruction;
-  class LLVMContext;
   typedef DenseMap<const Value *, Value *> ValueMapTy;
 
-  Value *MapValue(const Value *V, ValueMapTy &VM, LLVMContext &Context);
+  Value *MapValue(const Value *V, ValueMapTy &VM);
   void RemapInstruction(Instruction *I, ValueMapTy &VM);
 } // End llvm namespace
 

Modified: llvm/branches/Apple/Leela/include/llvm/Type.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Type.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Type.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Type.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #include "llvm/AbstractTypeUser.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/Support/Casting.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/System/Atomic.h"
 #include "llvm/ADT/GraphTraits.h"
 #include <string>

Modified: llvm/branches/Apple/Leela/include/llvm/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/Value.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/Value.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/Value.h Sun Nov  1 18:01:08 2009
@@ -210,6 +210,7 @@
     GlobalAliasVal,           // This is an instance of GlobalAlias
     GlobalVariableVal,        // This is an instance of GlobalVariable
     UndefValueVal,            // This is an instance of UndefValue
+    BlockAddressVal,          // This is an instance of BlockAddress
     ConstantExprVal,          // This is an instance of ConstantExpr
     ConstantAggregateZeroVal, // This is an instance of ConstantAggregateNull
     ConstantIntVal,           // This is an instance of ConstantInt

Modified: llvm/branches/Apple/Leela/include/llvm/ValueSymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/include/llvm/ValueSymbolTable.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/include/llvm/ValueSymbolTable.h (original)
+++ llvm/branches/Apple/Leela/include/llvm/ValueSymbolTable.h Sun Nov  1 18:01:08 2009
@@ -16,7 +16,7 @@
 
 #include "llvm/Value.h"
 #include "llvm/ADT/StringMap.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   template<typename ValueSubClass, typename ItemParentClass>

Modified: llvm/branches/Apple/Leela/lib/Analysis/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Analysis/InlineCost.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Analysis/InlineCost.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Analysis/InlineCost.cpp Sun Nov  1 18:01:08 2009
@@ -31,6 +31,9 @@
       // Eliminating a switch is a big win, proportional to the number of edges
       // deleted.
       Reduction += (SI->getNumSuccessors()-1) * 40;
+    else if (isa<IndirectBrInst>(*UI))
+      // Eliminating an indirect branch is a big win.
+      Reduction += 200;
     else if (CallInst *CI = dyn_cast<CallInst>(*UI)) {
       // Turning an indirect call into a direct call is a BIG win
       Reduction += CI->getCalledValue() == V ? 500 : 0;
@@ -147,19 +150,26 @@
       if (CI->isLosslessCast() || isa<IntToPtrInst>(CI) || 
           isa<PtrToIntInst>(CI))
         continue;
-    } else if (const GetElementPtrInst *GEPI =
-               dyn_cast<GetElementPtrInst>(II)) {
+    } else if (const GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(II)){
       // If a GEP has all constant indices, it will probably be folded with
       // a load/store.
       if (GEPI->hasAllConstantIndices())
         continue;
     }
 
-    if (isa<ReturnInst>(II))
-      ++NumRets;
-    
     ++NumInsts;
   }
+  
+  if (isa<ReturnInst>(BB->getTerminator()))
+    ++NumRets;
+  
+  // We never want to inline functions that contain an indirectbr.  This is
+  // incorrect because all the blockaddress's (e.g. in static global
+  // initializers would be referring to the original function, and this indirect
+  // jump would jump from the inlined copy of the function into the original
+  // function which is extremely undefined behavior.
+  if (isa<IndirectBrInst>(BB->getTerminator()))
+    NeverInline = true;
 }
 
 /// analyzeFunction - Fill in the current structure with information gleaned

Modified: llvm/branches/Apple/Leela/lib/Analysis/SparsePropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Analysis/SparsePropagation.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Analysis/SparsePropagation.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Analysis/SparsePropagation.cpp Sun Nov  1 18:01:08 2009
@@ -166,7 +166,7 @@
     return;
   }
   
-  if (isa<IndBrInst>(TI)) {
+  if (isa<IndirectBrInst>(TI)) {
     Succs.assign(Succs.size(), true);
     return;
   }

Modified: llvm/branches/Apple/Leela/lib/AsmParser/LLLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/AsmParser/LLLexer.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/AsmParser/LLLexer.cpp (original)
+++ llvm/branches/Apple/Leela/lib/AsmParser/LLLexer.cpp Sun Nov  1 18:01:08 2009
@@ -575,6 +575,7 @@
   KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
 
   KEYWORD(x);
+  KEYWORD(blockaddress);
 #undef KEYWORD
 
   // Keywords for types.
@@ -636,7 +637,7 @@
   INSTKEYWORD(ret,         Ret);
   INSTKEYWORD(br,          Br);
   INSTKEYWORD(switch,      Switch);
-  INSTKEYWORD(indbr,       IndBr);
+  INSTKEYWORD(indirectbr,  IndirectBr);
   INSTKEYWORD(invoke,      Invoke);
   INSTKEYWORD(unwind,      Unwind);
   INSTKEYWORD(unreachable, Unreachable);

Modified: llvm/branches/Apple/Leela/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/AsmParser/LLParser.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/AsmParser/LLParser.cpp (original)
+++ llvm/branches/Apple/Leela/lib/AsmParser/LLParser.cpp Sun Nov  1 18:01:08 2009
@@ -29,34 +29,6 @@
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
-namespace llvm {
-  /// ValID - Represents a reference of a definition of some sort with no type.
-  /// There are several cases where we have to parse the value but where the
-  /// type can depend on later context.  This may either be a numeric reference
-  /// or a symbolic (%var) reference.  This is just a discriminated union.
-  struct ValID {
-    enum {
-      t_LocalID, t_GlobalID,      // ID in UIntVal.
-      t_LocalName, t_GlobalName,  // Name in StrVal.
-      t_APSInt, t_APFloat,        // Value in APSIntVal/APFloatVal.
-      t_Null, t_Undef, t_Zero,    // No value.
-      t_EmptyArray,               // No value:  []
-      t_Constant,                 // Value in ConstantVal.
-      t_InlineAsm,                // Value in StrVal/StrVal2/UIntVal.
-      t_Metadata                  // Value in MetadataVal.
-    } Kind;
-
-    LLParser::LocTy Loc;
-    unsigned UIntVal;
-    std::string StrVal, StrVal2;
-    APSInt APSIntVal;
-    APFloat APFloatVal;
-    Constant *ConstantVal;
-    MetadataBase *MetadataVal;
-    ValID() : APFloatVal(0.0) {}
-  };
-}
-
 /// Run: module ::= toplevelentity*
 bool LLParser::Run() {
   // Prime the lexer.
@@ -69,6 +41,29 @@
 /// ValidateEndOfModule - Do final validity and sanity checks at the end of the
 /// module.
 bool LLParser::ValidateEndOfModule() {
+  // If there are entries in ForwardRefBlockAddresses at this point, they are
+  // references after the function was defined.  Resolve those now.
+  while (!ForwardRefBlockAddresses.empty()) {
+    // Okay, we are referencing an already-parsed function, resolve them now.
+    Function *TheFn = 0;
+    const ValID &Fn = ForwardRefBlockAddresses.begin()->first;
+    if (Fn.Kind == ValID::t_GlobalName)
+      TheFn = M->getFunction(Fn.StrVal);
+    else if (Fn.UIntVal < NumberedVals.size())
+      TheFn = dyn_cast<Function>(NumberedVals[Fn.UIntVal]);
+    
+    if (TheFn == 0)
+      return Error(Fn.Loc, "unknown function referenced by blockaddress");
+    
+    // Resolve all these references.
+    if (ResolveForwardRefBlockAddresses(TheFn, 
+                                      ForwardRefBlockAddresses.begin()->second,
+                                        0))
+      return true;
+    
+    ForwardRefBlockAddresses.erase(ForwardRefBlockAddresses.begin());
+  }
+  
   if (!ForwardRefTypes.empty())
     return Error(ForwardRefTypes.begin()->second.second,
                  "use of undefined type named '" +
@@ -103,6 +98,38 @@
   return false;
 }
 
+bool LLParser::ResolveForwardRefBlockAddresses(Function *TheFn, 
+                             std::vector<std::pair<ValID, GlobalValue*> > &Refs,
+                                               PerFunctionState *PFS) {
+  // Loop over all the references, resolving them.
+  for (unsigned i = 0, e = Refs.size(); i != e; ++i) {
+    BasicBlock *Res;
+    if (PFS) {
+      if (Refs[i].first.Kind == ValID::t_LocalName)
+        Res = PFS->GetBB(Refs[i].first.StrVal, Refs[i].first.Loc);
+      else
+        Res = PFS->GetBB(Refs[i].first.UIntVal, Refs[i].first.Loc);
+    } else if (Refs[i].first.Kind == ValID::t_LocalID) {
+      return Error(Refs[i].first.Loc,
+       "cannot take address of numeric label after it the function is defined");
+    } else {
+      Res = dyn_cast_or_null<BasicBlock>(
+                     TheFn->getValueSymbolTable().lookup(Refs[i].first.StrVal));
+    }
+    
+    if (Res == 0)
+      return Error(Refs[i].first.Loc,
+                   "referenced value is not a basic block");
+    
+    // Get the BlockAddress for this and update references to use it.
+    BlockAddress *BA = BlockAddress::get(TheFn, Res);
+    Refs[i].second->replaceAllUsesWith(BA);
+    Refs[i].second->eraseFromParent();
+  }
+  return false;
+}
+
+
 //===----------------------------------------------------------------------===//
 // Top-Level Entities
 //===----------------------------------------------------------------------===//
@@ -1557,8 +1584,9 @@
 // Function Semantic Analysis.
 //===----------------------------------------------------------------------===//
 
-LLParser::PerFunctionState::PerFunctionState(LLParser &p, Function &f)
-  : P(p), F(f) {
+LLParser::PerFunctionState::PerFunctionState(LLParser &p, Function &f,
+                                             int functionNumber)
+  : P(p), F(f), FunctionNumber(functionNumber) {
 
   // Insert unnamed arguments into the NumberedVals list.
   for (Function::arg_iterator AI = F.arg_begin(), E = F.arg_end();
@@ -1588,7 +1616,29 @@
     }
 }
 
-bool LLParser::PerFunctionState::VerifyFunctionComplete() {
+bool LLParser::PerFunctionState::FinishFunction() {
+  // Check to see if someone took the address of labels in this block.
+  if (!P.ForwardRefBlockAddresses.empty()) {
+    ValID FunctionID;
+    if (!F.getName().empty()) {
+      FunctionID.Kind = ValID::t_GlobalName;
+      FunctionID.StrVal = F.getName();
+    } else {
+      FunctionID.Kind = ValID::t_GlobalID;
+      FunctionID.UIntVal = FunctionNumber;
+    }
+  
+    std::map<ValID, std::vector<std::pair<ValID, GlobalValue*> > >::iterator
+      FRBAI = P.ForwardRefBlockAddresses.find(FunctionID);
+    if (FRBAI != P.ForwardRefBlockAddresses.end()) {
+      // Resolve all these references.
+      if (P.ResolveForwardRefBlockAddresses(&F, FRBAI->second, this))
+        return true;
+      
+      P.ForwardRefBlockAddresses.erase(FRBAI);
+    }
+  }
+  
   if (!ForwardRefVals.empty())
     return P.Error(ForwardRefVals.begin()->second.second,
                    "use of undefined value '%" + ForwardRefVals.begin()->first +
@@ -1971,6 +2021,35 @@
     return false;
   }
 
+  case lltok::kw_blockaddress: {
+    // ValID ::= 'blockaddress' '(' @foo ',' %bar ')'
+    Lex.Lex();
+
+    ValID Fn, Label;
+    LocTy FnLoc, LabelLoc;
+    
+    if (ParseToken(lltok::lparen, "expected '(' in block address expression") ||
+        ParseValID(Fn) ||
+        ParseToken(lltok::comma, "expected comma in block address expression")||
+        ParseValID(Label) ||
+        ParseToken(lltok::rparen, "expected ')' in block address expression"))
+      return true;
+    
+    if (Fn.Kind != ValID::t_GlobalID && Fn.Kind != ValID::t_GlobalName)
+      return Error(Fn.Loc, "expected function name in blockaddress");
+    if (Label.Kind != ValID::t_LocalID && Label.Kind != ValID::t_LocalName)
+      return Error(Label.Loc, "expected basic block name in blockaddress");
+    
+    // Make a global variable as a placeholder for this reference.
+    GlobalVariable *FwdRef = new GlobalVariable(*M, Type::getInt8Ty(Context),
+                                           false, GlobalValue::InternalLinkage,
+                                                0, "");
+    ForwardRefBlockAddresses[Fn].push_back(std::make_pair(Label, FwdRef));
+    ID.ConstantVal = FwdRef;
+    ID.Kind = ValID::t_Constant;
+    return false;
+  }
+      
   case lltok::kw_trunc:
   case lltok::kw_zext:
   case lltok::kw_sext:
@@ -2616,7 +2695,10 @@
     return TokError("expected '{' in function body");
   Lex.Lex();  // eat the {.
 
-  PerFunctionState PFS(*this, Fn);
+  int FunctionNumber = -1;
+  if (!Fn.hasName()) FunctionNumber = NumberedVals.size()-1;
+  
+  PerFunctionState PFS(*this, Fn, FunctionNumber);
 
   while (Lex.getKind() != lltok::rbrace && Lex.getKind() != lltok::kw_end)
     if (ParseBasicBlock(PFS)) return true;
@@ -2625,7 +2707,7 @@
   Lex.Lex();
 
   // Verify function is ok.
-  return PFS.VerifyFunctionComplete();
+  return PFS.FinishFunction();
 }
 
 /// ParseBasicBlock
@@ -2710,7 +2792,7 @@
   case lltok::kw_ret:         return ParseRet(Inst, BB, PFS);
   case lltok::kw_br:          return ParseBr(Inst, PFS);
   case lltok::kw_switch:      return ParseSwitch(Inst, PFS);
-  case lltok::kw_indbr:       return ParseIndBr(Inst, PFS);
+  case lltok::kw_indirectbr:  return ParseIndirectBr(Inst, PFS);
   case lltok::kw_invoke:      return ParseInvoke(Inst, PFS);
   // Binary Operators.
   case lltok::kw_add:
@@ -2983,19 +3065,19 @@
   return false;
 }
 
-/// ParseIndBr
+/// ParseIndirectBr
 ///  Instruction
-///    ::= 'indbr' TypeAndValue ',' '[' LabelList ']'
-bool LLParser::ParseIndBr(Instruction *&Inst, PerFunctionState &PFS) {
+///    ::= 'indirectbr' TypeAndValue ',' '[' LabelList ']'
+bool LLParser::ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS) {
   LocTy AddrLoc;
   Value *Address;
   if (ParseTypeAndValue(Address, AddrLoc, PFS) ||
-      ParseToken(lltok::comma, "expected ',' after indbr address") ||
-      ParseToken(lltok::lsquare, "expected '[' with indbr"))
+      ParseToken(lltok::comma, "expected ',' after indirectbr address") ||
+      ParseToken(lltok::lsquare, "expected '[' with indirectbr"))
     return true;
   
   if (!isa<PointerType>(Address->getType()))
-    return Error(AddrLoc, "indbr address must have pointer type");
+    return Error(AddrLoc, "indirectbr address must have pointer type");
   
   // Parse the destination list.
   SmallVector<BasicBlock*, 16> DestList;
@@ -3016,7 +3098,7 @@
   if (ParseToken(lltok::rsquare, "expected ']' at end of block list"))
     return true;
 
-  IndBrInst *IBI = IndBrInst::Create(Address, DestList.size());
+  IndirectBrInst *IBI = IndirectBrInst::Create(Address, DestList.size());
   for (unsigned i = 0, e = DestList.size(); i != e; ++i)
     IBI->addDestination(DestList[i]);
   Inst = IBI;

Modified: llvm/branches/Apple/Leela/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/AsmParser/LLParser.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/AsmParser/LLParser.h (original)
+++ llvm/branches/Apple/Leela/lib/AsmParser/LLParser.h Sun Nov  1 18:01:08 2009
@@ -31,8 +31,41 @@
   class MetadataBase;
   class MDString;
   class MDNode;
-  struct ValID;
 
+  /// ValID - Represents a reference of a definition of some sort with no type.
+  /// There are several cases where we have to parse the value but where the
+  /// type can depend on later context.  This may either be a numeric reference
+  /// or a symbolic (%var) reference.  This is just a discriminated union.
+  struct ValID {
+    enum {
+      t_LocalID, t_GlobalID,      // ID in UIntVal.
+      t_LocalName, t_GlobalName,  // Name in StrVal.
+      t_APSInt, t_APFloat,        // Value in APSIntVal/APFloatVal.
+      t_Null, t_Undef, t_Zero,    // No value.
+      t_EmptyArray,               // No value:  []
+      t_Constant,                 // Value in ConstantVal.
+      t_InlineAsm,                // Value in StrVal/StrVal2/UIntVal.
+      t_Metadata                  // Value in MetadataVal.
+    } Kind;
+    
+    LLLexer::LocTy Loc;
+    unsigned UIntVal;
+    std::string StrVal, StrVal2;
+    APSInt APSIntVal;
+    APFloat APFloatVal;
+    Constant *ConstantVal;
+    MetadataBase *MetadataVal;
+    ValID() : APFloatVal(0.0) {}
+    
+    bool operator<(const ValID &RHS) const {
+      if (Kind == t_LocalID || Kind == t_GlobalID)
+        return UIntVal < RHS.UIntVal;
+      assert((Kind == t_LocalName || Kind == t_GlobalName) && 
+             "Ordering not defined for this ValID kind yet");
+      return StrVal < RHS.StrVal;
+    }
+  };
+  
   class LLParser {
   public:
     typedef LLLexer::LocTy LocTy;
@@ -75,6 +108,11 @@
     std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
     std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
     std::vector<GlobalValue*> NumberedVals;
+    
+    // References to blockaddress.  The key is the function ValID, the value is
+    // a list of references to blocks in that function.
+    std::map<ValID, std::vector<std::pair<ValID, GlobalValue*> > >
+      ForwardRefBlockAddresses;
   public:
     LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) : 
       Context(m->getContext()), Lex(F, SM, Err, m->getContext()), M(m) {}
@@ -182,13 +220,17 @@
       std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
       std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
       std::vector<Value*> NumberedVals;
+      
+      /// FunctionNumber - If this is an unnamed function, this is the slot
+      /// number of it, otherwise it is -1.
+      int FunctionNumber;
     public:
-      PerFunctionState(LLParser &p, Function &f);
+      PerFunctionState(LLParser &p, Function &f, int FunctionNumber);
       ~PerFunctionState();
 
       Function &getFunction() const { return F; }
 
-      bool VerifyFunctionComplete();
+      bool FinishFunction();
 
       /// GetVal - Get a value with the specified name or ID, creating a
       /// forward reference record if needed.  This can return null if the value
@@ -268,7 +310,7 @@
     bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
     bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
     bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
-    bool ParseIndBr(Instruction *&Inst, PerFunctionState &PFS);
+    bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
     bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
 
     bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
@@ -291,6 +333,10 @@
     bool ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS);
     bool ParseExtractValue(Instruction *&I, PerFunctionState &PFS);
     bool ParseInsertValue(Instruction *&I, PerFunctionState &PFS);
+    
+    bool ResolveForwardRefBlockAddresses(Function *TheFn, 
+                             std::vector<std::pair<ValID, GlobalValue*> > &Refs,
+                                         PerFunctionState *PFS);
   };
 } // End llvm namespace
 

Modified: llvm/branches/Apple/Leela/lib/AsmParser/LLToken.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/AsmParser/LLToken.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/AsmParser/LLToken.h (original)
+++ llvm/branches/Apple/Leela/lib/AsmParser/LLToken.h Sun Nov  1 18:01:08 2009
@@ -110,12 +110,13 @@
     kw_fptoui, kw_fptosi, kw_inttoptr, kw_ptrtoint, kw_bitcast,
     kw_select, kw_va_arg,
 
-    kw_ret, kw_br, kw_switch, kw_indbr, kw_invoke, kw_unwind, kw_unreachable,
+    kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_unwind,
+    kw_unreachable,
 
     kw_malloc, kw_alloca, kw_free, kw_load, kw_store, kw_getelementptr,
 
     kw_extractelement, kw_insertelement, kw_shufflevector, kw_getresult,
-    kw_extractvalue, kw_insertvalue,
+    kw_extractvalue, kw_insertvalue, kw_blockaddress,
 
     // Unsigned Valued tokens (UIntVal).
     GlobalID,          // @42

Modified: llvm/branches/Apple/Leela/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Bitcode/Reader/BitcodeReader.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Bitcode/Reader/BitcodeReader.cpp Sun Nov  1 18:01:08 2009
@@ -1189,6 +1189,22 @@
                          AsmStr, ConstrStr, HasSideEffects);
       break;
     }
+    case bitc::CST_CODE_BLOCKADDRESS:{
+      if (Record.size() < 3) return Error("Invalid CE_BLOCKADDRESS record");
+      const Type *FnTy = getTypeByID(Record[0]);
+      if (FnTy == 0) return Error("Invalid CE_BLOCKADDRESS record");
+      Function *Fn =
+        dyn_cast_or_null<Function>(ValueList.getConstantFwdRef(Record[1],FnTy));
+      if (Fn == 0) return Error("Invalid CE_BLOCKADDRESS record");
+      
+      GlobalVariable *FwdRef = new GlobalVariable(*Fn->getParent(),
+                                                  Type::getInt8Ty(Context),
+                                            false, GlobalValue::InternalLinkage,
+                                                  0, "");
+      BlockAddrFwdRefs[Fn].push_back(std::make_pair(Record[2], FwdRef));
+      V = FwdRef;
+      break;
+    }  
     }
 
     ValueList.AssignValue(V, NextCstNo);
@@ -1972,22 +1988,22 @@
       I = SI;
       break;
     }
-    case bitc::FUNC_CODE_INST_INDBR: { // INDBR: [opty, op0, op1, ...]
+    case bitc::FUNC_CODE_INST_INDIRECTBR: { // INDIRECTBR: [opty, op0, op1, ...]
       if (Record.size() < 2)
-        return Error("Invalid INDBR record");
+        return Error("Invalid INDIRECTBR record");
       const Type *OpTy = getTypeByID(Record[0]);
       Value *Address = getFnValueByID(Record[1], OpTy);
       if (OpTy == 0 || Address == 0)
-        return Error("Invalid INDBR record");
+        return Error("Invalid INDIRECTBR record");
       unsigned NumDests = Record.size()-2;
-      IndBrInst *IBI = IndBrInst::Create(Address, NumDests);
+      IndirectBrInst *IBI = IndirectBrInst::Create(Address, NumDests);
       InstructionList.push_back(IBI);
       for (unsigned i = 0, e = NumDests; i != e; ++i) {
         if (BasicBlock *DestBB = getBasicBlock(Record[2+i])) {
           IBI->addDestination(DestBB);
         } else {
           delete IBI;
-          return Error("Invalid INDBR record!");
+          return Error("Invalid INDIRECTBR record!");
         }
       }
       I = IBI;
@@ -2240,6 +2256,27 @@
     }
   }
 
+  // See if anything took the address of blocks in this function.  If so,
+  // resolve them now.
+  /// BlockAddrFwdRefs - These are blockaddr references to basic blocks.  These
+  /// are resolved lazily when functions are loaded.
+  DenseMap<Function*, std::vector<BlockAddrRefTy> >::iterator BAFRI =
+    BlockAddrFwdRefs.find(F);
+  if (BAFRI != BlockAddrFwdRefs.end()) {
+    std::vector<BlockAddrRefTy> &RefList = BAFRI->second;
+    for (unsigned i = 0, e = RefList.size(); i != e; ++i) {
+      unsigned BlockIdx = RefList[i].first;
+      if (BlockIdx >= FunctionBBs.size())
+        return Error("Invalid blockaddress block #");
+    
+      GlobalVariable *FwdRef = RefList[i].second;
+      FwdRef->replaceAllUsesWith(BlockAddress::get(F, FunctionBBs[BlockIdx]));
+      FwdRef->eraseFromParent();
+    }
+    
+    BlockAddrFwdRefs.erase(BAFRI);
+  }
+  
   // Trim the value list down to the size it was before we parsed this function.
   ValueList.shrinkTo(ModuleValueListSize);
   std::vector<BasicBlock*>().swap(FunctionBBs);

Modified: llvm/branches/Apple/Leela/lib/Bitcode/Reader/BitcodeReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Bitcode/Reader/BitcodeReader.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Bitcode/Reader/BitcodeReader.h (original)
+++ llvm/branches/Apple/Leela/lib/Bitcode/Reader/BitcodeReader.h Sun Nov  1 18:01:08 2009
@@ -94,7 +94,7 @@
 class BitcodeReaderMDValueList {
   std::vector<WeakVH> MDValuePtrs;
   
-  LLVMContext& Context;
+  LLVMContext &Context;
 public:
   BitcodeReaderMDValueList(LLVMContext& C) : Context(C) {}
 
@@ -122,7 +122,7 @@
 };
 
 class BitcodeReader : public ModuleProvider {
-  LLVMContext& Context;
+  LLVMContext &Context;
   MemoryBuffer *Buffer;
   BitstreamReader StreamFile;
   BitstreamCursor Stream;
@@ -163,6 +163,12 @@
   /// map contains info about where to find deferred function body (in the
   /// stream) and what linkage the original function had.
   DenseMap<Function*, std::pair<uint64_t, unsigned> > DeferredFunctionInfo;
+  
+  /// BlockAddrFwdRefs - These are blockaddr references to basic blocks.  These
+  /// are resolved lazily when functions are loaded.
+  typedef std::pair<unsigned, GlobalVariable*> BlockAddrRefTy;
+  DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrFwdRefs;
+  
 public:
   explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext& C)
     : Context(C), Buffer(buffer), ErrorString(0), ValueList(C), MDValueList(C) {

Modified: llvm/branches/Apple/Leela/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Bitcode/Writer/BitcodeWriter.cpp Sun Nov  1 18:01:08 2009
@@ -749,10 +749,11 @@
         assert (0 && "Unknown FP type!");
       }
     } else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {
+      const ConstantArray *CA = cast<ConstantArray>(C);
       // Emit constant strings specially.
-      unsigned NumOps = C->getNumOperands();
+      unsigned NumOps = CA->getNumOperands();
       // If this is a null-terminated string, use the denser CSTRING encoding.
-      if (C->getOperand(NumOps-1)->isNullValue()) {
+      if (CA->getOperand(NumOps-1)->isNullValue()) {
         Code = bitc::CST_CODE_CSTRING;
         --NumOps;  // Don't encode the null, which isn't allowed by char6.
       } else {
@@ -762,7 +763,7 @@
       bool isCStr7 = Code == bitc::CST_CODE_CSTRING;
       bool isCStrChar6 = Code == bitc::CST_CODE_CSTRING;
       for (unsigned i = 0; i != NumOps; ++i) {
-        unsigned char V = cast<ConstantInt>(C->getOperand(i))->getZExtValue();
+        unsigned char V = cast<ConstantInt>(CA->getOperand(i))->getZExtValue();
         Record.push_back(V);
         isCStr7 &= (V & 128) == 0;
         if (isCStrChar6)
@@ -850,6 +851,13 @@
         Record.push_back(CE->getPredicate());
         break;
       }
+    } else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
+      assert(BA->getFunction() == BA->getBasicBlock()->getParent() &&
+             "Malformed blockaddress");
+      Code = bitc::CST_CODE_BLOCKADDRESS;
+      Record.push_back(VE.getTypeID(BA->getFunction()->getType()));
+      Record.push_back(VE.getValueID(BA->getFunction()));
+      Record.push_back(VE.getGlobalBasicBlockID(BA->getBasicBlock()));
     } else {
       llvm_unreachable("Unknown constant!");
     }
@@ -1013,8 +1021,8 @@
     for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
       Vals.push_back(VE.getValueID(I.getOperand(i)));
     break;
-  case Instruction::IndBr:
-    Code = bitc::FUNC_CODE_INST_INDBR;
+  case Instruction::IndirectBr:
+    Code = bitc::FUNC_CODE_INST_INDIRECTBR;
     Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
     for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
       Vals.push_back(VE.getValueID(I.getOperand(i)));

Modified: llvm/branches/Apple/Leela/lib/Bitcode/Writer/ValueEnumerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Bitcode/Writer/ValueEnumerator.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Bitcode/Writer/ValueEnumerator.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Bitcode/Writer/ValueEnumerator.cpp Sun Nov  1 18:01:08 2009
@@ -222,7 +222,9 @@
         EnumerateType(Type::getVoidTy(MD->getContext()));
     }
     return;
-  } else if (const NamedMDNode *N = dyn_cast<NamedMDNode>(MD)) {
+  }
+  
+  if (const NamedMDNode *N = dyn_cast<NamedMDNode>(MD)) {
     for(NamedMDNode::const_elem_iterator I = N->elem_begin(),
           E = N->elem_end(); I != E; ++I) {
       MetadataBase *M = *I;
@@ -273,7 +275,8 @@
       // graph that don't go through a global variable.
       for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
            I != E; ++I)
-        EnumerateValue(*I);
+        if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
+          EnumerateValue(*I);
 
       // Finally, add the value.  Doing this could make the ValueID reference be
       // dangling, don't reuse it.
@@ -319,15 +322,20 @@
 
     // This constant may have operands, make sure to enumerate the types in
     // them.
-    for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
-      EnumerateOperandType(C->getOperand(i));
+    for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
+      const User *Op = C->getOperand(i);
+      
+      // Don't enumerate basic blocks here, this happens as operands to
+      // blockaddress.
+      if (isa<BasicBlock>(Op)) continue;
+      
+      EnumerateOperandType(cast<Constant>(Op));
+    }
 
     if (const MDNode *N = dyn_cast<MDNode>(V)) {
-      for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
-        Value *Elem = N->getElement(i);
-        if (Elem)
+      for (unsigned i = 0, e = N->getNumElements(); i != e; ++i)
+        if (Value *Elem = N->getElement(i))
           EnumerateOperandType(Elem);
-      }
     }
   } else if (isa<MDString>(V) || isa<MDNode>(V))
     EnumerateValue(V);
@@ -396,3 +404,23 @@
   Values.resize(NumModuleValues);
   BasicBlocks.clear();
 }
+
+static void IncorporateFunctionInfoGlobalBBIDs(const Function *F,
+                                 DenseMap<const BasicBlock*, unsigned> &IDMap) {
+  unsigned Counter = 0;
+  for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
+    IDMap[BB] = ++Counter;
+}
+
+/// getGlobalBasicBlockID - This returns the function-specific ID for the
+/// specified basic block.  This is relatively expensive information, so it
+/// should only be used by rare constructs such as address-of-label.
+unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
+  unsigned &Idx = GlobalBasicBlockIDs[BB];
+  if (Idx != 0)
+    return Idx-1;
+
+  IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs);
+  return getGlobalBasicBlockID(BB);
+}
+

Modified: llvm/branches/Apple/Leela/lib/Bitcode/Writer/ValueEnumerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Bitcode/Writer/ValueEnumerator.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Bitcode/Writer/ValueEnumerator.h (original)
+++ llvm/branches/Apple/Leela/lib/Bitcode/Writer/ValueEnumerator.h Sun Nov  1 18:01:08 2009
@@ -53,6 +53,10 @@
   AttributeMapType AttributeMap;
   std::vector<AttrListPtr> Attributes;
   
+  /// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
+  /// the "getGlobalBasicBlockID" method.
+  mutable DenseMap<const BasicBlock*, unsigned> GlobalBasicBlockIDs;
+  
   typedef DenseMap<const Instruction*, unsigned> InstructionMapType;
   InstructionMapType InstructionMap;
   unsigned InstructionCount;
@@ -106,6 +110,11 @@
   const std::vector<AttrListPtr> &getAttributes() const {
     return Attributes;
   }
+  
+  /// getGlobalBasicBlockID - This returns the function-specific ID for the
+  /// specified basic block.  This is relatively expensive information, so it
+  /// should only be used by rare constructs such as address-of-label.
+  unsigned getGlobalBasicBlockID(const BasicBlock *BB) const;
 
   /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
   /// use these two methods to get its data into the ValueEnumerator!

Modified: llvm/branches/Apple/Leela/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sun Nov  1 18:01:08 2009
@@ -919,6 +919,8 @@
     default:
       llvm_unreachable("Unsupported operator!");
     }
+  } else if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
+    GetBlockAddressSymbol(BA)->print(O, MAI);
   } else {
     llvm_unreachable("Unknown constant value!");
   }
@@ -1613,6 +1615,24 @@
   return true;
 }
 
+MCSymbol *AsmPrinter::GetBlockAddressSymbol(const BlockAddress *BA) const {
+  return GetBlockAddressSymbol(BA->getFunction(), BA->getBasicBlock());
+}
+
+MCSymbol *AsmPrinter::GetBlockAddressSymbol(const Function *F,
+                                            const BasicBlock *BB) const {
+  assert(BB->hasName() &&
+         "Address of anonymous basic block not supported yet!");
+
+  // FIXME: This isn't guaranteed to produce a unique name even if the
+  // block and function have a name.
+  std::string Mangled =
+    Mang->getMangledName(F, Mang->makeNameProper(BB->getName()).c_str(),
+                         /*ForcePrivate=*/true);
+
+  return OutContext.GetOrCreateSymbol(StringRef(Mangled));
+}
+
 MCSymbol *AsmPrinter::GetMBBSymbol(unsigned MBBID) const {
   SmallString<60> Name;
   raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "BB"
@@ -1626,9 +1646,27 @@
 /// MachineBasicBlock, an alignment (if present) and a comment describing
 /// it if appropriate.
 void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
+  // Emit an alignment directive for this block, if needed.
   if (unsigned Align = MBB->getAlignment())
     EmitAlignment(Log2_32(Align));
 
+  // If the block has its address taken, emit a special label to satisfy
+  // references to the block. This is done so that we don't need to
+  // remember the number of this label, and so that we can make
+  // forward references to labels without knowing what their numbers
+  // will be.
+  if (MBB->hasAddressTaken()) {
+    GetBlockAddressSymbol(MBB->getBasicBlock()->getParent(),
+                          MBB->getBasicBlock())->print(O, MAI);
+    O << ':';
+    if (VerboseAsm) {
+      O.PadToColumn(MAI->getCommentColumn());
+      O << MAI->getCommentString() << " Address Taken";
+    }
+    O << '\n';
+  }
+
+  // Print the main label for the block.
   if (MBB->pred_empty() || MBB->isOnlyReachableByFallthrough()) {
     if (VerboseAsm)
       O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
@@ -1639,6 +1677,7 @@
       O << '\n';
   }
   
+  // Print some comments to accompany the label.
   if (VerboseAsm) {
     if (const BasicBlock *BB = MBB->getBasicBlock())
       if (BB->hasName()) {

Modified: llvm/branches/Apple/Leela/lib/CodeGen/BranchFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/BranchFolding.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/BranchFolding.cpp (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/BranchFolding.cpp Sun Nov  1 18:01:08 2009
@@ -881,8 +881,9 @@
   
   // If this block is empty, make everyone use its fall-through, not the block
   // explicitly.  Landing pads should not do this since the landing-pad table
-  // points to this block.
-  if (MBB->empty() && !MBB->isLandingPad()) {
+  // points to this block.  Blocks with their addresses taken shouldn't be
+  // optimized away.
+  if (MBB->empty() && !MBB->isLandingPad() && !MBB->hasAddressTaken()) {
     // Dead block?  Leave for cleanup later.
     if (MBB->pred_empty()) return MadeChange;
     

Modified: llvm/branches/Apple/Leela/lib/CodeGen/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/ELF.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/ELF.h (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/ELF.h Sun Nov  1 18:01:08 2009
@@ -22,7 +22,7 @@
 
 #include "llvm/CodeGen/BinaryObject.h"
 #include "llvm/CodeGen/MachineRelocation.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
   class GlobalValue;

Modified: llvm/branches/Apple/Leela/lib/CodeGen/MachineBasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/MachineBasicBlock.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/MachineBasicBlock.cpp (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/MachineBasicBlock.cpp Sun Nov  1 18:01:08 2009
@@ -24,7 +24,8 @@
 using namespace llvm;
 
 MachineBasicBlock::MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb)
-  : BB(bb), Number(-1), xParent(&mf), Alignment(0), IsLandingPad(false) {
+  : BB(bb), Number(-1), xParent(&mf), Alignment(0), IsLandingPad(false),
+    AddressTaken(false) {
   Insts.Parent = this;
 }
 
@@ -184,6 +185,7 @@
      << ", LLVM BB @" << (const void*) LBB << ", ID#" << getNumber();
   if (Alignment) OS << ", Alignment " << Alignment;
   if (isLandingPad()) OS << ", EH LANDING PAD";
+  if (hasAddressTaken()) OS << ", ADDRESS TAKEN";
   OS << ":\n";
 
   const TargetRegisterInfo *TRI = MF->getTarget().getRegisterInfo();  

Modified: llvm/branches/Apple/Leela/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/MachineInstr.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/MachineInstr.cpp Sun Nov  1 18:01:08 2009
@@ -13,6 +13,7 @@
 
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Constants.h"
+#include "llvm/Function.h"
 #include "llvm/InlineAsm.h"
 #include "llvm/Value.h"
 #include "llvm/Assembly/Writer.h"
@@ -180,6 +181,8 @@
   case MachineOperand::MO_ExternalSymbol:
     return !strcmp(getSymbolName(), Other.getSymbolName()) &&
            getOffset() == Other.getOffset();
+  case MachineOperand::MO_BlockAddress:
+    return getBlockAddress() == Other.getBlockAddress();
   }
 }
 
@@ -271,6 +274,13 @@
     if (getOffset()) OS << "+" << getOffset();
     OS << '>';
     break;
+  case MachineOperand::MO_BlockAddress:
+    OS << "<blockaddress: ";
+    WriteAsOperand(OS, getBlockAddress()->getFunction(), /*PrintType=*/false);
+    OS << ", ";
+    WriteAsOperand(OS, getBlockAddress()->getBasicBlock(), /*PrintType=*/false);
+    OS << '>';
+    break;
   default:
     llvm_unreachable("Unrecognized operand type");
   }

Modified: llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/InstrEmitter.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/InstrEmitter.cpp (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/InstrEmitter.cpp Sun Nov  1 18:01:08 2009
@@ -349,6 +349,8 @@
   } else if (ExternalSymbolSDNode *ES = dyn_cast<ExternalSymbolSDNode>(Op)) {
     MI->addOperand(MachineOperand::CreateES(ES->getSymbol(),
                                             ES->getTargetFlags()));
+  } else if (BlockAddressSDNode *BA = dyn_cast<BlockAddressSDNode>(Op)) {
+    MI->addOperand(MachineOperand::CreateBA(BA->getBlockAddress()));
   } else {
     assert(Op.getValueType() != MVT::Other &&
            Op.getValueType() != MVT::Flag &&

Modified: llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.h (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.h Sun Nov  1 18:01:08 2009
@@ -58,6 +58,7 @@
       if (isa<ConstantPoolSDNode>(Node))   return true;
       if (isa<JumpTableSDNode>(Node))      return true;
       if (isa<ExternalSymbolSDNode>(Node)) return true;
+      if (isa<BlockAddressSDNode>(Node))   return true;
       if (Node->getOpcode() == ISD::EntryToken) return true;
       return false;
     }

Modified: llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sun Nov  1 18:01:08 2009
@@ -30,6 +30,7 @@
 #include "llvm/Target/TargetLowering.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/Target/TargetIntrinsicInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -459,6 +460,11 @@
       ID.AddInteger(SVN->getMaskElt(i));
     break;
   }
+  case ISD::TargetBlockAddress:
+  case ISD::BlockAddress: {
+    ID.AddPointer(cast<BlockAddressSDNode>(N));
+    break;
+  }
   } // end switch (N->getOpcode())
 }
 
@@ -1304,6 +1310,23 @@
   return SDValue(N, 0);
 }
 
+SDValue SelectionDAG::getBlockAddress(BlockAddress *BA, DebugLoc DL,
+                                      bool isTarget) {
+  unsigned Opc = isTarget ? ISD::TargetBlockAddress : ISD::BlockAddress;
+
+  FoldingSetNodeID ID;
+  AddNodeIDNode(ID, Opc, getVTList(TLI.getPointerTy()), 0, 0);
+  ID.AddPointer(BA);
+  void *IP = 0;
+  if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
+    return SDValue(E, 0);
+  SDNode *N = NodeAllocator.Allocate<BlockAddressSDNode>();
+  new (N) BlockAddressSDNode(Opc, DL, TLI.getPointerTy(), BA);
+  CSEMap.InsertNode(N, IP);
+  AllNodes.push_back(N);
+  return SDValue(N, 0);
+}
+
 SDValue SelectionDAG::getSrcValue(const Value *V) {
   assert((!V || isa<PointerType>(V->getType())) &&
          "SrcValue is not a pointer?");
@@ -5387,14 +5410,17 @@
   case ISD::EH_RETURN: return "EH_RETURN";
   case ISD::ConstantPool:  return "ConstantPool";
   case ISD::ExternalSymbol: return "ExternalSymbol";
-  case ISD::INTRINSIC_WO_CHAIN: {
-    unsigned IID = cast<ConstantSDNode>(getOperand(0))->getZExtValue();
-    return Intrinsic::getName((Intrinsic::ID)IID);
-  }
+  case ISD::BlockAddress:  return "BlockAddress";
+  case ISD::INTRINSIC_WO_CHAIN:
   case ISD::INTRINSIC_VOID:
   case ISD::INTRINSIC_W_CHAIN: {
-    unsigned IID = cast<ConstantSDNode>(getOperand(1))->getZExtValue();
-    return Intrinsic::getName((Intrinsic::ID)IID);
+    unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
+    unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
+    if (IID < Intrinsic::num_intrinsics)
+      return Intrinsic::getName((Intrinsic::ID)IID);
+    else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
+      return TII->getName(IID);
+    llvm_unreachable("Invalid intrinsic ID");
   }
 
   case ISD::BUILD_VECTOR:   return "BUILD_VECTOR";
@@ -5406,6 +5432,7 @@
   case ISD::TargetJumpTable:  return "TargetJumpTable";
   case ISD::TargetConstantPool:  return "TargetConstantPool";
   case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
+  case ISD::TargetBlockAddress: return "TargetBlockAddress";
 
   case ISD::CopyToReg:     return "CopyToReg";
   case ISD::CopyFromReg:   return "CopyFromReg";
@@ -5763,6 +5790,13 @@
     OS << ">";
   } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
     OS << " <" << *M->getMemOperand() << ">";
+  } else if (const BlockAddressSDNode *BA =
+               dyn_cast<BlockAddressSDNode>(this)) {
+    OS << "<";
+    WriteAsOperand(OS, BA->getBlockAddress()->getFunction(), false);
+    OS << ", ";
+    WriteAsOperand(OS, BA->getBlockAddress()->getBasicBlock(), false);
+    OS << ">";
   }
 }
 

Modified: llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Sun Nov  1 18:01:08 2009
@@ -322,6 +322,12 @@
     MBBMap[BB] = MBB;
     MF->push_back(MBB);
 
+    // Transfer the address-taken flag. This is necessary because there could
+    // be multiple MachineBasicBlocks corresponding to one BasicBlock, and only
+    // the first one should be marked.
+    if (BB->hasAddressTaken())
+      MBB->setHasAddressTaken();
+
     // Create Machine PHI nodes for LLVM PHI nodes, lowering them as
     // appropriate.
     PHINode *PN;
@@ -895,6 +901,9 @@
       return DAG.getMergeValues(&Constants[0], NumElts, getCurDebugLoc());
     }
 
+    if (BlockAddress *BA = dyn_cast<BlockAddress>(C))
+      return DAG.getBlockAddress(BA, getCurDebugLoc());
+
     const VectorType *VecTy = cast<VectorType>(V->getType());
     unsigned NumElements = VecTy->getNumElements();
 
@@ -2142,7 +2151,7 @@
   }
 }
 
-void SelectionDAGLowering::visitIndBr(IndBrInst &I) {
+void SelectionDAGLowering::visitIndirectBr(IndirectBrInst &I) {
   // Update machine-CFG edges.
   for (unsigned i = 0, e = I.getNumSuccessors(); i != e; ++i)
     CurMBB->addSuccessor(FuncInfo.MBBMap[I.getSuccessor(i)]);
@@ -5837,8 +5846,7 @@
 
 #include "llvm/CodeGen/SelectionDAGISel.h"
 
-void SelectionDAGISel::
-LowerArguments(BasicBlock *LLVMBB) {
+void SelectionDAGISel::LowerArguments(BasicBlock *LLVMBB) {
   // If this is the entry block, emit arguments.
   Function &F = *LLVMBB->getParent();
   SelectionDAG &DAG = SDL->DAG;

Modified: llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h Sun Nov  1 18:01:08 2009
@@ -50,7 +50,7 @@
 class GCFunctionInfo;
 class ICmpInst;
 class IntToPtrInst;
-class IndBrInst;
+class IndirectBrInst;
 class InvokeInst;
 class InsertElementInst;
 class InsertValueInst;
@@ -451,7 +451,7 @@
   void visitRet(ReturnInst &I);
   void visitBr(BranchInst &I);
   void visitSwitch(SwitchInst &I);
-  void visitIndBr(IndBrInst &I);
+  void visitIndirectBr(IndirectBrInst &I);
   void visitUnreachable(UnreachableInst &I) { /* noop */ }
 
   // Helpers for visitSwitch

Modified: llvm/branches/Apple/Leela/lib/ExecutionEngine/ExecutionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/ExecutionEngine/ExecutionEngine.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ llvm/branches/Apple/Leela/lib/ExecutionEngine/ExecutionEngine.cpp Sun Nov  1 18:01:08 2009
@@ -46,7 +46,9 @@
 ExecutionEngine::EERegisterFn ExecutionEngine::ExceptionTableRegister = 0;
 
 
-ExecutionEngine::ExecutionEngine(ModuleProvider *P) : LazyFunctionCreator(0) {
+ExecutionEngine::ExecutionEngine(ModuleProvider *P)
+  : EEState(*this),
+    LazyFunctionCreator(0) {
   LazyCompilationDisabled = false;
   GVCompilationDisabled   = false;
   SymbolSearchingDisabled = false;
@@ -115,8 +117,7 @@
 
 void *ExecutionEngineState::RemoveMapping(
   const MutexGuard &, const GlobalValue *ToUnmap) {
-  std::map<AssertingVH<const GlobalValue>, void *>::iterator I =
-    GlobalAddressMap.find(ToUnmap);
+  GlobalAddressMapTy::iterator I = GlobalAddressMap.find(ToUnmap);
   void *OldVal;
   if (I == GlobalAddressMap.end())
     OldVal = 0;
@@ -139,14 +140,14 @@
 
   DEBUG(errs() << "JIT: Map \'" << GV->getName() 
         << "\' to [" << Addr << "]\n";);
-  void *&CurVal = state.getGlobalAddressMap(locked)[GV];
+  void *&CurVal = EEState.getGlobalAddressMap(locked)[GV];
   assert((CurVal == 0 || Addr == 0) && "GlobalMapping already established!");
   CurVal = Addr;
   
   // If we are using the reverse mapping, add it too
-  if (!state.getGlobalAddressReverseMap(locked).empty()) {
+  if (!EEState.getGlobalAddressReverseMap(locked).empty()) {
     AssertingVH<const GlobalValue> &V =
-      state.getGlobalAddressReverseMap(locked)[Addr];
+      EEState.getGlobalAddressReverseMap(locked)[Addr];
     assert((V == 0 || GV == 0) && "GlobalMapping already established!");
     V = GV;
   }
@@ -157,8 +158,8 @@
 void ExecutionEngine::clearAllGlobalMappings() {
   MutexGuard locked(lock);
   
-  state.getGlobalAddressMap(locked).clear();
-  state.getGlobalAddressReverseMap(locked).clear();
+  EEState.getGlobalAddressMap(locked).clear();
+  EEState.getGlobalAddressReverseMap(locked).clear();
 }
 
 /// clearGlobalMappingsFromModule - Clear all global mappings that came from a
@@ -167,11 +168,11 @@
   MutexGuard locked(lock);
   
   for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI) {
-    state.RemoveMapping(locked, FI);
+    EEState.RemoveMapping(locked, FI);
   }
   for (Module::global_iterator GI = M->global_begin(), GE = M->global_end(); 
        GI != GE; ++GI) {
-    state.RemoveMapping(locked, GI);
+    EEState.RemoveMapping(locked, GI);
   }
 }
 
@@ -181,25 +182,25 @@
 void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
   MutexGuard locked(lock);
 
-  std::map<AssertingVH<const GlobalValue>, void *> &Map =
-    state.getGlobalAddressMap(locked);
+  ExecutionEngineState::GlobalAddressMapTy &Map =
+    EEState.getGlobalAddressMap(locked);
 
   // Deleting from the mapping?
   if (Addr == 0) {
-    return state.RemoveMapping(locked, GV);
+    return EEState.RemoveMapping(locked, GV);
   }
   
   void *&CurVal = Map[GV];
   void *OldVal = CurVal;
 
-  if (CurVal && !state.getGlobalAddressReverseMap(locked).empty())
-    state.getGlobalAddressReverseMap(locked).erase(CurVal);
+  if (CurVal && !EEState.getGlobalAddressReverseMap(locked).empty())
+    EEState.getGlobalAddressReverseMap(locked).erase(CurVal);
   CurVal = Addr;
   
   // If we are using the reverse mapping, add it too
-  if (!state.getGlobalAddressReverseMap(locked).empty()) {
+  if (!EEState.getGlobalAddressReverseMap(locked).empty()) {
     AssertingVH<const GlobalValue> &V =
-      state.getGlobalAddressReverseMap(locked)[Addr];
+      EEState.getGlobalAddressReverseMap(locked)[Addr];
     assert((V == 0 || GV == 0) && "GlobalMapping already established!");
     V = GV;
   }
@@ -212,9 +213,9 @@
 void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) {
   MutexGuard locked(lock);
   
-  std::map<AssertingVH<const GlobalValue>, void*>::iterator I =
-    state.getGlobalAddressMap(locked).find(GV);
-  return I != state.getGlobalAddressMap(locked).end() ? I->second : 0;
+  ExecutionEngineState::GlobalAddressMapTy::iterator I =
+    EEState.getGlobalAddressMap(locked).find(GV);
+  return I != EEState.getGlobalAddressMap(locked).end() ? I->second : 0;
 }
 
 /// getGlobalValueAtAddress - Return the LLVM global value object that starts
@@ -224,17 +225,17 @@
   MutexGuard locked(lock);
 
   // If we haven't computed the reverse mapping yet, do so first.
-  if (state.getGlobalAddressReverseMap(locked).empty()) {
-    for (std::map<AssertingVH<const GlobalValue>, void *>::iterator
-         I = state.getGlobalAddressMap(locked).begin(),
-         E = state.getGlobalAddressMap(locked).end(); I != E; ++I)
-      state.getGlobalAddressReverseMap(locked).insert(std::make_pair(I->second,
+  if (EEState.getGlobalAddressReverseMap(locked).empty()) {
+    for (ExecutionEngineState::GlobalAddressMapTy::iterator
+         I = EEState.getGlobalAddressMap(locked).begin(),
+         E = EEState.getGlobalAddressMap(locked).end(); I != E; ++I)
+      EEState.getGlobalAddressReverseMap(locked).insert(std::make_pair(I->second,
                                                                      I->first));
   }
 
   std::map<void *, AssertingVH<const GlobalValue> >::iterator I =
-    state.getGlobalAddressReverseMap(locked).find(Addr);
-  return I != state.getGlobalAddressReverseMap(locked).end() ? I->second : 0;
+    EEState.getGlobalAddressReverseMap(locked).find(Addr);
+  return I != EEState.getGlobalAddressReverseMap(locked).end() ? I->second : 0;
 }
 
 // CreateArgv - Turn a vector of strings into a nice argv style array of
@@ -474,7 +475,7 @@
     return getPointerToFunction(F);
 
   MutexGuard locked(lock);
-  void *p = state.getGlobalAddressMap(locked)[GV];
+  void *p = EEState.getGlobalAddressMap(locked)[GV];
   if (p)
     return p;
 
@@ -484,7 +485,7 @@
     EmitGlobalVariable(GVar);
   else
     llvm_unreachable("Global hasn't had an address allocated yet!");
-  return state.getGlobalAddressMap(locked)[GV];
+  return EEState.getGlobalAddressMap(locked)[GV];
 }
 
 /// This function converts a Constant* into a GenericValue. The interesting 
@@ -759,8 +760,11 @@
       Result.PointerVal = 0;
     else if (const Function *F = dyn_cast<Function>(C))
       Result = PTOGV(getPointerToFunctionOrStub(const_cast<Function*>(F)));
-    else if (const GlobalVariable* GV = dyn_cast<GlobalVariable>(C))
+    else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
       Result = PTOGV(getOrEmitGlobalVariable(const_cast<GlobalVariable*>(GV)));
+    else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C))
+      Result = PTOGV(getPointerToBasicBlock(const_cast<BasicBlock*>(
+                                                        BA->getBasicBlock())));
     else
       llvm_unreachable("Unknown constant pointer type!");
     break;
@@ -1069,3 +1073,23 @@
   NumInitBytes += (unsigned)GVSize;
   ++NumGlobals;
 }
+
+ExecutionEngineState::ExecutionEngineState(ExecutionEngine &EE)
+  : EE(EE), GlobalAddressMap(this) {
+}
+
+sys::Mutex *ExecutionEngineState::AddressMapConfig::getMutex(
+  ExecutionEngineState *EES) {
+  return &EES->EE.lock;
+}
+void ExecutionEngineState::AddressMapConfig::onDelete(
+  ExecutionEngineState *EES, const GlobalValue *Old) {
+  void *OldVal = EES->GlobalAddressMap.lookup(Old);
+  EES->GlobalAddressReverseMap.erase(OldVal);
+}
+
+void ExecutionEngineState::AddressMapConfig::onRAUW(
+  ExecutionEngineState *, const GlobalValue *, const GlobalValue *) {
+  assert(false && "The ExecutionEngine doesn't know how to handle a"
+         " RAUW on a value it has a global mapping for.");
+}

Modified: llvm/branches/Apple/Leela/lib/ExecutionEngine/Interpreter/Execution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/ExecutionEngine/Interpreter/Execution.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/ExecutionEngine/Interpreter/Execution.cpp (original)
+++ llvm/branches/Apple/Leela/lib/ExecutionEngine/Interpreter/Execution.cpp Sun Nov  1 18:01:08 2009
@@ -572,9 +572,9 @@
   // runAtExitHandlers() assumes there are no stack frames, but
   // if exit() was called, then it had a stack frame. Blow away
   // the stack before interpreting atexit handlers.
-  ECStack.clear ();
-  runAtExitHandlers ();
-  exit (GV.IntVal.zextOrTrunc(32).getZExtValue());
+  ECStack.clear();
+  runAtExitHandlers();
+  exit(GV.IntVal.zextOrTrunc(32).getZExtValue());
 }
 
 /// Pop the last stack frame off of ECStack and then copy the result
@@ -585,8 +585,8 @@
 /// care of switching to the normal destination BB, if we are returning
 /// from an invoke.
 ///
-void Interpreter::popStackAndReturnValueToCaller (const Type *RetTy,
-                                                  GenericValue Result) {
+void Interpreter::popStackAndReturnValueToCaller(const Type *RetTy,
+                                                 GenericValue Result) {
   // Pop the current stack frame.
   ECStack.pop_back();
 
@@ -629,15 +629,15 @@
   // Unwind stack
   Instruction *Inst;
   do {
-    ECStack.pop_back ();
-    if (ECStack.empty ())
+    ECStack.pop_back();
+    if (ECStack.empty())
       llvm_report_error("Empty stack during unwind!");
-    Inst = ECStack.back ().Caller.getInstruction ();
-  } while (!(Inst && isa<InvokeInst> (Inst)));
+    Inst = ECStack.back().Caller.getInstruction();
+  } while (!(Inst && isa<InvokeInst>(Inst)));
 
   // Return from invoke
-  ExecutionContext &InvokingSF = ECStack.back ();
-  InvokingSF.Caller = CallSite ();
+  ExecutionContext &InvokingSF = ECStack.back();
+  InvokingSF.Caller = CallSite();
 
   // Go to exceptional destination BB of invoke instruction
   SwitchToNewBasicBlock(cast<InvokeInst>(Inst)->getUnwindDest(), InvokingSF);
@@ -678,6 +678,13 @@
   SwitchToNewBasicBlock(Dest, SF);
 }
 
+void Interpreter::visitIndirectBrInst(IndirectBrInst &I) {
+  ExecutionContext &SF = ECStack.back();
+  void *Dest = GVTOP(getOperandValue(I.getAddress(), SF));
+  SwitchToNewBasicBlock((BasicBlock*)Dest, SF);
+}
+
+
 // SwitchToNewBasicBlock - This method is used to jump to a new basic block.
 // This function handles the actual updating of block and instruction iterators
 // as well as execution of all of the PHI nodes in the destination block.
@@ -835,7 +842,7 @@
 
   // Check to see if this is an intrinsic function call...
   Function *F = CS.getCalledFunction();
-  if (F && F->isDeclaration ())
+  if (F && F->isDeclaration())
     switch (F->getIntrinsicID()) {
     case Intrinsic::not_intrinsic:
       break;

Modified: llvm/branches/Apple/Leela/lib/ExecutionEngine/Interpreter/Interpreter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/ExecutionEngine/Interpreter/Interpreter.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/ExecutionEngine/Interpreter/Interpreter.h (original)
+++ llvm/branches/Apple/Leela/lib/ExecutionEngine/Interpreter/Interpreter.h Sun Nov  1 18:01:08 2009
@@ -19,7 +19,7 @@
 #include "llvm/ExecutionEngine/GenericValue.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Support/CallSite.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/InstVisitor.h"
 #include "llvm/Support/raw_ostream.h"
@@ -135,6 +135,7 @@
   void visitReturnInst(ReturnInst &I);
   void visitBranchInst(BranchInst &I);
   void visitSwitchInst(SwitchInst &I);
+  void visitIndirectBrInst(IndirectBrInst &I);
 
   void visitBinaryOperator(BinaryOperator &I);
   void visitICmpInst(ICmpInst &I);
@@ -203,6 +204,7 @@
   void SwitchToNewBasicBlock(BasicBlock *Dest, ExecutionContext &SF);
 
   void *getPointerToFunction(Function *F) { return (void*)F; }
+  void *getPointerToBasicBlock(BasicBlock *BB) { return (void*)BB; }
 
   void initializeExecutionEngine() { }
   void initializeExternalFunctions();

Modified: llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JIT.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JIT.h (original)
+++ llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JIT.h Sun Nov  1 18:01:08 2009
@@ -127,6 +127,10 @@
   ///
   void *getPointerToFunction(Function *F);
 
+  void *getPointerToBasicBlock(BasicBlock *BB) {
+    assert(0 && "JIT does not support address-of-label yet!");
+  }
+  
   /// getOrEmitGlobalVariable - Return the address of the specified global
   /// variable, possibly emitting it to memory if needed.  This is used by the
   /// Emitter.

Modified: llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITDebugRegisterer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITDebugRegisterer.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITDebugRegisterer.h (original)
+++ llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITDebugRegisterer.h Sun Nov  1 18:01:08 2009
@@ -16,7 +16,7 @@
 #define LLVM_EXECUTION_ENGINE_JIT_DEBUGREGISTERER_H
 
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <string>
 
 // This must be kept in sync with gdb/gdb/jit.h .

Modified: llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
+++ llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITEmitter.cpp Sun Nov  1 18:01:08 2009
@@ -42,9 +42,11 @@
 #include "llvm/System/Disassembler.h"
 #include "llvm/System/Memory.h"
 #include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/ValueMap.h"
 #include <algorithm>
 #ifndef NDEBUG
 #include <iomanip>
@@ -61,38 +63,132 @@
 // JIT lazy compilation code.
 //
 namespace {
+  class JITResolverState;
+
+  template<typename ValueTy>
+  struct NoRAUWValueMapConfig : public ValueMapConfig<ValueTy> {
+    typedef JITResolverState *ExtraData;
+    static void onRAUW(JITResolverState *, Value *Old, Value *New) {
+      assert(false && "The JIT doesn't know how to handle a"
+             " RAUW on a value it has emitted.");
+    }
+  };
+
+  struct CallSiteValueMapConfig : public NoRAUWValueMapConfig<Function*> {
+    typedef JITResolverState *ExtraData;
+    static void onDelete(JITResolverState *JRS, Function *F);
+  };
+
   class JITResolverState {
   public:
-    typedef std::map<AssertingVH<Function>, void*> FunctionToStubMapTy;
-    typedef std::map<void*, Function*> StubToFunctionMapTy;
+    typedef ValueMap<Function*, void*, NoRAUWValueMapConfig<Function*> >
+      FunctionToStubMapTy;
+    typedef std::map<void*, AssertingVH<Function> > CallSiteToFunctionMapTy;
+    typedef ValueMap<Function *, SmallPtrSet<void*, 1>,
+                     CallSiteValueMapConfig> FunctionToCallSitesMapTy;
     typedef std::map<AssertingVH<GlobalValue>, void*> GlobalToIndirectSymMapTy;
   private:
     /// FunctionToStubMap - Keep track of the stub created for a particular
     /// function so that we can reuse them if necessary.
     FunctionToStubMapTy FunctionToStubMap;
 
-    /// StubToFunctionMap - Keep track of the function that each stub
-    /// corresponds to.
-    StubToFunctionMapTy StubToFunctionMap;
+    /// CallSiteToFunctionMap - Keep track of the function that each lazy call
+    /// site corresponds to, and vice versa.
+    CallSiteToFunctionMapTy CallSiteToFunctionMap;
+    FunctionToCallSitesMapTy FunctionToCallSitesMap;
 
     /// GlobalToIndirectSymMap - Keep track of the indirect symbol created for a
     /// particular GlobalVariable so that we can reuse them if necessary.
     GlobalToIndirectSymMapTy GlobalToIndirectSymMap;
 
   public:
+    JITResolverState() : FunctionToStubMap(this),
+                         FunctionToCallSitesMap(this) {}
+
     FunctionToStubMapTy& getFunctionToStubMap(const MutexGuard& locked) {
       assert(locked.holds(TheJIT->lock));
       return FunctionToStubMap;
     }
 
-    StubToFunctionMapTy& getStubToFunctionMap(const MutexGuard& locked) {
+    GlobalToIndirectSymMapTy& getGlobalToIndirectSymMap(const MutexGuard& locked) {
       assert(locked.holds(TheJIT->lock));
-      return StubToFunctionMap;
+      return GlobalToIndirectSymMap;
     }
 
-    GlobalToIndirectSymMapTy& getGlobalToIndirectSymMap(const MutexGuard& locked) {
+    pair<void *, Function *> LookupFunctionFromCallSite(
+        const MutexGuard &locked, void *CallSite) const {
       assert(locked.holds(TheJIT->lock));
-      return GlobalToIndirectSymMap;
+
+      // The address given to us for the stub may not be exactly right, it might be
+      // a little bit after the stub.  As such, use upper_bound to find it.
+      CallSiteToFunctionMapTy::const_iterator I =
+        CallSiteToFunctionMap.upper_bound(CallSite);
+      assert(I != CallSiteToFunctionMap.begin() &&
+             "This is not a known call site!");
+      --I;
+      return *I;
+    }
+
+    void AddCallSite(const MutexGuard &locked, void *CallSite, Function *F) {
+      assert(locked.holds(TheJIT->lock));
+
+      bool Inserted = CallSiteToFunctionMap.insert(
+          std::make_pair(CallSite, F)).second;
+      (void)Inserted;
+      assert(Inserted && "Pair was already in CallSiteToFunctionMap");
+      FunctionToCallSitesMap[F].insert(CallSite);
+    }
+
+    // Returns the Function of the stub if a stub was erased, or NULL if there
+    // was no stub.  This function uses the call-site->function map to find a
+    // relevant function, but asserts that only stubs and not other call sites
+    // will be passed in.
+    Function *EraseStub(const MutexGuard &locked, void *Stub) {
+      CallSiteToFunctionMapTy::iterator C2F_I =
+        CallSiteToFunctionMap.find(Stub);
+      if (C2F_I == CallSiteToFunctionMap.end()) {
+        // Not a stub.
+        return NULL;
+      }
+
+      Function *const F = C2F_I->second;
+#ifndef NDEBUG
+      void *RealStub = FunctionToStubMap.lookup(F);
+      assert(RealStub == Stub &&
+             "Call-site that wasn't a stub pass in to EraseStub");
+#endif
+      FunctionToStubMap.erase(F);
+      CallSiteToFunctionMap.erase(C2F_I);
+
+      // Remove the stub from the function->call-sites map, and remove the whole
+      // entry from the map if that was the last call site.
+      FunctionToCallSitesMapTy::iterator F2C_I = FunctionToCallSitesMap.find(F);
+      assert(F2C_I != FunctionToCallSitesMap.end() &&
+             "FunctionToCallSitesMap broken");
+      bool Erased = F2C_I->second.erase(Stub);
+      (void)Erased;
+      assert(Erased && "FunctionToCallSitesMap broken");
+      if (F2C_I->second.empty())
+        FunctionToCallSitesMap.erase(F2C_I);
+
+      return F;
+    }
+
+    void EraseAllCallSites(const MutexGuard &locked, Function *F) {
+      assert(locked.holds(TheJIT->lock));
+      EraseAllCallSitesPrelocked(F);
+    }
+    void EraseAllCallSitesPrelocked(Function *F) {
+      FunctionToCallSitesMapTy::iterator F2C = FunctionToCallSitesMap.find(F);
+      if (F2C == FunctionToCallSitesMap.end())
+        return;
+      for (SmallPtrSet<void*, 1>::const_iterator I = F2C->second.begin(),
+             E = F2C->second.end(); I != E; ++I) {
+        bool Erased = CallSiteToFunctionMap.erase(*I);
+        (void)Erased;
+        assert(Erased && "Missing call site->function mapping");
+      }
+      FunctionToCallSitesMap.erase(F2C);
     }
   };
 
@@ -100,7 +196,7 @@
   /// have not yet been compiled.
   class JITResolver {
     typedef JITResolverState::FunctionToStubMapTy FunctionToStubMapTy;
-    typedef JITResolverState::StubToFunctionMapTy StubToFunctionMapTy;
+    typedef JITResolverState::CallSiteToFunctionMapTy CallSiteToFunctionMapTy;
     typedef JITResolverState::GlobalToIndirectSymMapTy GlobalToIndirectSymMapTy;
 
     /// LazyResolverFn - The target lazy resolver function that we actually
@@ -154,7 +250,7 @@
     void *AddCallbackAtLocation(Function *F, void *Location) {
       MutexGuard locked(TheJIT->lock);
       /// Get the target-specific JIT resolver function.
-      state.getStubToFunctionMap(locked)[Location] = F;
+      state.AddCallSite(locked, Location, F);
       return (void*)(intptr_t)LazyResolverFn;
     }
     
@@ -177,14 +273,17 @@
 
 JITResolver *JITResolver::TheJITResolver = 0;
 
+void CallSiteValueMapConfig::onDelete(JITResolverState *JRS, Function *F) {
+  JRS->EraseAllCallSitesPrelocked(F);
+}
+
 /// getFunctionStubIfAvailable - This returns a pointer to a function stub
 /// if it has already been created.
 void *JITResolver::getFunctionStubIfAvailable(Function *F) {
   MutexGuard locked(TheJIT->lock);
 
   // If we already have a stub for this function, recycle it.
-  void *&Stub = state.getFunctionToStubMap(locked)[F];
-  return Stub;
+  return state.getFunctionToStubMap(locked).lookup(F);
 }
 
 /// getFunctionStub - This returns a pointer to a function stub, creating
@@ -230,7 +329,7 @@
 
   // Finally, keep track of the stub-to-Function mapping so that the
   // JITCompilerFn knows which function to compile!
-  state.getStubToFunctionMap(locked)[Stub] = F;
+  state.AddCallSite(locked, Stub, F);
   
   // If we are JIT'ing non-lazily but need to call a function that does not
   // exist yet, add it to the JIT's work list so that we can fill in the stub
@@ -291,10 +390,11 @@
                                     SmallVectorImpl<void*> &Ptrs) {
   MutexGuard locked(TheJIT->lock);
   
-  FunctionToStubMapTy &FM = state.getFunctionToStubMap(locked);
+  const FunctionToStubMapTy &FM = state.getFunctionToStubMap(locked);
   GlobalToIndirectSymMapTy &GM = state.getGlobalToIndirectSymMap(locked);
   
-  for (FunctionToStubMapTy::iterator i = FM.begin(), e = FM.end(); i != e; ++i){
+  for (FunctionToStubMapTy::const_iterator i = FM.begin(), e = FM.end();
+       i != e; ++i){
     Function *F = i->first;
     if (F->isDeclaration() && F->hasExternalLinkage()) {
       GVs.push_back(i->first);
@@ -310,20 +410,15 @@
 
 GlobalValue *JITResolver::invalidateStub(void *Stub) {
   MutexGuard locked(TheJIT->lock);
-  
-  FunctionToStubMapTy &FM = state.getFunctionToStubMap(locked);
-  StubToFunctionMapTy &SM = state.getStubToFunctionMap(locked);
+
   GlobalToIndirectSymMapTy &GM = state.getGlobalToIndirectSymMap(locked);
-  
+
   // Look up the cheap way first, to see if it's a function stub we are
   // invalidating.  If so, remove it from both the forward and reverse maps.
-  if (SM.find(Stub) != SM.end()) {
-    Function *F = SM[Stub];
-    SM.erase(Stub);
-    FM.erase(F);
+  if (Function *F = state.EraseStub(locked, Stub)) {
     return F;
   }
-  
+
   // Otherwise, it might be an indirect symbol stub.  Find it and remove it.
   for (GlobalToIndirectSymMapTy::iterator i = GM.begin(), e = GM.end();
        i != e; ++i) {
@@ -361,14 +456,12 @@
     // JIT lock to be unlocked.
     MutexGuard locked(TheJIT->lock);
 
-    // The address given to us for the stub may not be exactly right, it might be
-    // a little bit after the stub.  As such, use upper_bound to find it.
-    StubToFunctionMapTy::iterator I =
-      JR.state.getStubToFunctionMap(locked).upper_bound(Stub);
-    assert(I != JR.state.getStubToFunctionMap(locked).begin() &&
-           "This is not a known stub!");
-    F = (--I)->second;
-    ActualPtr = I->first;
+    // The address given to us for the stub may not be exactly right, it might
+    // be a little bit after the stub.  As such, use upper_bound to find it.
+    pair<void*, Function*> I =
+      JR.state.LookupFunctionFromCallSite(locked, Stub);
+    F = I.second;
+    ActualPtr = I.first;
   }
 
   // If we have already code generated the function, just return the address.
@@ -383,25 +476,21 @@
                         + F->getName() + "' when lazy compiles are disabled!");
     }
   
-    // We might like to remove the stub from the StubToFunction map.
-    // We can't do that! Multiple threads could be stuck, waiting to acquire the
-    // lock above. As soon as the 1st function finishes compiling the function,
-    // the next one will be released, and needs to be able to find the function
-    // it needs to call.
-    //JR.state.getStubToFunctionMap(locked).erase(I);
-
     DEBUG(errs() << "JIT: Lazily resolving function '" << F->getName()
           << "' In stub ptr = " << Stub << " actual ptr = "
           << ActualPtr << "\n");
 
     Result = TheJIT->getPointerToFunction(F);
   }
-  
-  // Reacquire the lock to erase the stub in the map.
+
+  // Reacquire the lock to update the GOT map.
   MutexGuard locked(TheJIT->lock);
 
-  // We don't need to reuse this stub in the future, as F is now compiled.
-  JR.state.getFunctionToStubMap(locked).erase(F);
+  // We might like to remove the call site from the CallSiteToFunction map, but
+  // we can't do that! Multiple threads could be stuck, waiting to acquire the
+  // lock above. As soon as the 1st function finishes compiling the function,
+  // the next one will be released, and needs to be able to find the function it
+  // needs to call.
 
   // FIXME: We could rewrite all references to this stub if we knew them.
 
@@ -492,6 +581,13 @@
     /// finishFunction.
     JITEvent_EmittedFunctionDetails EmissionDetails;
 
+    struct EmittedCode {
+      void *FunctionBody;
+      void *ExceptionTable;
+      EmittedCode() : FunctionBody(0), ExceptionTable(0) {}
+    };
+    DenseMap<const Function *, EmittedCode> EmittedFunctions;
+
     // CurFnStubUses - For a given Function, a vector of stubs that it
     // references.  This facilitates the JIT detecting that a stub is no
     // longer used, so that it may be deallocated.
@@ -958,7 +1054,8 @@
   BufferBegin = CurBufferPtr = MemMgr->startFunctionBody(F.getFunction(),
                                                          ActualSize);
   BufferEnd = BufferBegin+ActualSize;
-  
+  EmittedFunctions[F.getFunction()].FunctionBody = BufferBegin;
+
   // Ensure the constant pool/jump table info is at least 4-byte aligned.
   emitAlignment(16);
 
@@ -1148,6 +1245,7 @@
     BufferBegin = CurBufferPtr = MemMgr->startExceptionTable(F.getFunction(),
                                                              ActualSize);
     BufferEnd = BufferBegin+ActualSize;
+    EmittedFunctions[F.getFunction()].ExceptionTable = BufferBegin;
     uint8_t *EhStart;
     uint8_t *FrameRegister = DE->EmitDwarfTable(F, *this, FnStart, FnEnd,
                                                 EhStart);
@@ -1191,7 +1289,13 @@
 /// deallocateMemForFunction - Deallocate all memory for the specified
 /// function body.  Also drop any references the function has to stubs.
 void JITEmitter::deallocateMemForFunction(const Function *F) {
-  MemMgr->deallocateMemForFunction(F);
+  DenseMap<const Function *, EmittedCode>::iterator Emitted =
+    EmittedFunctions.find(F);
+  if (Emitted != EmittedFunctions.end()) {
+    MemMgr->deallocateFunctionBody(Emitted->second.FunctionBody);
+    MemMgr->deallocateExceptionTable(Emitted->second.ExceptionTable);
+    EmittedFunctions.erase(Emitted);
+  }
 
   // TODO: Do we need to unregister exception handling information from libgcc
   // here?

Modified: llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITMemoryManager.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITMemoryManager.cpp (original)
+++ llvm/branches/Apple/Leela/lib/ExecutionEngine/JIT/JITMemoryManager.cpp Sun Nov  1 18:01:08 2009
@@ -297,9 +297,6 @@
 
     uint8_t *GOTBase;     // Target Specific reserved memory
     void *DlsymTable;     // Stub external symbol information
-
-    std::map<const Function*, MemoryRangeHeader*> FunctionBlocks;
-    std::map<const Function*, MemoryRangeHeader*> TableBlocks;
   public:
     DefaultJITMemoryManager();
     ~DefaultJITMemoryManager();
@@ -414,7 +411,6 @@
              "Mismatched function start/end!");
 
       uintptr_t BlockSize = FunctionEnd - (uint8_t *)CurBlock;
-      FunctionBlocks[F] = CurBlock;
 
       // Release the memory at the end of this block that isn't needed.
       FreeMemoryList =CurBlock->TrimAllocationToSize(FreeMemoryList, BlockSize);
@@ -464,7 +460,6 @@
              "Mismatched table start/end!");
       
       uintptr_t BlockSize = TableEnd - (uint8_t *)CurBlock;
-      TableBlocks[F] = CurBlock;
 
       // Release the memory at the end of this block that isn't needed.
       FreeMemoryList =CurBlock->TrimAllocationToSize(FreeMemoryList, BlockSize);
@@ -478,15 +473,9 @@
       return DlsymTable;
     }
     
-    /// deallocateMemForFunction - Deallocate all memory for the specified
-    /// function body.
-    void deallocateMemForFunction(const Function *F) {
-      std::map<const Function*, MemoryRangeHeader*>::iterator
-        I = FunctionBlocks.find(F);
-      if (I == FunctionBlocks.end()) return;
-      
+    void deallocateBlock(void *Block) {
       // Find the block that is allocated for this function.
-      MemoryRangeHeader *MemRange = I->second;
+      MemoryRangeHeader *MemRange = static_cast<MemoryRangeHeader*>(Block) - 1;
       assert(MemRange->ThisAllocated && "Block isn't allocated!");
 
       // Fill the buffer with garbage!
@@ -496,27 +485,18 @@
 
       // Free the memory.
       FreeMemoryList = MemRange->FreeBlock(FreeMemoryList);
-      
-      // Finally, remove this entry from FunctionBlocks.
-      FunctionBlocks.erase(I);
-      
-      I = TableBlocks.find(F);
-      if (I == TableBlocks.end()) return;
-      
-      // Find the block that is allocated for this function.
-      MemRange = I->second;
-      assert(MemRange->ThisAllocated && "Block isn't allocated!");
+    }
 
-      // Fill the buffer with garbage!
-      if (PoisonMemory) {
-        memset(MemRange+1, 0xCD, MemRange->BlockSize-sizeof(*MemRange));
-      }
+    /// deallocateFunctionBody - Deallocate all memory for the specified
+    /// function body.
+    void deallocateFunctionBody(void *Body) {
+      deallocateBlock(Body);
+    }
 
-      // Free the memory.
-      FreeMemoryList = MemRange->FreeBlock(FreeMemoryList);
-      
-      // Finally, remove this entry from TableBlocks.
-      TableBlocks.erase(I);
+    /// deallocateExceptionTable - Deallocate memory for the specified
+    /// exception table.
+    void deallocateExceptionTable(void *ET) {
+      deallocateBlock(ET);
     }
 
     /// setMemoryWritable - When code generation is in progress,

Modified: llvm/branches/Apple/Leela/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Linker/LinkModules.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Linker/LinkModules.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Linker/LinkModules.cpp Sun Nov  1 18:01:08 2009
@@ -349,8 +349,7 @@
 
 // RemapOperand - Use ValueMap to convert constants from one module to another.
 static Value *RemapOperand(const Value *In,
-                           std::map<const Value*, Value*> &ValueMap,
-                           LLVMContext &Context) {
+                           std::map<const Value*, Value*> &ValueMap) {
   std::map<const Value*,Value*>::const_iterator I = ValueMap.find(In);
   if (I != ValueMap.end())
     return I->second;
@@ -365,31 +364,29 @@
     if (const ConstantArray *CPA = dyn_cast<ConstantArray>(CPV)) {
       std::vector<Constant*> Operands(CPA->getNumOperands());
       for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
-        Operands[i] =cast<Constant>(RemapOperand(CPA->getOperand(i), ValueMap, 
-                                                 Context));
-      Result =
-          ConstantArray::get(cast<ArrayType>(CPA->getType()), Operands);
+        Operands[i] =cast<Constant>(RemapOperand(CPA->getOperand(i), ValueMap));
+      Result = ConstantArray::get(cast<ArrayType>(CPA->getType()), Operands);
     } else if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(CPV)) {
       std::vector<Constant*> Operands(CPS->getNumOperands());
       for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
-        Operands[i] =cast<Constant>(RemapOperand(CPS->getOperand(i), ValueMap,
-                                                 Context));
-      Result =
-         ConstantStruct::get(cast<StructType>(CPS->getType()), Operands);
+        Operands[i] =cast<Constant>(RemapOperand(CPS->getOperand(i), ValueMap));
+      Result = ConstantStruct::get(cast<StructType>(CPS->getType()), Operands);
     } else if (isa<ConstantPointerNull>(CPV) || isa<UndefValue>(CPV)) {
       Result = const_cast<Constant*>(CPV);
     } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CPV)) {
       std::vector<Constant*> Operands(CP->getNumOperands());
       for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
-        Operands[i] = cast<Constant>(RemapOperand(CP->getOperand(i), ValueMap,
-                                     Context));
+        Operands[i] = cast<Constant>(RemapOperand(CP->getOperand(i), ValueMap));
       Result = ConstantVector::get(Operands);
     } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CPV)) {
       std::vector<Constant*> Ops;
       for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i)
-        Ops.push_back(cast<Constant>(RemapOperand(CE->getOperand(i),ValueMap,
-                                     Context)));
+        Ops.push_back(cast<Constant>(RemapOperand(CE->getOperand(i),ValueMap)));
       Result = CE->getWithOperands(Ops);
+    } else if (const BlockAddress *CE = dyn_cast<BlockAddress>(CPV)) {
+      Result = BlockAddress::get(
+                 cast<Function>(RemapOperand(CE->getFunction(), ValueMap)),
+                                 CE->getBasicBlock());
     } else {
       assert(!isa<GlobalValue>(CPV) && "Unmapped global?");
       llvm_unreachable("Unknown type of derived type constant value!");
@@ -896,8 +893,7 @@
     if (SGV->hasInitializer()) {      // Only process initialized GV's
       // Figure out what the initializer looks like in the dest module...
       Constant *SInit =
-        cast<Constant>(RemapOperand(SGV->getInitializer(), ValueMap,
-                       Dest->getContext()));
+        cast<Constant>(RemapOperand(SGV->getInitializer(), ValueMap));
       // Grab destination global variable or alias.
       GlobalValue *DGV = cast<GlobalValue>(ValueMap[SGV]->stripPointerCasts());
 
@@ -1084,7 +1080,7 @@
       for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end();
            OI != OE; ++OI)
         if (!isa<Instruction>(*OI) && !isa<BasicBlock>(*OI))
-          *OI = RemapOperand(*OI, ValueMap, Dest->getContext());
+          *OI = RemapOperand(*OI, ValueMap);
 
   // There is no need to map the arguments anymore.
   for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end();

Modified: llvm/branches/Apple/Leela/lib/MC/MCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/MC/MCAsmInfo.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/MC/MCAsmInfo.cpp (original)
+++ llvm/branches/Apple/Leela/lib/MC/MCAsmInfo.cpp Sun Nov  1 18:01:08 2009
@@ -13,7 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/MC/MCAsmInfo.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <cctype>
 #include <cstring>
 using namespace llvm;

Modified: llvm/branches/Apple/Leela/lib/Support/Allocator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Support/Allocator.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Support/Allocator.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Support/Allocator.cpp Sun Nov  1 18:01:08 2009
@@ -12,7 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Support/Allocator.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/Recycler.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Memory.h"

Modified: llvm/branches/Apple/Leela/lib/System/Unix/Memory.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/System/Unix/Memory.inc?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/System/Unix/Memory.inc (original)
+++ llvm/branches/Apple/Leela/lib/System/Unix/Memory.inc Sun Nov  1 18:01:08 2009
@@ -12,7 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Unix.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/System/Process.h"
 
 #ifdef HAVE_SYS_MMAN_H

Modified: llvm/branches/Apple/Leela/lib/System/Win32/Memory.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/System/Win32/Memory.inc?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/System/Win32/Memory.inc (original)
+++ llvm/branches/Apple/Leela/lib/System/Win32/Memory.inc Sun Nov  1 18:01:08 2009
@@ -13,7 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Win32.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/System/Process.h"
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/lib/Target/CBackend/CBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/CBackend/CBackend.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/CBackend/CBackend.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Target/CBackend/CBackend.cpp Sun Nov  1 18:01:08 2009
@@ -282,7 +282,7 @@
     void visitReturnInst(ReturnInst &I);
     void visitBranchInst(BranchInst &I);
     void visitSwitchInst(SwitchInst &I);
-    void visitIndBrInst(IndBrInst &I);
+    void visitIndirectBrInst(IndirectBrInst &I);
     void visitInvokeInst(InvokeInst &I) {
       llvm_unreachable("Lowerinvoke pass didn't work!");
     }
@@ -2581,7 +2581,7 @@
   Out << "  }\n";
 }
 
-void CWriter::visitIndBrInst(IndBrInst &IBI) {
+void CWriter::visitIndirectBrInst(IndirectBrInst &IBI) {
   Out << "  goto *(void*)(";
   writeOperand(IBI.getOperand(0));
   Out << ");\n";

Modified: llvm/branches/Apple/Leela/lib/Target/CellSPU/SPU.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/CellSPU/SPU.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/CellSPU/SPU.h (original)
+++ llvm/branches/Apple/Leela/lib/Target/CellSPU/SPU.h Sun Nov  1 18:01:08 2009
@@ -15,7 +15,7 @@
 #ifndef LLVM_TARGET_IBMCELLSPU_H
 #define LLVM_TARGET_IBMCELLSPU_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Target/TargetMachine.h"
 
 namespace llvm {

Modified: llvm/branches/Apple/Leela/lib/Target/CppBackend/CPPBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/CppBackend/CPPBackend.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/CppBackend/CPPBackend.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Target/CppBackend/CPPBackend.cpp Sun Nov  1 18:01:08 2009
@@ -1132,9 +1132,9 @@
       }
       break;
     }
-    case Instruction::IndBr: {
-      const IndBrInst *IBI = cast<IndBrInst>(I);
-      Out << "IndBrInst *" << iName << " = IndBrInst::Create("
+    case Instruction::IndirectBr: {
+      const IndirectBrInst *IBI = cast<IndirectBrInst>(I);
+      Out << "IndirectBrInst *" << iName << " = IndirectBrInst::Create("
           << opNames[0] << ", " << IBI->getNumDestinations() << ");";
       nl(Out);
       for (unsigned i = 1; i != IBI->getNumOperands(); ++i) {

Modified: llvm/branches/Apple/Leela/lib/Target/MSIL/MSILWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/MSIL/MSILWriter.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/MSIL/MSILWriter.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Target/MSIL/MSILWriter.cpp Sun Nov  1 18:01:08 2009
@@ -1535,7 +1535,7 @@
   case Type::StructTyID:
     for (unsigned I = 0, E = C->getNumOperands(); I<E; I++) {
       if (I!=0) Out << ",\n";
-      printStaticConstant(C->getOperand(I),Offset);
+      printStaticConstant(cast<Constant>(C->getOperand(I)), Offset);
     }
     break;
   case Type::PointerTyID:

Modified: llvm/branches/Apple/Leela/lib/Target/TargetIntrinsicInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/TargetIntrinsicInfo.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/TargetIntrinsicInfo.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Target/TargetIntrinsicInfo.cpp Sun Nov  1 18:01:08 2009
@@ -12,11 +12,19 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Target/TargetIntrinsicInfo.h"
+#include "llvm/Function.h"
+#include "llvm/ADT/StringMap.h"
 using namespace llvm;
 
-TargetIntrinsicInfo::TargetIntrinsicInfo(const char **desc, unsigned count)
-  : Intrinsics(desc), NumIntrinsics(count) {
+TargetIntrinsicInfo::TargetIntrinsicInfo() {
 }
 
 TargetIntrinsicInfo::~TargetIntrinsicInfo() {
 }
+
+unsigned TargetIntrinsicInfo::getIntrinsicID(Function *F) const {
+  const ValueName *ValName = F->getValueName();
+  if (!ValName)
+    return 0;
+  return lookupName(ValName->getKeyData(), ValName->getKeyLength());
+}

Modified: llvm/branches/Apple/Leela/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp Sun Nov  1 18:01:08 2009
@@ -329,6 +329,10 @@
     case MachineOperand::MO_ConstantPoolIndex:
       MCOp = LowerSymbolOperand(MO, GetConstantPoolIndexSymbol(MO));
       break;
+    case MachineOperand::MO_BlockAddress:
+      MCOp = LowerSymbolOperand(MO, AsmPrinter.GetBlockAddressSymbol(
+                                                 MO.getBlockAddress()));
+      break;
     }
     
     OutMI.addOperand(MCOp);

Modified: llvm/branches/Apple/Leela/lib/Target/X86/X86ISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/X86/X86ISelDAGToDAG.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/X86/X86ISelDAGToDAG.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Target/X86/X86ISelDAGToDAG.cpp Sun Nov  1 18:01:08 2009
@@ -72,6 +72,7 @@
     SDValue Segment;
     GlobalValue *GV;
     Constant *CP;
+    BlockAddress *BlockAddr;
     const char *ES;
     int JT;
     unsigned Align;    // CP alignment.
@@ -79,12 +80,12 @@
 
     X86ISelAddressMode()
       : BaseType(RegBase), Scale(1), IndexReg(), Disp(0),
-        Segment(), GV(0), CP(0), ES(0), JT(-1), Align(0),
+        Segment(), GV(0), CP(0), BlockAddr(0), ES(0), JT(-1), Align(0),
         SymbolFlags(X86II::MO_NO_FLAG) {
     }
 
     bool hasSymbolicDisplacement() const {
-      return GV != 0 || CP != 0 || ES != 0 || JT != -1;
+      return GV != 0 || CP != 0 || ES != 0 || JT != -1 || BlockAddr != 0;
     }
     
     bool hasBaseOrIndexReg() const {
@@ -242,6 +243,9 @@
         Disp = CurDAG->getTargetExternalSymbol(AM.ES, MVT::i32, AM.SymbolFlags);
       else if (AM.JT != -1)
         Disp = CurDAG->getTargetJumpTable(AM.JT, MVT::i32, AM.SymbolFlags);
+      else if (AM.BlockAddr)
+        Disp = CurDAG->getBlockAddress(AM.BlockAddr, DebugLoc()/*MVT::i32*/,
+                                       true /*AM.SymbolFlags*/);
       else
         Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i32);
 
@@ -761,10 +765,12 @@
     } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(N0)) {
       AM.ES = S->getSymbol();
       AM.SymbolFlags = S->getTargetFlags();
-    } else {
-      JumpTableSDNode *J = cast<JumpTableSDNode>(N0);
+    } else if (JumpTableSDNode *J = dyn_cast<JumpTableSDNode>(N0)) {
       AM.JT = J->getIndex();
       AM.SymbolFlags = J->getTargetFlags();
+    } else {
+      AM.BlockAddr = cast<BlockAddressSDNode>(N0)->getBlockAddress();
+      //AM.SymbolFlags = cast<BlockAddressSDNode>(N0)->getTargetFlags();
     }
 
     if (N.getOpcode() == X86ISD::WrapperRIP)
@@ -790,10 +796,12 @@
     } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(N0)) {
       AM.ES = S->getSymbol();
       AM.SymbolFlags = S->getTargetFlags();
-    } else {
-      JumpTableSDNode *J = cast<JumpTableSDNode>(N0);
+    } else if (JumpTableSDNode *J = dyn_cast<JumpTableSDNode>(N0)) {
       AM.JT = J->getIndex();
       AM.SymbolFlags = J->getTargetFlags();
+    } else {
+      AM.BlockAddr = cast<BlockAddressSDNode>(N0)->getBlockAddress();
+      //AM.SymbolFlags = cast<BlockAddressSDNode>(N0)->getTargetFlags();
     }
     return false;
   }

Modified: llvm/branches/Apple/Leela/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/X86/X86ISelLowering.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Target/X86/X86ISelLowering.cpp Sun Nov  1 18:01:08 2009
@@ -328,11 +328,13 @@
   if (Subtarget->is64Bit())
     setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom);
   setOperationAction(ISD::ExternalSymbol  , MVT::i32  , Custom);
+  setOperationAction(ISD::BlockAddress    , MVT::i32  , Custom);
   if (Subtarget->is64Bit()) {
     setOperationAction(ISD::ConstantPool  , MVT::i64  , Custom);
     setOperationAction(ISD::JumpTable     , MVT::i64  , Custom);
     setOperationAction(ISD::GlobalAddress , MVT::i64  , Custom);
     setOperationAction(ISD::ExternalSymbol, MVT::i64  , Custom);
+    setOperationAction(ISD::BlockAddress  , MVT::i64  , Custom);
   }
   // 64-bit addm sub, shl, sra, srl (iff 32-bit x86)
   setOperationAction(ISD::SHL_PARTS       , MVT::i32  , Custom);
@@ -4693,6 +4695,24 @@
 }
 
 SDValue
+X86TargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) {
+  unsigned WrapperKind = X86ISD::Wrapper;
+  CodeModel::Model M = getTargetMachine().getCodeModel();
+  if (Subtarget->isPICStyleRIPRel() &&
+      (M == CodeModel::Small || M == CodeModel::Kernel))
+    WrapperKind = X86ISD::WrapperRIP;
+
+  DebugLoc DL = Op.getDebugLoc();
+
+  BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress();
+  SDValue Result = DAG.getBlockAddress(BA, DL, /*isTarget=*/true);
+
+  Result = DAG.getNode(WrapperKind, DL, getPointerTy(), Result);
+
+  return Result;
+}
+
+SDValue
 X86TargetLowering::LowerGlobalAddress(const GlobalValue *GV, DebugLoc dl,
                                       int64_t Offset,
                                       SelectionDAG &DAG) const {
@@ -7019,6 +7039,7 @@
   case ISD::GlobalAddress:      return LowerGlobalAddress(Op, DAG);
   case ISD::GlobalTLSAddress:   return LowerGlobalTLSAddress(Op, DAG);
   case ISD::ExternalSymbol:     return LowerExternalSymbol(Op, DAG);
+  case ISD::BlockAddress:       return LowerBlockAddress(Op, DAG);
   case ISD::SHL_PARTS:
   case ISD::SRA_PARTS:
   case ISD::SRL_PARTS:          return LowerShift(Op, DAG);

Modified: llvm/branches/Apple/Leela/lib/Target/X86/X86ISelLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/X86/X86ISelLowering.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/X86/X86ISelLowering.h (original)
+++ llvm/branches/Apple/Leela/lib/Target/X86/X86ISelLowering.h Sun Nov  1 18:01:08 2009
@@ -635,6 +635,7 @@
     SDValue LowerINSERT_VECTOR_ELT_SSE4(SDValue Op, SelectionDAG &DAG);
     SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG);
     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG);
+    SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG);
     SDValue LowerGlobalAddress(const GlobalValue *GV, DebugLoc dl,
                                int64_t Offset, SelectionDAG &DAG) const;
     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG);

Modified: llvm/branches/Apple/Leela/lib/Target/X86/X86Instr64bit.td
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/X86/X86Instr64bit.td?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/X86/X86Instr64bit.td (original)
+++ llvm/branches/Apple/Leela/lib/Target/X86/X86Instr64bit.td Sun Nov  1 18:01:08 2009
@@ -1602,6 +1602,8 @@
           (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
           (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
+def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
+          (MOV64ri tblockaddress:$dst)>, Requires<[FarData]>;
 
 // In static codegen with small code model, we can get the address of a label
 // into a register with 'movl'.  FIXME: This is a hack, the 'imm' predicate of
@@ -1614,6 +1616,8 @@
           (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
           (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
+def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
+          (MOV64ri64i32 tblockaddress:$dst)>, Requires<[SmallCode]>;
 
 // In kernel code model, we can get the address of a label
 // into a register with 'movq'.  FIXME: This is a hack, the 'imm' predicate of
@@ -1626,6 +1630,8 @@
           (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
 def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
           (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
+def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
+          (MOV64ri32 tblockaddress:$dst)>, Requires<[KernelCode]>;
 
 // If we have small model and -static mode, it is safe to store global addresses
 // directly as immediates.  FIXME: This is really a hack, the 'imm' predicate
@@ -1642,6 +1648,9 @@
 def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
           (MOV64mi32 addr:$dst, texternalsym:$src)>,
           Requires<[NearData, IsStatic]>;
+def : Pat<(store (i64 (X86Wrapper tblockaddress:$src)), addr:$dst),
+          (MOV64mi32 addr:$dst, tblockaddress:$src)>,
+          Requires<[NearData, IsStatic]>;
 
 // Calls
 // Direct PC relative function call for small code model. 32-bit displacement

Modified: llvm/branches/Apple/Leela/lib/Target/X86/X86InstrInfo.td
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/X86/X86InstrInfo.td?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/X86/X86InstrInfo.td (original)
+++ llvm/branches/Apple/Leela/lib/Target/X86/X86InstrInfo.td Sun Nov  1 18:01:08 2009
@@ -3794,6 +3794,7 @@
 def : Pat<(i32 (X86Wrapper tglobaltlsaddr:$dst)),(MOV32ri tglobaltlsaddr:$dst)>;
 def : Pat<(i32 (X86Wrapper tglobaladdr :$dst)), (MOV32ri tglobaladdr :$dst)>;
 def : Pat<(i32 (X86Wrapper texternalsym:$dst)), (MOV32ri texternalsym:$dst)>;
+def : Pat<(i32 (X86Wrapper tblockaddress:$dst)), (MOV32ri tblockaddress:$dst)>;
 
 def : Pat<(add GR32:$src1, (X86Wrapper tconstpool:$src2)),
           (ADD32ri GR32:$src1, tconstpool:$src2)>;
@@ -3803,11 +3804,15 @@
           (ADD32ri GR32:$src1, tglobaladdr:$src2)>;
 def : Pat<(add GR32:$src1, (X86Wrapper texternalsym:$src2)),
           (ADD32ri GR32:$src1, texternalsym:$src2)>;
+def : Pat<(add GR32:$src1, (X86Wrapper tblockaddress:$src2)),
+          (ADD32ri GR32:$src1, tblockaddress:$src2)>;
 
 def : Pat<(store (i32 (X86Wrapper tglobaladdr:$src)), addr:$dst),
           (MOV32mi addr:$dst, tglobaladdr:$src)>;
 def : Pat<(store (i32 (X86Wrapper texternalsym:$src)), addr:$dst),
           (MOV32mi addr:$dst, texternalsym:$src)>;
+def : Pat<(store (i32 (X86Wrapper tblockaddress:$src)), addr:$dst),
+          (MOV32mi addr:$dst, tblockaddress:$src)>;
 
 // Calls
 // tailcall stuff

Modified: llvm/branches/Apple/Leela/lib/Transforms/IPO/GlobalDCE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/IPO/GlobalDCE.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/IPO/GlobalDCE.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/IPO/GlobalDCE.cpp Sun Nov  1 18:01:08 2009
@@ -192,13 +192,13 @@
 
 void GlobalDCE::MarkUsedGlobalsAsNeeded(Constant *C) {
   if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
-    GlobalIsNeeded(GV);
-  else {
-    // Loop over all of the operands of the constant, adding any globals they
-    // use to the list of needed globals.
-    for (User::op_iterator I = C->op_begin(), E = C->op_end(); I != E; ++I)
-      MarkUsedGlobalsAsNeeded(cast<Constant>(*I));
-  }
+    return GlobalIsNeeded(GV);
+  
+  // Loop over all of the operands of the constant, adding any globals they
+  // use to the list of needed globals.
+  for (User::op_iterator I = C->op_begin(), E = C->op_end(); I != E; ++I)
+    if (Constant *OpC = dyn_cast<Constant>(*I))
+      MarkUsedGlobalsAsNeeded(OpC);
 }
 
 // RemoveUnusedGlobalValue - Loop over all of the uses of the specified

Modified: llvm/branches/Apple/Leela/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/IPO/GlobalOpt.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/IPO/GlobalOpt.cpp Sun Nov  1 18:01:08 2009
@@ -2734,6 +2734,12 @@
           dyn_cast<ConstantInt>(getVal(Values, SI->getCondition()));
         if (!Val) return false;  // Cannot determine.
         NewBB = SI->getSuccessor(SI->findCaseValue(Val));
+      } else if (IndirectBrInst *IBI = dyn_cast<IndirectBrInst>(CurInst)) {
+        Value *Val = getVal(Values, IBI->getAddress())->stripPointerCasts();
+        if (BlockAddress *BA = dyn_cast<BlockAddress>(Val))
+          NewBB = BA->getBasicBlock();
+        else
+          return false;  // Cannot determine.
       } else if (ReturnInst *RI = dyn_cast<ReturnInst>(CurInst)) {
         if (RI->getNumOperands())
           RetVal = getVal(Values, RI->getOperand(0));

Modified: llvm/branches/Apple/Leela/lib/Transforms/IPO/StripSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/IPO/StripSymbols.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/IPO/StripSymbols.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/IPO/StripSymbols.cpp Sun Nov  1 18:01:08 2009
@@ -112,11 +112,11 @@
 
 static void RemoveDeadConstant(Constant *C) {
   assert(C->use_empty() && "Constant is not dead!");
-  SmallPtrSet<Constant *, 4> Operands;
+  SmallPtrSet<Constant*, 4> Operands;
   for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
     if (isa<DerivedType>(C->getOperand(i)->getType()) &&
         OnlyUsedBy(C->getOperand(i), C)) 
-      Operands.insert(C->getOperand(i));
+      Operands.insert(cast<Constant>(C->getOperand(i)));
   if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
     if (!GV->hasLocalLinkage()) return;   // Don't delete non static globals.
     GV->eraseFromParent();
@@ -126,7 +126,7 @@
       C->destroyConstant();
 
   // If the constant referenced anything, see if we can delete it as well.
-  for (SmallPtrSet<Constant *, 4>::iterator OI = Operands.begin(),
+  for (SmallPtrSet<Constant*, 4>::iterator OI = Operands.begin(),
          OE = Operands.end(); OI != OE; ++OI)
     RemoveDeadConstant(*OI);
 }
@@ -305,8 +305,7 @@
     if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
       if (GV->hasLocalLinkage())
         RemoveDeadConstant(GV);
-    }
-    else
+    } else
       RemoveDeadConstant(C);
   }
 

Modified: llvm/branches/Apple/Leela/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Scalar/CodeGenPrepare.cpp Sun Nov  1 18:01:08 2009
@@ -318,6 +318,7 @@
     if (Invoke->getSuccessor(1) == Dest)
       return;
   }
+  
 
   // As a hack, never split backedges of loops.  Even though the copy for any
   // PHIs inserted on the backedge would be dead for exits from the loop, we
@@ -852,7 +853,7 @@
 
   // Split all critical edges where the dest block has a PHI.
   TerminatorInst *BBTI = BB.getTerminator();
-  if (BBTI->getNumSuccessors() > 1) {
+  if (BBTI->getNumSuccessors() > 1 && !isa<IndirectBrInst>(BBTI)) {
     for (unsigned i = 0, e = BBTI->getNumSuccessors(); i != e; ++i) {
       BasicBlock *SuccBB = BBTI->getSuccessor(i);
       if (isa<PHINode>(SuccBB->begin()) && isCriticalEdge(BBTI, i, true))

Modified: llvm/branches/Apple/Leela/lib/Transforms/Scalar/CondPropagate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Scalar/CondPropagate.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Scalar/CondPropagate.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Scalar/CondPropagate.cpp Sun Nov  1 18:01:08 2009
@@ -196,18 +196,20 @@
   // possible, and to avoid invalidating "i".
   for (unsigned i = PN->getNumIncomingValues(); i != 0; --i)
     if (ConstantInt *CI = dyn_cast<ConstantInt>(PN->getIncomingValue(i-1))) {
-      // If we have a constant, forward the edge from its current to its
-      // ultimate destination.
-      unsigned DestCase = SI->findCaseValue(CI);
-      RevectorBlockTo(PN->getIncomingBlock(i-1),
-                      SI->getSuccessor(DestCase));
-      ++NumSwThread;
-
-      // If there were two predecessors before this simplification, or if the
-      // PHI node contained all the same value except for the one we just
-      // substituted, the PHI node may be deleted.  Don't iterate through it the
-      // last time.
-      if (SI->getCondition() != PN) return;
+      BasicBlock *PredBB = PN->getIncomingBlock(i-1);
+      if (isa<BranchInst>(PredBB->getTerminator())) {
+        // If we have a constant, forward the edge from its current to its
+        // ultimate destination.
+        unsigned DestCase = SI->findCaseValue(CI);
+        RevectorBlockTo(PredBB, SI->getSuccessor(DestCase));
+        ++NumSwThread;
+
+        // If there were two predecessors before this simplification, or if the
+        // PHI node contained all the same value except for the one we just
+        // substituted, the PHI node may be deleted.  Don't iterate through it the
+        // last time.
+        if (SI->getCondition() != PN) return;
+      }
     }
 }
 

Modified: llvm/branches/Apple/Leela/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Scalar/GVN.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Scalar/GVN.cpp Sun Nov  1 18:01:08 2009
@@ -1809,7 +1809,7 @@
 
 /// performPRE - Perform a purely local form of PRE that looks for diamond
 /// control flow patterns and attempts to perform simple PRE at the join point.
-bool GVN::performPRE(Function& F) {
+bool GVN::performPRE(Function &F) {
   bool Changed = false;
   SmallVector<std::pair<TerminatorInst*, unsigned>, 4> toSplit;
   DenseMap<BasicBlock*, Value*> predMap;
@@ -1874,6 +1874,10 @@
       // we would need to insert instructions in more than one pred.
       if (NumWithout != 1 || NumWith == 0)
         continue;
+      
+      // Don't do PRE across indirect branch.
+      if (isa<IndirectBrInst>(PREPred->getTerminator()))
+        continue;
 
       // We can't do PRE safely on a critical edge, so instead we schedule
       // the edge to be split and perform the PRE the next time we iterate

Modified: llvm/branches/Apple/Leela/lib/Transforms/Scalar/LoopUnswitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Scalar/LoopUnswitch.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Scalar/LoopUnswitch.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Scalar/LoopUnswitch.cpp Sun Nov  1 18:01:08 2009
@@ -34,6 +34,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/Analysis/ConstantFolding.h"
+#include "llvm/Analysis/InlineCost.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/LoopPass.h"
 #include "llvm/Analysis/Dominators.h"
@@ -56,9 +57,11 @@
 STATISTIC(NumTrivial , "Number of unswitches that are trivial");
 STATISTIC(NumSimplify, "Number of simplifications of unswitched code");
 
+// The specific value of 50 here was chosen based only on intuition and a
+// few specific examples.
 static cl::opt<unsigned>
 Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"),
-          cl::init(10), cl::Hidden);
+          cl::init(50), cl::Hidden);
   
 namespace {
   class LoopUnswitch : public LoopPass {
@@ -135,7 +138,6 @@
     void SplitExitEdges(Loop *L, const SmallVector<BasicBlock *, 8> &ExitBlocks);
 
     bool UnswitchIfProfitable(Value *LoopCond, Constant *Val);
-    unsigned getLoopUnswitchCost(Value *LIC);
     void UnswitchTrivialCondition(Loop *L, Value *Cond, Constant *Val,
                                   BasicBlock *ExitBlock);
     void UnswitchNontrivialCondition(Value *LIC, Constant *OnVal, Loop *L);
@@ -397,40 +399,6 @@
   return true;
 }
 
-/// getLoopUnswitchCost - Return the cost (code size growth) that will happen if
-/// we choose to unswitch current loop on the specified value.
-///
-unsigned LoopUnswitch::getLoopUnswitchCost(Value *LIC) {
-  // If the condition is trivial, always unswitch.  There is no code growth for
-  // this case.
-  if (IsTrivialUnswitchCondition(LIC))
-    return 0;
-  
-  // FIXME: This is really overly conservative.  However, more liberal 
-  // estimations have thus far resulted in excessive unswitching, which is bad
-  // both in compile time and in code size.  This should be replaced once
-  // someone figures out how a good estimation.
-  return currentLoop->getBlocks().size();
-  
-  unsigned Cost = 0;
-  // FIXME: this is brain dead.  It should take into consideration code
-  // shrinkage.
-  for (Loop::block_iterator I = currentLoop->block_begin(), 
-         E = currentLoop->block_end();
-       I != E; ++I) {
-    BasicBlock *BB = *I;
-    // Do not include empty blocks in the cost calculation.  This happen due to
-    // loop canonicalization and will be removed.
-    if (BB->begin() == BasicBlock::iterator(BB->getTerminator()))
-      continue;
-    
-    // Count basic blocks.
-    ++Cost;
-  }
-
-  return Cost;
-}
-
 /// UnswitchIfProfitable - We have found that we can unswitch currentLoop when
 /// LoopCond == Val to simplify the loop.  If we decide that this is profitable,
 /// unswitch the loop, reprocess the pieces, then return true.
@@ -439,24 +407,36 @@
   initLoopData();
   Function *F = loopHeader->getParent();
 
+  // If the condition is trivial, always unswitch.  There is no code growth for
+  // this case.
+  if (!IsTrivialUnswitchCondition(LoopCond)) {
+    // Check to see if it would be profitable to unswitch current loop.
 
-  // Check to see if it would be profitable to unswitch current loop.
-  unsigned Cost = getLoopUnswitchCost(LoopCond);
+    // Do not do non-trivial unswitch while optimizing for size.
+    if (OptimizeForSize || F->hasFnAttr(Attribute::OptimizeForSize))
+      return false;
 
-  // Do not do non-trivial unswitch while optimizing for size.
-  if (Cost && OptimizeForSize)
-    return false;
-  if (Cost && !F->isDeclaration() && F->hasFnAttr(Attribute::OptimizeForSize))
-    return false;
-
-  if (Cost > Threshold) {
-    // FIXME: this should estimate growth by the amount of code shared by the
-    // resultant unswitched loops.
-    //
-    DEBUG(errs() << "NOT unswitching loop %"
-          << currentLoop->getHeader()->getName() << ", cost too high: "
-          << currentLoop->getBlocks().size() << "\n");
-    return false;
+    // FIXME: This is overly conservative because it does not take into
+    // consideration code simplification opportunities and code that can
+    // be shared by the resultant unswitched loops.
+    CodeMetrics Metrics;
+    for (Loop::block_iterator I = currentLoop->block_begin(), 
+           E = currentLoop->block_end();
+         I != E; ++I)
+      Metrics.analyzeBasicBlock(*I);
+
+    // Limit the number of instructions to avoid causing significant code
+    // expansion, and the number of basic blocks, to avoid loops with
+    // large numbers of branches which cause loop unswitching to go crazy.
+    // This is a very ad-hoc heuristic.
+    if (Metrics.NumInsts > Threshold ||
+        Metrics.NumBlocks * 5 > Threshold ||
+        Metrics.NeverInline) {
+      DEBUG(errs() << "NOT unswitching loop %"
+            << currentLoop->getHeader()->getName() << ", cost too high: "
+            << currentLoop->getBlocks().size() << "\n");
+      return false;
+    }
   }
 
   Constant *CondVal;
@@ -795,7 +775,7 @@
     // uses replaced with undefs.
     // If I is not void type then replaceAllUsesWith undef.
     // This allows ValueHandlers and custom metadata to adjust itself.
-    if (I->getType() != Type::getVoidTy(I->getContext()))
+    if (!I->getType()->isVoidTy())
       I->replaceAllUsesWith(UndefValue::get(I->getType()));
   }
   

Modified: llvm/branches/Apple/Leela/lib/Transforms/Scalar/SCCP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Scalar/SCCP.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Scalar/SCCP.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Scalar/SCCP.cpp Sun Nov  1 18:01:08 2009
@@ -446,10 +446,16 @@
         Succs[BCValue.getConstant() == ConstantInt::getFalse(*Context)] = true;
       }
     }
-  } else if (isa<InvokeInst>(&TI)) {
+    return;
+  }
+  
+  if (isa<InvokeInst>(&TI)) {
     // Invoke instructions successors are always executable.
     Succs[0] = Succs[1] = true;
-  } else if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) {
+    return;
+  }
+  
+  if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) {
     LatticeVal &SCValue = getValueState(SI->getCondition());
     if (SCValue.isOverdefined() ||   // Overdefined condition?
         (SCValue.isConstant() && !isa<ConstantInt>(SCValue.getConstant()))) {
@@ -457,9 +463,20 @@
       Succs.assign(TI.getNumSuccessors(), true);
     } else if (SCValue.isConstant())
       Succs[SI->findCaseValue(cast<ConstantInt>(SCValue.getConstant()))] = true;
-  } else {
-    llvm_unreachable("SCCP: Don't know how to handle this terminator!");
+    return;
   }
+  
+  // TODO: This could be improved if the operand is a [cast of a] BlockAddress.
+  if (isa<IndirectBrInst>(&TI)) {
+    // Just mark all destinations executable!
+    Succs.assign(TI.getNumSuccessors(), true);
+    return;
+  }
+  
+#ifndef NDEBUG
+  errs() << "Unknown terminator instruction: " << TI << '\n';
+#endif
+  llvm_unreachable("SCCP: Don't know how to handle this terminator!");
 }
 
 
@@ -477,25 +494,27 @@
   if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
     if (BI->isUnconditional())
       return true;
-    else {
-      LatticeVal &BCValue = getValueState(BI->getCondition());
-      if (BCValue.isOverdefined()) {
-        // Overdefined condition variables mean the branch could go either way.
-        return true;
-      } else if (BCValue.isConstant()) {
-        // Not branching on an evaluatable constant?
-        if (!isa<ConstantInt>(BCValue.getConstant())) return true;
-
-        // Constant condition variables mean the branch can only go a single way
-        return BI->getSuccessor(BCValue.getConstant() ==
-                                       ConstantInt::getFalse(*Context)) == To;
-      }
-      return false;
+    
+    LatticeVal &BCValue = getValueState(BI->getCondition());
+    if (BCValue.isOverdefined()) {
+      // Overdefined condition variables mean the branch could go either way.
+      return true;
+    } else if (BCValue.isConstant()) {
+      // Not branching on an evaluatable constant?
+      if (!isa<ConstantInt>(BCValue.getConstant())) return true;
+
+      // Constant condition variables mean the branch can only go a single way
+      return BI->getSuccessor(BCValue.getConstant() ==
+                                     ConstantInt::getFalse(*Context)) == To;
     }
-  } else if (isa<InvokeInst>(TI)) {
-    // Invoke instructions successors are always executable.
+    return false;
+  }
+  
+  // Invoke instructions successors are always executable.
+  if (isa<InvokeInst>(TI))
     return true;
-  } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
+  
+  if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
     LatticeVal &SCValue = getValueState(SI->getCondition());
     if (SCValue.isOverdefined()) {  // Overdefined condition?
       // All destinations are executable!
@@ -515,12 +534,17 @@
       return SI->getDefaultDest() == To;
     }
     return false;
-  } else {
+  }
+  
+  // Just mark all destinations executable!
+  // TODO: This could be improved if the operand is a [cast of a] BlockAddress.
+  if (isa<IndirectBrInst>(&TI))
+    return true;
+  
 #ifndef NDEBUG
-    errs() << "Unknown terminator instruction: " << *TI << '\n';
+  errs() << "Unknown terminator instruction: " << *TI << '\n';
 #endif
-    llvm_unreachable(0);
-  }
+  llvm_unreachable(0);
 }
 
 // visit Implementations - Something changed in this instruction... Either an

Modified: llvm/branches/Apple/Leela/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Utils/BasicBlockUtils.cpp Sun Nov  1 18:01:08 2009
@@ -97,10 +97,14 @@
 
 /// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
 /// if possible.  The return value indicates success or failure.
-bool llvm::MergeBlockIntoPredecessor(BasicBlock* BB, Pass* P) {
+bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
   pred_iterator PI(pred_begin(BB)), PE(pred_end(BB));
-  // Can't merge the entry block.
-  if (pred_begin(BB) == pred_end(BB)) return false;
+  // Can't merge the entry block.  Don't merge away blocks who have their
+  // address taken: this is a bug if the predecessor block is the entry node
+  // (because we'd end up taking the address of the entry) and undesirable in
+  // any case.
+  if (pred_begin(BB) == pred_end(BB) ||
+      BB->hasAddressTaken()) return false;
   
   BasicBlock *PredBB = *PI++;
   for (; PI != PE; ++PI)  // Search all predecessors, see if they are all same
@@ -274,6 +278,8 @@
 /// SplitEdge -  Split the edge connecting specified block. Pass P must 
 /// not be NULL. 
 BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, Pass *P) {
+  assert(!isa<IndirectBrInst>(BB->getTerminator()) &&
+         "Cannot split an edge from an IndirectBrInst");
   TerminatorInst *LatchTerm = BB->getTerminator();
   unsigned SuccNum = 0;
 #ifndef NDEBUG

Modified: llvm/branches/Apple/Leela/lib/Transforms/Utils/BreakCriticalEdges.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Utils/BreakCriticalEdges.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Utils/BreakCriticalEdges.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Utils/BreakCriticalEdges.cpp Sun Nov  1 18:01:08 2009
@@ -70,7 +70,7 @@
   bool Changed = false;
   for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
     TerminatorInst *TI = I->getTerminator();
-    if (TI->getNumSuccessors() > 1)
+    if (TI->getNumSuccessors() > 1 && !isa<IndirectBrInst>(TI))
       for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
         if (SplitCriticalEdge(TI, i, this)) {
           ++NumBroken;
@@ -151,14 +151,29 @@
 
 /// SplitCriticalEdge - If this edge is a critical edge, insert a new node to
 /// split the critical edge.  This will update DominatorTree and
-/// DominatorFrontier  information if it is available, thus calling this pass
-/// will not invalidate  any of them.  This returns true if the edge was split,
-/// false otherwise.  This ensures that all edges to that dest go to one block
-/// instead of each going to a different block.
-//
+/// DominatorFrontier information if it is available, thus calling this pass
+/// will not invalidate either of them. This returns the new block if the edge
+/// was split, null otherwise.
+///
+/// If MergeIdenticalEdges is true (not the default), *all* edges from TI to the
+/// specified successor will be merged into the same critical edge block.  
+/// This is most commonly interesting with switch instructions, which may 
+/// have many edges to any one destination.  This ensures that all edges to that
+/// dest go to one block instead of each going to a different block, but isn't 
+/// the standard definition of a "critical edge".
+///
+/// It is invalid to call this function on a critical edge that starts at an
+/// IndirectBrInst.  Splitting these edges will almost always create an invalid
+/// program because the address of the new block won't be the one that is jumped
+/// to.
+///
 BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
                                     Pass *P, bool MergeIdenticalEdges) {
   if (!isCriticalEdge(TI, SuccNum, MergeIdenticalEdges)) return 0;
+  
+  assert(!isa<IndirectBrInst>(TI) &&
+         "Cannot split critical edge from IndirectBrInst");
+  
   BasicBlock *TIBB = TI->getParent();
   BasicBlock *DestBB = TI->getSuccessor(SuccNum);
 

Modified: llvm/branches/Apple/Leela/lib/Transforms/Utils/CloneFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Utils/CloneFunction.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Utils/CloneFunction.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Utils/CloneFunction.cpp Sun Nov  1 18:01:08 2009
@@ -20,9 +20,7 @@
 #include "llvm/IntrinsicInst.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/Function.h"
-#include "llvm/LLVMContext.h"
 #include "llvm/Support/CFG.h"
-#include "llvm/Support/Compiler.h"
 #include "llvm/Transforms/Utils/ValueMapper.h"
 #include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Analysis/DebugInfo.h"
@@ -176,7 +174,7 @@
 namespace {
   /// PruningFunctionCloner - This class is a private class used to implement
   /// the CloneAndPruneFunctionInto method.
-  struct VISIBILITY_HIDDEN PruningFunctionCloner {
+  struct PruningFunctionCloner {
     Function *NewFunc;
     const Function *OldFunc;
     DenseMap<const Value*, Value*> &ValueMap;
@@ -329,8 +327,7 @@
   SmallVector<Constant*, 8> Ops;
   for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
     if (Constant *Op = dyn_cast_or_null<Constant>(MapValue(I->getOperand(i),
-                                                           ValueMap,
-                                                           Context)))
+                                                           ValueMap)))
       Ops.push_back(Op);
     else
       return 0;  // All operands not constant!
@@ -366,7 +363,6 @@
                                      ClonedCodeInfo *CodeInfo,
                                      const TargetData *TD) {
   assert(NameSuffix && "NameSuffix cannot be null!");
-  LLVMContext &Context = OldFunc->getContext();
   
 #ifndef NDEBUG
   for (Function::const_arg_iterator II = OldFunc->arg_begin(), 
@@ -437,7 +433,7 @@
         if (BasicBlock *MappedBlock = 
             cast_or_null<BasicBlock>(ValueMap[PN->getIncomingBlock(pred)])) {
           Value *InVal = MapValue(PN->getIncomingValue(pred),
-                                  ValueMap, Context);
+                                  ValueMap);
           assert(InVal && "Unknown input value?");
           PN->setIncomingValue(pred, InVal);
           PN->setIncomingBlock(pred, MappedBlock);

Modified: llvm/branches/Apple/Leela/lib/Transforms/Utils/CloneModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Utils/CloneModule.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Utils/CloneModule.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Utils/CloneModule.cpp Sun Nov  1 18:01:08 2009
@@ -89,8 +89,7 @@
     GlobalVariable *GV = cast<GlobalVariable>(ValueMap[I]);
     if (I->hasInitializer())
       GV->setInitializer(cast<Constant>(MapValue(I->getInitializer(),
-                                                 ValueMap,
-                                                 M->getContext())));
+                                                 ValueMap)));
     GV->setLinkage(I->getLinkage());
     GV->setThreadLocal(I->isThreadLocal());
     GV->setConstant(I->isConstant());
@@ -121,7 +120,7 @@
     GlobalAlias *GA = cast<GlobalAlias>(ValueMap[I]);
     GA->setLinkage(I->getLinkage());
     if (const Constant* C = I->getAliasee())
-      GA->setAliasee(cast<Constant>(MapValue(C, ValueMap, M->getContext())));
+      GA->setAliasee(cast<Constant>(MapValue(C, ValueMap)));
   }
   
   return New;

Modified: llvm/branches/Apple/Leela/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Utils/Local.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Utils/Local.cpp Sun Nov  1 18:01:08 2009
@@ -110,7 +110,9 @@
       // unconditional branch.
       BI->setUnconditionalDest(Destination);
       return true;
-    } else if (Dest2 == Dest1) {       // Conditional branch to same location?
+    }
+    
+    if (Dest2 == Dest1) {       // Conditional branch to same location?
       // This branch matches something like this:
       //     br bool %cond, label %Dest, label %Dest
       // and changes it into:  br label %Dest
@@ -123,7 +125,10 @@
       BI->setUnconditionalDest(Dest1);
       return true;
     }
-  } else if (SwitchInst *SI = dyn_cast<SwitchInst>(T)) {
+    return false;
+  }
+  
+  if (SwitchInst *SI = dyn_cast<SwitchInst>(T)) {
     // If we are switching on a constant, we can convert the switch into a
     // single branch instruction!
     ConstantInt *CI = dyn_cast<ConstantInt>(SI->getCondition());
@@ -132,7 +137,7 @@
     assert(TheOnlyDest == SI->getDefaultDest() &&
            "Default destination is not successor #0?");
 
-    // Figure out which case it goes to...
+    // Figure out which case it goes to.
     for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i) {
       // Found case matching a constant operand?
       if (SI->getSuccessorValue(i) == CI) {
@@ -143,7 +148,7 @@
       // Check to see if this branch is going to the same place as the default
       // dest.  If so, eliminate it as an explicit compare.
       if (SI->getSuccessor(i) == DefaultDest) {
-        // Remove this entry...
+        // Remove this entry.
         DefaultDest->removePredecessor(SI->getParent());
         SI->removeCase(i);
         --i; --e;  // Don't skip an entry...
@@ -165,7 +170,7 @@
     // If we found a single destination that we can fold the switch into, do so
     // now.
     if (TheOnlyDest) {
-      // Insert the new branch..
+      // Insert the new branch.
       BranchInst::Create(TheOnlyDest, SI);
       BasicBlock *BB = SI->getParent();
 
@@ -179,22 +184,54 @@
           Succ->removePredecessor(BB);
       }
 
-      // Delete the old switch...
+      // Delete the old switch.
       BB->getInstList().erase(SI);
       return true;
-    } else if (SI->getNumSuccessors() == 2) {
+    }
+    
+    if (SI->getNumSuccessors() == 2) {
       // Otherwise, we can fold this switch into a conditional branch
       // instruction if it has only one non-default destination.
       Value *Cond = new ICmpInst(SI, ICmpInst::ICMP_EQ, SI->getCondition(),
                                  SI->getSuccessorValue(1), "cond");
-      // Insert the new branch...
+      // Insert the new branch.
       BranchInst::Create(SI->getSuccessor(1), SI->getSuccessor(0), Cond, SI);
 
-      // Delete the old switch...
+      // Delete the old switch.
       SI->eraseFromParent();
       return true;
     }
+    return false;
   }
+
+  if (IndirectBrInst *IBI = dyn_cast<IndirectBrInst>(T)) {
+    // indirectbr blockaddress(@F, @BB) -> br label @BB
+    if (BlockAddress *BA =
+          dyn_cast<BlockAddress>(IBI->getAddress()->stripPointerCasts())) {
+      BasicBlock *TheOnlyDest = BA->getBasicBlock();
+      // Insert the new branch.
+      BranchInst::Create(TheOnlyDest, IBI);
+      
+      for (unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
+        if (IBI->getDestination(i) == TheOnlyDest)
+          TheOnlyDest = 0;
+        else
+          IBI->getDestination(i)->removePredecessor(IBI->getParent());
+      }
+      IBI->eraseFromParent();
+      
+      // If we didn't find our destination in the IBI successor list, then we
+      // have undefined behavior.  Replace the unconditional branch with an
+      // 'unreachable' instruction.
+      if (TheOnlyDest) {
+        BB->getTerminator()->eraseFromParent();
+        new UnreachableInst(BB->getContext(), BB);
+      }
+      
+      return true;
+    }
+  }
+  
   return false;
 }
 

Modified: llvm/branches/Apple/Leela/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Transforms/Utils/ValueMapper.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Transforms/Utils/ValueMapper.cpp Sun Nov  1 18:01:08 2009
@@ -13,18 +13,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Transforms/Utils/ValueMapper.h"
-#include "llvm/BasicBlock.h"
 #include "llvm/DerivedTypes.h"  // For getNullValue(Type::Int32Ty)
 #include "llvm/Constants.h"
-#include "llvm/GlobalValue.h"
-#include "llvm/Instruction.h"
-#include "llvm/LLVMContext.h"
+#include "llvm/Function.h"
 #include "llvm/Metadata.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/ErrorHandling.h"
 using namespace llvm;
 
-Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext &Context) {
+Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
   Value *&VMSlot = VM[V];
   if (VMSlot) return VMSlot;      // Does it exist in the map yet?
   
@@ -36,80 +33,91 @@
   if (isa<GlobalValue>(V) || isa<InlineAsm>(V) || isa<MetadataBase>(V))
     return VMSlot = const_cast<Value*>(V);
 
-  if (Constant *C = const_cast<Constant*>(dyn_cast<Constant>(V))) {
-    if (isa<ConstantInt>(C) || isa<ConstantFP>(C) ||
-        isa<ConstantPointerNull>(C) || isa<ConstantAggregateZero>(C) ||
-        isa<UndefValue>(C) || isa<MDString>(C))
-      return VMSlot = C;           // Primitive constants map directly
-    else if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
-      for (User::op_iterator b = CA->op_begin(), i = b, e = CA->op_end();
-           i != e; ++i) {
-        Value *MV = MapValue(*i, VM, Context);
-        if (MV != *i) {
-          // This array must contain a reference to a global, make a new array
-          // and return it.
-          //
-          std::vector<Constant*> Values;
-          Values.reserve(CA->getNumOperands());
-          for (User::op_iterator j = b; j != i; ++j)
-            Values.push_back(cast<Constant>(*j));
-          Values.push_back(cast<Constant>(MV));
-          for (++i; i != e; ++i)
-            Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
-          return VM[V] = ConstantArray::get(CA->getType(), Values);
-        }
+  Constant *C = const_cast<Constant*>(dyn_cast<Constant>(V));
+  if (C == 0) return 0;
+  
+  if (isa<ConstantInt>(C) || isa<ConstantFP>(C) ||
+      isa<ConstantPointerNull>(C) || isa<ConstantAggregateZero>(C) ||
+      isa<UndefValue>(C) || isa<MDString>(C))
+    return VMSlot = C;           // Primitive constants map directly
+  
+  if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
+    for (User::op_iterator b = CA->op_begin(), i = b, e = CA->op_end();
+         i != e; ++i) {
+      Value *MV = MapValue(*i, VM);
+      if (MV != *i) {
+        // This array must contain a reference to a global, make a new array
+        // and return it.
+        //
+        std::vector<Constant*> Values;
+        Values.reserve(CA->getNumOperands());
+        for (User::op_iterator j = b; j != i; ++j)
+          Values.push_back(cast<Constant>(*j));
+        Values.push_back(cast<Constant>(MV));
+        for (++i; i != e; ++i)
+          Values.push_back(cast<Constant>(MapValue(*i, VM)));
+        return VM[V] = ConstantArray::get(CA->getType(), Values);
       }
-      return VM[V] = C;
-
-    } else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
-      for (User::op_iterator b = CS->op_begin(), i = b, e = CS->op_end();
-           i != e; ++i) {
-        Value *MV = MapValue(*i, VM, Context);
-        if (MV != *i) {
-          // This struct must contain a reference to a global, make a new struct
-          // and return it.
-          //
-          std::vector<Constant*> Values;
-          Values.reserve(CS->getNumOperands());
-          for (User::op_iterator j = b; j != i; ++j)
-            Values.push_back(cast<Constant>(*j));
-          Values.push_back(cast<Constant>(MV));
-          for (++i; i != e; ++i)
-            Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
-          return VM[V] = ConstantStruct::get(CS->getType(), Values);
-        }
+    }
+    return VM[V] = C;
+  }
+  
+  if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
+    for (User::op_iterator b = CS->op_begin(), i = b, e = CS->op_end();
+         i != e; ++i) {
+      Value *MV = MapValue(*i, VM);
+      if (MV != *i) {
+        // This struct must contain a reference to a global, make a new struct
+        // and return it.
+        //
+        std::vector<Constant*> Values;
+        Values.reserve(CS->getNumOperands());
+        for (User::op_iterator j = b; j != i; ++j)
+          Values.push_back(cast<Constant>(*j));
+        Values.push_back(cast<Constant>(MV));
+        for (++i; i != e; ++i)
+          Values.push_back(cast<Constant>(MapValue(*i, VM)));
+        return VM[V] = ConstantStruct::get(CS->getType(), Values);
       }
-      return VM[V] = C;
-
-    } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
-      std::vector<Constant*> Ops;
-      for (User::op_iterator i = CE->op_begin(), e = CE->op_end(); i != e; ++i)
-        Ops.push_back(cast<Constant>(MapValue(*i, VM, Context)));
-      return VM[V] = CE->getWithOperands(Ops);
-    } else if (ConstantVector *CP = dyn_cast<ConstantVector>(C)) {
-      for (User::op_iterator b = CP->op_begin(), i = b, e = CP->op_end();
-           i != e; ++i) {
-        Value *MV = MapValue(*i, VM, Context);
-        if (MV != *i) {
-          // This vector value must contain a reference to a global, make a new
-          // vector constant and return it.
-          //
-          std::vector<Constant*> Values;
-          Values.reserve(CP->getNumOperands());
-          for (User::op_iterator j = b; j != i; ++j)
-            Values.push_back(cast<Constant>(*j));
-          Values.push_back(cast<Constant>(MV));
-          for (++i; i != e; ++i)
-            Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
-          return VM[V] = ConstantVector::get(Values);
-        }
+    }
+    return VM[V] = C;
+  }
+  
+  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
+    std::vector<Constant*> Ops;
+    for (User::op_iterator i = CE->op_begin(), e = CE->op_end(); i != e; ++i)
+      Ops.push_back(cast<Constant>(MapValue(*i, VM)));
+    return VM[V] = CE->getWithOperands(Ops);
+  }
+  
+  if (ConstantVector *CV = dyn_cast<ConstantVector>(C)) {
+    for (User::op_iterator b = CV->op_begin(), i = b, e = CV->op_end();
+         i != e; ++i) {
+      Value *MV = MapValue(*i, VM);
+      if (MV != *i) {
+        // This vector value must contain a reference to a global, make a new
+        // vector constant and return it.
+        //
+        std::vector<Constant*> Values;
+        Values.reserve(CV->getNumOperands());
+        for (User::op_iterator j = b; j != i; ++j)
+          Values.push_back(cast<Constant>(*j));
+        Values.push_back(cast<Constant>(MV));
+        for (++i; i != e; ++i)
+          Values.push_back(cast<Constant>(MapValue(*i, VM)));
+        return VM[V] = ConstantVector::get(Values);
       }
-      return VM[V] = C;
-      
-    } else {
-      llvm_unreachable("Unknown type of constant!");
     }
+    return VM[V] = C;
   }
+  
+  if (BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
+    Function *F = cast<Function>(MapValue(BA->getFunction(), VM));
+    BasicBlock *BB = cast_or_null<BasicBlock>(MapValue(BA->getBasicBlock(),VM));
+    return VM[V] = BlockAddress::get(F, BB ? BB : BA->getBasicBlock());
+  }
+  
+  llvm_unreachable("Unknown type of constant!");
   return 0;
 }
 
@@ -118,7 +126,7 @@
 ///
 void llvm::RemapInstruction(Instruction *I, ValueMapTy &ValueMap) {
   for (User::op_iterator op = I->op_begin(), E = I->op_end(); op != E; ++op) {
-    Value *V = MapValue(*op, ValueMap, I->getParent()->getContext());
+    Value *V = MapValue(*op, ValueMap);
     assert(V && "Referenced value not in value map!");
     *op = V;
   }

Modified: llvm/branches/Apple/Leela/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/AsmWriter.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/AsmWriter.cpp Sun Nov  1 18:01:08 2009
@@ -1059,6 +1059,15 @@
     Out << "zeroinitializer";
     return;
   }
+  
+  if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
+    Out << "blockaddress(";
+    WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine);
+    Out << ", ";
+    WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine);
+    Out << ")";
+    return;
+  }
 
   if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
     // As a special case, print the array as a string if it is an array of
@@ -1843,8 +1852,8 @@
       writeOperand(I.getOperand(op+1), true);
     }
     Out << "\n  ]";
-  } else if (isa<IndBrInst>(I)) {
-    // Special case indbr instruction to get formatting nice and correct.
+  } else if (isa<IndirectBrInst>(I)) {
+    // Special case indirectbr instruction to get formatting nice and correct.
     Out << ' ';
     writeOperand(Operand, true);
     Out << ", ";

Modified: llvm/branches/Apple/Leela/lib/VMCore/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/BasicBlock.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/BasicBlock.cpp (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/BasicBlock.cpp Sun Nov  1 18:01:08 2009
@@ -58,6 +58,24 @@
 
 
 BasicBlock::~BasicBlock() {
+  // If the address of the block is taken and it is being deleted (e.g. because
+  // it is dead), this means that there is either a dangling constant expr
+  // hanging off the block, or an undefined use of the block (source code
+  // expecting the address of a label to keep the block alive even though there
+  // is no indirect branch).  Handle these cases by zapping the BlockAddress
+  // nodes.  There are no other possible uses at this point.
+  if (hasAddressTaken()) {
+    assert(!use_empty() && "There should be at least one blockaddress!");
+    Constant *Replacement =
+      ConstantInt::get(llvm::Type::getInt32Ty(getContext()), 1);
+    while (!use_empty()) {
+      BlockAddress *BA = cast<BlockAddress>(use_back());
+      BA->replaceAllUsesWith(ConstantExpr::getIntToPtr(Replacement,
+                                                       BA->getType()));
+      BA->destroyConstant();
+    }
+  }
+  
   assert(getParent() == 0 && "BasicBlock still linked into the program!");
   dropAllReferences();
   InstList.clear();
@@ -277,3 +295,4 @@
   }
   return New;
 }
+

Modified: llvm/branches/Apple/Leela/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/ConstantFold.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/ConstantFold.cpp Sun Nov  1 18:01:08 2009
@@ -179,6 +179,151 @@
 }
 
 
+/// ExtractConstantBytes - V is an integer constant which only has a subset of
+/// its bytes used.  The bytes used are indicated by ByteStart (which is the
+/// first byte used, counting from the least significant byte) and ByteSize,
+/// which is the number of bytes used.
+///
+/// This function analyzes the specified constant to see if the specified byte
+/// range can be returned as a simplified constant.  If so, the constant is
+/// returned, otherwise null is returned.
+/// 
+static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart,
+                                      unsigned ByteSize) {
+  assert(isa<IntegerType>(C->getType()) &&
+         (cast<IntegerType>(C->getType())->getBitWidth() & 7) == 0 &&
+         "Non-byte sized integer input");
+  unsigned CSize = cast<IntegerType>(C->getType())->getBitWidth()/8;
+  assert(ByteSize && "Must be accessing some piece");
+  assert(ByteStart+ByteSize <= CSize && "Extracting invalid piece from input");
+  assert(ByteSize != CSize && "Should not extract everything");
+  
+  // Constant Integers are simple.
+  if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
+    APInt V = CI->getValue();
+    if (ByteStart)
+      V = V.lshr(ByteStart*8);
+    V.trunc(ByteSize*8);
+    return ConstantInt::get(CI->getContext(), V);
+  }
+  
+  // In the input is a constant expr, we might be able to recursively simplify.
+  // If not, we definitely can't do anything.
+  ConstantExpr *CE = dyn_cast<ConstantExpr>(C);
+  if (CE == 0) return 0;
+  
+  switch (CE->getOpcode()) {
+  default: return 0;
+  case Instruction::Or: {
+    Constant *RHS = ExtractConstantBytes(CE->getOperand(1), ByteStart,ByteSize);
+    if (RHS == 0)
+      return 0;
+    
+    // X | -1 -> -1.
+    if (ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS))
+      if (RHSC->isAllOnesValue())
+        return RHSC;
+    
+    Constant *LHS = ExtractConstantBytes(CE->getOperand(0), ByteStart,ByteSize);
+    if (LHS == 0)
+      return 0;
+    return ConstantExpr::getOr(LHS, RHS);
+  }
+  case Instruction::And: {
+    Constant *RHS = ExtractConstantBytes(CE->getOperand(1), ByteStart,ByteSize);
+    if (RHS == 0)
+      return 0;
+    
+    // X & 0 -> 0.
+    if (RHS->isNullValue())
+      return RHS;
+    
+    Constant *LHS = ExtractConstantBytes(CE->getOperand(0), ByteStart,ByteSize);
+    if (LHS == 0)
+      return 0;
+    return ConstantExpr::getAnd(LHS, RHS);
+  }
+  case Instruction::LShr: {
+    ConstantInt *Amt = dyn_cast<ConstantInt>(CE->getOperand(1));
+    if (Amt == 0)
+      return 0;
+    unsigned ShAmt = Amt->getZExtValue();
+    // Cannot analyze non-byte shifts.
+    if ((ShAmt & 7) != 0)
+      return 0;
+    ShAmt >>= 3;
+    
+    // If the extract is known to be all zeros, return zero.
+    if (ByteStart >= CSize-ShAmt)
+      return Constant::getNullValue(IntegerType::get(CE->getContext(),
+                                                     ByteSize*8));
+    // If the extract is known to be fully in the input, extract it.
+    if (ByteStart+ByteSize+ShAmt <= CSize)
+      return ExtractConstantBytes(CE->getOperand(0), ByteStart+ShAmt, ByteSize);
+    
+    // TODO: Handle the 'partially zero' case.
+    return 0;
+  }
+    
+  case Instruction::Shl: {
+    ConstantInt *Amt = dyn_cast<ConstantInt>(CE->getOperand(1));
+    if (Amt == 0)
+      return 0;
+    unsigned ShAmt = Amt->getZExtValue();
+    // Cannot analyze non-byte shifts.
+    if ((ShAmt & 7) != 0)
+      return 0;
+    ShAmt >>= 3;
+    
+    // If the extract is known to be all zeros, return zero.
+    if (ByteStart+ByteSize <= ShAmt)
+      return Constant::getNullValue(IntegerType::get(CE->getContext(),
+                                                     ByteSize*8));
+    // If the extract is known to be fully in the input, extract it.
+    if (ByteStart >= ShAmt)
+      return ExtractConstantBytes(CE->getOperand(0), ByteStart-ShAmt, ByteSize);
+    
+    // TODO: Handle the 'partially zero' case.
+    return 0;
+  }
+      
+  case Instruction::ZExt: {
+    unsigned SrcBitSize =
+      cast<IntegerType>(CE->getOperand(0)->getType())->getBitWidth();
+    
+    // If extracting something that is completely zero, return 0.
+    if (ByteStart*8 >= SrcBitSize)
+      return Constant::getNullValue(IntegerType::get(CE->getContext(),
+                                                     ByteSize*8));
+
+    // If exactly extracting the input, return it.
+    if (ByteStart == 0 && ByteSize*8 == SrcBitSize)
+      return CE->getOperand(0);
+    
+    // If extracting something completely in the input, if if the input is a
+    // multiple of 8 bits, recurse.
+    if ((SrcBitSize&7) == 0 && (ByteStart+ByteSize)*8 <= SrcBitSize)
+      return ExtractConstantBytes(CE->getOperand(0), ByteStart, ByteSize);
+      
+    // Otherwise, if extracting a subset of the input, which is not multiple of
+    // 8 bits, do a shift and trunc to get the bits.
+    if ((ByteStart+ByteSize)*8 < SrcBitSize) {
+      assert((SrcBitSize&7) && "Shouldn't get byte sized case here");
+      Constant *Res = CE->getOperand(0);
+      if (ByteStart)
+        Res = ConstantExpr::getLShr(Res, 
+                                 ConstantInt::get(Res->getType(), ByteStart*8));
+      return ConstantExpr::getTrunc(Res, IntegerType::get(C->getContext(),
+                                                          ByteSize*8));
+    }
+    
+    // TODO: Handle the 'partially zero' case.
+    return 0;
+  }
+  }
+}
+
+
 Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, 
                                             unsigned opc, Constant *V,
                                             const Type *DestTy) {
@@ -236,6 +381,8 @@
   // We actually have to do a cast now. Perform the cast according to the
   // opcode specified.
   switch (opc) {
+  default:
+    llvm_unreachable("Failed to cast constant expression");
   case Instruction::FPTrunc:
   case Instruction::FPExt:
     if (ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
@@ -300,23 +447,27 @@
       return ConstantInt::get(Context, Result);
     }
     return 0;
-  case Instruction::Trunc:
+  case Instruction::Trunc: {
+    uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
     if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
-      uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
       APInt Result(CI->getValue());
-      Result.trunc(BitWidth);
+      Result.trunc(DestBitWidth);
       return ConstantInt::get(Context, Result);
     }
+    
+    // The input must be a constantexpr.  See if we can simplify this based on
+    // the bytes we are demanding.  Only do this if the source and dest are an
+    // even multiple of a byte.
+    if ((DestBitWidth & 7) == 0 &&
+        (cast<IntegerType>(V->getType())->getBitWidth() & 7) == 0)
+      if (Constant *Res = ExtractConstantBytes(V, 0, DestBitWidth / 8))
+        return Res;
+      
     return 0;
+  }
   case Instruction::BitCast:
     return FoldBitCast(Context, V, DestTy);
-  default:
-    assert(!"Invalid CE CastInst opcode");
-    break;
   }
-
-  llvm_unreachable("Failed to cast constant expression");
-  return 0;
 }
 
 Constant *llvm::ConstantFoldSelectInstruction(LLVMContext&,
@@ -483,7 +634,15 @@
                                                               Idxs + NumIdx));
 
   // Otherwise recurse.
-  return ConstantFoldExtractValueInstruction(Context, Agg->getOperand(*Idxs),
+  if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Agg))
+    return ConstantFoldExtractValueInstruction(Context, CS->getOperand(*Idxs),
+                                               Idxs+1, NumIdx-1);
+
+  if (ConstantArray *CA = dyn_cast<ConstantArray>(Agg))
+    return ConstantFoldExtractValueInstruction(Context, CA->getOperand(*Idxs),
+                                               Idxs+1, NumIdx-1);
+  ConstantVector *CV = cast<ConstantVector>(Agg);
+  return ConstantFoldExtractValueInstruction(Context, CV->getOperand(*Idxs),
                                              Idxs+1, NumIdx-1);
 }
 
@@ -563,11 +722,10 @@
     // Insertion of constant into aggregate constant.
     std::vector<Constant*> Ops(Agg->getNumOperands());
     for (unsigned i = 0; i < Agg->getNumOperands(); ++i) {
-      Constant *Op =
-        (*Idxs == i) ?
-        ConstantFoldInsertValueInstruction(Context, Agg->getOperand(i),
-                                           Val, Idxs+1, NumIdx-1) :
-        Agg->getOperand(i);
+      Constant *Op = cast<Constant>(Agg->getOperand(i));
+      if (*Idxs == i)
+        Op = ConstantFoldInsertValueInstruction(Context, Op,
+                                                Val, Idxs+1, NumIdx-1);
       Ops[i] = Op;
     }
     

Modified: llvm/branches/Apple/Leela/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/Constants.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/Constants.cpp (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/Constants.cpp Sun Nov  1 18:01:08 2009
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements the Constant* classes...
+// This file implements the Constant* classes.
 //
 //===----------------------------------------------------------------------===//
 
@@ -44,7 +44,7 @@
 
 // Constructor to create a '0' constant of arbitrary type...
 static const uint64_t zero[2] = {0, 0};
-Constant* Constant::getNullValue(const Type* Ty) {
+Constant *Constant::getNullValue(const Type *Ty) {
   switch (Ty->getTypeID()) {
   case Type::IntegerTyID:
     return ConstantInt::get(Ty, 0);
@@ -72,7 +72,7 @@
   }
 }
 
-Constant* Constant::getIntegerValue(const Type* Ty, const APInt &V) {
+Constant* Constant::getIntegerValue(const Type *Ty, const APInt &V) {
   const Type *ScalarTy = Ty->getScalarType();
 
   // Create the base integer constant.
@@ -89,13 +89,13 @@
   return C;
 }
 
-Constant* Constant::getAllOnesValue(const Type* Ty) {
-  if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
+Constant* Constant::getAllOnesValue(const Type *Ty) {
+  if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty))
     return ConstantInt::get(Ty->getContext(),
                             APInt::getAllOnesValue(ITy->getBitWidth()));
   
   std::vector<Constant*> Elts;
-  const VectorType* VTy = cast<VectorType>(Ty);
+  const VectorType *VTy = cast<VectorType>(Ty);
   Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType()));
   assert(Elts[0] && "Not a vector integer type!");
   return cast<ConstantVector>(ConstantVector::get(Elts));
@@ -140,7 +140,7 @@
   
   // ConstantExpr traps if any operands can trap. 
   for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
-    if (getOperand(i)->canTrap()) 
+    if (CE->getOperand(i)->canTrap()) 
       return true;
 
   // Otherwise, only specific operations can trap.
@@ -154,12 +154,27 @@
   case Instruction::SRem:
   case Instruction::FRem:
     // Div and rem can trap if the RHS is not known to be non-zero.
-    if (!isa<ConstantInt>(getOperand(1)) || getOperand(1)->isNullValue())
+    if (!isa<ConstantInt>(CE->getOperand(1)) ||CE->getOperand(1)->isNullValue())
       return true;
     return false;
   }
 }
 
+/// isConstantUsed - Return true if the constant has users other than constant
+/// exprs and other dangling things.
+bool Constant::isConstantUsed() const {
+  for (use_const_iterator UI = use_begin(), E = use_end(); UI != E; ++UI) {
+    const Constant *UC = dyn_cast<Constant>(*UI);
+    if (UC == 0 || isa<GlobalValue>(UC))
+      return true;
+    
+    if (UC->isConstantUsed())
+      return true;
+  }
+  return false;
+}
+
+
 
 /// getRelocationInfo - This method classifies the entry according to
 /// whether or not it may generate a relocation entry.  This must be
@@ -182,9 +197,13 @@
     return GlobalRelocations;    // Global reference.
   }
   
+  if (const BlockAddress *BA = dyn_cast<BlockAddress>(this))
+    return BA->getFunction()->getRelocationInfo();
+  
   PossibleRelocationsTy Result = NoRelocation;
   for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
-    Result = std::max(Result, getOperand(i)->getRelocationInfo());
+    Result = std::max(Result,
+                      cast<Constant>(getOperand(i))->getRelocationInfo());
   
   return Result;
 }
@@ -1010,7 +1029,7 @@
   return Elt;
 }
 
-//---- ConstantPointerNull::get() implementation...
+//---- ConstantPointerNull::get() implementation.
 //
 
 ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) {
@@ -1027,23 +1046,95 @@
 }
 
 
-//---- UndefValue::get() implementation...
+//---- UndefValue::get() implementation.
 //
 
 UndefValue *UndefValue::get(const Type *Ty) {
-  // Implicitly locked.
   return Ty->getContext().pImpl->UndefValueConstants.getOrCreate(Ty, 0);
 }
 
 // destroyConstant - Remove the constant from the constant table.
 //
 void UndefValue::destroyConstant() {
-  // Implicitly locked.
   getType()->getContext().pImpl->UndefValueConstants.remove(this);
   destroyConstantImpl();
 }
 
-//---- ConstantExpr::get() implementations...
+//---- BlockAddress::get() implementation.
+//
+
+BlockAddress *BlockAddress::get(BasicBlock *BB) {
+  assert(BB->getParent() != 0 && "Block must have a parent");
+  return get(BB->getParent(), BB);
+}
+
+BlockAddress *BlockAddress::get(Function *F, BasicBlock *BB) {
+  BlockAddress *&BA =
+    F->getContext().pImpl->BlockAddresses[std::make_pair(F, BB)];
+  if (BA == 0)
+    BA = new BlockAddress(F, BB);
+  
+  assert(BA->getFunction() == F && "Basic block moved between functions");
+  return BA;
+}
+
+BlockAddress::BlockAddress(Function *F, BasicBlock *BB)
+: Constant(Type::getInt8PtrTy(F->getContext()), Value::BlockAddressVal,
+           &Op<0>(), 2) {
+  setOperand(0, F);
+  setOperand(1, BB);
+  BB->AdjustBlockAddressRefCount(1);
+}
+
+
+// destroyConstant - Remove the constant from the constant table.
+//
+void BlockAddress::destroyConstant() {
+  getFunction()->getType()->getContext().pImpl
+    ->BlockAddresses.erase(std::make_pair(getFunction(), getBasicBlock()));
+  getBasicBlock()->AdjustBlockAddressRefCount(-1);
+  destroyConstantImpl();
+}
+
+void BlockAddress::replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) {
+  // This could be replacing either the Basic Block or the Function.  In either
+  // case, we have to remove the map entry.
+  Function *NewF = getFunction();
+  BasicBlock *NewBB = getBasicBlock();
+  
+  if (U == &Op<0>())
+    NewF = cast<Function>(To);
+  else
+    NewBB = cast<BasicBlock>(To);
+  
+  // See if the 'new' entry already exists, if not, just update this in place
+  // and return early.
+  BlockAddress *&NewBA =
+    getContext().pImpl->BlockAddresses[std::make_pair(NewF, NewBB)];
+  if (NewBA == 0) {
+    getBasicBlock()->AdjustBlockAddressRefCount(-1);
+    
+    // Remove the old entry, this can't cause the map to rehash (just a
+    // tombstone will get added).
+    getContext().pImpl->BlockAddresses.erase(std::make_pair(getFunction(),
+                                                            getBasicBlock()));
+    NewBA = this;
+    setOperand(0, NewF);
+    setOperand(1, NewBB);
+    getBasicBlock()->AdjustBlockAddressRefCount(1);
+    return;
+  }
+
+  // Otherwise, I do need to replace this with an existing value.
+  assert(NewBA != this && "I didn't contain From!");
+  
+  // Everyone using this now uses the replacement.
+  uncheckedReplaceAllUsesWith(NewBA);
+  
+  destroyConstant();
+}
+
+//---- ConstantExpr::get() implementations.
 //
 
 /// This is a utility function to handle folding of casts and lookup of the
@@ -1861,7 +1952,7 @@
 /// single invocation handles all 1000 uses.  Handling them one at a time would
 /// work, but would be really slow because it would have to unique each updated
 /// array instance.
-
+///
 void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
                                                 Use *U) {
   assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");

Modified: llvm/branches/Apple/Leela/lib/VMCore/ConstantsContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/ConstantsContext.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/ConstantsContext.h (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/ConstantsContext.h Sun Nov  1 18:01:08 2009
@@ -332,7 +332,7 @@
 // The number of operands for each ConstantCreator::create method is
 // determined by the ConstantTraits template.
 // ConstantCreator - A class that is used to create constants by
-// ValueMap*.  This class should be partially specialized if there is
+// ConstantUniqueMap*.  This class should be partially specialized if there is
 // something strange that needs to be done to interface to the ctor for the
 // constant.
 //
@@ -506,7 +506,7 @@
 
 template<class ValType, class TypeClass, class ConstantClass,
          bool HasLargeKey = false /*true for arrays and structs*/ >
-class ValueMap : public AbstractTypeUser {
+class ConstantUniqueMap : public AbstractTypeUser {
 public:
   typedef std::pair<const TypeClass*, ValType> MapKey;
   typedef std::map<MapKey, ConstantClass *> MapTy;
@@ -529,8 +529,8 @@
   ///
   AbstractTypeMapTy AbstractTypeMap;
     
-  /// ValueMapLock - Mutex for this map.
-  sys::SmartMutex<true> ValueMapLock;
+  /// ConstantUniqueMapLock - Mutex for this map.
+  sys::SmartMutex<true> ConstantUniqueMapLock;
 
 public:
   // NOTE: This function is not locked.  It is the caller's responsibility
@@ -619,7 +619,7 @@
   /// getOrCreate - Return the specified constant from the map, creating it if
   /// necessary.
   ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) {
-    sys::SmartScopedLock<true> Lock(ValueMapLock);
+    sys::SmartScopedLock<true> Lock(ConstantUniqueMapLock);
     MapKey Lookup(Ty, V);
     ConstantClass* Result = 0;
     
@@ -674,7 +674,7 @@
   }
 
   void remove(ConstantClass *CP) {
-    sys::SmartScopedLock<true> Lock(ValueMapLock);
+    sys::SmartScopedLock<true> Lock(ConstantUniqueMapLock);
     typename MapTy::iterator I = FindExistingElement(CP);
     assert(I != Map.end() && "Constant not found in constant table!");
     assert(I->second == CP && "Didn't find correct element?");
@@ -725,7 +725,7 @@
   }
     
   void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
-    sys::SmartScopedLock<true> Lock(ValueMapLock);
+    sys::SmartScopedLock<true> Lock(ConstantUniqueMapLock);
     typename AbstractTypeMapTy::iterator I = AbstractTypeMap.find(OldTy);
 
     assert(I != AbstractTypeMap.end() &&
@@ -778,7 +778,7 @@
   }
 
   void dump() const {
-    DEBUG(errs() << "Constant.cpp: ValueMap\n");
+    DEBUG(errs() << "Constant.cpp: ConstantUniqueMap\n");
   }
 };
 

Modified: llvm/branches/Apple/Leela/lib/VMCore/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/Function.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/Function.cpp (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/Function.cpp Sun Nov  1 18:01:08 2009
@@ -217,7 +217,20 @@
 void Function::dropAllReferences() {
   for (iterator I = begin(), E = end(); I != E; ++I)
     I->dropAllReferences();
-  BasicBlocks.clear();    // Delete all basic blocks...
+  
+  // Delete all basic blocks.
+  while (!BasicBlocks.empty()) {
+    // If there is still a reference to the block, it must be a 'blockaddress'
+    // constant pointing to it.  Just replace the BlockAddress with undef.
+    BasicBlock *BB = BasicBlocks.begin();
+    if (!BB->use_empty()) {
+      BlockAddress *BA = cast<BlockAddress>(BB->use_back());
+      BA->replaceAllUsesWith(UndefValue::get(BA->getType()));
+      BA->destroyConstant();
+    }
+    
+    BB->eraseFromParent();
+  }
 }
 
 void Function::addAttribute(unsigned i, Attributes attr) {

Modified: llvm/branches/Apple/Leela/lib/VMCore/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/Globals.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/Globals.cpp (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/Globals.cpp Sun Nov  1 18:01:08 2009
@@ -75,6 +75,7 @@
   }
 }
 
+
 /// Override destroyConstant to make sure it doesn't get called on
 /// GlobalValue's because they shouldn't be treated like other constants.
 void GlobalValue::destroyConstant() {

Modified: llvm/branches/Apple/Leela/lib/VMCore/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/Instruction.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/Instruction.cpp (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/Instruction.cpp Sun Nov  1 18:01:08 2009
@@ -103,7 +103,7 @@
   case Ret:    return "ret";
   case Br:     return "br";
   case Switch: return "switch";
-  case IndBr:  return "indbr";
+  case IndirectBr: return "indirectbr";
   case Invoke: return "invoke";
   case Unwind: return "unwind";
   case Unreachable: return "unreachable";

Modified: llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/Instructions.cpp Sun Nov  1 18:01:08 2009
@@ -3016,8 +3016,9 @@
 //                        SwitchInst Implementation
 //===----------------------------------------------------------------------===//
 
-void IndBrInst::init(Value *Address, unsigned NumDests) {
-  assert(Address);
+void IndirectBrInst::init(Value *Address, unsigned NumDests) {
+  assert(Address && isa<PointerType>(Address->getType()) &&
+         "Address of indirectbr must be a pointer");
   ReservedSpace = 1+NumDests;
   NumOperands = 1;
   OperandList = allocHungoffUses(ReservedSpace);
@@ -3033,7 +3034,7 @@
 ///   2. If NumOps > NumOperands, reserve space for NumOps operands.
 ///   3. If NumOps == NumOperands, trim the reserved space.
 ///
-void IndBrInst::resizeOperands(unsigned NumOps) {
+void IndirectBrInst::resizeOperands(unsigned NumOps) {
   unsigned e = getNumOperands();
   if (NumOps == 0) {
     NumOps = e*2;
@@ -3055,21 +3056,22 @@
   if (OldOps) Use::zap(OldOps, OldOps + e, true);
 }
 
-IndBrInst::IndBrInst(Value *Address, unsigned NumCases,
-                     Instruction *InsertBefore)
-: TerminatorInst(Type::getVoidTy(Address->getContext()), Instruction::IndBr,
+IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
+                               Instruction *InsertBefore)
+: TerminatorInst(Type::getVoidTy(Address->getContext()),Instruction::IndirectBr,
                  0, 0, InsertBefore) {
   init(Address, NumCases);
 }
 
-IndBrInst::IndBrInst(Value *Address, unsigned NumCases, BasicBlock *InsertAtEnd)
-: TerminatorInst(Type::getVoidTy(Address->getContext()), Instruction::IndBr,
+IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
+                               BasicBlock *InsertAtEnd)
+: TerminatorInst(Type::getVoidTy(Address->getContext()),Instruction::IndirectBr,
                  0, 0, InsertAtEnd) {
   init(Address, NumCases);
 }
 
-IndBrInst::IndBrInst(const IndBrInst &IBI)
-  : TerminatorInst(Type::getVoidTy(IBI.getContext()), Instruction::IndBr,
+IndirectBrInst::IndirectBrInst(const IndirectBrInst &IBI)
+  : TerminatorInst(Type::getVoidTy(IBI.getContext()), Instruction::IndirectBr,
                    allocHungoffUses(IBI.getNumOperands()),
                    IBI.getNumOperands()) {
   Use *OL = OperandList, *InOL = IBI.OperandList;
@@ -3078,13 +3080,13 @@
   SubclassOptionalData = IBI.SubclassOptionalData;
 }
 
-IndBrInst::~IndBrInst() {
+IndirectBrInst::~IndirectBrInst() {
   dropHungoffUses(OperandList);
 }
 
 /// addDestination - Add a destination.
 ///
-void IndBrInst::addDestination(BasicBlock *DestBB) {
+void IndirectBrInst::addDestination(BasicBlock *DestBB) {
   unsigned OpNo = NumOperands;
   if (OpNo+1 > ReservedSpace)
     resizeOperands(0);  // Get more space!
@@ -3095,8 +3097,8 @@
 }
 
 /// removeDestination - This method removes the specified successor from the
-/// indbr instruction.
-void IndBrInst::removeDestination(unsigned idx) {
+/// indirectbr instruction.
+void IndirectBrInst::removeDestination(unsigned idx) {
   assert(idx < getNumOperands()-1 && "Successor index out of range!");
   
   unsigned NumOps = getNumOperands();
@@ -3110,13 +3112,13 @@
   NumOperands = NumOps-1;
 }
 
-BasicBlock *IndBrInst::getSuccessorV(unsigned idx) const {
+BasicBlock *IndirectBrInst::getSuccessorV(unsigned idx) const {
   return getSuccessor(idx);
 }
-unsigned IndBrInst::getNumSuccessorsV() const {
+unsigned IndirectBrInst::getNumSuccessorsV() const {
   return getNumSuccessors();
 }
-void IndBrInst::setSuccessorV(unsigned idx, BasicBlock *B) {
+void IndirectBrInst::setSuccessorV(unsigned idx, BasicBlock *B) {
   setSuccessor(idx, B);
 }
 
@@ -3271,8 +3273,8 @@
   return new SwitchInst(*this);
 }
 
-IndBrInst *IndBrInst::clone_impl() const {
-  return new IndBrInst(*this);
+IndirectBrInst *IndirectBrInst::clone_impl() const {
+  return new IndirectBrInst(*this);
 }
 
 

Modified: llvm/branches/Apple/Leela/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/LLVMContextImpl.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/LLVMContextImpl.h Sun Nov  1 18:01:08 2009
@@ -109,25 +109,26 @@
   
   FoldingSet<MDNode> MDNodeSet;
   
-  ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
+  ConstantUniqueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
 
-  typedef ValueMap<std::vector<Constant*>, ArrayType, 
+  typedef ConstantUniqueMap<std::vector<Constant*>, ArrayType,
     ConstantArray, true /*largekey*/> ArrayConstantsTy;
   ArrayConstantsTy ArrayConstants;
   
-  typedef ValueMap<std::vector<Constant*>, StructType,
-                   ConstantStruct, true /*largekey*/> StructConstantsTy;
+  typedef ConstantUniqueMap<std::vector<Constant*>, StructType,
+    ConstantStruct, true /*largekey*/> StructConstantsTy;
   StructConstantsTy StructConstants;
   
-  typedef ValueMap<std::vector<Constant*>, VectorType,
-                   ConstantVector> VectorConstantsTy;
+  typedef ConstantUniqueMap<std::vector<Constant*>, VectorType,
+                            ConstantVector> VectorConstantsTy;
   VectorConstantsTy VectorConstants;
   
-  ValueMap<char, PointerType, ConstantPointerNull> NullPtrConstants;
+  ConstantUniqueMap<char, PointerType, ConstantPointerNull> NullPtrConstants;
   
-  ValueMap<char, Type, UndefValue> UndefValueConstants;
+  ConstantUniqueMap<char, Type, UndefValue> UndefValueConstants;
   
-  ValueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants;
+  DenseMap<std::pair<Function*, BasicBlock*> , BlockAddress*> BlockAddresses;
+  ConstantUniqueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants;
   
   ConstantInt *TheTrueVal;
   ConstantInt *TheFalseVal;

Modified: llvm/branches/Apple/Leela/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/VMCore/Verifier.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/VMCore/Verifier.cpp (original)
+++ llvm/branches/Apple/Leela/lib/VMCore/Verifier.cpp Sun Nov  1 18:01:08 2009
@@ -659,6 +659,12 @@
     BasicBlock *Entry = &F.getEntryBlock();
     Assert1(pred_begin(Entry) == pred_end(Entry),
             "Entry block to function must not have predecessors!", Entry);
+    
+    // The address of the entry block cannot be taken, unless it is dead.
+    if (Entry->hasAddressTaken()) {
+      Assert1(!BlockAddress::get(Entry)->isConstantUsed(),
+              "blockaddress may not be used with the entry block!", Entry);
+    }
   }
   
   // If this function is actually an intrinsic, verify that it is only used in

Modified: llvm/branches/Apple/Leela/projects/sample/lib/sample/sample.c
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/projects/sample/lib/sample/sample.c?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/projects/sample/lib/sample/sample.c (original)
+++ llvm/branches/Apple/Leela/projects/sample/lib/sample/sample.c Sun Nov  1 18:01:08 2009
@@ -11,7 +11,7 @@
 #include <stdlib.h>
 
 /* LLVM Header File
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 */
 
 /* Header file global to this project */

Modified: llvm/branches/Apple/Leela/test/Feature/terminators.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/test/Feature/terminators.ll?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/test/Feature/terminators.ll (original)
+++ llvm/branches/Apple/Leela/test/Feature/terminators.ll Sun Nov  1 18:01:08 2009
@@ -25,13 +25,19 @@
 }
 
 
+ at Addr = global i8* blockaddress(@indbrtest, %BB1)
+ at Addr3 = global i8* blockaddress(@squared, %Case1)
+
 
 define i32 @indbrtest(i8* %P, i32* %Q) {
-  indbr i8* %P, [label %BB1, label %BB2, label %BB3]
+  indirectbr i8* %P, [label %BB1, label %BB2, label %BB3]
 BB1:
-  indbr i32* %Q, []
+  indirectbr i32* %Q, []
 BB2:
-  indbr i32* %Q, [label %BB1, label %BB2]
+  %R = bitcast i8* blockaddress(@indbrtest, %BB3) to i8*
+  indirectbr i8* %R, [label %BB1, label %BB2, label %BB3]
 BB3:
   ret i32 2
 }
+
+

Removed: llvm/branches/Apple/Leela/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll?rev=85762&view=auto

==============================================================================
--- llvm/branches/Apple/Leela/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll (original)
+++ llvm/branches/Apple/Leela/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll (removed)
@@ -1,41 +0,0 @@
-; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-
- at X = external global i8
- at Y = external global i8
- at Z = external global i8
-
- at A = global i1 add (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @A = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z)) ; <i1*> [#uses=0]
- at B = global i1 sub (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @B = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z)) ; <i1*> [#uses=0]
- at C = global i1 mul (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @C = global i1 and (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z)) ; <i1*> [#uses=0]
-
- at D = global i1 sdiv (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @D = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
- at E = global i1 udiv (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @E = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
- at F = global i1 srem (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @F = global i1 false ; <i1*> [#uses=0]
- at G = global i1 urem (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @G = global i1 false ; <i1*> [#uses=0]
-
- at H = global i1 icmp ule (i32* bitcast (i8* @X to i32*), i32* bitcast (i8* @Y to i32*))
-; CHECK: @H = global i1 icmp ule (i8* @X, i8* @Y) ; <i1*> [#uses=0]
-
- at I = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 false)
-; CHECK: @I = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
- at J = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 true)
-; CHECK: @J = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]
-
- at K = global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 false)
-; CHECK: @K = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]
- at L = global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 true)
-; CHECK: @L = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
- at M = global i1 icmp ne (i1 icmp ult (i8* @X, i8* @Y), i1 true)
-; CHECK: @M = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]
- at N = global i1 icmp ne (i1 icmp ult (i8* @X, i8* @Y), i1 false)
-; CHECK: @N = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
-
- at O = global i1 icmp eq (i32 zext (i1 icmp ult (i8* @X, i8* @Y) to i32), i32 0)
-; CHECK: @O = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]

Copied: llvm/branches/Apple/Leela/test/Transforms/ConstProp/constant-expr.ll (from r84364, llvm/trunk/test/Transforms/ConstProp/constant-expr.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/test/Transforms/ConstProp/constant-expr.ll?p2=llvm/branches/Apple/Leela/test/Transforms/ConstProp/constant-expr.ll&p1=llvm/trunk/test/Transforms/ConstProp/constant-expr.ll&r1=84364&r2=85763&rev=85763&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/constant-expr.ll (original)
+++ llvm/branches/Apple/Leela/test/Transforms/ConstProp/constant-expr.ll Sun Nov  1 18:01:08 2009
@@ -5,37 +5,56 @@
 @Z = external global i8
 
 @A = global i1 add (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @A = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z)) ; <i1*> [#uses=0]
- at B = global i1 sub (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @B = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z)) ; <i1*> [#uses=0]
+; CHECK: @A = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
+ at B = global i1 sub (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z)), align 2
+; CHECK: @B = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
 @C = global i1 mul (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @C = global i1 and (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z)) ; <i1*> [#uses=0]
+; CHECK: @C = global i1 and (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
 
 @D = global i1 sdiv (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @D = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+; CHECK: @D = global i1 icmp ult (i8* @X, i8* @Y)
 @E = global i1 udiv (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
-; CHECK: @E = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+; CHECK: @E = global i1 icmp ult (i8* @X, i8* @Y)
 @F = global i1 srem (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
 ; CHECK: @F = global i1 false ; <i1*> [#uses=0]
 @G = global i1 urem (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
 ; CHECK: @G = global i1 false ; <i1*> [#uses=0]
 
 @H = global i1 icmp ule (i32* bitcast (i8* @X to i32*), i32* bitcast (i8* @Y to i32*))
-; CHECK: @H = global i1 icmp ule (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+; CHECK: @H = global i1 icmp ule (i8* @X, i8* @Y)
 
 @I = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 false)
-; CHECK: @I = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+; CHECK: @I = global i1 icmp ult (i8* @X, i8* @Y)
 @J = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 true)
-; CHECK: @J = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+; CHECK: @J = global i1 icmp uge (i8* @X, i8* @Y)
 
 @K = global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 false)
-; CHECK: @K = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+; CHECK: @K = global i1 icmp uge (i8* @X, i8* @Y)
 @L = global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 true)
-; CHECK: @L = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+; CHECK: @L = global i1 icmp ult (i8* @X, i8* @Y)
 @M = global i1 icmp ne (i1 icmp ult (i8* @X, i8* @Y), i1 true)
-; CHECK: @M = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+; CHECK: @M = global i1 icmp uge (i8* @X, i8* @Y)
 @N = global i1 icmp ne (i1 icmp ult (i8* @X, i8* @Y), i1 false)
-; CHECK: @N = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+; CHECK: @N = global i1 icmp ult (i8* @X, i8* @Y)
 
 @O = global i1 icmp eq (i32 zext (i1 icmp ult (i8* @X, i8* @Y) to i32), i32 0)
-; CHECK: @O = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0]
+; CHECK: @O = global i1 icmp uge (i8* @X, i8* @Y)
+
+
+
+; PR5176
+
+; CHECK: @T1 = global i1 true
+ at T1 = global i1 icmp eq (i64 and (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 64) to i64), i64 1), i64 0)
+
+; CHECK: @T2 = global i1* @B
+ at T2 = global i1* inttoptr (i64 add (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 192)), i256 192) to i64), i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 192)), i256 128) to i64)) to i1*)
+
+; CHECK: @T3 = global i64 add (i64 ptrtoint (i1* @B to i64), i64 -1)
+ at T3 = global i64 add (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 64) to i64), i64 -1)
+
+; CHECK: @T4 = global i1* @B
+ at T4 = global i1* inttoptr (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 64) to i64) to i1*)
+
+; CHECK: @T5 = global i1* @A
+ at T5 = global i1* inttoptr (i64 add (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 192) to i64), i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 128) to i64)) to i1*)
\ No newline at end of file

Modified: llvm/branches/Apple/Leela/test/Transforms/SimplifyCFG/basictest.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/test/Transforms/SimplifyCFG/basictest.ll?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/test/Transforms/SimplifyCFG/basictest.ll (original)
+++ llvm/branches/Apple/Leela/test/Transforms/SimplifyCFG/basictest.ll Sun Nov  1 18:01:08 2009
@@ -21,5 +21,10 @@
 }
 
 
-
-
+define void @test4() {
+entry:
+ br label %return
+return:
+ ret void
+}
+ at test4g = global i8* blockaddress(@test4, %return)

Modified: llvm/branches/Apple/Leela/tools/llvm-mc/AsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/tools/llvm-mc/AsmLexer.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/tools/llvm-mc/AsmLexer.h (original)
+++ llvm/branches/Apple/Leela/tools/llvm-mc/AsmLexer.h Sun Nov  1 18:01:08 2009
@@ -17,7 +17,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/MC/MCAsmLexer.h"
 #include "llvm/MC/MCAsmInfo.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <string>
 #include <cassert>
 

Modified: llvm/branches/Apple/Leela/unittests/ADT/StringMapTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/unittests/ADT/StringMapTest.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/unittests/ADT/StringMapTest.cpp (original)
+++ llvm/branches/Apple/Leela/unittests/ADT/StringMapTest.cpp Sun Nov  1 18:01:08 2009
@@ -9,7 +9,7 @@
 
 #include "gtest/gtest.h"
 #include "llvm/ADT/StringMap.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 using namespace llvm;
 
 namespace {

Modified: llvm/branches/Apple/Leela/unittests/ExecutionEngine/ExecutionEngineTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/unittests/ExecutionEngine/ExecutionEngineTest.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/unittests/ExecutionEngine/ExecutionEngineTest.cpp (original)
+++ llvm/branches/Apple/Leela/unittests/ExecutionEngine/ExecutionEngineTest.cpp Sun Nov  1 18:01:08 2009
@@ -113,4 +113,17 @@
   EXPECT_EQ(G2, Engine->getGlobalValueAtAddress(&Mem1));
 }
 
+TEST_F(ExecutionEngineTest, DestructionRemovesGlobalMapping) {
+  GlobalVariable *G1 =
+    NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
+  int32_t Mem1 = 3;
+  Engine->addGlobalMapping(G1, &Mem1);
+  // Make sure the reverse mapping is enabled.
+  EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem1));
+  // When the GV goes away, the ExecutionEngine should remove any
+  // mappings that refer to it.
+  G1->eraseFromParent();
+  EXPECT_EQ(NULL, Engine->getGlobalValueAtAddress(&Mem1));
+}
+
 }

Modified: llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp (original)
+++ llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp Sun Nov  1 18:01:08 2009
@@ -32,37 +32,36 @@
   OwningPtr<JITMemoryManager> MemMgr(
       JITMemoryManager::CreateDefaultMemManager());
   uintptr_t size;
-  uint8_t *start;
   std::string Error;
 
   // Allocate the functions.
   OwningPtr<Function> F1(makeFakeFunction());
   size = 1024;
-  start = MemMgr->startFunctionBody(F1.get(), size);
-  memset(start, 0xFF, 1024);
-  MemMgr->endFunctionBody(F1.get(), start, start + 1024);
+  uint8_t *FunctionBody1 = MemMgr->startFunctionBody(F1.get(), size);
+  memset(FunctionBody1, 0xFF, 1024);
+  MemMgr->endFunctionBody(F1.get(), FunctionBody1, FunctionBody1 + 1024);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 
   OwningPtr<Function> F2(makeFakeFunction());
   size = 1024;
-  start = MemMgr->startFunctionBody(F2.get(), size);
-  memset(start, 0xFF, 1024);
-  MemMgr->endFunctionBody(F2.get(), start, start + 1024);
+  uint8_t *FunctionBody2 = MemMgr->startFunctionBody(F2.get(), size);
+  memset(FunctionBody2, 0xFF, 1024);
+  MemMgr->endFunctionBody(F2.get(), FunctionBody2, FunctionBody2 + 1024);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 
   OwningPtr<Function> F3(makeFakeFunction());
   size = 1024;
-  start = MemMgr->startFunctionBody(F3.get(), size);
-  memset(start, 0xFF, 1024);
-  MemMgr->endFunctionBody(F3.get(), start, start + 1024);
+  uint8_t *FunctionBody3 = MemMgr->startFunctionBody(F3.get(), size);
+  memset(FunctionBody3, 0xFF, 1024);
+  MemMgr->endFunctionBody(F3.get(), FunctionBody3, FunctionBody3 + 1024);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 
   // Deallocate them out of order, in case that matters.
-  MemMgr->deallocateMemForFunction(F2.get());
+  MemMgr->deallocateFunctionBody(FunctionBody2);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
-  MemMgr->deallocateMemForFunction(F1.get());
+  MemMgr->deallocateFunctionBody(FunctionBody1);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
-  MemMgr->deallocateMemForFunction(F3.get());
+  MemMgr->deallocateFunctionBody(FunctionBody3);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 }
 
@@ -72,7 +71,6 @@
   OwningPtr<JITMemoryManager> MemMgr(
       JITMemoryManager::CreateDefaultMemManager());
   uintptr_t size;
-  uint8_t *start;
   std::string Error;
 
   // Big functions are a little less than the largest block size.
@@ -83,26 +81,26 @@
   // Allocate big functions
   OwningPtr<Function> F1(makeFakeFunction());
   size = bigFuncSize;
-  start = MemMgr->startFunctionBody(F1.get(), size);
+  uint8_t *FunctionBody1 = MemMgr->startFunctionBody(F1.get(), size);
   ASSERT_LE(bigFuncSize, size);
-  memset(start, 0xFF, bigFuncSize);
-  MemMgr->endFunctionBody(F1.get(), start, start + bigFuncSize);
+  memset(FunctionBody1, 0xFF, bigFuncSize);
+  MemMgr->endFunctionBody(F1.get(), FunctionBody1, FunctionBody1 + bigFuncSize);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 
   OwningPtr<Function> F2(makeFakeFunction());
   size = bigFuncSize;
-  start = MemMgr->startFunctionBody(F2.get(), size);
+  uint8_t *FunctionBody2 = MemMgr->startFunctionBody(F2.get(), size);
   ASSERT_LE(bigFuncSize, size);
-  memset(start, 0xFF, bigFuncSize);
-  MemMgr->endFunctionBody(F2.get(), start, start + bigFuncSize);
+  memset(FunctionBody2, 0xFF, bigFuncSize);
+  MemMgr->endFunctionBody(F2.get(), FunctionBody2, FunctionBody2 + bigFuncSize);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 
   OwningPtr<Function> F3(makeFakeFunction());
   size = bigFuncSize;
-  start = MemMgr->startFunctionBody(F3.get(), size);
+  uint8_t *FunctionBody3 = MemMgr->startFunctionBody(F3.get(), size);
   ASSERT_LE(bigFuncSize, size);
-  memset(start, 0xFF, bigFuncSize);
-  MemMgr->endFunctionBody(F3.get(), start, start + bigFuncSize);
+  memset(FunctionBody3, 0xFF, bigFuncSize);
+  MemMgr->endFunctionBody(F3.get(), FunctionBody3, FunctionBody3 + bigFuncSize);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 
   // Check that each large function took it's own slab.
@@ -111,43 +109,46 @@
   // Allocate small functions
   OwningPtr<Function> F4(makeFakeFunction());
   size = smallFuncSize;
-  start = MemMgr->startFunctionBody(F4.get(), size);
+  uint8_t *FunctionBody4 = MemMgr->startFunctionBody(F4.get(), size);
   ASSERT_LE(smallFuncSize, size);
-  memset(start, 0xFF, smallFuncSize);
-  MemMgr->endFunctionBody(F4.get(), start, start + smallFuncSize);
+  memset(FunctionBody4, 0xFF, smallFuncSize);
+  MemMgr->endFunctionBody(F4.get(), FunctionBody4,
+                          FunctionBody4 + smallFuncSize);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 
   OwningPtr<Function> F5(makeFakeFunction());
   size = smallFuncSize;
-  start = MemMgr->startFunctionBody(F5.get(), size);
+  uint8_t *FunctionBody5 = MemMgr->startFunctionBody(F5.get(), size);
   ASSERT_LE(smallFuncSize, size);
-  memset(start, 0xFF, smallFuncSize);
-  MemMgr->endFunctionBody(F5.get(), start, start + smallFuncSize);
+  memset(FunctionBody5, 0xFF, smallFuncSize);
+  MemMgr->endFunctionBody(F5.get(), FunctionBody5,
+                          FunctionBody5 + smallFuncSize);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 
   OwningPtr<Function> F6(makeFakeFunction());
   size = smallFuncSize;
-  start = MemMgr->startFunctionBody(F6.get(), size);
+  uint8_t *FunctionBody6 = MemMgr->startFunctionBody(F6.get(), size);
   ASSERT_LE(smallFuncSize, size);
-  memset(start, 0xFF, smallFuncSize);
-  MemMgr->endFunctionBody(F6.get(), start, start + smallFuncSize);
+  memset(FunctionBody6, 0xFF, smallFuncSize);
+  MemMgr->endFunctionBody(F6.get(), FunctionBody6,
+                          FunctionBody6 + smallFuncSize);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 
   // Check that the small functions didn't allocate any new slabs.
   EXPECT_EQ(3U, MemMgr->GetNumCodeSlabs());
 
   // Deallocate them out of order, in case that matters.
-  MemMgr->deallocateMemForFunction(F2.get());
+  MemMgr->deallocateFunctionBody(FunctionBody2);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
-  MemMgr->deallocateMemForFunction(F1.get());
+  MemMgr->deallocateFunctionBody(FunctionBody1);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
-  MemMgr->deallocateMemForFunction(F4.get());
+  MemMgr->deallocateFunctionBody(FunctionBody4);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
-  MemMgr->deallocateMemForFunction(F3.get());
+  MemMgr->deallocateFunctionBody(FunctionBody3);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
-  MemMgr->deallocateMemForFunction(F5.get());
+  MemMgr->deallocateFunctionBody(FunctionBody5);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
-  MemMgr->deallocateMemForFunction(F6.get());
+  MemMgr->deallocateFunctionBody(FunctionBody6);
   EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error;
 }
 

Modified: llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/JITTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/JITTest.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/JITTest.cpp (original)
+++ llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/JITTest.cpp Sun Nov  1 18:01:08 2009
@@ -9,6 +9,7 @@
 
 #include "gtest/gtest.h"
 #include "llvm/ADT/OwningPtr.h"
+#include "llvm/Assembly/Parser.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/Constant.h"
 #include "llvm/Constants.h"
@@ -22,6 +23,7 @@
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/TypeBuilder.h"
 #include "llvm/Target/TargetSelect.h"
 #include "llvm/Type.h"
@@ -49,14 +51,25 @@
  protected:
   virtual void SetUp() {
     M = new Module("<main>", Context);
+    MP = new ExistingModuleProvider(M);
     std::string Error;
-    TheJIT.reset(EngineBuilder(M).setEngineKind(EngineKind::JIT)
+    TheJIT.reset(EngineBuilder(MP).setEngineKind(EngineKind::JIT)
                  .setErrorStr(&Error).create());
     ASSERT_TRUE(TheJIT.get() != NULL) << Error;
   }
 
+  void LoadAssembly(const char *assembly) {
+    SMDiagnostic Error;
+    bool success = NULL != ParseAssemblyString(assembly, M, Error, Context);
+    std::string errMsg;
+    raw_string_ostream os(errMsg);
+    Error.Print("", os);
+    ASSERT_TRUE(success) << os.str();
+  }
+
   LLVMContext Context;
-  Module *M;  // Owned by ExecutionEngine.
+  Module *M;  // Owned by MP.
+  ModuleProvider *MP;  // Owned by ExecutionEngine.
   OwningPtr<ExecutionEngine> TheJIT;
 };
 
@@ -166,6 +179,20 @@
   EXPECT_EQ(8, TestFunctionPtr());
 }
 
+TEST_F(JITTest, ModuleDeletion) {
+  LoadAssembly("define void @main() { "
+               "  call i32 @computeVal() "
+               "  ret void "
+               "} "
+               " "
+               "define internal i32 @computeVal()  { "
+               "  ret i32 0 "
+               "} ");
+  Function *func = M->getFunction("main");
+  TheJIT->getPointerToFunction(func);
+  TheJIT->deleteModuleProvider(MP);
+}
+
 // This code is copied from JITEventListenerTest, but it only runs once for all
 // the tests in this directory.  Everything seems fine, but that's strange
 // behavior.

Modified: llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/Makefile?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/Makefile (original)
+++ llvm/branches/Apple/Leela/unittests/ExecutionEngine/JIT/Makefile Sun Nov  1 18:01:08 2009
@@ -9,7 +9,7 @@
 
 LEVEL = ../../..
 TESTNAME = JIT
-LINK_COMPONENTS := core support jit native
+LINK_COMPONENTS := asmparser core support jit native
 
 include $(LEVEL)/Makefile.config
 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest

Modified: llvm/branches/Apple/Leela/utils/TableGen/CodeGenDAGPatterns.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/utils/TableGen/CodeGenDAGPatterns.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/utils/TableGen/CodeGenDAGPatterns.h (original)
+++ llvm/branches/Apple/Leela/utils/TableGen/CodeGenDAGPatterns.h Sun Nov  1 18:01:08 2009
@@ -584,6 +584,8 @@
     return intrinsic_wo_chain_sdnode;
   }
   
+  bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); }
+
 private:
   void ParseNodeInfo();
   void ParseNodeTransforms();

Modified: llvm/branches/Apple/Leela/utils/TableGen/DAGISelEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/utils/TableGen/DAGISelEmitter.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/utils/TableGen/DAGISelEmitter.cpp (original)
+++ llvm/branches/Apple/Leela/utils/TableGen/DAGISelEmitter.cpp Sun Nov  1 18:01:08 2009
@@ -1967,6 +1967,7 @@
      << "  case ISD::TargetConstantPool:\n"
      << "  case ISD::TargetFrameIndex:\n"
      << "  case ISD::TargetExternalSymbol:\n"
+     << "  case ISD::TargetBlockAddress:\n"
      << "  case ISD::TargetJumpTable:\n"
      << "  case ISD::TargetGlobalTLSAddress:\n"
      << "  case ISD::TargetGlobalAddress:\n"
@@ -2067,8 +2068,16 @@
      << "  errs() << \"Cannot yet select: \";\n"
      << "  unsigned iid = cast<ConstantSDNode>(N.getOperand("
      << "N.getOperand(0).getValueType() == MVT::Other))->getZExtValue();\n"
-     << " llvm_report_error(\"Cannot yet select: intrinsic %\" +\n"
-     << "Intrinsic::getName((Intrinsic::ID)iid));\n"
+     << "  if (iid < Intrinsic::num_intrinsics)\n"
+     << "    llvm_report_error(\"Cannot yet select: intrinsic %\" + "
+     << "Intrinsic::getName((Intrinsic::ID)iid));\n";
+  if (CGP.hasTargetIntrinsics()) {
+    OS << "  else if (const TargetIntrinsicInfo *tii = TM.getIntrinsicInfo())\n"
+       << "    llvm_report_error(Twine(\"Cannot yet select: target intrinsic "
+       << "%\") + tii->getName(iid));\n";
+  }
+  OS << "  else\n"
+     << "    llvm_report_error(\"Cannot yet select: invalid intrinsic\");\n"
      << "}\n\n";
 }
 

Modified: llvm/branches/Apple/Leela/utils/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/utils/TableGen/Record.cpp?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/utils/TableGen/Record.cpp (original)
+++ llvm/branches/Apple/Leela/utils/TableGen/Record.cpp Sun Nov  1 18:01:08 2009
@@ -12,7 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Record.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/Format.h"
 #include "llvm/ADT/StringExtras.h"
 

Modified: llvm/branches/Apple/Leela/utils/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/utils/TableGen/Record.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/utils/TableGen/Record.h (original)
+++ llvm/branches/Apple/Leela/utils/TableGen/Record.h Sun Nov  1 18:01:08 2009
@@ -16,7 +16,7 @@
 #define RECORD_H
 
 #include "llvm/Support/SourceMgr.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/Support/raw_ostream.h"
 #include <map>
 

Modified: llvm/branches/Apple/Leela/utils/TableGen/TGLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/utils/TableGen/TGLexer.h?rev=85763&r1=85762&r2=85763&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/utils/TableGen/TGLexer.h (original)
+++ llvm/branches/Apple/Leela/utils/TableGen/TGLexer.h Sun Nov  1 18:01:08 2009
@@ -14,7 +14,7 @@
 #ifndef TGLEXER_H
 #define TGLEXER_H
 
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
 #include <vector>
 #include <string>
 #include <cassert>





More information about the llvm-branch-commits mailing list