Index: include/llvm/CodeGen/CommandFlags.h =================================================================== --- include/llvm/CodeGen/CommandFlags.h +++ include/llvm/CodeGen/CommandFlags.h @@ -80,6 +80,18 @@ "Large code model"), clEnumValEnd)); +cl::opt +PLLevel("pic-level", + cl::desc("Choose PIC level"), + cl::init(PICLevel::Default), + cl::values(clEnumValN(PICLevel::Default, "default", + "Target default PIC level"), + clEnumValN(PICLevel::Small, "small", + "Small PIC level (-fpic)"), + clEnumValN(PICLevel::Large, "large", + "Large PIC model (-fPIC)"), + clEnumValEnd)); + cl::opt FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile), cl::desc("Choose a file type (not all types are supported by all targets):"), Index: include/llvm/IR/Module.h =================================================================== --- include/llvm/IR/Module.h +++ include/llvm/IR/Module.h @@ -23,6 +23,7 @@ #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Metadata.h" #include "llvm/Support/CBindingWrapping.h" +#include "llvm/Support/CodeGen.h" #include "llvm/Support/DataTypes.h" #include @@ -637,6 +638,14 @@ unsigned getDwarfVersion() const; /// @} +/// @name Utility functions for querying and setting PIC level +/// @{ + + /// \brief Returns the PIC level (small or large model) + PICLevel::Level getPICLevel() const; + + /// \brief Set the PIC level (small or large model) + void setPICLevel(PICLevel::Level PL); }; /// An raw_ostream inserter for modules. Index: include/llvm/Support/CodeGen.h =================================================================== --- include/llvm/Support/CodeGen.h +++ include/llvm/Support/CodeGen.h @@ -30,6 +30,10 @@ enum Model { Default, JITDefault, Small, Kernel, Medium, Large }; } + namespace PICLevel { + enum Level { Default=0, Small=1, Large=2 }; + } + // TLS models. namespace TLSModel { enum Model { Index: lib/IR/Module.cpp =================================================================== --- lib/IR/Module.cpp +++ lib/IR/Module.cpp @@ -469,3 +469,16 @@ Entry.second.Name = &Entry; return &Entry.second; } + +PICLevel::Level Module::getPICLevel() const { + Value *Val = getModuleFlag("flag_pic"); + + if (Val == NULL) + return PICLevel::Default; + + return static_cast(cast(Val)->getZExtValue()); +} + +void Module::setPICLevel(PICLevel::Level PL) { + addModuleFlag(ModFlagBehavior::Error, "flag_pic", PL); +} Index: tools/llc/llc.cpp =================================================================== --- tools/llc/llc.cpp +++ tools/llc/llc.cpp @@ -287,6 +287,8 @@ assert(mod && "Should have exited if we didn't have a module!"); TargetMachine &Target = *target.get(); + mod->setPICLevel(PLLevel); + if (GenerateSoftFloatCalls) FloatABIForCalls = FloatABI::Soft;