Skip to content

Commit

Permalink
Revert 125820 and 125819 to fix PR9266.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126050 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Feb 19, 2011
1 parent b20f5c6 commit 96b1d4b
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 87 deletions.
25 changes: 24 additions & 1 deletion examples/PrintFunctionNames/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
set(MODULE TRUE)

set( LLVM_USED_LIBS
clangFrontendTool
clangFrontend
clangDriver
clangSerialization
clangCodeGen
clangParse
clangSema
clangStaticAnalyzerFrontend
clangStaticAnalyzerCheckers
clangStaticAnalyzerCore
clangAnalysis
clangIndex
clangRewrite
clangAST
clangLex
clangBasic
)

set( LLVM_LINK_COMPONENTS support mc)
# Why do we have to link to all this just to print out function names?
set( LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
asmparser
bitreader
bitwriter
codegen
ipo
selectiondag
)

add_clang_library(PrintFunctionNames PrintFunctionNames.cpp)

Expand Down
2 changes: 2 additions & 0 deletions examples/clang-interpreter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"

#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Config/config.h"
#include "llvm/ADT/OwningPtr.h"
Expand Down Expand Up @@ -129,6 +130,7 @@ int main(int argc, const char **argv, char * const *envp) {

// Create a compiler instance to handle the actual work.
CompilerInstance Clang;
Clang.setLLVMContext(new llvm::LLVMContext);
Clang.setInvocation(CI.take());

// Create the compilers actual diagnostics engine.
Expand Down
8 changes: 8 additions & 0 deletions include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
namespace llvm {
struct fltSemantics;
class StringRef;
class LLVMContext;
class Type;
}

namespace clang {
Expand Down Expand Up @@ -530,6 +532,12 @@ class TargetInfo {
virtual const char *getStaticInitSectionSpecifier() const {
return 0;
}

virtual const llvm::Type* adjustInlineAsmType(std::string& Constraint,
const llvm::Type* Ty,
llvm::LLVMContext& Context) const {
return Ty;
}
protected:
virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
return PointerWidth;
Expand Down
23 changes: 7 additions & 16 deletions include/clang/CodeGen/CodeGenAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "llvm/ADT/OwningPtr.h"

namespace llvm {
class LLVMContext;
class Module;
}

Expand All @@ -25,14 +24,9 @@ class CodeGenAction : public ASTFrontendAction {
private:
unsigned Act;
llvm::OwningPtr<llvm::Module> TheModule;
llvm::LLVMContext *VMContext;
bool OwnsVMContext;

protected:
/// Create a new code generation action. If the optional \arg _VMContext
/// parameter is supplied, the action uses it without taking ownership,
/// otherwise it creates a fresh LLVM context and takes ownership.
CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = 0);
CodeGenAction(unsigned _Act);

virtual bool hasIRSupport() const;

Expand All @@ -50,40 +44,37 @@ class CodeGenAction : public ASTFrontendAction {
/// been run. The result may be null on failure.
llvm::Module *takeModule();

/// Take the LLVM context used by this action.
llvm::LLVMContext *takeLLVMContext();

BackendConsumer *BEConsumer;
};

class EmitAssemblyAction : public CodeGenAction {
public:
EmitAssemblyAction(llvm::LLVMContext *_VMContext = 0);
EmitAssemblyAction();
};

class EmitBCAction : public CodeGenAction {
public:
EmitBCAction(llvm::LLVMContext *_VMContext = 0);
EmitBCAction();
};

class EmitLLVMAction : public CodeGenAction {
public:
EmitLLVMAction(llvm::LLVMContext *_VMContext = 0);
EmitLLVMAction();
};

class EmitLLVMOnlyAction : public CodeGenAction {
public:
EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = 0);
EmitLLVMOnlyAction();
};

class EmitCodeGenOnlyAction : public CodeGenAction {
public:
EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = 0);
EmitCodeGenOnlyAction();
};

class EmitObjAction : public CodeGenAction {
public:
EmitObjAction(llvm::LLVMContext *_VMContext = 0);
EmitObjAction();
};

}
Expand Down
2 changes: 2 additions & 0 deletions include/clang/Frontend/ASTConsumers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace llvm {
class raw_ostream;
class Module;
class LLVMContext;
namespace sys { class Path; }
}
namespace clang {
Expand Down
21 changes: 21 additions & 0 deletions include/clang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string>

namespace llvm {
class LLVMContext;
class raw_ostream;
class raw_fd_ostream;
class Timer;
Expand Down Expand Up @@ -58,6 +59,9 @@ class TargetInfo;
/// come in two forms; a short form that reuses the CompilerInstance objects,
/// and a long form that takes explicit instances of any required objects.
class CompilerInstance {
/// The LLVM context used for this instance.
llvm::OwningPtr<llvm::LLVMContext> LLVMContext;

/// The options used in this compiler instance.
llvm::OwningPtr<CompilerInvocation> Invocation;

Expand Down Expand Up @@ -150,6 +154,23 @@ class CompilerInstance {
// of the context or else not CompilerInstance specific.
bool ExecuteAction(FrontendAction &Act);

/// }
/// @name LLVM Context
/// {

bool hasLLVMContext() const { return LLVMContext != 0; }

llvm::LLVMContext &getLLVMContext() const {
assert(LLVMContext && "Compiler instance has no LLVM context!");
return *LLVMContext;
}

llvm::LLVMContext *takeLLVMContext() { return LLVMContext.take(); }

/// setLLVMContext - Replace the current LLVM context and take ownership of
/// \arg Value.
void setLLVMContext(llvm::LLVMContext *Value);

/// }
/// @name Compiler Invocation and Options
/// {
Expand Down
12 changes: 12 additions & 0 deletions lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,9 @@ class X86TargetInfo : public TargetInfo {
}
virtual bool validateAsmConstraint(const char *&Name,
TargetInfo::ConstraintInfo &info) const;
virtual const llvm::Type* adjustInlineAsmType(std::string& Constraint,
const llvm::Type* Ty,
llvm::LLVMContext& Context) const;
virtual std::string convertConstraint(const char Constraint) const;
virtual const char *getClobbers() const {
return "~{dirflag},~{fpsr},~{flags}";
Expand Down Expand Up @@ -1338,6 +1341,15 @@ X86TargetInfo::validateAsmConstraint(const char *&Name,
return false;
}

const llvm::Type*
X86TargetInfo::adjustInlineAsmType(std::string& Constraint,
const llvm::Type* Ty,
llvm::LLVMContext &Context) const {
if (Constraint=="y" && Ty->isVectorTy())
return llvm::Type::getX86_MMXTy(Context);
return Ty;
}


std::string
X86TargetInfo::convertConstraint(const char Constraint) const {
Expand Down
9 changes: 4 additions & 5 deletions lib/CodeGen/CGStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "CGDebugInfo.h"
#include "CodeGenModule.h"
#include "CodeGenFunction.h"
#include "TargetInfo.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/PrettyStackTrace.h"
#include "clang/Basic/TargetInfo.h"
Expand Down Expand Up @@ -1136,8 +1135,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
}
}
if (const llvm::Type* AdjTy =
getTargetHooks().adjustInlineAsmType(*this, OutputConstraint,
ResultRegTypes.back()))
Target.adjustInlineAsmType(OutputConstraint, ResultRegTypes.back(),
getLLVMContext()))
ResultRegTypes.back() = AdjTy;
} else {
ArgTypes.push_back(Dest.getAddress()->getType());
Expand Down Expand Up @@ -1208,8 +1207,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
}
}
if (const llvm::Type* AdjTy =
getTargetHooks().adjustInlineAsmType(*this, InputConstraint,
Arg->getType()))
Target.adjustInlineAsmType(InputConstraint, Arg->getType(),
getLLVMContext()))
Arg = Builder.CreateBitCast(Arg, AdjTy);

