[PATCH} Remove '.bc' input support from the frontend

Alp Toker alp at nuanti.com
Tue Jun 24 22:31:24 PDT 2014


The attached patch removes code that apparently supported '.bc' binary 
LLVM bitcode as a frontend input kind.

There were no tests and it's unclear if it was in a working state. I'm 
comfortable removing this because it doesn't really align with the 
frontend's primary objective of diagnosing textual input and lowering 
source code.

The removal lets us parse and diagnose '.ll' IR inputs more efficiently 
without duplicating file contents into memory.

(If there's desire to keep '.bc' support and someone contributes tests 
for it, I'm fine to explore other ways to achieve this optimisation.)

Requires the recently posted MemoryBuffer patch.

Alp.

-- 
http://www.nuanti.com
the browser experts

-------------- next part --------------
>From 6c4617344bb9f05d46ac9674b7c83e63724256c4 Mon Sep 17 00:00:00 2001
From: Alp Toker <alp at nuanti.com>
Date: Tue, 24 Jun 2014 23:46:25 +0300
Subject: [PATCH 3/3] Remove unused '.bc' input and optimize '.ll' support

The '.bc' binary input file support had no tests and didn't really really make
sense as a frontend input.

Removing it lets us avoid copying whole file contents into memory in the common
case because ParseAssembly() can share ownership unlike the catch-all
ParseIR().
---
 lib/CodeGen/CodeGenAction.cpp    | 10 +++-------
 lib/Frontend/FrontendOptions.cpp |  2 +-
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp
index 433be66..3e48fa1 100644
--- a/lib/CodeGen/CodeGenAction.cpp
+++ b/lib/CodeGen/CodeGenAction.cpp
@@ -20,13 +20,13 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/AsmParser/Parser.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/DiagnosticPrinter.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
-#include "llvm/IRReader/IRReader.h"
 #include "llvm/Linker/Linker.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -638,13 +638,9 @@ void CodeGenAction::ExecuteAction() {
     if (Invalid)
       return;
 
-    // FIXME: This is stupid, IRReader shouldn't take ownership.
-    llvm::MemoryBuffer *MainFileCopy =
-      llvm::MemoryBuffer::getMemBufferCopy(MainFile->getBuffer(),
-                                           getCurrentFile());
-
     llvm::SMDiagnostic Err;
-    TheModule.reset(ParseIR(MainFileCopy, Err, *VMContext));
+    TheModule.reset(ParseAssembly(const_cast<MemoryBuffer *>(MainFile), nullptr,
+                                  Err, *VMContext));
     if (!TheModule) {
       // Translate from the diagnostic info to the SourceManager location.
       SourceLocation Loc = SM.translateFileLineCol(
diff --git a/lib/Frontend/FrontendOptions.cpp b/lib/Frontend/FrontendOptions.cpp
index 1869d0c..dd233e3 100644
--- a/lib/Frontend/FrontendOptions.cpp
+++ b/lib/Frontend/FrontendOptions.cpp
@@ -26,6 +26,6 @@ InputKind FrontendOptions::getInputKindForExtension(StringRef Extension) {
     .Cases("cpp", "CPP", "c++", "cxx", "hpp", IK_CXX)
     .Case("cl", IK_OpenCL)
     .Case("cu", IK_CUDA)
-    .Cases("ll", "bc", IK_LLVM_IR)
+    .Case("ll", IK_LLVM_IR)
     .Default(IK_C);
 }
-- 
1.9.1



More information about the cfe-commits mailing list