[llvm] r221510 - Add Position-independent Code model Module API.
Justin Hibbits
jrh29 at alumni.cwru.edu
Thu Nov 6 20:46:10 PST 2014
Author: jhibbits
Date: Thu Nov 6 22:46:10 2014
New Revision: 221510
URL: http://llvm.org/viewvc/llvm-project?rev=221510&view=rev
Log:
Add Position-independent Code model Module API.
Summary:
This makes PIC levels a Module flag attribute, which can be queried by the
backend. The flag is named `PIC Level`, and can have a value of:
0 - Backend-default
1 - Small-model (-fpic)
2 - Large-model (-fPIC)
These match the `-pic-level' command line argument for clang, and the value of the
preprocessor macro `__PIC__'.
Test Plan:
New flags tests specific for the 'PIC Level' module flag.
Tests to be added as part of a future commit for PowerPC, which will use this new API.
Reviewers: rafael, echristo
Reviewed By: rafael, echristo
Subscribers: rafael, llvm-commits
Differential Revision: http://reviews.llvm.org/D5882
Added:
llvm/trunk/test/Linker/Inputs/module-flags-pic-1-b.ll
llvm/trunk/test/Linker/Inputs/module-flags-pic-2-b.ll
llvm/trunk/test/Linker/module-flags-pic-1-a.ll
llvm/trunk/test/Linker/module-flags-pic-2-a.ll
Modified:
llvm/trunk/include/llvm/IR/Module.h
llvm/trunk/include/llvm/Support/CodeGen.h
llvm/trunk/lib/IR/Module.cpp
Modified: llvm/trunk/include/llvm/IR/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Module.h?rev=221510&r1=221509&r2=221510&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Module.h (original)
+++ llvm/trunk/include/llvm/IR/Module.h Thu Nov 6 22:46:10 2014
@@ -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 <system_error>
@@ -634,6 +635,15 @@ public:
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.
Modified: llvm/trunk/include/llvm/Support/CodeGen.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CodeGen.h?rev=221510&r1=221509&r2=221510&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/CodeGen.h (original)
+++ llvm/trunk/include/llvm/Support/CodeGen.h Thu Nov 6 22:46:10 2014
@@ -30,6 +30,10 @@ namespace llvm {
enum Model { Default, JITDefault, Small, Kernel, Medium, Large };
}
+ namespace PICLevel {
+ enum Level { Default=0, Small=1, Large=2 };
+ }
+
// TLS models.
namespace TLSModel {
enum Model {
Modified: llvm/trunk/lib/IR/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Module.cpp?rev=221510&r1=221509&r2=221510&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Module.cpp (original)
+++ llvm/trunk/lib/IR/Module.cpp Thu Nov 6 22:46:10 2014
@@ -459,3 +459,16 @@ Comdat *Module::getOrInsertComdat(String
Entry.second.Name = &Entry;
return &Entry.second;
}
+
+PICLevel::Level Module::getPICLevel() const {
+ Value *Val = getModuleFlag("PIC Level");
+
+ if (Val == NULL)
+ return PICLevel::Default;
+
+ return static_cast<PICLevel::Level>(cast<ConstantInt>(Val)->getZExtValue());
+}
+
+void Module::setPICLevel(PICLevel::Level PL) {
+ addModuleFlag(ModFlagBehavior::Error, "PIC Level", PL);
+}
Added: llvm/trunk/test/Linker/Inputs/module-flags-pic-1-b.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/module-flags-pic-1-b.ll?rev=221510&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/module-flags-pic-1-b.ll (added)
+++ llvm/trunk/test/Linker/Inputs/module-flags-pic-1-b.ll Thu Nov 6 22:46:10 2014
@@ -0,0 +1 @@
+
Added: llvm/trunk/test/Linker/Inputs/module-flags-pic-2-b.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/module-flags-pic-2-b.ll?rev=221510&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/module-flags-pic-2-b.ll (added)
+++ llvm/trunk/test/Linker/Inputs/module-flags-pic-2-b.ll Thu Nov 6 22:46:10 2014
@@ -0,0 +1,3 @@
+!0 = metadata !{ i32 1, metadata !"PIC Level", i32 2 }
+
+!llvm.module.flags = !{!0}
Added: llvm/trunk/test/Linker/module-flags-pic-1-a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/module-flags-pic-1-a.ll?rev=221510&view=auto
==============================================================================
--- llvm/trunk/test/Linker/module-flags-pic-1-a.ll (added)
+++ llvm/trunk/test/Linker/module-flags-pic-1-a.ll Thu Nov 6 22:46:10 2014
@@ -0,0 +1,9 @@
+; RUN: llvm-link %s %p/Inputs/module-flags-pic-1-b.ll -S -o - | FileCheck %s
+
+; test linking modules with specified and default PIC levels
+
+!0 = metadata !{ i32 1, metadata !"PIC Level", i32 1 }
+
+!llvm.module.flags = !{!0}
+; CHECK: !llvm.module.flags = !{!0}
+; CHECK: !0 = metadata !{i32 1, metadata !"PIC Level", i32 1}
Added: llvm/trunk/test/Linker/module-flags-pic-2-a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/module-flags-pic-2-a.ll?rev=221510&view=auto
==============================================================================
--- llvm/trunk/test/Linker/module-flags-pic-2-a.ll (added)
+++ llvm/trunk/test/Linker/module-flags-pic-2-a.ll Thu Nov 6 22:46:10 2014
@@ -0,0 +1,10 @@
+; RUN: not llvm-link %s %p/Inputs/module-flags-pic-2-b.ll -S -o - 2> %t
+; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s
+
+; test linking modules with two different PIC levels
+
+!0 = metadata !{ i32 1, metadata !"PIC Level", i32 1 }
+
+!llvm.module.flags = !{!0}
+
+; CHECK-ERRORS: ERROR: linking module flags 'PIC Level': IDs have conflicting values
More information about the llvm-commits
mailing list