[PATCH] D21357: [CrossDSOCFI] Change the pass so that it doesn't require doInitialization()

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 14 15:42:00 PDT 2016


davide created this revision.
davide added reviewers: eugenis, chandlerc, pcc.
davide added a subscriber: llvm-commits.

Chandler tells me that the equivalent of doInitialization in the new PM is the constructor.
This one, though, doesn't access to the module. I think that for this particular pass doInitialization() can be avoided, so I tried to modify it accordingly. Please let me know if I missed something obvious as I'm not familiar at all with this pass.

http://reviews.llvm.org/D21357

Files:
  lib/Transforms/IPO/CrossDSOCFI.cpp

Index: lib/Transforms/IPO/CrossDSOCFI.cpp
===================================================================
--- lib/Transforms/IPO/CrossDSOCFI.cpp
+++ lib/Transforms/IPO/CrossDSOCFI.cpp
@@ -45,14 +45,12 @@
   CrossDSOCFI() : ModulePass(ID) {
     initializeCrossDSOCFIPass(*PassRegistry::getPassRegistry());
   }
-
-  Module *M;
   MDNode *VeryLikelyWeights;
 
   ConstantInt *extractBitSetTypeId(MDNode *MD);
-  void buildCFICheck();
+  void buildCFICheck(Module &M);
 
-  bool doInitialization(Module &M) override;
+  //bool doInitialization(Module &M) override;
   bool runOnModule(Module &M) override;
 };
 
@@ -65,14 +63,6 @@
 
 ModulePass *llvm::createCrossDSOCFIPass() { return new CrossDSOCFI; }
 
-bool CrossDSOCFI::doInitialization(Module &Mod) {
-  M = &Mod;
-  VeryLikelyWeights =
-      MDBuilder(M->getContext()).createBranchWeights((1U << 20) - 1, 1);
-
-  return false;
-}
-
 /// extractBitSetTypeId - Extracts TypeId from a hash-based bitset MDNode.
 ConstantInt *CrossDSOCFI::extractBitSetTypeId(MDNode *MD) {
   // This check excludes vtables for classes inside anonymous namespaces.
@@ -97,19 +87,19 @@
 }
 
 /// buildCFICheck - emits __cfi_check for the current module.
-void CrossDSOCFI::buildCFICheck() {
+void CrossDSOCFI::buildCFICheck(Module &M) {
   // FIXME: verify that __cfi_check ends up near the end of the code section,
   // but before the jump slots created in LowerBitSets.
   llvm::DenseSet<uint64_t> BitSetIds;
-  NamedMDNode *BitSetNM = M->getNamedMetadata("llvm.bitsets");
+  NamedMDNode *BitSetNM = M.getNamedMetadata("llvm.bitsets");
 
   if (BitSetNM)
     for (unsigned I = 0, E = BitSetNM->getNumOperands(); I != E; ++I)
       if (ConstantInt *TypeId = extractBitSetTypeId(BitSetNM->getOperand(I)))
         BitSetIds.insert(TypeId->getZExtValue());
 
-  LLVMContext &Ctx = M->getContext();
-  Constant *C = M->getOrInsertFunction(
+  LLVMContext &Ctx = M.getContext();
+  Constant *C = M.getOrInsertFunction(
       "__cfi_check", Type::getVoidTy(Ctx), Type::getInt64Ty(Ctx),
       Type::getInt8PtrTy(Ctx), Type::getInt8PtrTy(Ctx), nullptr);
   Function *F = dyn_cast<Function>(C);
@@ -128,7 +118,7 @@
 
   BasicBlock *TrapBB = BasicBlock::Create(Ctx, "fail", F);
   IRBuilder<> IRBFail(TrapBB);
-  Constant *CFICheckFailFn = M->getOrInsertFunction(
+  Constant *CFICheckFailFn = M.getOrInsertFunction(
       "__cfi_check_fail", Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx),
       Type::getInt8PtrTy(Ctx), nullptr);
   IRBFail.CreateCall(CFICheckFailFn, {&CFICheckFailData, &Addr});
@@ -144,7 +134,7 @@
     BasicBlock *TestBB = BasicBlock::Create(Ctx, "test", F);
     IRBuilder<> IRBTest(TestBB);
     Function *BitsetTestFn =
-        Intrinsic::getDeclaration(M, Intrinsic::bitset_test);
+        Intrinsic::getDeclaration(&M, Intrinsic::bitset_test);
 
     Value *Test = IRBTest.CreateCall(
         BitsetTestFn, {&Addr, MetadataAsValue::get(
@@ -161,8 +151,10 @@
   if (skipModule(M))
     return false;
 
+  VeryLikelyWeights =
+    MDBuilder(M.getContext()).createBranchWeights((1U << 20) - 1, 1);
   if (M.getModuleFlag("Cross-DSO CFI") == nullptr)
     return false;
-  buildCFICheck();
+  buildCFICheck(M);
   return true;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21357.60775.patch
Type: text/x-patch
Size: 3192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160614/d4d4bfa6/attachment.bin>


More information about the llvm-commits mailing list