[PATCH] D129288: [IR] Don't use blockaddresses as callbr arguments

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 06:47:36 PDT 2022


nikic created this revision.
nikic added reviewers: nickdesaulniers, nathanchance, efriedma, craig.topper.
Herald added subscribers: jsji, StephenFan, wenlei, jdoerfert, pengfei, asbirlea, zzheng, kbarton, hiraditya, nemanjai.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Following some recent discussions, this changes the representation of callbrs in IR. The change is very simple: The current blockaddress arguments are replaced with poison value placeholder arguments:

  ; Before:
  %res = callbr i8* asm "# $0\0A\09# ${2:l}", "=r,0,i,~{dirflag},~{fpsr},~{flags}"(i8* %0, i8* blockaddress(@test8, %foo))
  to label %asm.fallthrough [label %foo]
  ; After:
  %res = callbr i8* asm "# $0\0A\09# ${2:l}", "=r,0,i,~{dirflag},~{fpsr},~{flags}"(i8* %0, i8* poison)
  to label %asm.fallthrough [label %foo]

These placeholder arguments behave "as if" we actually put a blockaddress to the corresponding indirect target there (this replacement happens only when lowering to SDAG). The benefit of this is that we can easily update the successors of a callbr, without having to worry about also updating blockaddress references. This would allow us to remove various limitations and gotcha, e.g. that callbr successors can only be updated with specific APIs, and that the instruction effectively cannot be cloned.

Why the poison placeholders? This makes it easy to satisfy the existing inlineasm infrastructure. It would be cleaner to omit the placeholder arguments and just say that trailing inlinasm constraints refer to the indirect target labels. InlineAsm itself doesn't have knowledge about those though, so it would not be possible to verify InlineAsm constraints in isolation.


https://reviews.llvm.org/D129288

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/asm-goto.c
  clang/test/CodeGen/asm.c
  clang/test/Modules/asm-goto.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/Instructions.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/Analysis/BasicAA/pr52735.ll
  llvm/test/Assembler/call-arg-is-callee.ll
  llvm/test/Bitcode/callbr.ll
  llvm/test/CodeGen/AArch64/callbr-asm-label.ll
  llvm/test/CodeGen/AArch64/callbr-asm-obj-file.ll
  llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll
  llvm/test/CodeGen/ARM/speculation-hardening-sls.ll
  llvm/test/CodeGen/PowerPC/ppc64-inlineasm-clobber.ll
  llvm/test/CodeGen/SystemZ/asm-20.ll
  llvm/test/CodeGen/X86/callbr-asm-bb-exports.ll
  llvm/test/CodeGen/X86/callbr-asm-blockplacement.ll
  llvm/test/CodeGen/X86/callbr-asm-branch-folding.ll
  llvm/test/CodeGen/X86/callbr-asm-destinations.ll
  llvm/test/CodeGen/X86/callbr-asm-errors.ll
  llvm/test/CodeGen/X86/callbr-asm-instr-scheduling.ll
  llvm/test/CodeGen/X86/callbr-asm-kill.mir
  llvm/test/CodeGen/X86/callbr-asm-label-addr.ll
  llvm/test/CodeGen/X86/callbr-asm-obj-file.ll
  llvm/test/CodeGen/X86/callbr-asm-outputs-pred-succ.ll
  llvm/test/CodeGen/X86/callbr-asm-outputs.ll
  llvm/test/CodeGen/X86/callbr-asm-phi-placement.ll
  llvm/test/CodeGen/X86/callbr-asm-sink.ll
  llvm/test/CodeGen/X86/callbr-asm.ll
  llvm/test/CodeGen/X86/callbr-codegenprepare.ll
  llvm/test/CodeGen/X86/inline-asm-pic.ll
  llvm/test/CodeGen/X86/shrinkwrap-callbr.ll
  llvm/test/CodeGen/X86/speculation-hardening-sls.ll
  llvm/test/CodeGen/X86/tail-dup-asm-goto.ll
  llvm/test/Instrumentation/MemorySanitizer/msan_asm_conservative.ll
  llvm/test/Transforms/CallSiteSplitting/callsite-split-callbr.ll
  llvm/test/Transforms/CodeExtractor/PartialInlinePGOMultiRegion.ll
  llvm/test/Transforms/Coroutines/coro-debug.ll
  llvm/test/Transforms/GVN/callbr-loadpre-critedge.ll
  llvm/test/Transforms/GVN/callbr-scalarpre-critedge.ll
  llvm/test/Transforms/GVN/critical-edge-split-failure.ll
  llvm/test/Transforms/IROutliner/illegal-callbr.ll
  llvm/test/Transforms/Inline/blockaddress.ll
  llvm/test/Transforms/Inline/callbr.ll
  llvm/test/Transforms/JumpThreading/callbr-edge-split.ll
  llvm/test/Transforms/JumpThreading/pr46857-callbr.ll
  llvm/test/Transforms/LICM/callbr-crash.ll
  llvm/test/Transforms/LoopDeletion/two-predecessors.ll
  llvm/test/Transforms/LoopRotate/callbr.ll
  llvm/test/Transforms/LoopStrengthReduce/callbr-critical-edge-splitting.ll
  llvm/test/Transforms/LoopStrengthReduce/callbr-critical-edge-splitting2.ll
  llvm/test/Transforms/LoopUnroll/callbr.ll
  llvm/test/Transforms/PGOProfile/callbr.ll
  llvm/test/Transforms/SimpleLoopUnswitch/not-safe-to-clone.ll
  llvm/test/Transforms/SimplifyCFG/callbr-destinations.ll
  llvm/test/Transforms/SimplifyCFG/jump-threading.ll
  llvm/test/Verifier/callbr.ll
  llvm/test/Verifier/dominates.ll
  llvm/test/tools/llvm-diff/callbr.ll
  llvm/test/tools/llvm-diff/phinode.ll
  llvm/test/tools/llvm-reduce/remove-function-arguments-of-funcs-used-in-blockaddress.ll
  llvm/unittests/IR/InstructionsTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129288.442883.patch
Type: text/x-patch
Size: 76557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220707/df05433c/attachment.bin>


More information about the llvm-commits mailing list