Add support for naked functions
authorAnton Korobeynikov <asl@math.spbu.ru>
Fri, 17 Jul 2009 18:07:26 +0000 (18:07 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Fri, 17 Jul 2009 18:07:26 +0000 (18:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76198 91177308-0d34-0410-b5e6-96231b3b80d8

docs/LangRef.html
include/llvm-c/Core.h
include/llvm/Attributes.h
lib/AsmParser/LLLexer.cpp
lib/AsmParser/LLParser.cpp
lib/AsmParser/LLToken.h
lib/CodeGen/PrologEpilogInserter.cpp
lib/VMCore/Attributes.cpp

index 15f95e2a11c477052022048040e426d6bb0ed6f2..4885a84192a37b17eff498fa257bcaaedf532caa 100644 (file)
@@ -1109,6 +1109,9 @@ red zone, even if the target-specific ABI normally permits it.
 <dt><tt>noimplicitfloat</tt></dt>
 <dd>This attributes disables implicit floating point instructions.</dd>
 
+<dt><tt>naked</tt></dt>
+<dd>This attribute disables prologue / epilogue emission for the function</dd>
+
 </dl>
 
 </div>
index d723d11111afb87e825bf866f64ec395e896ae49..ee8058e8cc573848518cd28f1128a15546595606 100644 (file)
@@ -98,7 +98,8 @@ typedef enum {
     LLVMByValAttribute      = 1<<7,
     LLVMNestAttribute       = 1<<8,
     LLVMReadNoneAttribute   = 1<<9,
-    LLVMReadOnlyAttribute   = 1<<10
+    LLVMReadOnlyAttribute   = 1<<10,
+    LLVMNakedAttribute      = 1<<24
 } LLVMAttribute;
 
 typedef enum {
index 134e350202853ca7f607b9f040fda37aca9e7194..49f6057f31aed7ec7e31abd239cec29fdbd7d7bc 100644 (file)
@@ -57,6 +57,7 @@ const Attributes NoCapture = 1<<21; ///< Function creates no aliases of pointer
 const Attributes NoRedZone = 1<<22; /// disable redzone
 const Attributes NoImplicitFloat = 1<<23; /// disable implicit floating point
                                           /// instructions.
+const Attributes Naked     = 1<<24; ///< Naked function
 
 /// @brief Attributes that only apply to function parameters.
 const Attributes ParameterOnly = ByVal | Nest | StructRet | NoCapture;
@@ -65,7 +66,7 @@ const Attributes ParameterOnly = ByVal | Nest | StructRet | NoCapture;
 /// be used on return values or function parameters.
 const Attributes FunctionOnly = NoReturn | NoUnwind | ReadNone | ReadOnly | 
   NoInline | AlwaysInline | OptimizeForSize | StackProtect | StackProtectReq |
-  NoRedZone | NoImplicitFloat;
+  NoRedZone | NoImplicitFloat | Naked;
 
 /// @brief Parameter attributes that do not apply to vararg call arguments.
 const Attributes VarArgsIncompatible = StructRet;
index 97e8e6ad18b955f39bc72ddd0e985cb6e5d8585d..1dc463110bc6d19a391568ca8d94c1d32cc5869d 100644 (file)
@@ -541,6 +541,7 @@ lltok::Kind LLLexer::LexIdentifier() {
   KEYWORD(sspreq);
   KEYWORD(noredzone);
   KEYWORD(noimplicitfloat);
+  KEYWORD(naked);
 
   KEYWORD(type);
   KEYWORD(opaque);
index 080575df84a68fcdbc4f6d9e798deec5361db35e..6a6478f37bae6802459f2ecdb033d3e71d0f517b 100644 (file)
@@ -775,6 +775,7 @@ bool LLParser::ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind) {
     case lltok::kw_sspreq:          Attrs |= Attribute::StackProtectReq; break;
     case lltok::kw_noredzone:       Attrs |= Attribute::NoRedZone; break;
     case lltok::kw_noimplicitfloat: Attrs |= Attribute::NoImplicitFloat; break;
+    case lltok::kw_naked:           Attrs |= Attribute::Naked; break;
         
     case lltok::kw_align: {
       unsigned Alignment;
index b5194ad83f3eb2eec6ab1ca80e3f52514fdbd761..8f813f39b643cd3fdfcaafabb22e578df3968314 100644 (file)
@@ -84,6 +84,7 @@ namespace lltok {
     kw_sspreq,
     kw_noredzone,
     kw_noimplicitfloat,
+    kw_naked,
 
     kw_type,
     kw_opaque,
index 546a84ec876286750f478c18c8348bc2666a6552..5aa37c9044de477fb90f06386628b815a719861b 100644 (file)
@@ -51,6 +51,7 @@ FunctionPass *llvm::createPrologEpilogCodeInserter() { return new PEI(); }
 /// frame indexes with appropriate references.
 ///
 bool PEI::runOnMachineFunction(MachineFunction &Fn) {
+  const Function* F = Fn.getFunction();
   const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
   RS = TRI->requiresRegisterScavenging(Fn) ? new RegScavenger() : NULL;
 
@@ -80,7 +81,8 @@ bool PEI::runOnMachineFunction(MachineFunction &Fn) {
   placeCSRSpillsAndRestores(Fn);
 
   // Add the code to save and restore the callee saved registers
-  insertCSRSpillsAndRestores(Fn);
+  if (!F->hasFnAttr(Attribute::Naked))
+    insertCSRSpillsAndRestores(Fn);
 
   // Allow the target machine to make final modifications to the function
   // before the frame layout is finalized.
@@ -94,7 +96,8 @@ bool PEI::runOnMachineFunction(MachineFunction &Fn) {
   // called functions.  Because of this, calculateCalleeSavedRegisters
   // must be called before this function in order to set the HasCalls
   // and MaxCallFrameSize variables.
-  insertPrologEpilogCode(Fn);
+  if (!F->hasFnAttr(Attribute::Naked))
+    insertPrologEpilogCode(Fn);
 
   // Replace all MO_FrameIndex operands with physical register references
   // and actual offsets.
index 8dfbd1d50216d3191f25db0920280a29faa7a4ce..5d763c34fe587a9c10f4589306d4ada377fd0988 100644 (file)
@@ -40,7 +40,7 @@ std::string Attribute::getAsString(Attributes Attrs) {
   if (Attrs & Attribute::NoCapture)
     Result += "nocapture ";
   if (Attrs & Attribute::StructRet)
-    Result += "sret ";  
+    Result += "sret ";
   if (Attrs & Attribute::ByVal)
     Result += "byval ";
   if (Attrs & Attribute::Nest)
@@ -63,6 +63,8 @@ std::string Attribute::getAsString(Attributes Attrs) {
     Result += "noredzone ";
   if (Attrs & Attribute::NoImplicitFloat)
     Result += "noimplicitfloat ";
+  if (Attrs & Attribute::Naked)
+    Result += "naked ";
   if (Attrs & Attribute::Alignment) {
     Result += "align ";
     Result += utostr(Attribute::getAlignmentFromAttrs(Attrs));