llvm.org GIT mirror llvm / 893f22f
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221510 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Hibbits 5 years ago
7 changed file(s) with 50 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
2222 #include "llvm/IR/GlobalVariable.h"
2323 #include "llvm/IR/Metadata.h"
2424 #include "llvm/Support/CBindingWrapping.h"
25 #include "llvm/Support/CodeGen.h"
2526 #include "llvm/Support/DataTypes.h"
2627 #include
2728
633634 unsigned getDwarfVersion() const;
634635
635636 /// @}
637 /// @name Utility functions for querying and setting PIC level
638 /// @{
639
640 /// \brief Returns the PIC level (small or large model)
641 PICLevel::Level getPICLevel() const;
642
643 /// \brief Set the PIC level (small or large model)
644 void setPICLevel(PICLevel::Level PL);
645 /// @}
636646 };
637647
638648 /// An raw_ostream inserter for modules.
2727 // Code model types.
2828 namespace CodeModel {
2929 enum Model { Default, JITDefault, Small, Kernel, Medium, Large };
30 }
31
32 namespace PICLevel {
33 enum Level { Default=0, Small=1, Large=2 };
3034 }
3135
3236 // TLS models.
458458 Entry.second.Name = &Entry;
459459 return &Entry.second;
460460 }
461
462 PICLevel::Level Module::getPICLevel() const {
463 Value *Val = getModuleFlag("PIC Level");
464
465 if (Val == NULL)
466 return PICLevel::Default;
467
468 return static_cast(cast(Val)->getZExtValue());
469 }
470
471 void Module::setPICLevel(PICLevel::Level PL) {
472 addModuleFlag(ModFlagBehavior::Error, "PIC Level", PL);
473 }
0 !0 = metadata !{ i32 1, metadata !"PIC Level", i32 2 }
1
2 !llvm.module.flags = !{!0}
0 ; RUN: llvm-link %s %p/Inputs/module-flags-pic-1-b.ll -S -o - | FileCheck %s
1
2 ; test linking modules with specified and default PIC levels
3
4 !0 = metadata !{ i32 1, metadata !"PIC Level", i32 1 }
5
6 !llvm.module.flags = !{!0}
7 ; CHECK: !llvm.module.flags = !{!0}
8 ; CHECK: !0 = metadata !{i32 1, metadata !"PIC Level", i32 1}
0 ; RUN: not llvm-link %s %p/Inputs/module-flags-pic-2-b.ll -S -o - 2> %t
1 ; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s
2
3 ; test linking modules with two different PIC levels
4
5 !0 = metadata !{ i32 1, metadata !"PIC Level", i32 1 }
6
7 !llvm.module.flags = !{!0}
8
9 ; CHECK-ERRORS: ERROR: linking module flags 'PIC Level': IDs have conflicting values