Orc: Drop some else-after-return, reflow a few spots, and avoid use of pointee types
[oota-llvm.git] / include / llvm / ExecutionEngine / Orc / CompileOnDemandLayer.h
index ce5aa8f..07914e3 100644 (file)
@@ -246,10 +246,9 @@ private:
         StubInits[mangle(F.getName(), DL)] =
           std::make_pair(CCInfo.getAddress(),
                          JITSymbolBase::flagsFromGlobalValue(F));
-        CCInfo.setCompileAction(
-          [this, &LD, LMH, &F]() {
-            return this->extractAndCompile(LD, LMH, F);
-          });
+        CCInfo.setCompileAction([this, &LD, LMH, &F]() {
+          return this->extractAndCompile(LD, LMH, F);
+        });
       }
 
       LMResources.StubsMgr = CreateIndirectStubsManager();
@@ -339,10 +338,7 @@ private:
 
   static std::string mangle(StringRef Name, const DataLayout &DL) {
     std::string MangledName;
-    {
-      raw_string_ostream MangledNameStream(MangledName);
-      Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
-    }
+    Mangler::getNameWithPrefix(raw_string_ostream(MangledName), Name, DL);
     return MangledName;
   }
 
@@ -401,42 +397,42 @@ private:
     M->setDataLayout(SrcM.getDataLayout());
     ValueToValueMapTy VMap;
 
-    auto Materializer = createLambdaMaterializer(
-      [this, &LMResources, &M, &VMap](Value *V) -> Value* {
-        if (auto *GV = dyn_cast<GlobalVariable>(V)) {
-          return cloneGlobalVariableDecl(*M, *GV);
-        } else if (auto *F = dyn_cast<Function>(V)) {
-          // Check whether we want to clone an available_externally definition.
-          if (LMResources.StubsToClone.count(F)) {
-            // Ok - we want an inlinable stub. For that to work we need a decl
-            // for the stub pointer.
-            auto *StubPtr = createImplPointer(*F->getType(), *M,
-                                              F->getName() + "$stub_ptr",
-                                              nullptr);
-            auto *ClonedF = cloneFunctionDecl(*M, *F);
-            makeStub(*ClonedF, *StubPtr);
-            ClonedF->setLinkage(GlobalValue::AvailableExternallyLinkage);
-            ClonedF->addFnAttr(Attribute::AlwaysInline);
-            return ClonedF;
-          }
+    auto Materializer = createLambdaMaterializer([this, &LMResources, &M,
+                                                  &VMap](Value *V) -> Value * {
+      if (auto *GV = dyn_cast<GlobalVariable>(V))
+        return cloneGlobalVariableDecl(*M, *GV);
 
+      if (auto *F = dyn_cast<Function>(V)) {
+        // Check whether we want to clone an available_externally definition.
+        if (!LMResources.StubsToClone.count(F))
           return cloneFunctionDecl(*M, *F);
-        } else if (auto *A = dyn_cast<GlobalAlias>(V)) {
-          auto *PTy = cast<PointerType>(A->getType());
-          if (PTy->getElementType()->isFunctionTy())
-            return Function::Create(cast<FunctionType>(PTy->getElementType()),
-                                    GlobalValue::ExternalLinkage,
-                                    A->getName(), M.get());
-          // else
-          return new GlobalVariable(*M, PTy->getElementType(), false,
-                                    GlobalValue::ExternalLinkage,
-                                    nullptr, A->getName(), nullptr,
-                                    GlobalValue::NotThreadLocal,
-                                    PTy->getAddressSpace());
-        }
-        // Else.
-        return nullptr;
-      });
+
+        // Ok - we want an inlinable stub. For that to work we need a decl
+        // for the stub pointer.
+        auto *StubPtr = createImplPointer(*F->getType(), *M,
+                                          F->getName() + "$stub_ptr", nullptr);
+        auto *ClonedF = cloneFunctionDecl(*M, *F);
+        makeStub(*ClonedF, *StubPtr);
+        ClonedF->setLinkage(GlobalValue::AvailableExternallyLinkage);
+        ClonedF->addFnAttr(Attribute::AlwaysInline);
+        return ClonedF;
+      }
+
+      if (auto *A = dyn_cast<GlobalAlias>(V)) {
+        auto *Ty = A->getValueType();
+        if (Ty->isFunctionTy())
+          return Function::Create(cast<FunctionType>(Ty),
+                                  GlobalValue::ExternalLinkage, A->getName(),
+                                  M.get());
+
+        return new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage,
+                                  nullptr, A->getName(), nullptr,
+                                  GlobalValue::NotThreadLocal,
+                                  A->getType()->getAddressSpace());
+      }
+
+      return nullptr;
+    });
 
     // Create decls in the new module.
     for (auto *F : Part)