ArgTypes.push_back(Arg->getType());
Expand Down
40 changes: 12 additions & 28 deletions lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,9 @@ void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,

//

CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext)
: Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
OwnsVMContext(!_VMContext) {}

CodeGenAction::~CodeGenAction() {
TheModule.reset();
if (OwnsVMContext)
delete VMContext;
}
CodeGenAction::CodeGenAction(unsigned _Act) : Act(_Act) {}

CodeGenAction::~CodeGenAction() {}

bool CodeGenAction::hasIRSupport() const { return true; }

Expand All @@ -249,11 +243,6 @@ llvm::Module *CodeGenAction::takeModule() {
return TheModule.take();
}

llvm::LLVMContext *CodeGenAction::takeLLVMContext() {
OwnsVMContext = false;
return VMContext;
}

static raw_ostream *GetOutputStream(CompilerInstance &CI,
llvm::StringRef InFile,
BackendAction Action) {
Expand Down Expand Up @@ -286,7 +275,7 @@ ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI,
new BackendConsumer(BA, CI.getDiagnostics(),
CI.getCodeGenOpts(), CI.getTargetOpts(),
CI.getFrontendOpts().ShowTimers, InFile, OS.take(),
*VMContext);
CI.getLLVMContext());
return BEConsumer;
}

