aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2015-08-14 16:45:42 +0000
committerReid Kleckner <rnk@google.com>2015-08-14 16:45:42 +0000
commita57d0151542c228e36838c0a600c5ec9c05b2ea8 (patch)
tree732d02b3a3951f469c7c60ff5d52f7d2d9167a94 /llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
parent4cceca7c15e256c1e01c3476bab8045955842fbc (diff)
downloadllvm-a57d0151542c228e36838c0a600c5ec9c05b2ea8.zip
llvm-a57d0151542c228e36838c0a600c5ec9c05b2ea8.tar.gz
llvm-a57d0151542c228e36838c0a600c5ec9c05b2ea8.tar.bz2
[sancov] Leave llvm.localescape in the entry block
Summary: Similar to the change we applied to ASan. The same test case works. Reviewers: samsonov Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D11961 llvm-svn: 245067
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/Instrumentation.cpp')
-rw-r--r--llvm/lib/Transforms/Instrumentation/Instrumentation.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp b/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
index 2750585..68aee22 100644
--- a/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
@@ -12,12 +12,47 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/InitializePasses.h"
+#include "llvm/Transforms/Instrumentation.h"
#include "llvm-c/Initialization.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/InitializePasses.h"
#include "llvm/PassRegistry.h"
using namespace llvm;
+/// Moves I before IP. Returns new insert point.
+static BasicBlock::iterator moveBeforeInsertPoint(BasicBlock::iterator I, BasicBlock::iterator IP) {
+ // If I is IP, move the insert point down.
+ if (I == IP)
+ return ++IP;
+ // Otherwise, move I before IP and return IP.
+ I->moveBefore(IP);
+ return IP;
+}
+
+/// Instrumentation passes often insert conditional checks into entry blocks.
+/// Call this function before splitting the entry block to move instructions
+/// that must remain in the entry block up before the split point. Static
+/// allocas and llvm.localescape calls, for example, must remain in the entry
+/// block.
+BasicBlock::iterator llvm::PrepareToSplitEntryBlock(BasicBlock &BB,
+ BasicBlock::iterator IP) {
+ assert(&BB.getParent()->getEntryBlock() == &BB);
+ for (auto I = IP, E = BB.end(); I != E; ++I) {
+ bool KeepInEntry = false;
+ if (auto *AI = dyn_cast<AllocaInst>(I)) {
+ if (AI->isStaticAlloca())
+ KeepInEntry = true;
+ } else if (auto *II = dyn_cast<IntrinsicInst>(I)) {
+ if (II->getIntrinsicID() == llvm::Intrinsic::localescape)
+ KeepInEntry = true;
+ }
+ if (KeepInEntry)
+ IP = moveBeforeInsertPoint(I, IP);
+ }
+ return IP;
+}
+
/// initializeInstrumentation - Initialize all passes in the TransformUtils
/// library.
void llvm::initializeInstrumentation(PassRegistry &Registry) {