Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add a new @llvm.donothing intrinsic that, well, does nothing, and tea…

…ch CodeGen to ignore calls to it

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159383 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information...
commit c57595eda28b86f64400519246313bb3e1eb364b 1 parent 992c9c9
Nuno Lopes nunoplopes authored
3  include/llvm/Intrinsics.td
@@ -412,6 +412,9 @@ def int_trap : Intrinsic<[], [], [IntrNoReturn]>,
412 412 def int_debugtrap : Intrinsic<[]>,
413 413 GCCBuiltin<"__builtin_debugtrap">;
414 414
  415 +// NOP: calls/invokes to this intrinsic are removed by codegen
  416 +def int_donothing : Intrinsic<[], [], [IntrNoMem]>;
  417 +
415 418 // Intrisics to support half precision floating point format
416 419 let Properties = [IntrNoMem] in {
417 420 def int_convert_to_fp16 : Intrinsic<[llvm_i16_ty], [llvm_float_ty]>,
9 lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1828,9 +1828,13 @@ void SelectionDAGBuilder::visitInvoke(const InvokeInst &I) {
1828 1828 MachineBasicBlock *LandingPad = FuncInfo.MBBMap[I.getSuccessor(1)];
1829 1829
1830 1830 const Value *Callee(I.getCalledValue());
  1831 + const Function *Fn = dyn_cast<Function>(Callee);
1831 1832 if (isa<InlineAsm>(Callee))
1832 1833 visitInlineAsm(&I);
1833   - else
  1834 + else if (Fn && Fn->isIntrinsic()) {
  1835 + assert(Fn->getIntrinsicID() == Intrinsic::donothing);
  1836 + return; // ignore invokes to @llvm.donothing
  1837 + } else
1834 1838 LowerCallTo(&I, getValue(Callee), false, LandingPad);
1835 1839
1836 1840 // If the value of the invoke is used outside of its defining block, make it
@@ -5178,6 +5182,9 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
5178 5182 case Intrinsic::lifetime_end:
5179 5183 // Discard region information.
5180 5184 return 0;
  5185 + case Intrinsic::donothing:
  5186 + // ignore
  5187 + return 0;
5181 5188 }
5182 5189 }
5183 5190
31 test/CodeGen/Generic/donothing.ll
... ... @@ -0,0 +1,31 @@
  1 +; RUN: llc < %s | FileCheck %s
  2 +
  3 +declare i32 @__gxx_personality_v0(...)
  4 +declare void @__cxa_call_unexpected(i8*)
  5 +declare void @llvm.donothing() readnone
  6 +
  7 +; CHECK: f1
  8 +define void @f1() nounwind uwtable ssp {
  9 +entry:
  10 +; CHECK-NOT donothing
  11 + invoke void @llvm.donothing()
  12 + to label %invoke.cont unwind label %lpad
  13 +
  14 +invoke.cont:
  15 + ret void
  16 +
  17 +lpad:
  18 + %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
  19 + filter [0 x i8*] zeroinitializer
  20 + %1 = extractvalue { i8*, i32 } %0, 0
  21 + tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind
  22 + unreachable
  23 +}
  24 +
  25 +; CHECK: f2
  26 +define void @f2() nounwind {
  27 +entry:
  28 +; CHECK-NOT donothing
  29 + call void @llvm.donothing()
  30 + ret void
  31 +}

0 comments on commit c57595e

Please sign in to comment.
Something went wrong with that request. Please try again.