Expand All @@ -312,7 +301,7 @@ void CodeGenAction::ExecuteAction() {
getCurrentFile().c_str());

llvm::SMDiagnostic Err;
TheModule.reset(ParseIR(MainFileCopy, Err, *VMContext));
TheModule.reset(ParseIR(MainFileCopy, Err, CI.getLLVMContext()));
if (!TheModule) {
// Translate from the diagnostic info to the SourceManager location.
SourceLocation Loc = SM.getLocation(
Expand Down Expand Up @@ -343,20 +332,15 @@ void CodeGenAction::ExecuteAction() {

//

EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *_VMContext)
: CodeGenAction(Backend_EmitAssembly, _VMContext) {}
EmitAssemblyAction::EmitAssemblyAction()
: CodeGenAction(Backend_EmitAssembly) {}

EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext)
: CodeGenAction(Backend_EmitBC, _VMContext) {}
EmitBCAction::EmitBCAction() : CodeGenAction(Backend_EmitBC) {}

EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext)
: CodeGenAction(Backend_EmitLL, _VMContext) {}
EmitLLVMAction::EmitLLVMAction() : CodeGenAction(Backend_EmitLL) {}

EmitLLVMOnlyAction::EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext)
: CodeGenAction(Backend_EmitNothing, _VMContext) {}
EmitLLVMOnlyAction::EmitLLVMOnlyAction() : CodeGenAction(Backend_EmitNothing) {}

EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext)
: CodeGenAction(Backend_EmitMCNull, _VMContext) {}
EmitCodeGenOnlyAction::EmitCodeGenOnlyAction() : CodeGenAction(Backend_EmitMCNull) {}

EmitObjAction::EmitObjAction(llvm::LLVMContext *_VMContext)
: CodeGenAction(Backend_EmitObj, _VMContext) {}
EmitObjAction::EmitObjAction() : CodeGenAction(Backend_EmitObj) {}
22 changes: 0 additions & 22 deletions lib/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,6 @@ bool UseX86_MMXType(const llvm::Type *IRType) {
IRType->getScalarSizeInBits() != 64;
}

static const llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
llvm::StringRef Constraint,
const llvm::Type* Ty) {
if (Constraint=="y" && UseX86_MMXType(Ty))
return llvm::Type::getX86_MMXTy(CGF.getLLVMContext());
return Ty;
}

//===----------------------------------------------------------------------===//
// X86-32 ABI Implementation
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -423,13 +415,6 @@ class X86_32TargetCodeGenInfo : public TargetCodeGenInfo {

bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
llvm::Value *Address) const;

const llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
llvm::StringRef Constraint,
const llvm::Type* Ty) const {
return X86AdjustInlineAsmType(CGF, Constraint, Ty);
}

};

}
Expand Down Expand Up @@ -910,13 +895,6 @@ class X86_64TargetCodeGenInfo : public TargetCodeGenInfo {

return false;
}

const llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
llvm::StringRef Constraint,
const llvm::Type* Ty) const {
return X86AdjustInlineAsmType(CGF, Constraint, Ty);
}

};

class WinX86_64TargetCodeGenInfo : public TargetCodeGenInfo {
Expand Down
9 changes: 0 additions & 9 deletions lib/CodeGen/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
#ifndef CLANG_CODEGEN_TARGETINFO_H
#define CLANG_CODEGEN_TARGETINFO_H

#include "llvm/ADT/StringRef.h"

namespace llvm {
class GlobalValue;
class Type;
class Value;
}

Expand Down Expand Up @@ -105,12 +102,6 @@ namespace clang {
llvm::Value *Address) const {
return Address;
}

virtual const llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
llvm::StringRef Constraint,
const llvm::Type* Ty) const {
return Ty;
}
};
}

Expand Down
Loading

0 comments on commit 96b1d4b

Please sign in to comment.