llvm/lib/Transforms/Utils
Duncan P. N. Exon Smith 698c0a7097 ValueMapper: Treat LocalAsMetadata more like function-local Values
This is a partial re-commit -- maybe more of a re-implementation -- of
r265631 (reverted in r265637).

This makes RF_IgnoreMissingLocals behave (almost) consistently between
the Value and the Metadata hierarchy.  In particular:

  - MapValue returns nullptr or "metadata !{}" for missing locals in
    MetadataAsValue/LocalAsMetadata bridging paris, depending on
    the RF_IgnoreMissingLocals flag.

  - MapValue doesn't memoize LocalAsMetadata-related results.

  - MapMetadata no longer deals with LocalAsMetadata or
    RF_IgnoreMissingLocals at all.  (This wasn't in r265631 at all, but
    I realized during testing it would make the patch simpler with no
    loss of generality.)

r265631 went too far, making both functions universally ignore
RF_IgnoreMissingLocals.  This broke building (e.g.) compiler-rt.
Reassociate (and possibly other passes) don't currently maintain
dominates-use invariants for metadata operands, resulting in IR like
this:

    define void @foo(i32 %arg) {
      call void @llvm.some.intrinsic(metadata i32 %x)
      %x = add i32 1, i32 %arg
    }

If the inliner chooses to inline @foo into another function, then
RemapInstruction will call `MapValue(metadata i32 %x)` and assert that
the return is not nullptr.

I've filed PR27273 to add a Verifier check and fix the underlying
problem in the optimization passes.

As a workaround, return `!{}` instead of nullptr for unmapped
LocalAsMetadata when RF_IgnoreMissingLocals is unset.  Otherwise, match
the behaviour of r265631.

Original commit message:

    ValueMapper: Make LocalAsMetadata match function-local Values

    Start treating LocalAsMetadata similarly to function-local members of
    the Value hierarchy in MapValue and MapMetadata.

      - Don't memoize them.
      - Return nullptr if they are missing.

    This also cleans up ConstantAsMetadata to stop listening to the
    RF_IgnoreMissingLocals flag.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265759 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-08 00:33:44 +00:00
..
AddDiscriminators.cpp Remove llvm::getDISubprogram in favor of Function::getSubprogram 2016-03-11 02:14:16 +00:00
ASanStackFrameLayout.cpp
BasicBlockUtils.cpp [LV] Preserve LoopInfo when store predication is used 2016-03-15 18:06:20 +00:00
BreakCriticalEdges.cpp
BuildLibCalls.cpp Fix Clang-tidy readability-redundant-control-flow warnings; other minor fixes. 2016-02-02 18:20:45 +00:00
BypassSlowDivision.cpp
CloneFunction.cpp IR: RF_IgnoreMissingValues => RF_IgnoreMissingLocals, NFC 2016-04-07 00:26:43 +00:00
CloneModule.cpp Preserve extern_weak linkage in CloneModule. 2016-03-31 20:21:31 +00:00
CMakeLists.txt [ThinLTO] Move global processing from Linker to TransformUtils (NFC) 2016-02-10 18:11:31 +00:00
CmpInstAnalysis.cpp
CodeExtractor.cpp
CtorUtils.cpp
DemoteRegToStack.cpp
Evaluator.cpp IR: Introduce ConstantAggregate, NFC 2016-04-05 21:10:45 +00:00
FlattenCFG.cpp
FunctionImportUtils.cpp Rework linkInModule(), making it oblivious to ThinLTO 2016-03-19 00:40:31 +00:00
GlobalStatus.cpp NFC: make AtomicOrdering an enum class 2016-04-06 21:19:33 +00:00
InlineFunction.cpp Don't insert stackrestore on deoptimizing returns 2016-04-01 02:51:30 +00:00
InstructionNamer.cpp
IntegerDivision.cpp TransformUtils: Avoid getNodePtrUnchecked() in integer division, NFC 2016-02-21 20:14:29 +00:00
LCSSA.cpp [AA] Preserve the AA results wrapper pass as well as BasicAA in a few 2016-02-19 03:12:14 +00:00
LLVMBuild.txt
Local.cpp [RS4GC] Lower calls to @llvm.experimental.deoptimize 2016-03-25 20:12:13 +00:00
LoopSimplify.cpp
LoopUnroll.cpp Follow-up for r265605: don't mutate vector we're iterating. 2016-04-07 00:09:42 +00:00
LoopUnrollRuntime.cpp IR: RF_IgnoreMissingValues => RF_IgnoreMissingLocals, NFC 2016-04-07 00:26:43 +00:00
LoopUtils.cpp Remove HasFnAttribute guards to getFnAttribute calls 2016-03-30 15:41:12 +00:00
LoopVersioning.cpp [LoopVersioning] Relax an assert for LCSSA PHIs 2016-03-22 18:38:15 +00:00
LowerInvoke.cpp
LowerSwitch.cpp
Mem2Reg.cpp
MemorySSA.cpp Fix "warning: variabl 'XX’ set but not used" in release build (variable used in assertion, NFC) 2016-04-02 05:34:19 +00:00
MetaRenamer.cpp
ModuleUtils.cpp [ModuleUtils] Use range-based loop. NFC. 2016-03-23 00:43:35 +00:00
PromoteMemoryToRegister.cpp Remove uses of builtin comma operator. 2016-02-18 22:09:30 +00:00
SanitizerStats.cpp
SimplifyCFG.cpp IR: RF_IgnoreMissingValues => RF_IgnoreMissingLocals, NFC 2016-04-07 00:26:43 +00:00
SimplifyIndVar.cpp [IndVars] Make the fix for PR26973 more obvious; NFCI 2016-03-18 20:37:11 +00:00
SimplifyInstructions.cpp
SimplifyLibCalls.cpp [SimplifyLibCalls] Garbage collect dead code. 2016-04-03 01:46:52 +00:00
SplitModule.cpp Preserve blockaddress use edges in the module splitter. 2016-03-31 21:55:11 +00:00
SSAUpdater.cpp
SymbolRewriter.cpp
UnifyFunctionExitNodes.cpp
Utils.cpp This patch adds MemorySSA to LLVM. 2016-02-02 22:46:49 +00:00
ValueMapper.cpp ValueMapper: Treat LocalAsMetadata more like function-local Values 2016-04-08 00:33:44 +00:00